知识库

个人知识管理

用户工具

站点工具


博客:sublime_text3_无法输中文

sublime text3 ubuntu下无法输中文的解决方案

解决方案

1. 保存如下代码到sublime_imfix.c

#include <gtk/gtkimcontext.h>
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);
  g_object_set_data(G_OBJECT(context),"window",window);
 
  if(!GDK_IS_WINDOW (window))
      return;
  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);
}

2. 安装编译需要的头文件所在包libgtk2.0-dev

sudo apt-get install libgtk2.0-dev

3. 编译

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

4. 将编译后的so文件放入sublime安装目录下

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

此时,如果通过命令行`subl`启动sublime,将可以使用搜狗for linux的中文输入。

5. 修改文件sublime_text.desktop中的Exec一栏的内容

[Desktop Entry]
Version=1.0
Type=Application
Name=Sublime Text
GenericName=Text Editor
Comment=Sophisticated text editor for code, markup and prose
Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text %F"
Terminal=false
MimeType=text/plain;
Icon=sublime-text
Categories=TextEditor;Development;
StartupNotify=true
Actions=Window;Document;

[Desktop Action Window]
Name=New Window
Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text -nb"
OnlyShowIn=Unity;

[Desktop Action Document]
Name=New File
Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text --command new_file"
OnlyShowIn=Unity;

参考引用

博客/sublime_text3_无法输中文.txt · 最后更改: 2019/09/11 00:49 (外部编辑)