改编自:http://blog.youkuaiyun.com/cywosp/article/details/32350899
安装必要的库(如下)和搜狗linux输入法。
sudo apt-get update
安装C/C++的编译环境和gtk libgtk2.0-dev
sudo apt-get install build-essential
sudo apt-get install libgtk2.0-dev
sudo apt-get install gtk+-2.0
官方网站上下载64位的.deb文件(http://www.sublimetext.com/3) ,具体为 http://c758482.r82.cf2.rackcdn.com/sublime-text_build-3083_amd64.deb 文件,
下载后双击即会自动使用默认的安装软件安装。
sublime-imfix.c 文件自己创建
//===========--start--====================
/*
* sublime-imfix.c
* Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.
* By Cjacker Huang <jianzhong.huang at i-soft.com.cn> *
*
* gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
* LD_PRELOAD=./libsublime-imfix.so sublime_text
*/
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
typedef GdkSegment GdkRegionBox;
struct _GdkRegion
{
long size;
long numRects;
GdkRegionBox *rects;
GdkRegionBox extents;
};
GtkIMContext *local_context;
void
gdk_region_get_clipbox (const GdkRegion *region,
GdkRectangle *rectangle)
{
g_return_if_fail (region != NULL);
g_return_if_fail (rectangle != NULL);
rectangle->x = region->extents.x1;
rectangle->y = region->extents.y1;
rectangle->width = region->extents.x2 - region->extents.x1;
rectangle->height = region->extents.y2 - region->extents.y1;
GdkRectangle rect;
rect.x = rectangle->x;
rect.y = rectangle->y;
rect.width = 0;
rect.height = rectangle->height;
//The caret width is 2;
//Maybe sometimes we will make a mistake, but for most of the time, it should be the caret.
if (rectangle->width == 2 && GTK_IS_IM_CONTEXT(local_context)) {
gtk_im_context_set_cursor_location(local_context, rectangle);
}
}
//this is needed, for example, if you input something in file dialog and return back the edit area
//context will lost, so here we set it again.
static GdkFilterReturn event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer im_context)
{
XEvent *xev = (XEvent *)xevent;
if (xev->type == KeyRelease && GTK_IS_IM_CONTEXT(im_context)) {
GdkWindow *win = g_object_get_data(G_OBJECT(im_context), "window");
if (GDK_IS_WINDOW(win)) {
gtk_im_context_set_client_window(im_context, win);
}
}
return GDK_FILTER_CONTINUE;
}
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);
}
if (!GDK_IS_WINDOW (window)) {
return;
}
g_object_set_data(G_OBJECT(context), "window", window);
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);
local_context = context;
}
gdk_window_add_filter (window, event_filter, context);
}
//===========--stop--====================
cd /opt/sublime_text/
把 sublime-imfix.c 文件复制到 /opt/sublime_text/ 下面。
切换到 root用户(否则权限不够)
运行:gcc -shared -o libsublime-imfix.so sublime-imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
// 如果是root用户是无法输入中文的。
切换到普通用户输入: LD_PRELOAD=./libsublime-imfix.so subl
就可以使用sublime输入中文了。
继续切换到root用户:
方便启动,运行
sudo cp libsublime-imfix.so /usr/lib/
修改文件:
sudo vim /usr/share/applications/sublime_text.desktop
1,将 Exec=/opt/sublime_text/sublime_text %F 修改为
Exec=bash -c 'LD_PRELOAD=/usr/lib/libsublime-imfix.so /opt/sublime_text/sublime_text' %F
2,将 Exec=/opt/sublime_text/sublime_text -n 修改为
Exec=bash -c 'LD_PRELOAD=/usr/lib/libsublime-imfix.so /opt/sublime_text/sublime_text' -n
最后把图标锁定到任务栏,就可以正常了
配置sublime:可以不用设置,根据自己喜好。
preferences-->settings-user 菜单那里复制粘贴一下内容
{
"auto_complete": false,
"auto_match_enabled": false,
"color_scheme": "Packages/Color Scheme - Default/Mac Classic.tmTheme",
"fallback_encoding": "UTF-8",
"font_face": "微软雅黑",
"font_size": 13,
"ignored_packages":
[
"Vintage." // 后面加上点就是gvim的操作方式
],
"tab_size": 2,
"update_check": false, //不更新
"word_wrap": true
}
ubuntu14.04 下subline编辑器的安装与配置输入中文解决方案
最新推荐文章于 2019-07-23 23:31:44 发布