Sublimetext 3 Support Chinese input

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;

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'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 (local_context, rectangle);
}
}

This was needed, for example, if you input something in file dialog and return to the edit area
Context would 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);
}
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--CFL AGS gtk+-2.0 '-fpic
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.

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.