Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the Chinese input problem of Sublime Text under Linux

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to solve the Chinese input problem of Sublime Text under Linux". In the daily operation, I believe that many people have doubts about how to solve the Chinese input problem of Sublime Text under Linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to solve the Chinese input problem of Sublime Text under Linux". Next, please follow the editor to study!

1. Save the following code as sublime_imfix.c

The code is as follows:

/ *

Sublime-imfix.c

Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.

By Cjacker Huang

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

# include

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

}

two。 Compile the dynamic library:

The code is as follows:

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

3. Set up LD_PRELOAD and start Sublime Text:

The code is as follows:

LD_PRELOAD=./libsublime-imfix.so sublime_text

In order not to type such a long list of things every time you start Sublime Text, write a script to start Sublime:

The code is as follows:

#! / bin/bash

SUBLIME_HOME= "/ opt/sublime_text"

LD_LIB=$SUBLIME_HOME/libsublime-imfix.so

Sh-c "LD_PRELOAD=$LD_LIB $SUBLIME_HOME/sublime_text $@"

Put libsublime-imfix.so in the Sublime Text directory and modify the SUBLIME_HOME in the script so that Sublime Text can enter Chinese.

At this point, the study on "how to solve the Chinese input problem of Sublime Text under Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report