1. Save the following code for SUBLIME_IMFIX.C
/*Sublime-imfix.cuse ld_preload to interpose some function to fix sublime Input method support for Linux. by Cjacker Huang <jianzhong.huang at i-soft.com.cn> gcc-shared-o libsublime-imfix.so sublime_imfix.c ' Pkg-config --libs--cflags gtk+-2.0 '-fpicld_preload=./libsublime-imfix.so sublime_text*/#include<gtk/gtk.h>#include<gdk/gdkx.h>typedef gdksegment Gdkregionbox;struct_gdkregion{Longsize; Longnumrects; Gdkregionbox*rects; Gdkregionbox extents;}; Gtkimcontext*Local_context;voidGdk_region_get_clipbox (ConstGdkregion *Region , Gdkrectangle*rectangle) {G_return_if_fail ( region!=NULL); G_return_if_fail (Rectangle!=NULL); Rectangle->x = region->extents.x1; Rectangle->y = region->extents.y1; Rectangle->width = region->extents.x2-region->extents.x1; Rectangle->height = region->extents.y2-region->extents.y1; Gdkrectangle rect; Rect.x= rectangle->x; Rect.y= rectangle->y; Rect.width=0; Rect.height= rectangle->height; //The caret width is 2; //maybe sometimes we'll make a mistake, but for most of the time, it should is the caret. if(Rectangle->width = =2&&Gtk_is_im_context (Local_context)) {gtk_im_context_set_cursor_location (local_context, rectangle); }} //This was needed, for example, if you input something in file dialog and return to the edit area//context would lost, so here we set it again. StaticGdkfilterreturn Event_filter (gdkxevent *xevent, Gdkevent *Event, Gpointer Im_context) {XEvent*xev = (XEvent *) xevent; if(Xev->type = = Keyrelease &&Gtk_is_im_context (Im_context)) {Gdkwindow* win = G_object_get_data (G_object (Im_context),"window"); if(Gdk_is_window (Win)) Gtk_im_context_set_client_window (Im_context, Win); } returnGdk_filter_continue;} voidGtk_im_context_set_client_window (Gtkimcontext *context, Gdkwindow*window) {Gtkimcontextclass*Klass; G_return_if_fail (Gtk_is_im_context (CONTEXT)); Klass=Gtk_im_context_get_class (CONTEXT); if(klass->Set_client_window) Klass-Set_client_window (context, window); if(!Gdk_is_window (WINDOW))return; G_object_set_data (G_object (context),"window", window); intwidth =gdk_window_get_width (window); intHeight =gdk_window_get_height (window); if(Width! =0&& Height! =0) {gtk_im_context_focus_in (context); Local_context=context; } gdk_window_add_filter (window, event_filter, context); }
2. Compiling the dynamic library:
Gcc-shared-o libsublime-imfix.so sublime_imfix.c ' pkg-config--libs--cflags gtk+-2.0'-fPIC
3. Set Ld_preload and start Sublime Text:
Ld_preload=./libsublime-imfix.so Sublime_text
In order not to start sublime text every time to play such a long list of things, wrote a startup sublime script:
#!/bin/bash Sublime_home="/opt/sublime_text"ld_lib= $SUBLIME _home/ libsublime-"ld_preload= $LD _lib $SUBLIME _home/sublime_text [email protected]"
(Place the libsublime-imfix.so in the sublime text directory and modify the Sublime_home in the script)
Original link: http://my.oschina.net/tsl0922/blog/113495
Perfect solution for Linux under Sublime Text Chinese input (reprint)