logo

etc_portage

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/etc_portage.git

0001-better-Input-Method-Editor-IME-support.patch (4610B)


  1. From e85b6b64660214121164ea97fb098eaa4935f7db Mon Sep 17 00:00:00 2001
  2. From: Ivan Tham <pickfire@riseup.net>
  3. Date: Tue, 12 Feb 2019 18:41:41 +0100
  4. Subject: [PATCH 1/5] better Input Method Editor (IME) support
  5. Features:
  6. - Allow input methods swap with hotkey (E.g. left ctrl + left shift).
  7. - Over-the-spot pre-editing style, pre-edit data placed over insertion point.
  8. - Restart IME without segmentation fault.
  9. TODO:
  10. - Automatically pickup IME if st started before IME
  11. ---
  12. st.c | 1 +
  13. win.h | 1 +
  14. x.c | 69 ++++++++++++++++++++++++++++++++++++++++++++---------------
  15. 3 files changed, 54 insertions(+), 17 deletions(-)
  16. diff --git a/st.c b/st.c
  17. index b8e6077..cf8687e 100644
  18. --- a/st.c
  19. +++ b/st.c
  20. @@ -2594,6 +2594,7 @@ draw(void)
  21. term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
  22. term.ocx = cx, term.ocy = term.c.y;
  23. xfinishdraw();
  24. + xximspot(term.ocx, term.ocy);
  25. }
  26. void
  27. diff --git a/win.h b/win.h
  28. index 31f327d..a6ef1b9 100644
  29. --- a/win.h
  30. +++ b/win.h
  31. @@ -36,3 +36,4 @@ void xsetmode(int, unsigned int);
  32. void xsetpointermotion(int);
  33. void xsetsel(char *);
  34. int xstartdraw(void);
  35. +void xximspot(int, int);
  36. diff --git a/x.c b/x.c
  37. index 0422421..865dacc 100644
  38. --- a/x.c
  39. +++ b/x.c
  40. @@ -139,6 +139,9 @@ static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
  41. static void xdrawglyph(Glyph, int, int);
  42. static void xclear(int, int, int, int);
  43. static int xgeommasktogravity(int);
  44. +static void ximopen(Display *);
  45. +static void ximinstantiate(Display *, XPointer, XPointer);
  46. +static void ximdestroy(XIM, XPointer, XPointer);
  47. static void xinit(int, int);
  48. static void cresize(int, int);
  49. static void xresize(int, int);
  50. @@ -996,6 +999,43 @@ xunloadfonts(void)
  51. xunloadfont(&dc.ibfont);
  52. }
  53. +void
  54. +ximopen(Display *dpy)
  55. +{
  56. + XIMCallback destroy = { .client_data = NULL, .callback = ximdestroy };
  57. +
  58. + if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
  59. + XSetLocaleModifiers("@im=local");
  60. + if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
  61. + XSetLocaleModifiers("@im=");
  62. + if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL)
  63. + die("XOpenIM failed. Could not open input device.\n");
  64. + }
  65. + }
  66. + if (XSetIMValues(xw.xim, XNDestroyCallback, &destroy, NULL) != NULL)
  67. + die("XSetIMValues failed. Could not set input method value.\n");
  68. + xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
  69. + XNClientWindow, xw.win, XNFocusWindow, xw.win, NULL);
  70. + if (xw.xic == NULL)
  71. + die("XCreateIC failed. Could not obtain input method.\n");
  72. +}
  73. +
  74. +void
  75. +ximinstantiate(Display *dpy, XPointer client, XPointer call)
  76. +{
  77. + ximopen(dpy);
  78. + XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
  79. + ximinstantiate, NULL);
  80. +}
  81. +
  82. +void
  83. +ximdestroy(XIM xim, XPointer client, XPointer call)
  84. +{
  85. + xw.xim = NULL;
  86. + XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
  87. + ximinstantiate, NULL);
  88. +}
  89. +
  90. void
  91. xinit(int cols, int rows)
  92. {
  93. @@ -1033,7 +1073,7 @@ xinit(int cols, int rows)
  94. xw.attrs.background_pixel = dc.col[defaultbg].pixel;
  95. xw.attrs.border_pixel = dc.col[defaultbg].pixel;
  96. xw.attrs.bit_gravity = NorthWestGravity;
  97. - xw.attrs.event_mask = FocusChangeMask | KeyPressMask
  98. + xw.attrs.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
  99. | ExposureMask | VisibilityChangeMask | StructureNotifyMask
  100. | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
  101. xw.attrs.colormap = xw.cmap;
  102. @@ -1061,22 +1101,7 @@ xinit(int cols, int rows)
  103. xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
  104. /* input methods */
  105. - if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
  106. - XSetLocaleModifiers("@im=local");
  107. - if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
  108. - XSetLocaleModifiers("@im=");
  109. - if ((xw.xim = XOpenIM(xw.dpy,
  110. - NULL, NULL, NULL)) == NULL) {
  111. - die("XOpenIM failed. Could not open input"
  112. - " device.\n");
  113. - }
  114. - }
  115. - }
  116. - xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing
  117. - | XIMStatusNothing, XNClientWindow, xw.win,
  118. - XNFocusWindow, xw.win, NULL);
  119. - if (xw.xic == NULL)
  120. - die("XCreateIC failed. Could not obtain input method.\n");
  121. + ximopen(xw.dpy);
  122. /* white cursor, black outline */
  123. cursor = XCreateFontCursor(xw.dpy, mouseshape);
  124. @@ -1554,6 +1579,16 @@ xfinishdraw(void)
  125. defaultfg : defaultbg].pixel);
  126. }
  127. +void
  128. +xximspot(int x, int y)
  129. +{
  130. + XPoint spot = { borderpx + x * win.cw, borderpx + (y + 1) * win.ch };
  131. + XVaNestedList attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
  132. +
  133. + XSetICValues(xw.xic, XNPreeditAttributes, attr, NULL);
  134. + XFree(attr);
  135. +}
  136. +
  137. void
  138. expose(XEvent *ev)
  139. {
  140. --
  141. 2.21.0