After installing the Sublimetext 3 in Ubuntu 14.04, I found that since I did not support the input of Chinese, I found that many people encountered the same problem, but there was only one solution. The following are summarized according to their own installation and solution:
1. Installation of Sublimetext 3
Ubuntu14.04
Sogou IME for Linux
Sublime Text 3
2. Copy the following code into the file Sublime-imfix.c file, which needs to be created by itself and can be placed anywhere.
/*
* 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'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.
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. Compiling
Compile the file as described in the comment on the file header, enter the directory where the file is stored in the terminal, and enter the following command:
gcc-shared-o libsublime-imfix.so sublime_imfix.c ' pkg-config--libs--cflags gtk+-2.0 '-fPIC
Finally get libsublime-imfix.so this shared library in the current directory.
4. right mouse button open support Chinese
Here you'll find a simple way to modify the icon connection to quickly open the sublimetext. Copy the libsublime-imfix.so to the default path in the system library:
sudo cp libsublime-imfix.so/usr/lib/
Modify the/usr/share/applications/sublime_text.desktop file
sudo vim/usr/share/applications/sublime_text.desktop
After opening, change the Exec=/opt/sublime_text/sublime_text%f revision to
Exec=bash-c ' Ld_preload=/usr/lib/libsublime-imfix.so/opt/sublime_text/sublime_text '%F
Change the exec=/opt/sublime_text/sublime_text-n revision to
Exec=bash-c ' Ld_preload=/usr/lib/libsublime-imfix.so/opt/sublime_text/sublime_text '-n
This allows you to open Sublimetext 3 with a shortcut to support Chinese input.
5. Command line open support Chinese
Modify the contents of a file/usr/bin/subl
sudo gedit/usr/bin/subl
Will
#!/bin/sh
exec/opt/sublime_text/sublime_text "[email protected]"
Revision changed to
#!/bin/sh
ld_preload=/opt/sublime_text/libsublime-imfix.so exec/opt/sublime_text/sublime_text "[Email protected]"
At this point, executing subl in the command will be able to use Sogou for Linux Chinese input
This article from the "Technology is tossing" blog, reproduced please contact the author!
Enables Sublimetext 3 to support Chinese input method in Ubuntu 14.04