Enables Sublimetext 3 to support Chinese input method in Ubuntu 14.04

Source: Internet
Author: User
Tags gtk

after installing the Sublimetext 3 in Ubuntu 14.04, I found that since I did not support the input of Chinese, I found that many people encountered the same problem, but there was only one solution. The following are summarized according to their own installation and solution:


1. Installation of Sublimetext 3
There are several ways to install, as described in this article is the 64-bit. deb file downloaded from the official website, specifically http://c758482.r82.cf2.rackcdn.com/sublime-text_build-3059_ The Amd64.deb file, which is downloaded and then double-clicked, is automatically installed using the default installation software.

2. Installation of dependent software
sudo apt-get install build-essential Libgtk2.0-dev

3. Copy the following code into the file Sublime_imfix.c file, which needs to be created by itself and can be placed anywhere.

/* * 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;voidgdk_region_get_clipbox (const gdkregion *region, Gdkrectangle *r    Ectangle) {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-&Gt;x;    Rect.y = rectangle->y;    rect.width = 0;    Rect.height = rectangle->height;    The caret width is 2;    Maybe sometimes we'll make a mistake, but for most of the time, it should is the caret. if (rectangle->width = = 2 && gtk_is_im_context (Local_context)) {gtk_im_context_set_cursor_location (loca    L_context, rectangle); }}//this is needed, for example, if your input something in file dialog and return back the edit Area//context would lost, s o Here we set it again.static gdkfilterreturn event_filter (gdkxevent *xevent, gdkevent *event, Gpointer im_context) {X    Event *xev = (XEvent *) XEvent; if (Xev->type = = Keyrelease && gtk_is_im_context (im_context)) {Gdkwindow *win = G_object_get_data (G_OBJ        ECT (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);}




compile the file as described in the comment on the file header, enter the directory where the file is stored in the terminal, and enter the following command: gcc-shared-o libsublime-imfix.so sublime_imfix.c ' pkg-config--libs--cflags gtk+-2.0 '-fPIC
finally get libsublime-imfix.so this shared library in the current directory.
4. Chinese input
By default, we have installed the Chinese input method (Sogou input Methods Linux version). Get the 3rd step in the library libsublime-imfix.so, first try to see if the normal use of Chinese input method, enter the following command in the terminal:
ld_preload=./libsublime-imfix.so subl #subl是安装好SublimeText 3 after the program start command
If everything is OK, after the startup, Sogou Input method can be entered.

5. For convenience
in the 4th step if the input ld_preload each time this is too inconvenient, here provides a simple way to modify the icon connection, quickly open the sublimetext. Copy the libsublime-imfix.so to the default path in the system library:
sudo cp libsublime-imfix.so/usr/lib/
Modify the/usr/share/applications/sublime_text.desktop file
sudo vim/usr/share/applications/sublime_text.desktop
after opening, change the Exec=/opt/sublime_text/sublime_text%f revision to
exec=bash-c ' Ld_preload=/usr/lib/libsublime-imfix.so/opt/sublime_text/sublime_text '%F

Change the exec=/opt/sublime_text/sublime_text-n revision to
exec=bash-c ' Ld_preload=/usr/lib/libsublime-imfix.so/opt/sublime_text/sublime_text '-n
This allows you to open Sublimetext 3 with a shortcut to support Chinese input.

Note: The fifth step is limited to the use of. deb file installation, if you use the source code installed, you need to make a modification, write a script will ld_preload plus

Enables Sublimetext 3 to support Chinese input method in Ubuntu 14.04

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.