zoukankan      html  css  js  c++  java
  • ubuntu 12.04 支持中文----完胜版

    原文地址 http://pobeta.com/ubuntu-sublime.html,

     1    
     2 
     3     /*
     4     sublime-imfix.c
     5     Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.
     6     By Cjacker Huang <jianzhong.huang at i-soft.com.cn>
     7 
     8     gcc -shared -o libsublime-imfix.so sublime_imfix.c  `pkg-config --libs --cflags gtk+-2.0` -fPIC
     9     LD_PRELOAD=./libsublime-imfix.so sublime_text
    10     */
    11     #include <gtk/gtk.h>
    12     #include <gdk/gdkx.h>
    13     typedef GdkSegment GdkRegionBox;
    14 
    15     struct _GdkRegion
    16     {
    17       long size;
    18       long numRects;
    19       GdkRegionBox *rects;
    20       GdkRegionBox extents;
    21     };
    22 
    23     GtkIMContext *local_context;
    24 
    25     void
    26     gdk_region_get_clipbox (const GdkRegion *region,
    27                 GdkRectangle    *rectangle)
    28     {
    29       g_return_if_fail (region != NULL);
    30       g_return_if_fail (rectangle != NULL);
    31 
    32       rectangle->x = region->extents.x1;
    33       rectangle->y = region->extents.y1;
    34       rectangle->width = region->extents.x2 - region->extents.x1;
    35       rectangle->height = region->extents.y2 - region->extents.y1;
    36       GdkRectangle rect;
    37       rect.x = rectangle->x;
    38       rect.y = rectangle->y;
    39       rect.width = 0;
    40       rect.height = rectangle->height;
    41       //The caret width is 2;
    42       //Maybe sometimes we will make a mistake, but for most of the time, it should be the caret.
    43       if(rectangle->width == 2 && GTK_IS_IM_CONTEXT(local_context)) {
    44             gtk_im_context_set_cursor_location(local_context, rectangle);
    45       }
    46     }
    47 
    48     //this is needed, for example, if you input something in file dialog and return back the edit area
    49     //context will lost, so here we set it again.
    50 
    51     static GdkFilterReturn event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer im_context)
    52     {
    53         XEvent *xev = (XEvent *)xevent;
    54         if(xev->type == KeyRelease && GTK_IS_IM_CONTEXT(im_context)) {
    55            GdkWindow * win = g_object_get_data(G_OBJECT(im_context),"window");
    56            if(GDK_IS_WINDOW(win))
    57              gtk_im_context_set_client_window(im_context, win);
    58         }
    59         return GDK_FILTER_CONTINUE;
    60     }
    61 
    62     void gtk_im_context_set_client_window (GtkIMContext *context,
    63               GdkWindow    *window)
    64     {
    65       GtkIMContextClass *klass;
    66       g_return_if_fail (GTK_IS_IM_CONTEXT (context));
    67       klass = GTK_IM_CONTEXT_GET_CLASS (context);
    68       if (klass->set_client_window)
    69         klass->set_client_window (context, window);
    70 
    71       if(!GDK_IS_WINDOW (window))
    72         return;
    73       g_object_set_data(G_OBJECT(context),"window",window);
    74       int width = gdk_window_get_width(window);
    75       int height = gdk_window_get_height(window);
    76       if(width != 0 && height !=0) {
    77         gtk_im_context_focus_in(context);
    78         local_context = context;
    79       }
    80       gdk_window_add_filter (window, event_filter, context);
    81     }
    82 
    83 
    84 2.编译成共享库
    85 
    86     gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC 
    87 
    88 3.执行
    89 
    90     LD_PRELOAD=./libsublime-imfix.so sublime_text(看自己的在什么位置,叫做什么名字)
     1 . 如果每次执行sublime 都要执行上面第三步中的“执行”的话,很麻烦。
     2 
     3     所以我们建立一个脚本文件subl(无扩展名),文件内容为:
     4 
     5     #!/bin/bash
     6     sh -c "LD_PRELOAD=/home/allen/sublime-text/libsublime-imfix.so /home/allen/sublime-text/sublime_text"
     7

    chmod -R 777 subl;

    在终端运行

  • 相关阅读:
    java学习day02---Spring Boot综合运用---活动模块
    java学习day01---GC
    课程学习总结报告
    结合中断上下文切换和进程上下文切换分析Linux内核的一般执行过程
    深入理解系统调用
    基于mykernel 2.0编写一个操作系统内核
    超码 候选码 主码 替换码 数据库 定义
    如何评测软件工程知识技能水平?
    创新产品的需求分析:未来的图书会是什么样子?
    案例分析:设计模式与代码的结构特性(桥接模式)
  • 原文地址:https://www.cnblogs.com/zhangjun516/p/3213660.html
Copyright © 2011-2022 走看看