晚上通過參照網上的解決方法,實踐了一下,解決了sublime 在linux下的中文輸入問題linux
1:切換到~目錄,而後新建一個sublime_imfix.c的文件bash
touch sublime_imfix.c
2:編輯sublime_imfix.c文件 app
gedit sublime_imfix.c
將下面的代碼複製到打開的gedit中spa
#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); }
3:將複製好的代碼文件sublime_imfix.c編譯成libsublime-imfix.so文件
code
cd ~ gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
到這一步可能會一個有一個錯誤說什麼「gtk/gtkimcontext.h: 沒有那個文件或目錄」字符串
這時你新開一個終端執行apt-get install libgtk2.0-devget
4:接下來再次執行
it
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
5:而後將編譯的libsublime-imfix.so文件拷貝到sublime_text所在文件夾io
sudo mv libsublime-imfix.so /opt/sublime_text/
6:修改文件/usr/bin/subl的內容編譯
sudo gedit /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 "$@"
7::還須要修改文件sublime_text.desktop的內容。
sudo gedit /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"
8:最後,最後,最後,打開sublime,切換到中文輸入,try
10:shutdown -h now
睡覺,睡覺,睡覺