概述:ubuntu下面使用sublime写代码,不能输入中文写注释都比较麻烦,所以就搜了一下如何输入中文。写篇博客记录一下,测试成功。@H_502_2@
测试环境
系统:ubuntu 14.04lts
sublime text@H_502_2@
安装编译环境@H_502_2@
sudo apt-get install build-essential libgtk2.0-dev@H_502_2@
#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文件。@H_502_2@
gcc -shared -o libsublime-imfix.so sublime-imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
复制到sublime安装目录@H_502_2@
sudo mv libsublime-imfix.so /opt/sublime_text/
其中/opt/sublime_text为sublime的安装目录。@H_502_2@
sudo gedit /usr/bin/subl//subl命令就是sublime终端启动的命令
#!/bin/sh
SUBLIME_HOME="/opt/sublime_text"
export LD_PRELOAD=$SUBLIME_HOME/libsublime-imfix.so//需要写在exec命令之前生效
exec /opt/sublime_text/sublime_text "$@"//subl命令能打开sublime的原因
修改sublime_text.desktop@H_502_2@
sudo vim /usr/share/applications/sublime-text.desktop@H_502_2@
[Desktop Entry]
Version=1.0
Type=Application
Name=Sublime Text
GenericName=Text Editor
Comment=Sophisticated text editor for code,markup and prose
Exec=/usr/bin/subl %F #这里修改执行路径为/usr/bin/subl,subl文件刚才已经修改过,大家应该记得
Terminal=false
MimeType=text/plain;
Icon=sublime-text
Categories=TextEditor;Development;
StartupNotify=true
Actions=Window;Document;
[Desktop Action Window]
Name=New Window
Exec=/usr/bin/subl -n #这里修改执行路径为/usr/bin/subl,subl文件刚才已经修改过,大家应该记得
OnlyShowIn=Unity;
[Desktop Action Document]
Name=New File
Exec=/usr/bin/subl new_file #这里修改执行路径为/usr/bin/subl,subl文件刚才已经修改过,大家应该记得
OnlyShowIn=Unity;
上面的过程亲测有效。@H_502_2@
——2017.1.3@H_502_2@