首先确认你安装了sublime3和搜狗输入法,这两个软件都有官方网站,安装步骤官网上都有。
将下列代码保存为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);
}
将上面的.c文件编译成共享库,命令如下,如果没有安装gtk2.0,可以先安装这个。
sudo apt-get install libgtk2.0-dev
cd ~
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
然后将这个共享库拷贝到sublime的文件夹中。
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 "$@"
sudo gedit /usr/share/applications/sublime_text.desktop
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"
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"
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"
这个时候重启sublime就可以输入中文了。