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所在路径
推荐阅读
-
Linux 下 Sublime Text 中文输入问题的解决方案
-
ubuntu安装sublime不能输入中文的解决方法
-
Android Studio 升级到3.0后输入法中文状态下无法选词的终极解决方案
-
Ubuntu下Sublime Text无法输入中文最简单的解决方案
-
sublime text linux上中文输入问题的终极解决方案
-
Linux 下 Sublime Text 中文输入问题的解决方案
-
Ubuntu下sublime中文无法输入的处理方案
-
关于ubuntu下安装完PHP+Apache后,无法解析php的解决方案
-
ubuntu下使用sublime text时如何完美输入中文
-
Ubuntu下MYSQL的中文输入简析_MySQL