这篇“Ubuntu下sublime中文无法输入如何解决”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Ubuntu下sublime中文无法输入如何解决”文章吧。
copy下列代码,保存为sublime_fix.c
复制代码 代码如下:
#include <gtk/gtk.h>#include <gdk/gdkx.h>typedef gdksegment gdkregionbox;struct _gdkregion{ long size; long numrects; gdkregionbox *rects; gdkregionbox extents;};gtkimcontext *local_context;voidgdk_region_get_clipbox (const gdkregion *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; if(rectangle->width == 2 && gtk_is_im_context(local_context)) { gtk_im_context_set_cursor_location(local_context, rectangle); }}
static gdkfilterreturn 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); } return gdk_filter_continue;}void gtk_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); int width = gdk_window_get_width(window); int height = 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);}
使用下列命令编译它
复制代码 代码如下:
gcc -shared -o libsublime-imfix.so sublime_fix.c `pkg-config --libs --cflags gtk+-2.0/` -fpic
添加运行权限给libsublime-imfix.so
复制代码 代码如下:
chmod +x libsublime-imfix.so
将编译后的文件libsublime-imfix.so复制到sublime的文件夹下面
在sublime安装目录下新建文件为sublime_sh.sh,copy内容如下:
复制代码 代码如下:
#!/bin/bash
sublime_home="~/software" #你的sublime安装目录
ld_lib="$sublime_home/libsublime-imfix.so"
sh -c "ld_preload=$ld_lib $sublime_home/sublime $@"
你已经可以通过teminal启动sublime了,运行./sublime_sh.sh即可
若要通过启动器启动sublime,请将你sublime.desktop里面的exec路径修改为sublime_sh.sh所在路径