Perfect solution for Linux under Sublime Text Chinese input

Source: Internet
Author: User
Tags gtk sublime text

Article turned from: https://www.sinosky.org/linux-sublime-text-fcitx.html

Test system: Ubuntu 12.10 (theoretically all Linux distributions are generic)

Input Method: Fcitx 4.2.6.1

Sublime text version: Sublime text 3 dev (Build 3026)

--------------------------------------------------------------------

My Computer Configuration is: linuxMint17.1

Input Method: Sogou Input Method

Sublime text version: Sublime text 3

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

/*Sublime-imfix.cuse ld_preload to interpose some function to fix sublime Input method support for Linux. by Cjacker huanggcc-shared-o libsublime-imfix.so sublime-imfix.c ' pkg-config--libs--cflags gtk+-2.0 '-fPICLD_PRELOAD= ./libsublime-imfix.so Subl*/#include<gtk/gtk.h>#include<gdk/gdkx.h>typedef gdksegment Gdkregionbox;struct_gdkregion{Longsize; Longnumrects; Gdkregionbox*rects; Gdkregionbox extents;}; Gtkimcontext*Local_context;voidGdk_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 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.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);}

2. Install the C + + compiler environment and GTK Libgtk2.0-dev

sudo apt-get install build-essentialsudo apt-get install LIBGTK2. 0-dev

3. Compiling a shared internal library

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

4. Set ld_preload and start Sublime Text

Ld_preload=./libsublime-imfix.so Subl

5. Change /usr/share/applications/sublime_text.desktop to

[Desktop entry][...] Exec=env ld_preload=/opt/sublime_text/libsublime-imfix.so/opt/sublime_text/sublime_text%F[...] [Desktop Action Window] [...] Exec=env ld_preload=/opt/sublime_text/libsublime-imfix.so/opt/sublime_text/sublime_text-n[...] [Desktop Action Document] [...] Exec=env ld_preload=/opt/sublime_text/libsublime-imfix.so/opt/sublime_text/sublime_text--command New_ file[...]

Don't forget to put it libsublime-imfix.so /opt/sublime_text/ in the middle

6. Change /usr/bin/subl to

#!/bin/sh

Export ld_preload=/opt/sublime_text/libsublime-imfix.so
Exec/opt/sublime_text/sublime_text "[Email protected]"

Restart the computer, you can see sublime can input Chinese.

Perfect solution for Linux under Sublime Text Chinese input

Related Article

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.