Ubuntu下sublime中文无法输入的处理方案
注:
只测试了了fcitx,没有测试ibus
因为不是新手教程,所以安装sublime,fcitx,gcc等等的就不说了
若看不懂请留言
下面为实现过程:
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所在路径
上一篇: php模式设计之观察者模式应用实例分析
下一篇: 基于Android自定义控件实现雷达效果
推荐阅读