updated on Wed Jan 25 08:34:36 UTC 2012
[aur-mirror.git] / fcitx4vim / ImeRemote.patch
blobd7403b71e08c5caecacf299eacc0cfc70ab52cb6
1 diff -Nur src/ImeRemote.c src.n/ImeRemote.c
2 --- src/ImeRemote.c 1970-01-01 08:00:00.000000000 +0800
3 +++ src.n/ImeRemote.c 2009-10-15 10:33:10.920103339 +0800
4 @@ -0,0 +1,134 @@
5 +/*
6 + * =====================================================================================
7 + *
8 + * Filename: ImRemote.c
9 + *
10 + * Description:
11 + *
12 + * Version: 1.0
13 + * Revision: none
14 + * Compiler: gcc
15 + *
16 + * Author: wind (xihe), xihels@gmail.com
17 + * Company: cyclone
18 + *
19 + * =====================================================================================
20 + */
22 +#ifdef HAVE_CONFIG_H
23 +# include <config.h>
24 +#endif
26 +#include <errno.h>
27 +#include <stdio.h>
28 +#include <stdlib.h>
29 +#include <string.h>
30 +#include <sys/socket.h>
31 +#include <sys/types.h>
32 +#include <sys/stat.h>
33 +#include <sys/un.h>
34 +#include <unistd.h>
35 +#include <fcntl.h>
36 +#include "xim.h"
38 +static const char socketfile[]="/tmp/fcitx.socket";
39 +CARD16 g_last_connect_id;
41 +int create_socket(const char *name)
43 + int fd;
44 + int r;
45 + struct sockaddr_un uds_addr;
47 + /* JIC */
48 + unlink(name);
50 + fd = socket(AF_UNIX, SOCK_STREAM, 0);
51 + if (fd < 0) {
52 + return fd;
53 + }
55 + /* setup address struct */
56 + memset(&uds_addr, 0, sizeof(uds_addr));
57 + uds_addr.sun_family = AF_UNIX;
58 + strcpy(uds_addr.sun_path, name);
60 + /* bind it to the socket */
61 + r = bind(fd, (struct sockaddr *)&uds_addr, sizeof(uds_addr));
62 + if (r < 0) {
63 + return r;
64 + }
67 + /* listen - allow 10 to queue */
68 + r = listen(fd, 10);
69 + if (r < 0) {
70 + return r;
71 + }
73 + return fd;
77 +int ud_accept(int listenfd)
79 + for (;;) {
80 + int newsock = 0;
81 + struct sockaddr_un cliaddr;
82 + socklen_t len = sizeof(struct sockaddr_un);
84 + newsock = accept(listenfd, (struct sockaddr *)&cliaddr, &len);
85 + if (newsock < 0) {
86 + if (errno == EINTR) {
87 + continue; /* signal */
88 + }
89 + }
91 + return newsock;
92 + }
95 +static void send_ime_state(int fd)
97 + IME_STATE r = ConnectIDGetState(g_last_connect_id);
98 + write(fd, &r, sizeof(r));
102 +extern void DisplayMainWindow (void);
103 +static void main_loop (int socket_fd)
105 + int O; // µÍ16λ, 0 = get, 1 = set;
106 + // ¸ß16λ, Ö»ÓÃÓÚ set, 0 ¹Ø±ÕÊäÈë·¨, 1 ´ò¿ªÊäÈë·¨.
107 + for (;;) {
108 + int client_fd = ud_accept(socket_fd);
109 + read(client_fd, &O, sizeof(int));
110 + if (!O) {
111 + send_ime_state(client_fd);
112 + } else {
113 + O >>= 16;
114 + SetIMState(O);
115 + if (O) {
116 + DisplayMainWindow();
117 + DrawMainWindow();
120 + close(client_fd);
124 +void* remoteThread (void* val)
126 + int socket_fd = create_socket(socketfile);
127 + if (socket_fd < 0) {
128 + fprintf(stderr, "Can't open socket %s: %s\n", socketfile, strerror(errno));
129 + return 0;
132 + fcntl(socket_fd, F_SETFD, FD_CLOEXEC);
133 + chmod(socketfile, 0666);
134 + main_loop(socket_fd);
135 + close(socket_fd);
136 + return 0;
137 +} /* ---------- end of function main ---------- */
139 diff -Nur src/main.c src.n/main.c
140 --- src/main.c 2009-05-26 23:54:49.000000000 +0800
141 +++ src.n/main.c 2009-10-15 10:03:02.179584034 +0800
142 @@ -64,6 +64,7 @@
143 #ifndef CODESET
144 #define CODESET 14
145 #endif
146 +#include <pthread.h>
148 extern Display *dpy;
149 extern Window inputWindow;
150 @@ -72,6 +73,8 @@
152 extern HIDE_MAINWINDOW hideMainWindow;
154 +extern void* remoteThread(void*);
156 int main (int argc, char *argv[])
158 XEvent event;
159 @@ -182,6 +185,8 @@
160 DrawTrayWindow (INACTIVE_ICON); //ÏÔʾÍÐÅÌͼ±ê
161 #endif
163 + pthread_t pid;
164 + pthread_create(&pid, NULL, remoteThread, NULL);
165 //Ö÷Ñ­»·£¬¼´XWindowµÄÏûϢѭ»·
166 for (;;) {
167 XNextEvent (dpy, &event); //µÈ´ýÒ»¸öʼþ·¢Éú
168 diff -Nur src/Makefile.am src.n/Makefile.am
169 --- src/Makefile.am 2009-05-02 23:24:59.000000000 +0800
170 +++ src.n/Makefile.am 2009-10-14 18:39:07.572008952 +0800
171 @@ -32,7 +32,8 @@
172 QuickPhrase.c QuickPhrase.h \
173 AutoEng.c AutoEng.h \
174 fcitx.h extra.c extra.h \
175 - internalVersion.c
176 + internalVersion.c \
177 + ImeRemote.c
179 fcitx_LDADD = ../lib/libXimd.a
180 -fcitx_LDFLAGS = -lXpm -lXtst
181 +fcitx_LDFLAGS = -lXpm -lXtst -lpthread
182 diff -Nur src/Makefile.in src.n/Makefile.in
183 --- src/Makefile.in 2009-10-08 22:08:05.000000000 +0800
184 +++ src.n/Makefile.in 2009-10-14 18:39:11.053537314 +0800
185 @@ -55,7 +55,8 @@
186 sp.$(OBJEXT) tools.$(OBJEXT) ui.$(OBJEXT) table.$(OBJEXT) \
187 xim.$(OBJEXT) qw.$(OBJEXT) tray.$(OBJEXT) TrayWindow.$(OBJEXT) \
188 vk.$(OBJEXT) about.$(OBJEXT) QuickPhrase.$(OBJEXT) \
189 - AutoEng.$(OBJEXT) extra.$(OBJEXT) internalVersion.$(OBJEXT)
190 + AutoEng.$(OBJEXT) extra.$(OBJEXT) internalVersion.$(OBJEXT) \
191 + ImeRemote.$(OBJEXT)
192 fcitx_OBJECTS = $(am_fcitx_OBJECTS)
193 fcitx_DEPENDENCIES = ../lib/libXimd.a
194 fcitx_LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(fcitx_LDFLAGS) \
195 @@ -112,6 +113,7 @@
196 PACKAGE_NAME = @PACKAGE_NAME@
197 PACKAGE_STRING = @PACKAGE_STRING@
198 PACKAGE_TARNAME = @PACKAGE_TARNAME@
199 +PACKAGE_URL = @PACKAGE_URL@
200 PACKAGE_VERSION = @PACKAGE_VERSION@
201 PATH_SEPARATOR = @PATH_SEPARATOR@
202 PKG_CONFIG = @PKG_CONFIG@
203 @@ -203,10 +205,11 @@
204 QuickPhrase.c QuickPhrase.h \
205 AutoEng.c AutoEng.h \
206 fcitx.h extra.c extra.h \
207 - internalVersion.c
208 + internalVersion.c \
209 + ImeRemote.c
211 fcitx_LDADD = ../lib/libXimd.a
212 -fcitx_LDFLAGS = -lXpm -lXtst
213 +fcitx_LDFLAGS = -lXpm -lXtst -lpthread
214 all: all-am
216 .SUFFIXES:
217 @@ -292,6 +295,7 @@
219 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AutoEng.Po@am__quote@
220 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/IC.Po@am__quote@
221 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ImeRemote.Po@am__quote@
222 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/InputWindow.Po@am__quote@
223 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/KeyList.Po@am__quote@
224 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MainWindow.Po@am__quote@
225 diff -Nur src/xim.c src.n/xim.c
226 --- src/xim.c 2009-09-15 08:21:15.000000000 +0800
227 +++ src.n/xim.c 2009-10-15 09:47:12.179555894 +0800
228 @@ -611,8 +611,10 @@
232 +extern CARD16 g_last_connect_id;
233 IME_STATE ConnectIDGetState (CARD16 connect_id)
235 + g_last_connect_id = connect_id;
236 CONNECT_ID *temp;
238 temp = connectIDsHead;