ubuntu 12.04 支持中文----完胜版
原文地址 http://pobeta.com/ubuntu-sublime.html,
1 2 3 /* 4 sublime-imfix.c 5 Use LD_PRELOAD to interpose some function to fix sublime input method support for linux. 6 By Cjacker Huang <jianzhong.huang at i-soft.com.cn> 7 8 gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC 9 LD_PRELOAD=./libsublime-imfix.so sublime_text 10 */ 11 #include <gtk/gtk.h> 12 #include <gdk/gdkx.h> 13 typedef GdkSegment GdkRegionBox; 14 15 struct _GdkRegion 16 { 17 long size; 18 long numRects; 19 GdkRegionBox *rects; 20 GdkRegionBox extents; 21 }; 22 23 GtkIMContext *local_context; 24 25 void 26 gdk_region_get_clipbox (const GdkRegion *region, 27 GdkRectangle *rectangle) 28 { 29 g_return_if_fail (region != NULL); 30 g_return_if_fail (rectangle != NULL); 31 32 rectangle->x = region->extents.x1; 33 rectangle->y = region->extents.y1; 34 rectangle->width = region->extents.x2 - region->extents.x1; 35 rectangle->height = region->extents.y2 - region->extents.y1; 36 GdkRectangle rect; 37 rect.x = rectangle->x; 38 rect.y = rectangle->y; 39 rect.width = 0; 40 rect.height = rectangle->height; 41 //The caret width is 2; 42 //Maybe sometimes we will make a mistake, but for most of the time, it should be the caret. 43 if(rectangle->width == 2 && GTK_IS_IM_CONTEXT(local_context)) { 44 gtk_im_context_set_cursor_location(local_context, rectangle); 45 } 46 } 47 48 //this is needed, for example, if you input something in file dialog and return back the edit area 49 //context will lost, so here we set it again. 50 51 static GdkFilterReturn event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer im_context) 52 { 53 XEvent *xev = (XEvent *)xevent; 54 if(xev->type == KeyRelease && GTK_IS_IM_CONTEXT(im_context)) { 55 GdkWindow * win = g_object_get_data(G_OBJECT(im_context),"window"); 56 if(GDK_IS_WINDOW(win)) 57 gtk_im_context_set_client_window(im_context, win); 58 } 59 return GDK_FILTER_CONTINUE; 60 } 61 62 void gtk_im_context_set_client_window (GtkIMContext *context, 63 GdkWindow *window) 64 { 65 GtkIMContextClass *klass; 66 g_return_if_fail (GTK_IS_IM_CONTEXT (context)); 67 klass = GTK_IM_CONTEXT_GET_CLASS (context); 68 if (klass->set_client_window) 69 klass->set_client_window (context, window); 70 71 if(!GDK_IS_WINDOW (window)) 72 return; 73 g_object_set_data(G_OBJECT(context),"window",window); 74 int width = gdk_window_get_width(window); 75 int height = gdk_window_get_height(window); 76 if(width != 0 && height !=0) { 77 gtk_im_context_focus_in(context); 78 local_context = context; 79 } 80 gdk_window_add_filter (window, event_filter, context); 81 } 82 83 84 2.编译成共享库 85 86 gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC 87 88 3.执行 89 90 LD_PRELOAD=./libsublime-imfix.so sublime_text(看自己的在什么位置,叫做什么名字)
1 . 如果每次执行sublime 都要执行上面第三步中的“执行”的话,很麻烦。 2 3 所以我们建立一个脚本文件subl(无扩展名),文件内容为: 4 5 #!/bin/bash 6 sh -c "LD_PRELOAD=/home/allen/sublime-text/libsublime-imfix.so /home/allen/sublime-text/sublime_text" 7
chmod -R 777 subl;
在终端运行