一.Ubuntu/Linux Mint 系統(tǒng)+已經安裝搜狗輸入法
二.復制以下代碼,并新建文件sublime_imfix.c于(~目錄)下
#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);
}
三.將上一步的代碼編譯成共享庫libsublime-imfix.so
cd ~
gcc -shared -o libsublime-imfix.so sublime_imfix.cpkg-config --libs --cflags gtk+-2.0
-fPIC
四.錯誤提示:error,gtk/gtkimcontext.....
輸入以下命令
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所在文件夾
sudo mv libsublime-imfix.so /opt/sublime_text/
六.修改文件/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 "$@"
此時撩匕,在命令中執(zhí)行 subl 將可以使用搜狗for linux的中文輸入
sh /usr/bin/subl
七.右鍵打開文件輸入中文
為了使用鼠標右鍵打開文件時能夠使用中文輸入憔辫,還需要修改文件sublime_text.desktop的內容
sudo gedit /usr/share/applications/sublime_text.desktop
a將[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"
b將[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"
c將[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"