Ubuntu installs sublime and resolves Chinese input issues

Source: Internet
Author: User
Tags gtk sublime text

1 Adding a source

sudo add-apt-repository ppa:webupd8team/sublime-text-2

2 Installing Sublime

sudo apt-get update

sudo apt-get install Sublime-text

3. Solve Chinese input problem

3.1 Save the following code to the file sublime_imfix.c

/*
sublime-imfix.c
Use the 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 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.

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

3.2 compile the code from the previous step into the shared library libsublime-imfix.so, with the following command:

1, cd ~

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

3.3 then copy the libsublime-imfix.so to the folder where Sublime_text is located

sudo mv libsublime-imfix.so/opt/sublime_text_2/

3.4 Modifying the contents of a file/usr/bin/subl

Will #!/bin/sh

/opt/sublime_text_2/sublime_text "[Email protected]"

Revision changed to

#!/bin/sh

ld_preload=/opt/sublime_text_2/libsublime-imfix.so exec/opt/sublime_text_2/sublime_text "[Email protected]"

3.5 Restart the computer, you can now enter Chinese in sublime text 2

Ubuntu installs sublime and resolves Chinese input issues

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.