环境
ubuntu 16.04 amd64
sublime text3
准备工作
#安装 libgtk2.0-dev ,否则报错,No package 'gtk+-2.0' found ;
apt-get install libgtk2.0-dev
编译工作
1. 编辑 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);
}
2. 编译 sublime_imfix.c
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
编译完成后,会在同一目录下生成一个libsublime-imfix.so
将它复制到sublime的安装目录
cp libsublime-imfix.so /opt/sublime_text/
验证
1. 临时
关闭 sublime text3 ,使用命令行启动;
cd /opt/sublime_text/
LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text
2. 自动加载
在命令行,显示的指定加载so 文件,非常不方便,所以使用alias 一个sublime 命令,启动时自动加载so 文件;
grep 'sublime' ~/.bashrc
#添加以下字段到配置文件;
alias sublime='LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text'
3. 加载文件
source ~/.bashrc
使用
sublime