⑴Sublime Text是一个代码编辑器,拥有强大的功能,但Sublime Text 在Linux下运行的时候存在无法输入中文的问题,遇到该问题该如何解决呢?下面小编就给大家介绍下Linux下Sublime Text 无法输入中文的解决方法。
⑵.保存下面的代码为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;
Ⅷg -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-.` -fPIC
Ⅸ. 设置 LD_PRELOAD 并启动 Sublime Text:
ⅩLD_PRELOAD=。/libsublime-imfix.so sublime_text
㈠为了不用每次启动Sublime Text都打这么一长串东西,写了个启动Sublime的脚本:
㈡#!/bin/bash
㈢SUBLIME_HOME=“/opt/sublime_text”
㈣LD_LIB=$SUBLIME_HOME/libsublime-imfix.so
㈤sh -c “LD_PRELOAD=$LD_LIB $SUBLIME_HOME/sublime_text $”
㈥把libsublime-imfix.so放到Sublime Text目录下并修改脚本中的SUBLIME_HOME,这样Sublime Text 就可以输入中文了。
㈦上面就是Linux下Sublime Text 无法输入中文的解决方法的介绍了,只要按照上面的步骤,就能在Sublime Text 中输入中文了,是不是很简单呢?赶紧试试看吧。