任意位置建立sublime_imfix.c文件, 代碼以下html
#include <gtk/gtkimcontext.h> 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); }
將 sublime_imfix.c 編譯成共享庫libsublime-imfix.so,命令以下:linux
# ps: 若是缺乏組件,則:sudo apt-get install libgtk2.0-dev gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
而後將libsublime-imfix.so拷貝到sublime_text所在文件夾vim
sudo mv libsublime-imfix.so /opt/sublime_text/
修改文件/usr/bin/subl的內容bash
sudo vim /usr/bin/subl #!/bin/sh exec /opt/sublime_text/sublime_text "$@" => #!/bin/sh LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text "$@" 此時,在命令中執行 subl 將能夠使用搜狗for linux的中文輸入
完美解決問題:還須要修改文件sublime_text.desktop的內容app
sudo vim /usr/share/applications/sublime_text.desktop [Desktop Entry] Exec=/opt/sublime_text/sublime_text %F => Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text %F" [Desktop Action Window] Exec=/opt/sublime_text/sublime_text -n => Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text -n" [Desktop Action Document] Exec=/opt/sublime_text/sublime_text --command new_file => Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text --command new_file" 注意:修改時請注意雙引號"",不然會致使不能打開帶有空格文件名的文件。