Solve the Problem of Sublime Text 2 Chinese Input in Ubuntu (using fcitx input method)

Source: Internet
Author: User

I use Ubuntu 13.10, fcitx input method, and Google pinyin.

After installing Sublime Text 2 yesterday, we found that the fcitx input method could not be switched. I found many methods on the Internet. This method is very effective at last, so I will share it with you:

Save the following code and save it ~ 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 +-1000'-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 shocould 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 );

Install the C/C ++ compiling environment and gtk libgtk2.0-dev

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

Enter the sublime-imfix.c directory with the terminal and run the following command

Gcc-shared-o libsublime-imfix.so sublime-imfix.c 'pkg-config -- libs -- cflags gtk +-2.0'-fPIC

Modify/usr/share/applications/sublime in a text editor. desktop file (this was created when you installed sublime text 2), find the line starting with "Exec =" (there are two lines), and change subl

Bash-c 'LD _ PRELOAD = ~ /Libsublime-imfix.so subl'

OK. Click sublime text 2 in the starter to enter Chinese! (Note: you cannot switch the Chinese Input Method when entering subl on the terminal)

Ubuntu 12.10 install and crack Sublime Text 2

Install Sublime Text 2 on Ubuntu 13.04

Code artifact-Sublime Text package management tools and extensions

How to Develop the Sublime Text 2 plug-in

Install and crack the Sublime Text 2 editor in Windows Mac Linux

Text Editor Sublime Text User Experience

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.