st-ime-20190202-3be4cf1.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       st-ime-20190202-3be4cf1.diff (3994B)
       ---
            1 diff --git a/st.c b/st.c
            2 index b8e6077..cf8687e 100644
            3 --- a/st.c
            4 +++ b/st.c
            5 @@ -2594,6 +2594,7 @@ draw(void)
            6                          term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
            7          term.ocx = cx, term.ocy = term.c.y;
            8          xfinishdraw();
            9 +        xximspot(term.ocx, term.ocy);
           10  }
           11  
           12  void
           13 diff --git a/win.h b/win.h
           14 index 31f327d..a6ef1b9 100644
           15 --- a/win.h
           16 +++ b/win.h
           17 @@ -36,3 +36,4 @@ void xsetmode(int, unsigned int);
           18  void xsetpointermotion(int);
           19  void xsetsel(char *);
           20  int xstartdraw(void);
           21 +void xximspot(int, int);
           22 diff --git a/x.c b/x.c
           23 index 0422421..315ea91 100644
           24 --- a/x.c
           25 +++ b/x.c
           26 @@ -139,6 +139,9 @@ static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
           27  static void xdrawglyph(Glyph, int, int);
           28  static void xclear(int, int, int, int);
           29  static int xgeommasktogravity(int);
           30 +static void ximopen(Display *);
           31 +static void ximinstantiate(Display *, XPointer, XPointer);
           32 +static void ximdestroy(XIM, XPointer, XPointer);
           33  static void xinit(int, int);
           34  static void cresize(int, int);
           35  static void xresize(int, int);
           36 @@ -996,6 +999,46 @@ xunloadfonts(void)
           37          xunloadfont(&dc.ibfont);
           38  }
           39  
           40 +void
           41 +ximopen(Display *dpy)
           42 +{
           43 +        XIMCallback destroy = { .client_data = NULL, .callback = ximdestroy };
           44 +
           45 +        if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
           46 +                XSetLocaleModifiers("@im=local");
           47 +                if ((xw.xim =  XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
           48 +                        XSetLocaleModifiers("@im=");
           49 +                        if ((xw.xim = XOpenIM(xw.dpy,
           50 +                                        NULL, NULL, NULL)) == NULL) {
           51 +                                die("XOpenIM failed. Could not open input"
           52 +                                        " device.\n");
           53 +                        }
           54 +                }
           55 +        }
           56 +        if (XSetIMValues(xw.xim, XNDestroyCallback, &destroy, NULL) != NULL)
           57 +                die("XSetIMValues failed. Could not set input method value.\n");
           58 +        xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
           59 +                                XNClientWindow, xw.win, XNFocusWindow, xw.win, NULL);
           60 +        if (xw.xic == NULL)
           61 +                die("XCreateIC failed. Could not obtain input method.\n");
           62 +}
           63 +
           64 +void
           65 +ximinstantiate(Display *dpy, XPointer client, XPointer call)
           66 +{
           67 +        ximopen(dpy);
           68 +        XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
           69 +                                        ximinstantiate, NULL);
           70 +}
           71 +
           72 +void
           73 +ximdestroy(XIM xim, XPointer client, XPointer call)
           74 +{
           75 +        xw.xim = NULL;
           76 +        XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
           77 +                                        ximinstantiate, NULL);
           78 +}
           79 +
           80  void
           81  xinit(int cols, int rows)
           82  {
           83 @@ -1033,7 +1076,7 @@ xinit(int cols, int rows)
           84          xw.attrs.background_pixel = dc.col[defaultbg].pixel;
           85          xw.attrs.border_pixel = dc.col[defaultbg].pixel;
           86          xw.attrs.bit_gravity = NorthWestGravity;
           87 -        xw.attrs.event_mask = FocusChangeMask | KeyPressMask
           88 +        xw.attrs.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
           89                  | ExposureMask | VisibilityChangeMask | StructureNotifyMask
           90                  | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
           91          xw.attrs.colormap = xw.cmap;
           92 @@ -1061,22 +1104,7 @@ xinit(int cols, int rows)
           93          xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
           94  
           95          /* input methods */
           96 -        if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
           97 -                XSetLocaleModifiers("@im=local");
           98 -                if ((xw.xim =  XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
           99 -                        XSetLocaleModifiers("@im=");
          100 -                        if ((xw.xim = XOpenIM(xw.dpy,
          101 -                                        NULL, NULL, NULL)) == NULL) {
          102 -                                die("XOpenIM failed. Could not open input"
          103 -                                        " device.\n");
          104 -                        }
          105 -                }
          106 -        }
          107 -        xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing
          108 -                                           | XIMStatusNothing, XNClientWindow, xw.win,
          109 -                                           XNFocusWindow, xw.win, NULL);
          110 -        if (xw.xic == NULL)
          111 -                die("XCreateIC failed. Could not obtain input method.\n");
          112 +        ximopen(xw.dpy);
          113  
          114          /* white cursor, black outline */
          115          cursor = XCreateFontCursor(xw.dpy, mouseshape);
          116 @@ -1554,6 +1582,16 @@ xfinishdraw(void)
          117                                  defaultfg : defaultbg].pixel);
          118  }
          119  
          120 +void
          121 +xximspot(int x, int y)
          122 +{
          123 +        XPoint spot = { borderpx + x * win.cw, borderpx + (y + 1) * win.ch };
          124 +        XVaNestedList attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
          125 +
          126 +        XSetICValues(xw.xic, XNPreeditAttributes, attr, NULL);
          127 +        XFree(attr);
          128 +}
          129 +
          130  void
          131  expose(XEvent *ev)
          132  {