ubuntut13.10下面解决sublime text2里不能输入中文的问题

T61上装了Ubuntu  13.10 64bit,再按照自己的习惯安装了cario-dock和sublimetext2,由于ibus在这个版本下面工作不正常,最后安装了fcitx作为自己的输入法。

先说一个大家经常碰到的问题,fcitx用ctrl+space不能切换输入法的解决方法 。

在‘ 应用菜单’里的‘system setting’里的‘区域和语言’里的'切换到上个源',默认选上了‘ctrl+space’,和fcitx的冲突,选中后按'backspace'取消掉

wKiom1LqWyzzUC4aAAE3RFkUKSo951.jpg



2、要通过ppa方式安装sublime text2,以前的下载包、解压什么的太老土了。

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text

3、然后把下面代码的代码保存下来,放到你的/home/leo/Share下面,(leo是我的用户名,放哪里不是很重要,后面路径参数要写对),命名为sublime-imfix.c(感谢ubuntu.org.cn

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

4、终端下,安装编译时候需要的环境:

sudo apt-get install build-essential
sudo apt-get install libgtk2.0-dev

5、终端下,进入sublime-imfix.c所在目录后,开始编译,后会得到libsublime-imfix.so

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

7、然后修改ST2的启动配置

sudo gedit /usr/share/applications/sublime-text-2.desktop

8、找到

Exec=/usr/bin/subl %F

修改成,注意括号的位置,要把%F给包括进来

Exec=bash -c 'LD_PRELOAD=/home/leo/Share/libsublime-imfix.so /usr/bin/subl %F'

同时把

Exec=/usr/bin/subl -n
Exec=/usr/bin/subl --command new_file

改成

Exec=bash -c 'LD_PRELOAD=/home/leo/Share/libsublime-imfix.so /usr/bin/subl' -n
Exec=bash -c 'LD_PRELOAD=/home/leo/Share/libsublime-imfix.so /usr/bin/subl' --command new_file

9、这里,通过应用程序能直接打开sublimetext2,并用能输入中文 ,但是把sublime-text固定到cario-dock的启动栏里还不能正常启动,因此要作一些配置。

在该启动器的配置项里,把'comand to launch on click:'改成‘LD_PRELOAD=/home/leo/Share/libsublime-imfix.so  /usr/bin/subl’,这样可以在dock里直接点sublimetext2按钮启动并输入中文。

wKioL1LqXxqApzCvAAEHSA2HuQM765.jpg


你可能感兴趣的:(ubuntu,中文,SublimeText2,fcitx,cario-dock)