TmpPhoto: gcin_xim-on-gtkim.diff
| File gcin_xim-on-gtkim.diff, 41.6 kB (added by anonymous, 1 year ago) |
|---|
-
gcin-1.3.5~pre5/Makefile
old new 178 178 $(im-srv): 179 179 $(MAKE) -C im-srv 180 180 181 $(xim-on-gtkim): 182 $(MAKE) -C xim-on-gtkim 181 183 182 184 ibin: 183 185 install $(PROGS) $(bindir); \ … … 194 200 $(MAKE) -C data install 195 201 $(MAKE) -C im-client install 196 202 $(MAKE) -C gtk-im install 203 ifeq ($(USE_XIM),N) 204 $(MAKE) -C xim-on-gtkim install 205 endif 197 206 if [ $(QT_IM) = 'Y' ]; then $(MAKE) -C qt-im install; fi 198 207 if [ $(prefix) = /usr/local ]; then \ 199 208 install -m 644 gcin.png /usr/share/icons; \ … … 224 229 $(MAKE) -C man clean 225 230 $(MAKE) -C menu clean 226 231 $(MAKE) -C po clean 232 $(MAKE) -C xim-on-gtkim clean 227 233 rm -f *.o *.E *.db *.pico *.so config.mak tags $(PROGS) $(PROGS_CV) \ 228 234 $(DATA) .depend gcin.spec trad2sim gcin.spec.tmp gcin.log 229 235 find . '(' -name '.ted*' -o -name '*~' -o -name 'core.*' -o -name 'vgcore.*' ')' -exec rm {} \; -
gcin-1.3.5~pre5/xim-on-gtkim/COPYING
old new 1 GNU GENERAL PUBLIC LICENSE 2 Version 2, June 1991 3 4 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 Everyone is permitted to copy and distribute verbatim copies 7 of this license document, but changing it is not allowed. 8 9 Preamble 10 11 The licenses for most software are designed to take away your 12 freedom to share and change it. By contrast, the GNU General Public 13 License is intended to guarantee your freedom to share and change free 14 software--to make sure the software is free for all its users. This 15 General Public License applies to most of the Free Software 16 Foundation's software and to any other program whose authors commit to 17 using it. (Some other Free Software Foundation software is covered by 18 the GNU Library General Public License instead.) You can apply it to 19 your programs, too. 20 21 When we speak of free software, we are referring to freedom, not 22 price. Our General Public Licenses are designed to make sure that you 23 have the freedom to distribute copies of free software (and charge for 24 this service if you wish), that you receive source code or can get it 25 if you want it, that you can change the software or use pieces of it 26 in new free programs; and that you know you can do these things. 27 28 To protect your rights, we need to make restrictions that forbid 29 anyone to deny you these rights or to ask you to surrender the rights. 30 These restrictions translate to certain responsibilities for you if you 31 distribute copies of the software, or if you modify it. 32 33 For example, if you distribute copies of such a program, whether 34 gratis or for a fee, you must give the recipients all the rights that 35 you have. You must make sure that they, too, receive or can get the 36 source code. And you must show them these terms so they know their 37 rights. 38 39 We protect your rights with two steps: (1) copyright the software, and 40 (2) offer you this license which gives you legal permission to copy, 41 distribute and/or modify the software. 42 43 Also, for each author's protection and ours, we want to make certain 44 that everyone understands that there is no warranty for this free 45 software. If the software is modified by someone else and passed on, we 46 want its recipients to know that what they have is not the original, so 47 that any problems introduced by others will not reflect on the original 48 authors' reputations. 49 50 Finally, any free program is threatened constantly by software 51 patents. We wish to avoid the danger that redistributors of a free 52 program will individually obtain patent licenses, in effect making the 53 program proprietary. To prevent this, we have made it clear that any 54 patent must be licensed for everyone's free use or not licensed at all. 55 56 The precise terms and conditions for copying, distribution and 57 modification follow. 58 59 GNU GENERAL PUBLIC LICENSE 60 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 62 0. This License applies to any program or other work which contains 63 a notice placed by the copyright holder saying it may be distributed 64 under the terms of this General Public License. The "Program", below, 65 refers to any such program or work, and a "work based on the Program" 66 means either the Program or any derivative work under copyright law: 67 that is to say, a work containing the Program or a portion of it, 68 either verbatim or with modifications and/or translated into another 69 language. (Hereinafter, translation is included without limitation in 70 the term "modification".) Each licensee is addressed as "you". 71 72 Activities other than copying, distribution and modification are not 73 covered by this License; they are outside its scope. The act of 74 running the Program is not restricted, and the output from the Program 75 is covered only if its contents constitute a work based on the 76 Program (independent of having been made by running the Program). 77 Whether that is true depends on what the Program does. 78 79 1. You may copy and distribute verbatim copies of the Program's 80 source code as you receive it, in any medium, provided that you 81 conspicuously and appropriately publish on each copy an appropriate 82 copyright notice and disclaimer of warranty; keep intact all the 83 notices that refer to this License and to the absence of any warranty; 84 and give any other recipients of the Program a copy of this License 85 along with the Program. 86 87 You may charge a fee for the physical act of transferring a copy, and 88 you may at your option offer warranty protection in exchange for a fee. 89 90 2. You may modify your copy or copies of the Program or any portion 91 of it, thus forming a work based on the Program, and copy and 92 distribute such modifications or work under the terms of Section 1 93 above, provided that you also meet all of these conditions: 94 95 a) You must cause the modified files to carry prominent notices 96 stating that you changed the files and the date of any change. 97 98 b) You must cause any work that you distribute or publish, that in 99 whole or in part contains or is derived from the Program or any 100 part thereof, to be licensed as a whole at no charge to all third 101 parties under the terms of this License. 102 103 c) If the modified program normally reads commands interactively 104 when run, you must cause it, when started running for such 105 interactive use in the most ordinary way, to print or display an 106 announcement including an appropriate copyright notice and a 107 notice that there is no warranty (or else, saying that you provide 108 a warranty) and that users may redistribute the program under 109 these conditions, and telling the user how to view a copy of this 110 License. (Exception: if the Program itself is interactive but 111 does not normally print such an announcement, your work based on 112 the Program is not required to print an announcement.) 113 114 These requirements apply to the modified work as a whole. If 115 identifiable sections of that work are not derived from the Program, 116 and can be reasonably considered independent and separate works in 117 themselves, then this License, and its terms, do not apply to those 118 sections when you distribute them as separate works. But when you 119 distribute the same sections as part of a whole which is a work based 120 on the Program, the distribution of the whole must be on the terms of 121 this License, whose permissions for other licensees extend to the 122 entire whole, and thus to each and every part regardless of who wrote it. 123 124 Thus, it is not the intent of this section to claim rights or contest 125 your rights to work written entirely by you; rather, the intent is to 126 exercise the right to control the distribution of derivative or 127 collective works based on the Program. 128 129 In addition, mere aggregation of another work not based on the Program 130 with the Program (or with a work based on the Program) on a volume of 131 a storage or distribution medium does not bring the other work under 132 the scope of this License. 133 134 3. You may copy and distribute the Program (or a work based on it, 135 under Section 2) in object code or executable form under the terms of 136 Sections 1 and 2 above provided that you also do one of the following: 137 138 a) Accompany it with the complete corresponding machine-readable 139 source code, which must be distributed under the terms of Sections 140 1 and 2 above on a medium customarily used for software interchange; or, 141 142 b) Accompany it with a written offer, valid for at least three 143 years, to give any third party, for a charge no more than your 144 cost of physically performing source distribution, a complete 145 machine-readable copy of the corresponding source code, to be 146 distributed under the terms of Sections 1 and 2 above on a medium 147 customarily used for software interchange; or, 148 149 c) Accompany it with the information you received as to the offer 150 to distribute corresponding source code. (This alternative is 151 allowed only for noncommercial distribution and only if you 152 received the program in object code or executable form with such 153 an offer, in accord with Subsection b above.) 154 155 The source code for a work means the preferred form of the work for 156 making modifications to it. For an executable work, complete source 157 code means all the source code for all modules it contains, plus any 158 associated interface definition files, plus the scripts used to 159 control compilation and installation of the executable. However, as a 160 special exception, the source code distributed need not include 161 anything that is normally distributed (in either source or binary 162 form) with the major components (compiler, kernel, and so on) of the 163 operating system on which the executable runs, unless that component 164 itself accompanies the executable. 165 166 If distribution of executable or object code is made by offering 167 access to copy from a designated place, then offering equivalent 168 access to copy the source code from the same place counts as 169 distribution of the source code, even though third parties are not 170 compelled to copy the source along with the object code. 171 172 4. You may not copy, modify, sublicense, or distribute the Program 173 except as expressly provided under this License. Any attempt 174 otherwise to copy, modify, sublicense or distribute the Program is 175 void, and will automatically terminate your rights under this License. 176 However, parties who have received copies, or rights, from you under 177 this License will not have their licenses terminated so long as such 178 parties remain in full compliance. 179 180 5. You are not required to accept this License, since you have not 181 signed it. However, nothing else grants you permission to modify or 182 distribute the Program or its derivative works. These actions are 183 prohibited by law if you do not accept this License. Therefore, by 184 modifying or distributing the Program (or any work based on the 185 Program), you indicate your acceptance of this License to do so, and 186 all its terms and conditions for copying, distributing or modifying 187 the Program or works based on it. 188 189 6. Each time you redistribute the Program (or any work based on the 190 Program), the recipient automatically receives a license from the 191 original licensor to copy, distribute or modify the Program subject to 192 these terms and conditions. You may not impose any further 193 restrictions on the recipients' exercise of the rights granted herein. 194 You are not responsible for enforcing compliance by third parties to 195 this License. 196 197 7. If, as a consequence of a court judgment or allegation of patent 198 infringement or for any other reason (not limited to patent issues), 199 conditions are imposed on you (whether by court order, agreement or 200 otherwise) that contradict the conditions of this License, they do not 201 excuse you from the conditions of this License. If you cannot 202 distribute so as to satisfy simultaneously your obligations under this 203 License and any other pertinent obligations, then as a consequence you 204 may not distribute the Program at all. For example, if a patent 205 license would not permit royalty-free redistribution of the Program by 206 all those who receive copies directly or indirectly through you, then 207 the only way you could satisfy both it and this License would be to 208 refrain entirely from distribution of the Program. 209 210 If any portion of this section is held invalid or unenforceable under 211 any particular circumstance, the balance of the section is intended to 212 apply and the section as a whole is intended to apply in other 213 circumstances. 214 215 It is not the purpose of this section to induce you to infringe any 216 patents or other property right claims or to contest validity of any 217 such claims; this section has the sole purpose of protecting the 218 integrity of the free software distribution system, which is 219 implemented by public license practices. Many people have made 220 generous contributions to the wide range of software distributed 221 through that system in reliance on consistent application of that 222 system; it is up to the author/donor to decide if he or she is willing 223 to distribute software through any other system and a licensee cannot 224 impose that choice. 225 226 This section is intended to make thoroughly clear what is believed to 227 be a consequence of the rest of this License. 228 229 8. If the distribution and/or use of the Program is restricted in 230 certain countries either by patents or by copyrighted interfaces, the 231 original copyright holder who places the Program under this License 232 may add an explicit geographical distribution limitation excluding 233 those countries, so that distribution is permitted only in or among 234 countries not thus excluded. In such case, this License incorporates 235 the limitation as if written in the body of this License. 236 237 9. The Free Software Foundation may publish revised and/or new versions 238 of the General Public License from time to time. Such new versions will 239 be similar in spirit to the present version, but may differ in detail to 240 address new problems or concerns. 241 242 Each version is given a distinguishing version number. If the Program 243 specifies a version number of this License which applies to it and "any 244 later version", you have the option of following the terms and conditions 245 either of that version or of any later version published by the Free 246 Software Foundation. If the Program does not specify a version number of 247 this License, you may choose any version ever published by the Free Software 248 Foundation. 249 250 10. If you wish to incorporate parts of the Program into other free 251 programs whose distribution conditions are different, write to the author 252 to ask for permission. For software which is copyrighted by the Free 253 Software Foundation, write to the Free Software Foundation; we sometimes 254 make exceptions for this. Our decision will be guided by the two goals 255 of preserving the free status of all derivatives of our free software and 256 of promoting the sharing and reuse of software generally. 257 258 NO WARRANTY 259 260 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 REPAIR OR CORRECTION. 269 270 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 POSSIBILITY OF SUCH DAMAGES. 279 280 END OF TERMS AND CONDITIONS 281 282 How to Apply These Terms to Your New Programs 283 284 If you develop a new program, and you want it to be of the greatest 285 possible use to the public, the best way to achieve this is to make it 286 free software which everyone can redistribute and change under these terms. 287 288 To do so, attach the following notices to the program. It is safest 289 to attach them to the start of each source file to most effectively 290 convey the exclusion of warranty; and each file should have at least 291 the "copyright" line and a pointer to where the full notice is found. 292 293 <one line to give the program's name and a brief idea of what it does.> 294 Copyright (C) <year> <name of author> 295 296 This program is free software; you can redistribute it and/or modify 297 it under the terms of the GNU General Public License as published by 298 the Free Software Foundation; either version 2 of the License, or 299 (at your option) any later version. 300 301 This program is distributed in the hope that it will be useful, 302 but WITHOUT ANY WARRANTY; without even the implied warranty of 303 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 GNU General Public License for more details. 305 306 You should have received a copy of the GNU General Public License 307 along with this program; if not, write to the Free Software 308 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 309 310 311 Also add information on how to contact you by electronic and paper mail. 312 313 If the program is interactive, make it output a short notice like this 314 when it starts in an interactive mode: 315 316 Gnomovision version 69, Copyright (C) year name of author 317 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 This is free software, and you are welcome to redistribute it 319 under certain conditions; type `show c' for details. 320 321 The hypothetical commands `show w' and `show c' should show the appropriate 322 parts of the General Public License. Of course, the commands you use may 323 be called something other than `show w' and `show c'; they could even be 324 mouse-clicks or menu items--whatever suits your program. 325 326 You should also get your employer (if you work as a programmer) or your 327 school, if any, to sign a "copyright disclaimer" for the program, if 328 necessary. Here is a sample; alter the names: 329 330 Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 333 <signature of Ty Coon>, 1 April 1989 334 Ty Coon, President of Vice 335 336 This General Public License does not permit incorporating your program into 337 proprietary programs. If your program is a subroutine library, you may 338 consider it more useful to permit linking proprietary applications with the 339 library. If this is what you want to do, use the GNU Library General 340 Public License instead of this License. -
gcin-1.3.5~pre5/xim-on-gtkim/Makefile
old new 1 include ../config.mak 2 3 .SUFFIXES: .c .o .E 4 WALL=-Wall 5 CFLAGS= $(WALL) $(OPTFLAGS) -I.. -I../IMdkit/include $(GTKINC) -DDEBUG="0$(GCIN_DEBUG)" 6 IMdkitLIB = ../IMdkit/lib/libXimd.a 7 OBJS = gdk-private.o main.o 8 9 xim-on-gtkim: $(OBJS) $(IMdkitLIB) 10 rm -f core.* 11 $(CC) -o $@ $(OBJS) $(IMdkitLIB) $(LDFLAGS) 12 13 install: xim-on-gtkim 14 if [ $(prefix) = /usr/local ]; then \ 15 install -d $(bindir); \ 16 install -m 755 xim-on-gtkim $(bindir); \ 17 else \ 18 install -d $(bindir); \ 19 install -m 755 xim-on-gtkim $(bindir); \ 20 fi 21 $(IMdkitLIB): 22 $(MAKE) -C ../IMdkit/lib 23 24 25 clean: 26 rm -f *.a *.o *~ *.E *.db config.mak tags core.* .depend xim-on-gtkim 27 28 .depend: 29 $(CC) $(CFLAGS) -MM *.c > $@ 30 31 include .depend -
gcin-1.3.5~pre5/xim-on-gtkim/gdk-private.c
old new 1 /* xim-on-gtkim 2 * Copyright (C) 2007 Huang Peng <phuang@redhat.com> 3 * 4 * gdk-private.c: Copied some code from gtk2 5 * 6 * This tool is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public 17 * License along with this library; if not, write to the 18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 * Boston, MA 02111-1307, USA. 20 */ 21 #include <gtk/gtk.h> 22 #include <gdk/gdkx.h> 23 #include <gdk/gdkkeysyms.h> 24 25 void 26 translate_key_event (GdkDisplay *display, 27 GdkEvent *event, 28 XEvent *xevent) 29 { 30 GdkKeymap *keymap = gdk_keymap_get_for_display (display); 31 gunichar c = 0; 32 gchar buf[7]; 33 34 event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE; 35 event->key.time = xevent->xkey.time; 36 37 event->key.state = (GdkModifierType) xevent->xkey.state; 38 //event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state); 39 event->key.group = 0; 40 event->key.hardware_keycode = xevent->xkey.keycode; 41 42 event->key.keyval = GDK_VoidSymbol; 43 44 gdk_keymap_translate_keyboard_state (keymap, 45 event->key.hardware_keycode, 46 event->key.state, 47 event->key.group, 48 &event->key.keyval, 49 NULL, NULL, NULL); 50 51 //_gdk_keymap_add_virtual_modifiers (keymap, &event->key.state); 52 event->key.is_modifier = 53 (event->key.state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0; 54 // event->key.is_modifier = _gdk_keymap_key_is_modifier (keymap, event->key.hardware_keycode); 55 56 /* Fill in event->string crudely, since various programs 57 * depend on it. 58 */ 59 event->key.string = NULL; 60 61 if (event->key.keyval != GDK_VoidSymbol) 62 c = gdk_keyval_to_unicode (event->key.keyval); 63 64 if (c) 65 { 66 gsize bytes_written; 67 gint len; 68 69 /* Apply the control key - Taken from Xlib 70 */ 71 if (event->key.state & GDK_CONTROL_MASK) 72 { 73 if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F; 74 else if (c == '2') 75 { 76 event->key.string = g_memdup ("\0\0", 2); 77 event->key.length = 1; 78 buf[0] = '\0'; 79 goto out; 80 } 81 else if (c >= '3' && c <= '7') c -= ('3' - '\033'); 82 else if (c == '8') c = '\177'; 83 else if (c == '/') c = '_' & 0x1F; 84 } 85 86 len = g_unichar_to_utf8 (c, buf); 87 buf[len] = '\0'; 88 89 event->key.string = g_locale_from_utf8 (buf, len, 90 NULL, &bytes_written, 91 NULL); 92 if (event->key.string) 93 event->key.length = bytes_written; 94 } 95 else if (event->key.keyval == GDK_Escape) 96 { 97 event->key.length = 1; 98 event->key.string = g_strdup ("\033"); 99 } 100 else if (event->key.keyval == GDK_Return || 101 event->key.keyval == GDK_KP_Enter) 102 { 103 event->key.length = 1; 104 event->key.string = g_strdup ("\r"); 105 } 106 107 if (!event->key.string) 108 { 109 event->key.length = 0; 110 event->key.string = g_strdup (""); 111 } 112 113 out: 114 return; 115 } 116 -
gcin-1.3.5~pre5/xim-on-gtkim/main.c
old new 1 /* xim-on-gtkim 2 * Copyright (C) 2007 Huang Peng <phuang@redhat.com> 3 * 4 * main.c: 5 * 6 * This tool is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public 17 * License along with this library; if not, write to the 18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 * Boston, MA 02111-1307, USA. 20 */ 21 #include <X11/Xproto.h> 22 #include <X11/Xlib.h> 23 #include <X11/keysym.h> 24 #include <X11/Xutil.h> 25 #include <XimProto.h> 26 #include <IMdkit.h> 27 #include <Xi18n.h> 28 #include <stdio.h> 29 #include <gtk/gtk.h> 30 #include <gdk/gdkx.h> 31 #include <gdk/gdkkeysyms.h> 32 #include <langinfo.h> 33 #include <locale.h> 34 #include <iconv.h> 35 36 #define _GNU_SOURCES 37 #include <getopt.h> 38 39 #define LOG(level, fmt, args...) \ 40 if (g_debug_level >= (level)) { \ 41 fprintf (stderr, fmt, args); \ 42 } 43 44 45 #include "gdk-private.h" 46 47 struct _X11ICONN { 48 GtkIMContext *context; 49 GList *clients; 50 }; 51 typedef struct _X11ICONN X11ICONN; 52 53 struct _X11IC { 54 GdkWindow *client_window; 55 GdkWindow *focus_window; 56 gint32 input_style; 57 X11ICONN *conn; 58 gint icid; 59 gint connect_id; 60 gchar *lang; 61 GdkRectangle preedit_area; 62 }; 63 typedef struct _X11IC X11IC; 64 65 66 67 static void _xim_commit_cb (GtkIMContext *context, gchar *arg, gpointer data); 68 69 static GHashTable *g_clients = NULL; 70 static GHashTable *g_connections = NULL; 71 static X11IC *g_focus_ic = NULL; 72 static XIMS g_xims = NULL; 73 static gchar g_server_name[128] = "gik"; 74 static gchar g_locale[1024] = 75 "aa,af,am,an,ar,as,az,be,bg,bn,br,bs," 76 "ca,cs,cy,da,de,dz,el,en,es,et,eu," 77 "fa,fi,fo,fr,fy,ga,gd,gl,gu,gv," 78 "he,hi,hr,hu,hy,id,is,it,iw,ja," 79 "ka,kk,kl,km,kn,ko,ku,kw,ky,lg,lo,lt,lv," 80 "mg,mi,mk,ml,mn,mr,ms,mt,nb,ne,nl,nn,no,nr," 81 "oc,om,or,pa,pl,pt,ro,ru,rw," 82 "se,si,sk,sl,so,sq,sr,ss,st,sv," 83 "ta,te,tg,th,ti,tl,tn,tr,ts,tt," 84 "uk,ur,uz,ve,vi,wa,xh,yi,zh,zu"; 85 86 static gint g_debug_level = 0; 87 88 89 static void 90 _xim_preedit_start (XIMS xims, int icid, int connect_id) 91 { 92 IMPreeditStateStruct ips; 93 ips.major_code = 0; 94 ips.minor_code = 0; 95 ips.icid = icid; 96 ips.connect_id = connect_id; 97 IMPreeditStart (xims, (XPointer)&ips); 98 } 99 100 static void 101 _xim_preedit_end (XIMS xims, int icid, int connect_id) 102 { 103 IMPreeditStateStruct ips; 104 ips.major_code = 0; 105 ips.minor_code = 0; 106 ips.icid = icid; 107 ips.connect_id = connect_id; 108 IMPreeditEnd (xims, (XPointer)&ips); 109 } 110 111 int 112 _xim_store_ic_values (X11IC *ic, IMChangeICStruct *call_data) 113 { 114 XICAttribute *ic_attr = call_data->ic_attr; 115 XICAttribute *pre_attr = call_data->preedit_attr; 116 XICAttribute *sts_attr = call_data->status_attr; 117 118 gint i; 119 guint32 attrs = 1; 120 121 if (ic == NULL) { 122 return 0; 123 } 124 #define _is_attr(a, b) (strcmp(a, b->name) == 0) 125 for (i=0; i< (int) call_data->ic_attr_num; ++i, ++ic_attr) { 126 if (_is_attr (XNInputStyle, ic_attr)) { 127 ic->input_style = *(gint32 *) ic_attr->value; 128 } 129 else if (_is_attr (XNClientWindow, ic_attr)) { 130 Window w; 131 132 if (ic->client_window != NULL) { 133 g_object_unref (ic->client_window); 134 } 135 136 w = *(Window *) call_data->ic_attr[i].value; 137 ic->client_window = gdk_window_foreign_new (w); 138 } 139 else if (_is_attr (XNFocusWindow, ic_attr)) { 140 Window w; 141 142 if (ic->focus_window != NULL) { 143 g_object_unref (ic->focus_window); 144 } 145 146 w = *(Window *) call_data->ic_attr[i].value; 147 ic->focus_window = gdk_window_foreign_new (w); 148 } 149 else { 150 // fprintf (stderr, "Unknown attr: %s\n", ic_attr->name); 151 } 152 } 153 154 for (i=0; i< (int) call_data->preedit_attr_num; ++i, ++pre_attr) { 155 if (_is_attr (XNSpotLocation, pre_attr)) { 156 ic->preedit_area.x = ((XPoint *)pre_attr->value)->x; 157 ic->preedit_area.y = ((XPoint *)pre_attr->value)->y; 158 } 159 else { 160 // fprintf (stderr, "Unknown attr: %s\n", pre_attr->name); 161 } 162 } 163 164 for (i=0; i< (int) call_data->status_attr_num; ++i, ++sts_attr) { 165 // printf ("set status: %s\n", sts_attr->name); 166 } 167 168 #undef _is_attr 169 170 return attrs; 171 172 } 173 174 175 static void 176 _xim_commit_cb (GtkIMContext *context, gchar *arg, gpointer data) 177 { 178 char *clist[1]; 179 XTextProperty tp; 180 IMCommitStruct cms; 181 182 gint connect_id = (gint)data; 183 184 g_return_if_fail (connect_id == g_focus_ic->connect_id); 185 186 clist[0] = arg; 187 Xutf8TextListToTextProperty (GDK_DISPLAY (), clist, 1, XCompoundTextStyle, &tp); 188 189 memset (&cms, 0, sizeof (cms)); 190 cms.major_code = XIM_COMMIT; 191 cms.icid = g_focus_ic->icid; 192 cms.connect_id = g_focus_ic->connect_id; 193 cms.flag = XimLookupChars; 194 cms.commit_string = (char *)tp.value; 195 IMCommitString (g_xims, (XPointer) & cms); 196 197 XFree (tp.value); 198 199 } 200 201 202 int 203 xim_create_ic (XIMS xims, IMChangeICStruct *call_data) 204 { 205 static int base_icid = 1; 206 X11IC *ic; 207 int i; 208 209 LOG (1, "XIM_CREATE_IC ic=%d, connect_id=%d\n", call_data->icid, call_data->connect_id); 210 211 call_data->icid = base_icid ++; 212 213 ic = g_malloc0 (sizeof (X11IC)); 214 ic->icid = call_data->icid; 215 ic->connect_id = call_data->connect_id; 216 ic->conn = (X11ICONN *)g_hash_table_lookup (g_connections, 217 (gconstpointer)(unsigned long)call_data->connect_id); 218 219 i = _xim_store_ic_values (ic, call_data); 220 221 222 g_hash_table_insert (g_clients, (gpointer)ic->icid, (gpointer) ic); 223 ic->conn->clients = g_list_append (ic->conn->clients, (gpointer) ic); 224 225 return 1; 226 } 227 228 229 int 230 xim_destroy_ic (XIMS xims, IMChangeICStruct *call_data) 231 { 232 X11IC *ic; 233 234 LOG (1, "XIM_DESTROY_IC ic=%d, connect_id=%d\n", call_data->icid, call_data->connect_id); 235 236 ic = (X11IC *)g_hash_table_lookup (g_clients, 237 (gconstpointer)(unsigned long)call_data->icid); 238 239 ic->conn->clients = g_list_remove (ic->conn->clients, (gconstpointer)ic); 240 g_hash_table_remove (g_clients, 241 (gconstpointer)(unsigned long)call_data->icid); 242 243 g_free (ic); 244 245 return 1; 246 } 247 248 int 249 xim_set_ic_focus (XIMS xims, IMChangeFocusStruct *call_data) 250 { 251 X11IC *ic; 252 253 LOG (1, "XIM_SET_IC_FOCUS ic=%d, connect_id=%d\n", call_data->icid, call_data->connect_id); 254 255 ic = (X11IC *)g_hash_table_lookup (g_clients, 256 (gconstpointer)(unsigned long)call_data->icid); 257 258 if (ic == g_focus_ic) { 259 return 1; 260 } 261 262 if (g_focus_ic != NULL) { 263 gtk_im_context_focus_out (g_focus_ic->conn->context); 264 } 265 266 gtk_im_context_set_client_window (ic->conn->context, 267 (ic->focus_window != NULL) ? ic->focus_window : ic->client_window); 268 gtk_im_context_focus_in (ic->conn->context); 269 270 g_focus_ic = ic; 271 272 return 1; 273 274 } 275 276 int 277 xim_unset_ic_focus (XIMS xims, IMChangeFocusStruct *call_data) 278 { 279 X11IC *ic; 280 281 LOG (1, "XIM_UNSET_IC_FOCUS ic=%d, connect_id=%d\n", call_data->icid, call_data->connect_id); 282 283 ic = (X11IC *)g_hash_table_lookup (g_clients, 284 (gconstpointer)(unsigned long)call_data->icid); 285 286 if (ic != g_focus_ic) { 287 return 1; 288 } 289 290 if (g_focus_ic != NULL) { 291 gtk_im_context_focus_out (g_focus_ic->conn->context); 292 } 293 294 g_focus_ic = NULL; 295 296 return 1; 297 298 } 299 300 int 301 xim_forward_event (XIMS xims, IMForwardEventStruct *call_data) 302 { 303 304 X11IC *ic; 305 XKeyEvent *xevent; 306 GdkEventKey event; 307 GdkWindow *window; 308 309 ic = (X11IC *)g_hash_table_lookup (g_clients, 310 (gconstpointer)(unsigned long)call_data->icid); 311 312 g_return_val_if_fail (ic != NULL, 1); 313 g_return_val_if_fail (ic == g_focus_ic, 1); 314 315 window = ic->focus_window != NULL ? ic->focus_window : ic->client_window; 316 317 xevent = (XKeyEvent*) &(call_data->event); 318 319 translate_key_event (gdk_drawable_get_display (window), 320 (GdkEvent *)&event, (XEvent *)xevent); 321 322 event.send_event = xevent->send_event; 323 event.window = window; 324 325 if (gtk_im_context_filter_keypress (ic->conn->context, &event)) { 326 return 1; 327 } 328 else { 329 IMForwardEventStruct fe; 330 XEvent xkp; 331 XKeyEvent *event = (XKeyEvent*) (&xkp); 332 333 memset (&fe, 0, sizeof (fe)); 334 fe.major_code = XIM_FORWARD_EVENT; 335 fe.icid = ic->icid; 336 fe.connect_id = ic->connect_id; 337 fe.sync_bit = 0; 338 fe.serial_number = 0L; 339 fe.event = call_data->event; 340 IMForwardEvent (g_xims, (XPointer) & fe); 341 return 1; 342 } 343 } 344 345 346 int 347 xim_open (XIMS xims, IMOpenStruct *call_data) 348 { 349 X11ICONN *conn; 350 gchar *last; 351 352 LOG (1, "XIM_OPEN connect_id=%d\n", call_data->connect_id); 353 354 conn = (X11ICONN *)g_hash_table_lookup (g_connections, 355 (gconstpointer)(unsigned long)call_data->connect_id); 356 357 g_return_val_if_fail (conn == NULL, 1); 358 359 conn = (X11ICONN *) g_malloc0(sizeof (X11ICONN)); 360 conn->context = GTK_IM_CONTEXT (gtk_im_multicontext_new ()); 361 362 g_hash_table_insert (g_connections, 363 (gpointer)(unsigned long)call_data->connect_id, 364 (gpointer) conn); 365 366 g_signal_connect_after (conn->context, 367 "commit", 368 G_CALLBACK (_xim_commit_cb), 369 (gpointer)(unsigned long)call_data->connect_id); 370 371 return 1; 372 } 373 374 static void 375 _free_ic (gpointer data, gpointer user_data) 376 { 377 X11IC *ic = (X11IC *) data; 378 379 g_return_if_fail (ic != NULL); 380 381 /* Remove the IC from g_client dictionary */ 382 g_hash_table_remove (g_clients, 383 (gconstpointer)(unsigned long)ic->icid); 384 385 g_free (ic); 386 } 387 388 int 389 xim_close (XIMS ims, IMCloseStruct *call_data) 390 { 391 X11ICONN *conn; 392 393 LOG (1, "XIM_CLOSE connect_id=%d\n", call_data->connect_id); 394 395 conn = (X11ICONN *)g_hash_table_lookup (g_connections, 396 (gconstpointer)(unsigned long)call_data->connect_id); 397 398 g_return_val_if_fail (conn != NULL, 1); 399 400 g_list_foreach (conn->clients, _free_ic, NULL); 401 402 g_list_free (conn->clients); 403 404 g_object_unref (conn->context); 405 406 g_hash_table_remove (g_connections, (gconstpointer)(unsigned long)call_data->connect_id); 407 408 g_free (conn); 409 410 return 1; 411 } 412 413 414 415 int 416 xim_set_ic_values (XIMS xims, IMChangeICStruct *call_data) 417 { 418 X11IC *ic; 419 gint i; 420 421 LOG (1, "XIM_SET_IC_VALUES ic=%d connect_id=%d\n", call_data->icid, call_data->connect_id); 422 423 ic = (X11IC *)g_hash_table_lookup (g_clients, 424 (gconstpointer)(unsigned long)call_data->icid); 425 426 g_return_val_if_fail (ic != NULL, 1); 427 428 i = _xim_store_ic_values (ic, call_data); 429 430 if (i) { 431 gtk_im_context_set_cursor_location (ic->conn->context, &ic->preedit_area); 432 } 433 434 return i; 435 } 436 437 438 int 439 xim_reset_ic (XIMS xims, IMResetICStruct *call_data) 440 { 441 X11IC *ic; 442 443 LOG (1, "XIM_RESET_IC ic=%d connect_id=%d\n", call_data->icid, call_data->connect_id); 444 445 ic = (X11IC *)g_hash_table_lookup (g_clients, 446 (gconstpointer)(unsigned long)call_data->icid); 447 448 g_return_val_if_fail (ic != NULL, 1); 449 450 gtk_im_context_reset (ic->conn->context); 451 452 return 1; 453 } 454 455 int 456 ims_protocol_handler (XIMS xims, IMProtocol *call_data) 457 { 458 g_return_val_if_fail (xims != NULL, 1); 459 g_return_val_if_fail (call_data != NULL, 1); 460 461 switch (call_data->major_code) { 462 case XIM_OPEN: 463 return xim_open (xims, (IMOpenStruct *)call_data); 464 case XIM_CLOSE: 465 return xim_close (xims, (IMCloseStruct *)call_data); 466 case XIM_CREATE_IC: 467 return xim_create_ic (xims, (IMChangeICStruct *)call_data); 468 case XIM_DESTROY_IC: 469 return xim_destroy_ic (xims, (IMChangeICStruct *)call_data); 470 case XIM_SET_IC_VALUES: 471 return xim_set_ic_values (xims, (IMChangeICStruct *)call_data); 472 case XIM_GET_IC_VALUES: 473 return 1; 474 case XIM_FORWARD_EVENT: 475 return xim_forward_event (xims, (IMForwardEventStruct *)call_data); 476 case XIM_SET_IC_FOCUS: 477 return xim_set_ic_focus (xims, (IMChangeFocusStruct *)call_data); 478 case XIM_UNSET_IC_FOCUS: 479 return xim_unset_ic_focus (xims, (IMChangeFocusStruct *)call_data); 480 case XIM_RESET_IC: 481 return xim_reset_ic (xims, (IMResetICStruct *)call_data); 482 case XIM_TRIGGER_NOTIFY: 483 case XIM_PREEDIT_START_REPLY: 484 case XIM_PREEDIT_CARET_REPLY: 485 case XIM_SYNC_REPLY: 486 return 1; 487 default: 488 break; 489 } 490 return 1; 491 } 492 493 494 static void 495 _xim_forward_gdk_event (GdkEventKey *event) 496 { 497 IMForwardEventStruct fe; 498 XEvent xkp; 499 memset (&xkp, 0, sizeof (xkp)); 500 memset (&fe, 0, sizeof (fe)); 501 502 xkp.xkey.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease; 503 xkp.xkey.serial = 0L; 504 xkp.xkey.send_event = False; 505 xkp.xkey.same_screen = False; 506 xkp.xkey.display = GDK_WINDOW_XDISPLAY (event->window); 507 xkp.xkey.window = GDK_WINDOW_XWINDOW (event->window); 508 xkp.xkey.subwindow = None; 509 xkp.xkey.root = DefaultRootWindow (GDK_WINDOW_XDISPLAY (event->window)); 510 xkp.xkey.time = event->time; 511
