Solution to fcitx Chinese Input Method in Sublime Text 2 in Ubuntu

Source: Internet
Author: User

Solution to fcitx Chinese Input Method in Sublime Text 2 in Ubuntu

The Linux version is Ubuntu 13.04 beta 2, and fcitx sogou input method is installed by the way. However, it is found that Chinese characters cannot be entered in sublime text 2. fcitx entered normally in Ubuntu 12.04.2, but there are some minor issues.

Based on the principle of finding and solving the problem, we can find a solution. After posting on Google and the Forum, we found a solution.

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

Compile a shared library

1. Save the following code as a sublime-imfix.c File

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

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

Sudo apt-get install build-essential

Sudo apt-get install libgtk2.0-dev

3. Compile the Shared Library

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

4. Start Sublime Text 2

Now, run the following command to start Sublime Text 2. You can use fcitx to enter Chinese characters!

LD_PRELOAD =./libsublime-imfix.so sublime_text

But in this case, every time we have to use the command in the terminal to start sublime text 2, this is very inconvenient, next we also need to modify the sublime-text-2.desktop to reach click the icon to start.

Open terminal go to applications modify sublime-text-2.desktop

Cd/usr/share/applications

Sudo vim sublime-text-2.desktop.

After opening the sublime-text-2.desktop

Exec =/usr/bin/sublime-text-2% F

Change

Exec = bash-c 'LD _ PRELOAD =/usr/lib/libsublime-imfix.so/usr/bin/sublime-text-2' % F

In addition

Exec =/usr/bin/sublime-text-2 -- new-window

Change

Exec = bash-c 'LD _ PRELOAD =/usr/lib/libsublime-imfix.so/usr/bin/sublime-text-2' -- new-window

Now, click sublime text2 in dash to start your code journey.

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.