⑴Sublime Text 是一款代码编辑器,如果想要中文输入的话需要使用fcitx输入法,最近有网友碰到Sublime Text 无法使用fcitx输入法的情况,下面小编就给大家介绍下Ubuntu Sublime Text 无法切换fcitx输入法的解决方法。
⑵保存下面这份代码保存为 ~/sublime-imfix.c
⑶sublime-imfix.c
⑷Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.
⑸By Cjacker Huang 《jianzhong.huang at i-soft..》
⑹g -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-.` -fPIC
⑺LD_PRELOAD=。/libsublime-imfix.so sublime_text
⑻#include 《gtk/gtk.h》
⑼#include 《gdk/gdkx.h》
⑽typedef GdkSegment GdkRegionBox;
⑾struct _GdkRegion
⑿long size;
⒀long numRects;
⒁GdkRegionBox *rects;
⒂GdkRegionBox extents;
⒃GtkIMContext *local_context;
⒄gdk_region_get_clipbox (const GdkRegion *region,
⒅GdkRectangle *rectangle
⒆g_return_if_fail (region != NULL;
⒇g_return_if_fail (rectangle != NULL;
⒈rectangle-》x = region-》extents.x;
⒉rectangle-》y = region-》extents.y;
⒊rectangle-》width = region-》extents.x - region-》extents.x;
⒋rectangle-》height = region-》extents.y - region-》extents.y;
⒌GdkRectangle rect;
⒍rect.x = rectangle-》x;
⒎rect.y = rectangle-》y;
⒏rect.width = ;
⒐rect.height = rectangle-》height;
⒑//The caret width is ;
⒒//Maybe sometimes we will make a mistake, but for most of the time, it should be the caret.
⒓if(rectangle-》width == && GTK_IS_IM_CONTEXT(local_context {
⒔gtk_im_context_set_cursor_location(local_context, rectangle;
⒕//this is needed, for example, if you input something in file dialog and return back the edit area
⒖//context will lost, so here we set it again.
⒗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
Ⅰ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 != && height != {
Ⅴgtk_im_context_focus_in(context;
Ⅵlocal_context = context;
Ⅶgdk_window_add_filter (window, event_filter, context;
Ⅷ安装C/C++的编译环境和gtk libgtk.-dev
Ⅸsudo apt-get install build-essential
Ⅹsudo apt-get install libgtk.-dev
㈠用终端进入 sublime-imfix.c 所在目录,运行下面命令
㈡g -shared -o libsublime-imfix.so sublime-imfix.c `pkg-config --libs --cflags gtk+-.` -fPIC
㈢用修改 /usr/share/applications/sublime.desktop 文件(这是你安装sublime text 时自己建的,找到开头为“Exec=”的行(有两行,把subl修改为
㈣bash -c ‘LD_PRELOAD=~/libsublime-imfix.so subl’
㈤OK,在启动器那里点击sublime text 就可以中文输入了!(注意:在终端输入subl打开时不能切换中文输入法
㈥上面就是Ubuntu Sublime Text 无法使用fcitx输入法的解决方法的介绍了,按照本文介绍的方法修改subl后,要从启动器启动Sublime Text 。