“ubuntu教程”在ubuntu 14.04中使sublimetext 3支持中文

来源: 电脑维修教程 阅读:     发表时间:

在ubuntu 14.04中安装了sublimetext 3以后发现既然不撑持输入中文,因而在网上搜罗一下,发现良多人碰到了一样的问题,可是解决法子大该就只有一个。下面

在ubuntu 14.04中安装了sublimetext 3以后发现既然不撑持输入中文,因而在网上搜罗一下,发现良多人碰到了一样的问题,可是解决法子大该就只有一个。下面按照本身的安装及解决法子总结以下:

1. sublimetext 3的安装

ubuntu14.04

搜狗输入法 for linux

sublime text 3

2.拷贝以下代码到文件sublime-imfix.c文件中,该文件需要自己建立,随意放到那边都行。

/*

* 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);

}

3.编译

依照文件头上注释所说的编译该文件,在终端里进入到寄存该文件的目次中,输入以下号令:

gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fpic

最后在当前目次下获得libsublime-imfix.so这个同享库。

4.鼠标右键打开撑持中文

在这里供给简单点窜图标毗连的体例,快速打开sublimetext。将libsublime-imfix.so拷贝到系统库的默认路径中:

sudo cp libsublime-imfix.so /usr/lib/

点窜/usr/share/applications/sublime_text.desktop文件

sudo vim /usr/share/applications/sublime_text.desktop

打开后将exec=/opt/sublime_text/sublime_text %f点窜为

exec=bash -c 'ld_preload=/usr/lib/libsublime-imfix.so /opt/sublime_text/sublime_text' %f

将exec=/opt/sublime_text/sublime_text -n点窜为

exec=bash -c 'ld_preload=/usr/lib/libsublime-imfix.so /opt/sublime_text/sublime_text' -n

如许就经由过程快捷体例打开sublimetext 3便可以撑持中文输入了。

5.号令行打开撑持中文

点窜文件/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 "$@"

此时,在号令中执行subl将可使用搜狗for linux的中文输入

以上是:解决“ubuntu教程”在ubuntu 14.04中使sublimetext 3支持中文问题的详细资料教程