1.系统环境:ubuntu,deepin sublime_text3
2.解决方法的步骤:
1)将下面的代码保存到文件sublime_imfix.c(位于~目录):
#include 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);g_object_set_data(G_OBJECT(context),"window",window);if(!GDK_IS_WINDOW (window))return;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);}
2)将上一步的代码编译成共享库libsublime-imfix.so,命令如下:
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
如果报如下错误:
No package 'gtk+-2.0' foundsublime_imfix.c:1:30: fatal error: gtk/gtkimcontext.h: 没有那个文件或目录 #include^
解决方法:
apt-get install build-essential libgtk2.0-dev
然后接着执行步骤2).
3)将libsublime-imfix.so拷贝到sublime_text所在文件夹(此处是/usr/local/sublime):
mv libsublime-imfix.so /usr/local/sublime/
4)修改文件/usr/bin/sublime的内容(如没有,可自行建立):
#!/bin/shexport LD_PRELOAD=/usr/local/sublime_text/libsublime-imfix.so exec /usr/local/sublime/sublime_text "$@"
5)为了使用鼠标右键打开文件时能够使用中文输入,还需要修改文件sublime_text.desktop中EXEC的值:
vim /usr/share/applications/sublime_text.desktop[Desktop Entry]Exec=bash -c "LD_PRELOAD=/usr/local/sublime/libsublime-imfix.so exec /usr/local/sublime/sublime_text %F"[Desktop Action Window]Exec=bash -c "LD_PRELOAD=/usr/local/sublime/libsublime-imfix.so exec /usr/local/sublime/sublime_text -n"[Desktop Action Document]Exec=bash -c "LD_PRELOAD=/usr/local/sublime/libsublime-imfix.so exec /usr/local/sublime/sublime_text --command new_file"
6)执行效果图: