Drip recording--enable Sublimetext 3 in Ubuntu 14.04 to support Chinese input method

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 collected it online and found that very many people had the same problem, but there was only one way to solve it. The following are summaries of their own installation and resolution methods, such as the following:


1. Installation of Sublimetext 3
There are a variety of installation methods, described in this article is to download the 64-bit. deb file from the official site. Details are http://c758482.r82.cf2.rackcdn.com/sublime-text_build-3059_amd64.deb files. After downloading, you will be actively using the default installation software.



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

3. Copy such as the following code into the file sublime_imfix.c file, the file needs to be created by itself, wherever you can put it.
/*
* 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>

typedefGdksegment Gdkregionbox;

struct_gdkregion
{
Long size;
Long numrects;
Gdkregionbox *rects;
Gdkregionbox extents;
};

Gtkimcontext *local_context;

void
Gdk_region_get_clipbox (ConstGdkregion *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 is 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.

StaticGdkfilterreturn 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);
}
}

returnGdk_filter_continue;
}

voidGtk_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);
intwidth = gdk_window_get_width (window);
intHeight = 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 according to the gaze on the file header, enter the folder where the file is stored in the terminal, and enter for example 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 under the current folder.
4. Chinese input
By default, we have installed the Chinese input method (Sogou input Methods Linux version). Get the 3rd step of the Library libsublime-imfix.so, first try to use the Chinese input method, in the terminal input such as the following command:
ld_preload=./libsublime-imfix.so Subl #subl是安装好SublimeText 3 after the program start command
Assuming everything is OK, after startup. Sogou Input method can be able to input.

5. For convenience
in the 4th step it is assumed that it is inconvenient to enter ld_preload every time. Here you'll find a simple way to change the icon connection and open the Sublimetext at high speed. Copy the libsublime-imfix.so to the default path in the system library:
sudo cp libsublime-imfix.so/usr/lib/
Change/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 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 to
exec=bash-c ' Ld_preload=/usr/lib/libsublime-imfix.so/opt/sublime_text/sublime_text '-n
This allows the Sublimetext 3 to be opened with a shortcut to support Chinese input.

Note: The fifth step is limited to the use of. Deb installation, assuming that the source code is installed, you need to make a few modifications, write a script will ld_preload plus you can










Drip recording--enable Sublimetext 3 in Ubuntu 14.04 to support Chinese input method

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.