ubuntu15.04 under Sublime text cannot be entered in Chinese solution

Source: Internet
Author: User
Tags gtk sublime text

Because the input focus of the Chinese input method cannot be inserted into the sublime input window, you need to force the insertion of the input focus using code.
The code is provided by Cjacker, you can see the original discussion posts:

http://www.sublimetext.com/forum/viewtopic.php?f=3&t=7006&start=10#p41343

1. Save code to file 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+-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 make a mistake, but for most of the "time", it should 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 your input something in file dialog and return to the edit area//cont

    Ext'll 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) {Gtkim
      Contextclass *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. Compile to Shared library

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

3. Loading into the sublime program using the Ld_preload method:

Ld_preload=./libsublime-imfix.so Sublime_text

Because I typically invoke the SUBL batch program in the console, the only way to do this is to change the contents of the SUBL directly:
1. Open the Subl file with the editor:

sudo subl $ (which Subl)

2. Modify the contents of Subl:

#!/bin/bash
ld_preload=/opt/sublime_text/libsublime-imfix.so exec/opt/sublime_text/sublime_text "$@"

3. Copy the shared library file generated above to the specified directory

In the future, you can start the sublime text program directly with SUBL, and you can enter Chinese.

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.