1. 程式人生 > >ubuntu 系統在 Sublime Text 中不能輸入中文的解決辦法

ubuntu 系統在 Sublime Text 中不能輸入中文的解決辦法

本人親測的系統為ubuntu14.04 和ubuntu16.04

輸入法使用的是:搜狗輸入法

具體步驟如下:

1 在~目錄下建立 sublime-imfix.c 檔案,並將下面的程式碼拷貝進去儲存.

 /*
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 subl
*/
#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 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);
}

2  安裝 C/C++ 的編譯環境和 gtk libgtk2.0-dev

sudo apt-get install build-essential
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

上面命令執行後會生成 libsublime-imfix.so 檔案 然後將 libsublime-imfix.so 放到 /opt/sublime_text/ 中

4  

修改 /usr/bin/subl 為

#!/bin/sh

export LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so
exec /opt/sublime_text/sublime_text "[email protected]"

5 修改 /usr/share/applications/sublime_text.desktop 檔案中Desktop Entry,Desktop Action Window,Desktop Action Document中的Exce為如下內容:

複製程式碼
[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
[...]

6 重啟電腦即可(有時候不一定需要重啟,可自己試一下能不能輸入中文即可)

注意:

修改時請注意雙引號>"",否則會導致不能開啟帶有空格檔名的檔案。

此處僅修改了>/usr/share/applications/sublime-text.desktop,但可以正常使用了。

opt/sublime_text/目錄下的>sublime-text.desktop可以修改,也可不修改。


相關推薦

Ubuntu安裝Sublime Text輸入中文

中文 bject data- gen 能夠 ppa microsoft windows bin Sumblime Text3是一款傳說中的神級代碼編輯器,具有

Ubuntu安裝“Sublime Text 3”,並解決Sublime Text 3無法輸入中文的問題

##一、“Sublime Text 3”的安裝 ####1. 官網下載程式解壓到自己的軟體目錄下(比如"~/Software") ####2. 進入sublimetext目錄中,即可執行: $ cd ~/Software/sublime_text_3 $ ./sublime_text

python連接ubuntu系統的mysql出現錯誤的解決辦法

出現 pro http 監聽 image com 虛擬機 add alt 出現這種錯誤 首先查看虛擬機的端口是否打開 防火墻是否關閉 賬號和密碼是都正確 如果正確 ,還是不行 就可能是mysql的權限問題了 首先,查看mysql的遠程登錄問題 在mysql中設置gra

Snap Build Your Own Blocks輸入中文解決辦法

val 它的 解決方法 關心 信息 span 技術分享 應該 輸出 Snap Build Your Own Blocks輸入中文解決辦法 Snap! (formerly BYOB) is a visual, drag-and-drop programming languag

【Virtualbox虛擬機器Ubuntu系統安裝VBoxGuestAdditions.iso增強包解決辦法

如果在系統啟動介面,點選“裝置”出現下面“安裝增強包功能”出現錯誤,那麼則採用以下方法! 【1】進入安裝好的系統,Ctrl+Alt+T開啟終端,sudo su 進入root 許可權,ls  /medi

CMD下無法輸入中文解決辦法

CMD.EXE 命令提示符程式發現不能輸入漢字,而且出現中文資訊就是"?"亂碼,DOS命令幫助全成了英文,不能在 CMD 命令提示符下輸入中文進入中文命名的資料夾等中文字元的問題。 1. 出現中文資訊就是"?"亂碼,DOS命令幫助全成了英文 解決方法就是將下面的內容複

Ubuntu系統開機進入grub rescue模式解決辦法

Ubuntu系統開機後進入"grub rescue>"模式?肯定是grub開機管理程式出問題了,出現這種問題也不用急著重灌系統,還有解救辦法。下面我就描述下自己的經歷吧。 我們有10臺普通PC機用作伺服器(OS為Ubuntu 12.04 LTS),之前安裝系統的時候沒

ubuntu系統無法訪問無法磁碟最佳解決辦法

出現如下錯誤: Error mounting /dev/sda8 at /media/fzh/System: Command-line `mount -t "ntfs" -o "uhelper=udisks2,nodev,nosuid,uid=1000,gid=1000" "/dev/sda8" "/me

ubuntu 系統Sublime Text 不能輸入中文解決辦法

本人親測的系統為ubuntu14.04 和ubuntu16.04 輸入法使用的是:搜狗輸入法 具體步驟如下: 1 在~目錄下建立 sublime-imfix.c 檔案,並將下面的程式碼拷貝進去儲存.  /* sublime-imfix.c Use LD_PRELOAD to

解決openSUSESublime Text 3的中文顯示和輸入問題

ase continue opensuse back .so文件 text 裏的 測試 mes Sublime Text 2是免安裝的,下載完解壓就可以了。我這邊解壓路徑是/home/fhp/App/SublimeText2 為了能在終端直接使用sublime

ubuntu技巧--sublime text 3 解決中文輸入

適用於新安裝的系統,要是做了很多操作,那就不好說了 換成163的源,更新, language support裡新增中文,介面語言是不必設為中文的 到http://pinyin.sogou.com/linux/?r=pinyin下載deb包安裝 langu

解決UbuntuSublime Text 3無法輸入中文

sublime很好用,但是ubuntu下不能輸入中文,這是一個很大的問題。不知道為什麼開發著一直也不解決,好在還是有高手在,總能找到方法。網上方法很多,但是也很亂,現在我將自己的經驗總結一下。 首先,我參考了好幾篇文章,都是蠻不錯的,先列出來: 我的方法 1.下載我們需要的

UbuntuSublime Text 中文輸入 問題

參考網址 : https://github.com/lyfeyaj/sublime-text-imfix 1.依次執行如下命令,在上面git網址有usage用法,此處copy過來 sudo apt-get update && sudo apt-get upgrad

解決Linux下Sublime text 3的中文輸入問題

Sublime Text幾乎是我現在唯一用的程式碼&文字編輯器了,功能強大而又不失簡約。但其在Linux下對中文輸入不支援一直很讓人蛋疼,一般寫程式碼無所謂支不支援中文,但是我想把所有的文字工作都交給Sublime Text,這就必然離不開中文輸入了。 今天解決了一下它的中文支援問題,補丁方

ubuntu MySQL數據庫輸入中文亂碼 解決方案

title str itl alt 查詢 ref cte class nbsp 一、登錄MySQL查看用SHOW VARIABLES LIKE ‘character%’;下字符集,顯示如下:+--------------------------+--------------

Mac系統 Sublime Text 3 控制臺無法輸出中文該怎麽處理

ioe 輸出 error not encoding [ ] uil 解決 osi 電腦配置 MacBook Pro (Retina, 15-inch, Mid 2015)系統版本 10.13.2 我在本機安裝了sublime text3 為python3.6 配置了一編譯系

Sublime Text 安裝失敗的解決

一般是輸入的程式碼問題 更新後的程式碼: import urllib.request,os,hashlib; h = ‘6f4c264a24d933ce70df5dedcf1dcaeeebe013ee18cced0ef93d5f746d80ef60’; pf = ‘Package Contr

如何解決MySQL輸入中文報錯的情況1366 (HY000): Incorrect string value

如何在MySQL中輸入中文 經過我的不斷摸索,在MySQL建表後,往表中的varchar(255)中輸入中文時報錯,大概是因為資料庫的預設編碼模式是latin1而不是utf8。所以其它部落格就會叫你去修改my.ini配置檔案裡的資訊,或者說在MySQL介面裡設定,如下: MySQL查

Ubuntu下 QT Creater 不能輸入中文解決方法

參考連結:https://blog.csdn.net/amusi1994/article/details/78147696 1. 安裝 fcitx-frontend-qt5 我沒有執行 sudo apt-get install fcitx-frontend-qt5 ,因為我安裝的是

ubuntu 16.04下搜狗輸入法不能輸入中文解決(linux下常見軟體崩潰問題解決方案)

之前一段時間正常使用的搜狗輸入法突然無法輸出中文(具體現象是,可以撥出搜狗輸入法介面,但是候選詞列表無顯示),解決之後記錄下來,希望能為同樣遇到這個問題的人提供參考 我的系統是 ubuntu 16.04 LTS, 搜狗版本: sogoupi