Ubuntu下sublime中文无法输入的处理方案
<p>注:</p>
<p>
只测试了了fcitx,没有测试ibus<br>
因为不是新手教程,所以安装sublime,fcitx,gcc等等的就不说了<br>
若看不懂请留言<br>
下面为实现过程:</p>
<p>
copy下列代码,保存为sublime_fix.c</p>
<p>
</p>
<div class="codetitle">
<span><u>复制代码</u></span> 代码如下:</div>
<div class="codebody" id="code17231">
<p>
<br>
#include <gtk/gtk.h><br>
#include <gdk/gdkx.h><br>
typedef GdkSegment GdkRegionBox;<br>
struct _GdkRegion<br>
{<br>
long size;<br>
long numRects;<br>
GdkRegionBox *rects;<br>
GdkRegionBox extents;<br>
};<br>
GtkIMContext *local_context;<br>
voidgdk_region_get_clipbox (const GdkRegion *region , GdkRectangle *rectangle)<br>
{<br>
g_return_if_fail (region != NULL);<br>
g_return_if_fail (rectangle != NULL);<br>
rectangle->x = region->extents.x1;<br>
rectangle->y = region->extents.y1;<br>
rectangle->width = region->extents.x2 - region->extents.x1;<br>
rectangle->height = region->extents.y2 - region->extents.y1;<br>
GdkRectangle rect;<br>
rect.x = rectangle->x;<br>
rect.y = rectangle->y;<br>
rect.width = 0;<br>
rect.height = rectangle->height;<br>
if(rectangle->width == 2 && GTK_IS_IM_CONTEXT(local_context)) {<br>
gtk_im_context_set_cursor_location(local_context, rectangle);<br>
}<br>
}</p>
<p>
</p>
<p>
static GdkFilterReturn event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer im_context)<br>
{<br>
XEvent *xev = (XEvent *)xevent;<br>
if(xev->type == KeyRelease && GTK_IS_IM_CONTEXT(im_context)) {<br>
GdkWindow * win = g_object_get_data(G_OBJECT(im_context),"window");<br>
if(GDK_IS_WINDOW(win))<br>
gtk_im_context_set_client_window(im_context, win);<br>
}<br>
return GDK_FILTER_CONTINUE;<br>
}<br>
void gtk_im_context_set_client_window (GtkIMContext *context , GdkWindow *window)<br>
{<br>
GtkIMContextClass *klass;<br>
g_return_if_fail (GTK_IS_IM_CONTEXT (context));<br>
klass = GTK_IM_CONTEXT_GET_CLASS (context);<br>
if (klass->set_client_window)<br>
klass->set_client_window (context, window);<br>
if(!GDK_IS_WINDOW (window))<br>
return;<br>
g_object_set_data(G_OBJECT(context),"window",window);<br>
int width = gdk_window_get_width(window);<br>
int height = gdk_window_get_height(window);<br>
if(width != 0 && height !=0) {<br>
gtk_im_context_focus_in(context);<br>
local_context = context;<br>
}<br>
gdk_window_add_filter (window, event_filter, context);<br>
}</p>
</div>
<p>
</p>
<p>
使用下列命令编译它</p>
<p>
</p>
<div class="codetitle">
<span><u>复制代码</u></span> 代码如下:</div>
<div class="codebody" id="code8945">
<br>
gcc -shared -o libsublime-imfix.so sublime_fix.c `pkg-config --libs --cflags gtk+-2.0/` -fPIC</div>
<p>
</p>
<p>
添加运行权限给libsublime-imfix.so</p>
<p>
</p>
<div class="codetitle">
<span><u>复制代码</u></span> 代码如下:</div>
<div class="codebody" id="code86919">
<br>
chmod +x libsublime-imfix.so</div>
<p>
</p>
<p>
将编译后的文件libsublime-imfix.so复制到sublime的文件夹下面<br>
在sublime安装目录下新建文件为sublime_sh.sh,copy内容如下:</p>
<p>
</p>
<div class="codetitle">
<span><u>复制代码</u></span> 代码如下:</div>
<div class="codebody" id="code26440">
<br>
#!/bin/bash<br>
SUBLIME_HOME="~/software" #你的sublime安装目录<br>
LD_LIB="$SUBLIME_HOME/libsublime-imfix.so"<br>
sh -c "LD_PRELOAD=$LD_LIB $SUBLIME_HOME/sublime $@"</div>
<p>
</p>
<p>
你已经可以通过teminal启动sublime了,运行./sublime_sh.sh即可<br>
若要通过启动器启动sublime,请将你sublime.desktop里面的exec路径修改为sublime_sh.sh所在路径</p>
頁:
[1]