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
6 + * =====================================================================================
8 + * Filename: ImRemote.c
16 + * Author: wind (xihe), xihels@gmail.com
19 + * =====================================================================================
30 +#include <sys/socket.h>
31 +#include <sys/types.h>
32 +#include <sys/stat.h>
38 +static const char socketfile[]="/tmp/fcitx.socket";
39 +CARD16 g_last_connect_id;
41 +int create_socket(const char *name)
45 + struct sockaddr_un uds_addr;
50 + fd = socket(AF_UNIX, SOCK_STREAM, 0);
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));
67 + /* listen - allow 10 to queue */
77 +int ud_accept(int listenfd)
81 + struct sockaddr_un cliaddr;
82 + socklen_t len = sizeof(struct sockaddr_un);
84 + newsock = accept(listenfd, (struct sockaddr *)&cliaddr, &len);
86 + if (errno == EINTR) {
87 + continue; /* signal */
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 ´ò¿ªÊäÈë·¨.
108 + int client_fd = ud_accept(socket_fd);
109 + read(client_fd, &O, sizeof(int));
111 + send_ime_state(client_fd);
116 + DisplayMainWindow();
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));
132 + fcntl(socket_fd, F_SETFD, FD_CLOEXEC);
133 + chmod(socketfile, 0666);
134 + main_loop(socket_fd);
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
146 +#include <pthread.h>
149 extern Window inputWindow;
152 extern HIDE_MAINWINDOW hideMainWindow;
154 +extern void* remoteThread(void*);
156 int main (int argc, char *argv[])
160 DrawTrayWindow (INACTIVE_ICON); //ÏÔʾÍÐÅÌͼ±ê
164 + pthread_create(&pid, NULL, remoteThread, NULL);
165 //Ö÷Ñ»·£¬¼´XWindowµÄÏûϢѻ·
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
172 QuickPhrase.c QuickPhrase.h \
173 AutoEng.c AutoEng.h \
174 fcitx.h extra.c extra.h \
176 + internalVersion.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
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) \
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 \
208 + internalVersion.c \
211 fcitx_LDADD = ../lib/libXimd.a
212 -fcitx_LDFLAGS = -lXpm -lXtst
213 +fcitx_LDFLAGS = -lXpm -lXtst -lpthread
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
232 +extern CARD16 g_last_connect_id;
233 IME_STATE ConnectIDGetState (CARD16 connect_id)
235 + g_last_connect_id = connect_id;
238 temp = connectIDsHead;