logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0001-Port-to-wayland-using-wld.patch (125874B)


  1. From 86283aea345fd72e4889eee233daefc41615d979 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Sun, 30 Oct 2016 23:54:56 -0700
  4. Subject: [PATCH] Port to wayland using wld
  5. ---
  6. Makefile | 12 +-
  7. config.def.h | 500 ++++++-----
  8. config.mk | 12 +-
  9. st.c | 2366 +++++++++++++++++++++++++-------------------------
  10. 4 files changed, 1463 insertions(+), 1427 deletions(-)
  11. diff --git a/Makefile b/Makefile
  12. index fb026c4..053d3e0 100644
  13. --- a/Makefile
  14. +++ b/Makefile
  15. @@ -3,7 +3,7 @@
  16. include config.mk
  17. -SRC = st.c
  18. +SRC = st.c xdg-shell-unstable-v5-protocol.c
  19. OBJ = ${SRC:.c=.o}
  20. all: options st
  21. @@ -17,6 +17,16 @@ options:
  22. config.h:
  23. cp config.def.h config.h
  24. +xdg-shell-unstable-v5-protocol.c:
  25. + @echo GEN $@
  26. + @wayland-scanner code ${XDG_SHELL_PROTO} $@
  27. +
  28. +xdg-shell-unstable-v5-client-protocol.h:
  29. + @echo GEN $@
  30. + @wayland-scanner client-header ${XDG_SHELL_PROTO} $@
  31. +
  32. +st.o: xdg-shell-unstable-v5-client-protocol.h
  33. +
  34. .c.o:
  35. @echo CC $<
  36. @${CC} -c ${CFLAGS} $<
  37. diff --git a/config.def.h b/config.def.h
  38. index a719e36..49ca50b 100644
  39. --- a/config.def.h
  40. +++ b/config.def.h
  41. @@ -38,13 +38,13 @@ static char worddelimiters[] = " ";
  42. static unsigned int doubleclicktimeout = 300;
  43. static unsigned int tripleclicktimeout = 600;
  44. +/* key repeat timeouts (in milliseconds) */
  45. +static unsigned int keyrepeatdelay = 500;
  46. +static unsigned int keyrepeatinterval = 25;
  47. +
  48. /* alt screens */
  49. static int allowaltscreen = 1;
  50. -/* frames per second st should at maximum draw to the screen */
  51. -static unsigned int xfps = 120;
  52. -static unsigned int actionfps = 30;
  53. -
  54. /*
  55. * blinking timeout (set to 0 to disable blinking) for the terminal blinking
  56. * attribute.
  57. @@ -60,7 +60,9 @@ static unsigned int cursorthickness = 2;
  58. * bell volume. It must be a value between -100 and 100. Use 0 for disabling
  59. * it
  60. */
  61. -static int bellvolume = 0;
  62. +/* XXX: Wayland does not have a bell.
  63. + * static int bellvolume = 0;
  64. + */
  65. /* default TERM value */
  66. static char termname[] = "st-256color";
  67. @@ -138,11 +140,9 @@ static unsigned int cols = 80;
  68. static unsigned int rows = 24;
  69. /*
  70. - * Default colour and shape of the mouse cursor
  71. + * Default shape of the mouse cursor
  72. */
  73. -static unsigned int mouseshape = XC_xterm;
  74. -static unsigned int mousefg = 7;
  75. -static unsigned int mousebg = 0;
  76. +static char mouseshape[] = "xterm";
  77. /*
  78. * Color used to display font attributes when fontconfig selected a font which
  79. @@ -156,36 +156,38 @@ static unsigned int defaultattr = 11;
  80. */
  81. static MouseShortcut mshortcuts[] = {
  82. /* button mask string */
  83. - { Button4, XK_ANY_MOD, "\031" },
  84. - { Button5, XK_ANY_MOD, "\005" },
  85. + { -1, MOD_MASK_NONE, "" }
  86. +};
  87. +
  88. +static Axiskey ashortcuts[] = {
  89. + /* axis direction mask string */
  90. + { AXIS_VERTICAL, +1, MOD_MASK_ANY, "\031"},
  91. + { AXIS_VERTICAL, -1, MOD_MASK_ANY, "\005"},
  92. };
  93. /* Internal keyboard shortcuts. */
  94. -#define MODKEY Mod1Mask
  95. +#define MODKEY MOD_MASK_ALT
  96. static Shortcut shortcuts[] = {
  97. - /* mask keysym function argument */
  98. - { XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} },
  99. - { ControlMask, XK_Print, toggleprinter, {.i = 0} },
  100. - { ShiftMask, XK_Print, printscreen, {.i = 0} },
  101. - { XK_ANY_MOD, XK_Print, printsel, {.i = 0} },
  102. - { MODKEY|ShiftMask, XK_Prior, xzoom, {.f = +1} },
  103. - { MODKEY|ShiftMask, XK_Next, xzoom, {.f = -1} },
  104. - { MODKEY|ShiftMask, XK_Home, xzoomreset, {.f = 0} },
  105. - { ShiftMask, XK_Insert, selpaste, {.i = 0} },
  106. - { MODKEY|ShiftMask, XK_Insert, clippaste, {.i = 0} },
  107. - { MODKEY|ShiftMask, XK_C, clipcopy, {.i = 0} },
  108. - { MODKEY|ShiftMask, XK_V, clippaste, {.i = 0} },
  109. - { MODKEY, XK_Num_Lock, numlock, {.i = 0} },
  110. - { MODKEY, XK_Control_L, iso14755, {.i = 0} },
  111. + /* modifier key function argument */
  112. + { MOD_MASK_ANY, XKB_KEY_Break, sendbreak, {.i = 0} },
  113. + { MOD_MASK_CTRL, XKB_KEY_Print, toggleprinter, {.i = 0} },
  114. + { MOD_MASK_SHIFT, XKB_KEY_Print, printscreen, {.i = 0} },
  115. + { MOD_MASK_ANY, XKB_KEY_Print, printsel, {.i = 0} },
  116. + { MODKEY|MOD_MASK_SHIFT, XKB_KEY_Prior, wlzoom, {.f = +1} },
  117. + { MODKEY|MOD_MASK_SHIFT, XKB_KEY_Next, wlzoom, {.f = -1} },
  118. + { MODKEY|MOD_MASK_SHIFT, XKB_KEY_Home, wlzoomreset, {.f = 0} },
  119. + { MOD_MASK_SHIFT, XKB_KEY_Insert, selpaste, {.i = 0} },
  120. + { MODKEY, XKB_KEY_Num_Lock, numlock, {.i = 0} },
  121. + { MODKEY, XKB_KEY_Control_L, iso14755, {.i = 0} },
  122. };
  123. /*
  124. * Special keys (change & recompile st.info accordingly)
  125. *
  126. * Mask value:
  127. - * * Use XK_ANY_MOD to match the key no matter modifiers state
  128. - * * Use XK_NO_MOD to match the key alone (no modifiers)
  129. + * * Use MOD_MASK_ANY to match the key no matter modifiers state
  130. + * * Use MOD_MASK_NONE to match the key alone (no modifiers)
  131. * appkey value:
  132. * * 0: no value
  133. * * > 0: keypad application mode enabled
  134. @@ -201,7 +203,7 @@ static Shortcut shortcuts[] = {
  135. * * < 0: crlf mode is disabled
  136. *
  137. * Be careful with the order of the definitions because st searches in
  138. - * this table sequentially, so any XK_ANY_MOD must be in the last
  139. + * this table sequentially, so any MOD_MASK_ANY must be in the last
  140. * position for a key.
  141. */
  142. @@ -209,239 +211,233 @@ static Shortcut shortcuts[] = {
  143. * If you want keys other than the X11 function keys (0xFD00 - 0xFFFF)
  144. * to be mapped below, add them to this array.
  145. */
  146. -static KeySym mappedkeys[] = { -1 };
  147. +static xkb_keysym_t mappedkeys[] = { -1 };
  148. -/*
  149. - * State bits to ignore when matching key or button events. By default,
  150. - * numlock (Mod2Mask) and keyboard layout (XK_SWITCH_MOD) are ignored.
  151. - */
  152. -static uint ignoremod = Mod2Mask|XK_SWITCH_MOD;
  153. +/* State bits to ignore when matching key or button events. */
  154. +static uint ignoremod = 0;
  155. /*
  156. * Override mouse-select while mask is active (when MODE_MOUSE is set).
  157. - * Note that if you want to use ShiftMask with selmasks, set this to an other
  158. - * modifier, set to 0 to not use it.
  159. + * Note that if you want to use MOD_MASK_SHIFT with selmasks, set this to an
  160. + * other modifier, set to 0 to not use it.
  161. */
  162. -static uint forceselmod = ShiftMask;
  163. +static uint forceselmod = MOD_MASK_SHIFT;
  164. /*
  165. * This is the huge key array which defines all compatibility to the Linux
  166. * world. Please decide about changes wisely.
  167. */
  168. static Key key[] = {
  169. - /* keysym mask string appkey appcursor crlf */
  170. - { XK_KP_Home, ShiftMask, "\033[2J", 0, -1, 0},
  171. - { XK_KP_Home, ShiftMask, "\033[1;2H", 0, +1, 0},
  172. - { XK_KP_Home, XK_ANY_MOD, "\033[H", 0, -1, 0},
  173. - { XK_KP_Home, XK_ANY_MOD, "\033[1~", 0, +1, 0},
  174. - { XK_KP_Up, XK_ANY_MOD, "\033Ox", +1, 0, 0},
  175. - { XK_KP_Up, XK_ANY_MOD, "\033[A", 0, -1, 0},
  176. - { XK_KP_Up, XK_ANY_MOD, "\033OA", 0, +1, 0},
  177. - { XK_KP_Down, XK_ANY_MOD, "\033Or", +1, 0, 0},
  178. - { XK_KP_Down, XK_ANY_MOD, "\033[B", 0, -1, 0},
  179. - { XK_KP_Down, XK_ANY_MOD, "\033OB", 0, +1, 0},
  180. - { XK_KP_Left, XK_ANY_MOD, "\033Ot", +1, 0, 0},
  181. - { XK_KP_Left, XK_ANY_MOD, "\033[D", 0, -1, 0},
  182. - { XK_KP_Left, XK_ANY_MOD, "\033OD", 0, +1, 0},
  183. - { XK_KP_Right, XK_ANY_MOD, "\033Ov", +1, 0, 0},
  184. - { XK_KP_Right, XK_ANY_MOD, "\033[C", 0, -1, 0},
  185. - { XK_KP_Right, XK_ANY_MOD, "\033OC", 0, +1, 0},
  186. - { XK_KP_Prior, ShiftMask, "\033[5;2~", 0, 0, 0},
  187. - { XK_KP_Prior, XK_ANY_MOD, "\033[5~", 0, 0, 0},
  188. - { XK_KP_Begin, XK_ANY_MOD, "\033[E", 0, 0, 0},
  189. - { XK_KP_End, ControlMask, "\033[J", -1, 0, 0},
  190. - { XK_KP_End, ControlMask, "\033[1;5F", +1, 0, 0},
  191. - { XK_KP_End, ShiftMask, "\033[K", -1, 0, 0},
  192. - { XK_KP_End, ShiftMask, "\033[1;2F", +1, 0, 0},
  193. - { XK_KP_End, XK_ANY_MOD, "\033[4~", 0, 0, 0},
  194. - { XK_KP_Next, ShiftMask, "\033[6;2~", 0, 0, 0},
  195. - { XK_KP_Next, XK_ANY_MOD, "\033[6~", 0, 0, 0},
  196. - { XK_KP_Insert, ShiftMask, "\033[2;2~", +1, 0, 0},
  197. - { XK_KP_Insert, ShiftMask, "\033[4l", -1, 0, 0},
  198. - { XK_KP_Insert, ControlMask, "\033[L", -1, 0, 0},
  199. - { XK_KP_Insert, ControlMask, "\033[2;5~", +1, 0, 0},
  200. - { XK_KP_Insert, XK_ANY_MOD, "\033[4h", -1, 0, 0},
  201. - { XK_KP_Insert, XK_ANY_MOD, "\033[2~", +1, 0, 0},
  202. - { XK_KP_Delete, ControlMask, "\033[M", -1, 0, 0},
  203. - { XK_KP_Delete, ControlMask, "\033[3;5~", +1, 0, 0},
  204. - { XK_KP_Delete, ShiftMask, "\033[2K", -1, 0, 0},
  205. - { XK_KP_Delete, ShiftMask, "\033[3;2~", +1, 0, 0},
  206. - { XK_KP_Delete, XK_ANY_MOD, "\033[P", -1, 0, 0},
  207. - { XK_KP_Delete, XK_ANY_MOD, "\033[3~", +1, 0, 0},
  208. - { XK_KP_Multiply, XK_ANY_MOD, "\033Oj", +2, 0, 0},
  209. - { XK_KP_Add, XK_ANY_MOD, "\033Ok", +2, 0, 0},
  210. - { XK_KP_Enter, XK_ANY_MOD, "\033OM", +2, 0, 0},
  211. - { XK_KP_Enter, XK_ANY_MOD, "\r", -1, 0, -1},
  212. - { XK_KP_Enter, XK_ANY_MOD, "\r\n", -1, 0, +1},
  213. - { XK_KP_Subtract, XK_ANY_MOD, "\033Om", +2, 0, 0},
  214. - { XK_KP_Decimal, XK_ANY_MOD, "\033On", +2, 0, 0},
  215. - { XK_KP_Divide, XK_ANY_MOD, "\033Oo", +2, 0, 0},
  216. - { XK_KP_0, XK_ANY_MOD, "\033Op", +2, 0, 0},
  217. - { XK_KP_1, XK_ANY_MOD, "\033Oq", +2, 0, 0},
  218. - { XK_KP_2, XK_ANY_MOD, "\033Or", +2, 0, 0},
  219. - { XK_KP_3, XK_ANY_MOD, "\033Os", +2, 0, 0},
  220. - { XK_KP_4, XK_ANY_MOD, "\033Ot", +2, 0, 0},
  221. - { XK_KP_5, XK_ANY_MOD, "\033Ou", +2, 0, 0},
  222. - { XK_KP_6, XK_ANY_MOD, "\033Ov", +2, 0, 0},
  223. - { XK_KP_7, XK_ANY_MOD, "\033Ow", +2, 0, 0},
  224. - { XK_KP_8, XK_ANY_MOD, "\033Ox", +2, 0, 0},
  225. - { XK_KP_9, XK_ANY_MOD, "\033Oy", +2, 0, 0},
  226. - { XK_Up, ShiftMask, "\033[1;2A", 0, 0, 0},
  227. - { XK_Up, Mod1Mask, "\033[1;3A", 0, 0, 0},
  228. - { XK_Up, ShiftMask|Mod1Mask,"\033[1;4A", 0, 0, 0},
  229. - { XK_Up, ControlMask, "\033[1;5A", 0, 0, 0},
  230. - { XK_Up, ShiftMask|ControlMask,"\033[1;6A", 0, 0, 0},
  231. - { XK_Up, ControlMask|Mod1Mask,"\033[1;7A", 0, 0, 0},
  232. - { XK_Up,ShiftMask|ControlMask|Mod1Mask,"\033[1;8A", 0, 0, 0},
  233. - { XK_Up, XK_ANY_MOD, "\033[A", 0, -1, 0},
  234. - { XK_Up, XK_ANY_MOD, "\033OA", 0, +1, 0},
  235. - { XK_Down, ShiftMask, "\033[1;2B", 0, 0, 0},
  236. - { XK_Down, Mod1Mask, "\033[1;3B", 0, 0, 0},
  237. - { XK_Down, ShiftMask|Mod1Mask,"\033[1;4B", 0, 0, 0},
  238. - { XK_Down, ControlMask, "\033[1;5B", 0, 0, 0},
  239. - { XK_Down, ShiftMask|ControlMask,"\033[1;6B", 0, 0, 0},
  240. - { XK_Down, ControlMask|Mod1Mask,"\033[1;7B", 0, 0, 0},
  241. - { XK_Down,ShiftMask|ControlMask|Mod1Mask,"\033[1;8B",0, 0, 0},
  242. - { XK_Down, XK_ANY_MOD, "\033[B", 0, -1, 0},
  243. - { XK_Down, XK_ANY_MOD, "\033OB", 0, +1, 0},
  244. - { XK_Left, ShiftMask, "\033[1;2D", 0, 0, 0},
  245. - { XK_Left, Mod1Mask, "\033[1;3D", 0, 0, 0},
  246. - { XK_Left, ShiftMask|Mod1Mask,"\033[1;4D", 0, 0, 0},
  247. - { XK_Left, ControlMask, "\033[1;5D", 0, 0, 0},
  248. - { XK_Left, ShiftMask|ControlMask,"\033[1;6D", 0, 0, 0},
  249. - { XK_Left, ControlMask|Mod1Mask,"\033[1;7D", 0, 0, 0},
  250. - { XK_Left,ShiftMask|ControlMask|Mod1Mask,"\033[1;8D",0, 0, 0},
  251. - { XK_Left, XK_ANY_MOD, "\033[D", 0, -1, 0},
  252. - { XK_Left, XK_ANY_MOD, "\033OD", 0, +1, 0},
  253. - { XK_Right, ShiftMask, "\033[1;2C", 0, 0, 0},
  254. - { XK_Right, Mod1Mask, "\033[1;3C", 0, 0, 0},
  255. - { XK_Right, ShiftMask|Mod1Mask,"\033[1;4C", 0, 0, 0},
  256. - { XK_Right, ControlMask, "\033[1;5C", 0, 0, 0},
  257. - { XK_Right, ShiftMask|ControlMask,"\033[1;6C", 0, 0, 0},
  258. - { XK_Right, ControlMask|Mod1Mask,"\033[1;7C", 0, 0, 0},
  259. - { XK_Right,ShiftMask|ControlMask|Mod1Mask,"\033[1;8C",0, 0, 0},
  260. - { XK_Right, XK_ANY_MOD, "\033[C", 0, -1, 0},
  261. - { XK_Right, XK_ANY_MOD, "\033OC", 0, +1, 0},
  262. - { XK_ISO_Left_Tab, ShiftMask, "\033[Z", 0, 0, 0},
  263. - { XK_Return, Mod1Mask, "\033\r", 0, 0, -1},
  264. - { XK_Return, Mod1Mask, "\033\r\n", 0, 0, +1},
  265. - { XK_Return, XK_ANY_MOD, "\r", 0, 0, -1},
  266. - { XK_Return, XK_ANY_MOD, "\r\n", 0, 0, +1},
  267. - { XK_Insert, ShiftMask, "\033[4l", -1, 0, 0},
  268. - { XK_Insert, ShiftMask, "\033[2;2~", +1, 0, 0},
  269. - { XK_Insert, ControlMask, "\033[L", -1, 0, 0},
  270. - { XK_Insert, ControlMask, "\033[2;5~", +1, 0, 0},
  271. - { XK_Insert, XK_ANY_MOD, "\033[4h", -1, 0, 0},
  272. - { XK_Insert, XK_ANY_MOD, "\033[2~", +1, 0, 0},
  273. - { XK_Delete, ControlMask, "\033[M", -1, 0, 0},
  274. - { XK_Delete, ControlMask, "\033[3;5~", +1, 0, 0},
  275. - { XK_Delete, ShiftMask, "\033[2K", -1, 0, 0},
  276. - { XK_Delete, ShiftMask, "\033[3;2~", +1, 0, 0},
  277. - { XK_Delete, XK_ANY_MOD, "\033[P", -1, 0, 0},
  278. - { XK_Delete, XK_ANY_MOD, "\033[3~", +1, 0, 0},
  279. - { XK_BackSpace, XK_NO_MOD, "\177", 0, 0, 0},
  280. - { XK_BackSpace, Mod1Mask, "\033\177", 0, 0, 0},
  281. - { XK_Home, ShiftMask, "\033[2J", 0, -1, 0},
  282. - { XK_Home, ShiftMask, "\033[1;2H", 0, +1, 0},
  283. - { XK_Home, XK_ANY_MOD, "\033[H", 0, -1, 0},
  284. - { XK_Home, XK_ANY_MOD, "\033[1~", 0, +1, 0},
  285. - { XK_End, ControlMask, "\033[J", -1, 0, 0},
  286. - { XK_End, ControlMask, "\033[1;5F", +1, 0, 0},
  287. - { XK_End, ShiftMask, "\033[K", -1, 0, 0},
  288. - { XK_End, ShiftMask, "\033[1;2F", +1, 0, 0},
  289. - { XK_End, XK_ANY_MOD, "\033[4~", 0, 0, 0},
  290. - { XK_Prior, ControlMask, "\033[5;5~", 0, 0, 0},
  291. - { XK_Prior, ShiftMask, "\033[5;2~", 0, 0, 0},
  292. - { XK_Prior, XK_ANY_MOD, "\033[5~", 0, 0, 0},
  293. - { XK_Next, ControlMask, "\033[6;5~", 0, 0, 0},
  294. - { XK_Next, ShiftMask, "\033[6;2~", 0, 0, 0},
  295. - { XK_Next, XK_ANY_MOD, "\033[6~", 0, 0, 0},
  296. - { XK_F1, XK_NO_MOD, "\033OP" , 0, 0, 0},
  297. - { XK_F1, /* F13 */ ShiftMask, "\033[1;2P", 0, 0, 0},
  298. - { XK_F1, /* F25 */ ControlMask, "\033[1;5P", 0, 0, 0},
  299. - { XK_F1, /* F37 */ Mod4Mask, "\033[1;6P", 0, 0, 0},
  300. - { XK_F1, /* F49 */ Mod1Mask, "\033[1;3P", 0, 0, 0},
  301. - { XK_F1, /* F61 */ Mod3Mask, "\033[1;4P", 0, 0, 0},
  302. - { XK_F2, XK_NO_MOD, "\033OQ" , 0, 0, 0},
  303. - { XK_F2, /* F14 */ ShiftMask, "\033[1;2Q", 0, 0, 0},
  304. - { XK_F2, /* F26 */ ControlMask, "\033[1;5Q", 0, 0, 0},
  305. - { XK_F2, /* F38 */ Mod4Mask, "\033[1;6Q", 0, 0, 0},
  306. - { XK_F2, /* F50 */ Mod1Mask, "\033[1;3Q", 0, 0, 0},
  307. - { XK_F2, /* F62 */ Mod3Mask, "\033[1;4Q", 0, 0, 0},
  308. - { XK_F3, XK_NO_MOD, "\033OR" , 0, 0, 0},
  309. - { XK_F3, /* F15 */ ShiftMask, "\033[1;2R", 0, 0, 0},
  310. - { XK_F3, /* F27 */ ControlMask, "\033[1;5R", 0, 0, 0},
  311. - { XK_F3, /* F39 */ Mod4Mask, "\033[1;6R", 0, 0, 0},
  312. - { XK_F3, /* F51 */ Mod1Mask, "\033[1;3R", 0, 0, 0},
  313. - { XK_F3, /* F63 */ Mod3Mask, "\033[1;4R", 0, 0, 0},
  314. - { XK_F4, XK_NO_MOD, "\033OS" , 0, 0, 0},
  315. - { XK_F4, /* F16 */ ShiftMask, "\033[1;2S", 0, 0, 0},
  316. - { XK_F4, /* F28 */ ControlMask, "\033[1;5S", 0, 0, 0},
  317. - { XK_F4, /* F40 */ Mod4Mask, "\033[1;6S", 0, 0, 0},
  318. - { XK_F4, /* F52 */ Mod1Mask, "\033[1;3S", 0, 0, 0},
  319. - { XK_F5, XK_NO_MOD, "\033[15~", 0, 0, 0},
  320. - { XK_F5, /* F17 */ ShiftMask, "\033[15;2~", 0, 0, 0},
  321. - { XK_F5, /* F29 */ ControlMask, "\033[15;5~", 0, 0, 0},
  322. - { XK_F5, /* F41 */ Mod4Mask, "\033[15;6~", 0, 0, 0},
  323. - { XK_F5, /* F53 */ Mod1Mask, "\033[15;3~", 0, 0, 0},
  324. - { XK_F6, XK_NO_MOD, "\033[17~", 0, 0, 0},
  325. - { XK_F6, /* F18 */ ShiftMask, "\033[17;2~", 0, 0, 0},
  326. - { XK_F6, /* F30 */ ControlMask, "\033[17;5~", 0, 0, 0},
  327. - { XK_F6, /* F42 */ Mod4Mask, "\033[17;6~", 0, 0, 0},
  328. - { XK_F6, /* F54 */ Mod1Mask, "\033[17;3~", 0, 0, 0},
  329. - { XK_F7, XK_NO_MOD, "\033[18~", 0, 0, 0},
  330. - { XK_F7, /* F19 */ ShiftMask, "\033[18;2~", 0, 0, 0},
  331. - { XK_F7, /* F31 */ ControlMask, "\033[18;5~", 0, 0, 0},
  332. - { XK_F7, /* F43 */ Mod4Mask, "\033[18;6~", 0, 0, 0},
  333. - { XK_F7, /* F55 */ Mod1Mask, "\033[18;3~", 0, 0, 0},
  334. - { XK_F8, XK_NO_MOD, "\033[19~", 0, 0, 0},
  335. - { XK_F8, /* F20 */ ShiftMask, "\033[19;2~", 0, 0, 0},
  336. - { XK_F8, /* F32 */ ControlMask, "\033[19;5~", 0, 0, 0},
  337. - { XK_F8, /* F44 */ Mod4Mask, "\033[19;6~", 0, 0, 0},
  338. - { XK_F8, /* F56 */ Mod1Mask, "\033[19;3~", 0, 0, 0},
  339. - { XK_F9, XK_NO_MOD, "\033[20~", 0, 0, 0},
  340. - { XK_F9, /* F21 */ ShiftMask, "\033[20;2~", 0, 0, 0},
  341. - { XK_F9, /* F33 */ ControlMask, "\033[20;5~", 0, 0, 0},
  342. - { XK_F9, /* F45 */ Mod4Mask, "\033[20;6~", 0, 0, 0},
  343. - { XK_F9, /* F57 */ Mod1Mask, "\033[20;3~", 0, 0, 0},
  344. - { XK_F10, XK_NO_MOD, "\033[21~", 0, 0, 0},
  345. - { XK_F10, /* F22 */ ShiftMask, "\033[21;2~", 0, 0, 0},
  346. - { XK_F10, /* F34 */ ControlMask, "\033[21;5~", 0, 0, 0},
  347. - { XK_F10, /* F46 */ Mod4Mask, "\033[21;6~", 0, 0, 0},
  348. - { XK_F10, /* F58 */ Mod1Mask, "\033[21;3~", 0, 0, 0},
  349. - { XK_F11, XK_NO_MOD, "\033[23~", 0, 0, 0},
  350. - { XK_F11, /* F23 */ ShiftMask, "\033[23;2~", 0, 0, 0},
  351. - { XK_F11, /* F35 */ ControlMask, "\033[23;5~", 0, 0, 0},
  352. - { XK_F11, /* F47 */ Mod4Mask, "\033[23;6~", 0, 0, 0},
  353. - { XK_F11, /* F59 */ Mod1Mask, "\033[23;3~", 0, 0, 0},
  354. - { XK_F12, XK_NO_MOD, "\033[24~", 0, 0, 0},
  355. - { XK_F12, /* F24 */ ShiftMask, "\033[24;2~", 0, 0, 0},
  356. - { XK_F12, /* F36 */ ControlMask, "\033[24;5~", 0, 0, 0},
  357. - { XK_F12, /* F48 */ Mod4Mask, "\033[24;6~", 0, 0, 0},
  358. - { XK_F12, /* F60 */ Mod1Mask, "\033[24;3~", 0, 0, 0},
  359. - { XK_F13, XK_NO_MOD, "\033[1;2P", 0, 0, 0},
  360. - { XK_F14, XK_NO_MOD, "\033[1;2Q", 0, 0, 0},
  361. - { XK_F15, XK_NO_MOD, "\033[1;2R", 0, 0, 0},
  362. - { XK_F16, XK_NO_MOD, "\033[1;2S", 0, 0, 0},
  363. - { XK_F17, XK_NO_MOD, "\033[15;2~", 0, 0, 0},
  364. - { XK_F18, XK_NO_MOD, "\033[17;2~", 0, 0, 0},
  365. - { XK_F19, XK_NO_MOD, "\033[18;2~", 0, 0, 0},
  366. - { XK_F20, XK_NO_MOD, "\033[19;2~", 0, 0, 0},
  367. - { XK_F21, XK_NO_MOD, "\033[20;2~", 0, 0, 0},
  368. - { XK_F22, XK_NO_MOD, "\033[21;2~", 0, 0, 0},
  369. - { XK_F23, XK_NO_MOD, "\033[23;2~", 0, 0, 0},
  370. - { XK_F24, XK_NO_MOD, "\033[24;2~", 0, 0, 0},
  371. - { XK_F25, XK_NO_MOD, "\033[1;5P", 0, 0, 0},
  372. - { XK_F26, XK_NO_MOD, "\033[1;5Q", 0, 0, 0},
  373. - { XK_F27, XK_NO_MOD, "\033[1;5R", 0, 0, 0},
  374. - { XK_F28, XK_NO_MOD, "\033[1;5S", 0, 0, 0},
  375. - { XK_F29, XK_NO_MOD, "\033[15;5~", 0, 0, 0},
  376. - { XK_F30, XK_NO_MOD, "\033[17;5~", 0, 0, 0},
  377. - { XK_F31, XK_NO_MOD, "\033[18;5~", 0, 0, 0},
  378. - { XK_F32, XK_NO_MOD, "\033[19;5~", 0, 0, 0},
  379. - { XK_F33, XK_NO_MOD, "\033[20;5~", 0, 0, 0},
  380. - { XK_F34, XK_NO_MOD, "\033[21;5~", 0, 0, 0},
  381. - { XK_F35, XK_NO_MOD, "\033[23;5~", 0, 0, 0},
  382. + /* keysym mask string appkey appcursor crlf */
  383. + { XKB_KEY_KP_Home, MOD_MASK_SHIFT, "\033[2J", 0, -1, 0},
  384. + { XKB_KEY_KP_Home, MOD_MASK_SHIFT, "\033[1;2H", 0, +1, 0},
  385. + { XKB_KEY_KP_Home, MOD_MASK_ANY, "\033[H", 0, -1, 0},
  386. + { XKB_KEY_KP_Home, MOD_MASK_ANY, "\033[1~", 0, +1, 0},
  387. + { XKB_KEY_KP_Up, MOD_MASK_ANY, "\033Ox", +1, 0, 0},
  388. + { XKB_KEY_KP_Up, MOD_MASK_ANY, "\033[A", 0, -1, 0},
  389. + { XKB_KEY_KP_Up, MOD_MASK_ANY, "\033OA", 0, +1, 0},
  390. + { XKB_KEY_KP_Down, MOD_MASK_ANY, "\033Or", +1, 0, 0},
  391. + { XKB_KEY_KP_Down, MOD_MASK_ANY, "\033[B", 0, -1, 0},
  392. + { XKB_KEY_KP_Down, MOD_MASK_ANY, "\033OB", 0, +1, 0},
  393. + { XKB_KEY_KP_Left, MOD_MASK_ANY, "\033Ot", +1, 0, 0},
  394. + { XKB_KEY_KP_Left, MOD_MASK_ANY, "\033[D", 0, -1, 0},
  395. + { XKB_KEY_KP_Left, MOD_MASK_ANY, "\033OD", 0, +1, 0},
  396. + { XKB_KEY_KP_Right, MOD_MASK_ANY, "\033Ov", +1, 0, 0},
  397. + { XKB_KEY_KP_Right, MOD_MASK_ANY, "\033[C", 0, -1, 0},
  398. + { XKB_KEY_KP_Right, MOD_MASK_ANY, "\033OC", 0, +1, 0},
  399. + { XKB_KEY_KP_Prior, MOD_MASK_SHIFT, "\033[5;2~", 0, 0, 0},
  400. + { XKB_KEY_KP_Prior, MOD_MASK_ANY, "\033[5~", 0, 0, 0},
  401. + { XKB_KEY_KP_Begin, MOD_MASK_ANY, "\033[E", 0, 0, 0},
  402. + { XKB_KEY_KP_End, MOD_MASK_CTRL, "\033[J", -1, 0, 0},
  403. + { XKB_KEY_KP_End, MOD_MASK_CTRL, "\033[1;5F", +1, 0, 0},
  404. + { XKB_KEY_KP_End, MOD_MASK_SHIFT, "\033[K", -1, 0, 0},
  405. + { XKB_KEY_KP_End, MOD_MASK_SHIFT, "\033[1;2F", +1, 0, 0},
  406. + { XKB_KEY_KP_End, MOD_MASK_ANY, "\033[4~", 0, 0, 0},
  407. + { XKB_KEY_KP_Next, MOD_MASK_SHIFT, "\033[6;2~", 0, 0, 0},
  408. + { XKB_KEY_KP_Next, MOD_MASK_ANY, "\033[6~", 0, 0, 0},
  409. + { XKB_KEY_KP_Insert, MOD_MASK_SHIFT, "\033[2;2~", +1, 0, 0},
  410. + { XKB_KEY_KP_Insert, MOD_MASK_SHIFT, "\033[4l", -1, 0, 0},
  411. + { XKB_KEY_KP_Insert, MOD_MASK_CTRL, "\033[L", -1, 0, 0},
  412. + { XKB_KEY_KP_Insert, MOD_MASK_CTRL, "\033[2;5~", +1, 0, 0},
  413. + { XKB_KEY_KP_Insert, MOD_MASK_ANY, "\033[4h", -1, 0, 0},
  414. + { XKB_KEY_KP_Insert, MOD_MASK_ANY, "\033[2~", +1, 0, 0},
  415. + { XKB_KEY_KP_Delete, MOD_MASK_CTRL, "\033[M", -1, 0, 0},
  416. + { XKB_KEY_KP_Delete, MOD_MASK_CTRL, "\033[3;5~", +1, 0, 0},
  417. + { XKB_KEY_KP_Delete, MOD_MASK_SHIFT, "\033[2K", -1, 0, 0},
  418. + { XKB_KEY_KP_Delete, MOD_MASK_SHIFT, "\033[3;2~", +1, 0, 0},
  419. + { XKB_KEY_KP_Delete, MOD_MASK_ANY, "\033[P", -1, 0, 0},
  420. + { XKB_KEY_KP_Delete, MOD_MASK_ANY, "\033[3~", +1, 0, 0},
  421. + { XKB_KEY_KP_Multiply, MOD_MASK_ANY, "\033Oj", +2, 0, 0},
  422. + { XKB_KEY_KP_Add, MOD_MASK_ANY, "\033Ok", +2, 0, 0},
  423. + { XKB_KEY_KP_Enter, MOD_MASK_ANY, "\033OM", +2, 0, 0},
  424. + { XKB_KEY_KP_Enter, MOD_MASK_ANY, "\r", -1, 0, -1},
  425. + { XKB_KEY_KP_Enter, MOD_MASK_ANY, "\r\n", -1, 0, +1},
  426. + { XKB_KEY_KP_Subtract, MOD_MASK_ANY, "\033Om", +2, 0, 0},
  427. + { XKB_KEY_KP_Decimal, MOD_MASK_ANY, "\033On", +2, 0, 0},
  428. + { XKB_KEY_KP_Divide, MOD_MASK_ANY, "\033Oo", +2, 0, 0},
  429. + { XKB_KEY_KP_0, MOD_MASK_ANY, "\033Op", +2, 0, 0},
  430. + { XKB_KEY_KP_1, MOD_MASK_ANY, "\033Oq", +2, 0, 0},
  431. + { XKB_KEY_KP_2, MOD_MASK_ANY, "\033Or", +2, 0, 0},
  432. + { XKB_KEY_KP_3, MOD_MASK_ANY, "\033Os", +2, 0, 0},
  433. + { XKB_KEY_KP_4, MOD_MASK_ANY, "\033Ot", +2, 0, 0},
  434. + { XKB_KEY_KP_5, MOD_MASK_ANY, "\033Ou", +2, 0, 0},
  435. + { XKB_KEY_KP_6, MOD_MASK_ANY, "\033Ov", +2, 0, 0},
  436. + { XKB_KEY_KP_7, MOD_MASK_ANY, "\033Ow", +2, 0, 0},
  437. + { XKB_KEY_KP_8, MOD_MASK_ANY, "\033Ox", +2, 0, 0},
  438. + { XKB_KEY_KP_9, MOD_MASK_ANY, "\033Oy", +2, 0, 0},
  439. + { XKB_KEY_Up, MOD_MASK_SHIFT, "\033[1;2A", 0, 0, 0},
  440. + { XKB_KEY_Up, MOD_MASK_ALT, "\033[1;3A", 0, 0, 0},
  441. + { XKB_KEY_Up, MOD_MASK_SHIFT|MOD_MASK_ALT,"\033[1;4A", 0, 0, 0},
  442. + { XKB_KEY_Up, MOD_MASK_CTRL, "\033[1;5A", 0, 0, 0},
  443. + { XKB_KEY_Up,MOD_MASK_SHIFT|MOD_MASK_CTRL,"\033[1;6A", 0, 0, 0},
  444. + { XKB_KEY_Up, MOD_MASK_CTRL|MOD_MASK_ALT,"\033[1;7A", 0, 0, 0},
  445. + { XKB_KEY_Up,MOD_MASK_SHIFT|MOD_MASK_CTRL|MOD_MASK_ALT,"\033[1;8A",0,0,0},
  446. + { XKB_KEY_Up, MOD_MASK_ANY, "\033[A", 0, -1, 0},
  447. + { XKB_KEY_Up, MOD_MASK_ANY, "\033OA", 0, +1, 0},
  448. + { XKB_KEY_Down, MOD_MASK_SHIFT, "\033[1;2B", 0, 0, 0},
  449. + { XKB_KEY_Down, MOD_MASK_ALT, "\033[1;3B", 0, 0, 0},
  450. + { XKB_KEY_Down,MOD_MASK_SHIFT|MOD_MASK_ALT,"\033[1;4B", 0, 0, 0},
  451. + { XKB_KEY_Down, MOD_MASK_CTRL, "\033[1;5B", 0, 0, 0},
  452. + { XKB_KEY_Down,MOD_MASK_SHIFT|MOD_MASK_CTRL,"\033[1;6B", 0, 0, 0},
  453. + { XKB_KEY_Down,MOD_MASK_CTRL|MOD_MASK_ALT,"\033[1;7B", 0, 0, 0},
  454. + { XKB_KEY_Down,MOD_MASK_SHIFT|MOD_MASK_CTRL|MOD_MASK_ALT,"\033[1;8B",0,0,0},
  455. + { XKB_KEY_Down, MOD_MASK_ANY, "\033[B", 0, -1, 0},
  456. + { XKB_KEY_Down, MOD_MASK_ANY, "\033OB", 0, +1, 0},
  457. + { XKB_KEY_Left, MOD_MASK_SHIFT, "\033[1;2D", 0, 0, 0},
  458. + { XKB_KEY_Left, MOD_MASK_ALT, "\033[1;3D", 0, 0, 0},
  459. + { XKB_KEY_Left,MOD_MASK_SHIFT|MOD_MASK_ALT,"\033[1;4D", 0, 0, 0},
  460. + { XKB_KEY_Left, MOD_MASK_CTRL, "\033[1;5D", 0, 0, 0},
  461. + { XKB_KEY_Left,MOD_MASK_SHIFT|MOD_MASK_CTRL,"\033[1;6D", 0, 0, 0},
  462. + { XKB_KEY_Left,MOD_MASK_CTRL|MOD_MASK_ALT,"\033[1;7D", 0, 0, 0},
  463. + { XKB_KEY_Left,MOD_MASK_SHIFT|MOD_MASK_CTRL|MOD_MASK_ALT,"\033[1;8D",0,0,0},
  464. + { XKB_KEY_Left, MOD_MASK_ANY, "\033[D", 0, -1, 0},
  465. + { XKB_KEY_Left, MOD_MASK_ANY, "\033OD", 0, +1, 0},
  466. + { XKB_KEY_Right, MOD_MASK_SHIFT, "\033[1;2C", 0, 0, 0},
  467. + { XKB_KEY_Right, MOD_MASK_ALT, "\033[1;3C", 0, 0, 0},
  468. + { XKB_KEY_Right,MOD_MASK_SHIFT|MOD_MASK_ALT,"\033[1;4C", 0, 0, 0},
  469. + { XKB_KEY_Right, MOD_MASK_CTRL, "\033[1;5C", 0, 0, 0},
  470. + { XKB_KEY_Right,MOD_MASK_SHIFT|MOD_MASK_CTRL,"\033[1;6C", 0, 0, 0},
  471. + { XKB_KEY_Right,MOD_MASK_CTRL|MOD_MASK_ALT,"\033[1;7C", 0, 0, 0},
  472. + { XKB_KEY_Right,MOD_MASK_SHIFT|MOD_MASK_CTRL|MOD_MASK_ALT,"\033[1;8C",0,0,0},
  473. + { XKB_KEY_Right, MOD_MASK_ANY, "\033[C", 0, -1, 0},
  474. + { XKB_KEY_Right, MOD_MASK_ANY, "\033OC", 0, +1, 0},
  475. + { XKB_KEY_ISO_Left_Tab, MOD_MASK_SHIFT, "\033[Z", 0, 0, 0},
  476. + { XKB_KEY_Return, MOD_MASK_ALT, "\033\r", 0, 0, -1},
  477. + { XKB_KEY_Return, MOD_MASK_ALT, "\033\r\n", 0, 0, +1},
  478. + { XKB_KEY_Return, MOD_MASK_ANY, "\r", 0, 0, -1},
  479. + { XKB_KEY_Return, MOD_MASK_ANY, "\r\n", 0, 0, +1},
  480. + { XKB_KEY_Insert, MOD_MASK_SHIFT, "\033[4l", -1, 0, 0},
  481. + { XKB_KEY_Insert, MOD_MASK_SHIFT, "\033[2;2~", +1, 0, 0},
  482. + { XKB_KEY_Insert, MOD_MASK_CTRL, "\033[L", -1, 0, 0},
  483. + { XKB_KEY_Insert, MOD_MASK_CTRL, "\033[2;5~", +1, 0, 0},
  484. + { XKB_KEY_Insert, MOD_MASK_ANY, "\033[4h", -1, 0, 0},
  485. + { XKB_KEY_Insert, MOD_MASK_ANY, "\033[2~", +1, 0, 0},
  486. + { XKB_KEY_Delete, MOD_MASK_CTRL, "\033[M", -1, 0, 0},
  487. + { XKB_KEY_Delete, MOD_MASK_CTRL, "\033[3;5~", +1, 0, 0},
  488. + { XKB_KEY_Delete, MOD_MASK_SHIFT, "\033[2K", -1, 0, 0},
  489. + { XKB_KEY_Delete, MOD_MASK_SHIFT, "\033[3;2~", +1, 0, 0},
  490. + { XKB_KEY_Delete, MOD_MASK_ANY, "\033[P", -1, 0, 0},
  491. + { XKB_KEY_Delete, MOD_MASK_ANY, "\033[3~", +1, 0, 0},
  492. + { XKB_KEY_BackSpace, MOD_MASK_NONE, "\177", 0, 0, 0},
  493. + { XKB_KEY_BackSpace, MOD_MASK_CTRL, "\033\177", 0, 0, 0},
  494. + { XKB_KEY_Home, MOD_MASK_SHIFT, "\033[2J", 0, -1, 0},
  495. + { XKB_KEY_Home, MOD_MASK_SHIFT, "\033[1;2H", 0, +1, 0},
  496. + { XKB_KEY_Home, MOD_MASK_ANY, "\033[H", 0, -1, 0},
  497. + { XKB_KEY_Home, MOD_MASK_ANY, "\033[1~", 0, +1, 0},
  498. + { XKB_KEY_End, MOD_MASK_CTRL, "\033[J", -1, 0, 0},
  499. + { XKB_KEY_End, MOD_MASK_CTRL, "\033[1;5F", +1, 0, 0},
  500. + { XKB_KEY_End, MOD_MASK_SHIFT, "\033[K", -1, 0, 0},
  501. + { XKB_KEY_End, MOD_MASK_SHIFT, "\033[1;2F", +1, 0, 0},
  502. + { XKB_KEY_End, MOD_MASK_ANY, "\033[4~", 0, 0, 0},
  503. + { XKB_KEY_Prior, MOD_MASK_CTRL, "\033[5;5~", 0, 0, 0},
  504. + { XKB_KEY_Prior, MOD_MASK_SHIFT, "\033[5;2~", 0, 0, 0},
  505. + { XKB_KEY_Prior, MOD_MASK_ANY, "\033[5~", 0, 0, 0},
  506. + { XKB_KEY_Next, MOD_MASK_CTRL, "\033[6;5~", 0, 0, 0},
  507. + { XKB_KEY_Next, MOD_MASK_SHIFT, "\033[6;2~", 0, 0, 0},
  508. + { XKB_KEY_Next, MOD_MASK_ANY, "\033[6~", 0, 0, 0},
  509. + { XKB_KEY_F1, MOD_MASK_NONE, "\033OP" , 0, 0, 0},
  510. + { XKB_KEY_F1, /* F13 */ MOD_MASK_SHIFT, "\033[1;2P", 0, 0, 0},
  511. + { XKB_KEY_F1, /* F25 */ MOD_MASK_CTRL, "\033[1;5P", 0, 0, 0},
  512. + { XKB_KEY_F1, /* F37 */ MOD_MASK_LOGO, "\033[1;6P", 0, 0, 0},
  513. + { XKB_KEY_F1, /* F49 */ MOD_MASK_ALT, "\033[1;3P", 0, 0, 0},
  514. + { XKB_KEY_F2, MOD_MASK_NONE, "\033OQ" , 0, 0, 0},
  515. + { XKB_KEY_F2, /* F14 */ MOD_MASK_SHIFT, "\033[1;2Q", 0, 0, 0},
  516. + { XKB_KEY_F2, /* F26 */ MOD_MASK_CTRL, "\033[1;5Q", 0, 0, 0},
  517. + { XKB_KEY_F2, /* F38 */ MOD_MASK_LOGO, "\033[1;6Q", 0, 0, 0},
  518. + { XKB_KEY_F2, /* F50 */ MOD_MASK_ALT, "\033[1;3Q", 0, 0, 0},
  519. + { XKB_KEY_F3, MOD_MASK_NONE, "\033OR" , 0, 0, 0},
  520. + { XKB_KEY_F3, /* F15 */ MOD_MASK_SHIFT, "\033[1;2R", 0, 0, 0},
  521. + { XKB_KEY_F3, /* F27 */ MOD_MASK_CTRL, "\033[1;5R", 0, 0, 0},
  522. + { XKB_KEY_F3, /* F39 */ MOD_MASK_LOGO, "\033[1;6R", 0, 0, 0},
  523. + { XKB_KEY_F3, /* F51 */ MOD_MASK_ALT, "\033[1;3R", 0, 0, 0},
  524. + { XKB_KEY_F4, MOD_MASK_NONE, "\033OS" , 0, 0, 0},
  525. + { XKB_KEY_F4, /* F16 */ MOD_MASK_SHIFT, "\033[1;2S", 0, 0, 0},
  526. + { XKB_KEY_F4, /* F28 */ MOD_MASK_CTRL, "\033[1;5S", 0, 0, 0},
  527. + { XKB_KEY_F4, /* F40 */ MOD_MASK_LOGO, "\033[1;6S", 0, 0, 0},
  528. + { XKB_KEY_F4, /* F52 */ MOD_MASK_ALT, "\033[1;3S", 0, 0, 0},
  529. + { XKB_KEY_F5, MOD_MASK_NONE, "\033[15~", 0, 0, 0},
  530. + { XKB_KEY_F5, /* F17 */ MOD_MASK_SHIFT, "\033[15;2~", 0, 0, 0},
  531. + { XKB_KEY_F5, /* F29 */ MOD_MASK_CTRL, "\033[15;5~", 0, 0, 0},
  532. + { XKB_KEY_F5, /* F41 */ MOD_MASK_LOGO, "\033[15;6~", 0, 0, 0},
  533. + { XKB_KEY_F5, /* F53 */ MOD_MASK_ALT, "\033[15;3~", 0, 0, 0},
  534. + { XKB_KEY_F6, MOD_MASK_NONE, "\033[17~", 0, 0, 0},
  535. + { XKB_KEY_F6, /* F18 */ MOD_MASK_SHIFT, "\033[17;2~", 0, 0, 0},
  536. + { XKB_KEY_F6, /* F30 */ MOD_MASK_CTRL, "\033[17;5~", 0, 0, 0},
  537. + { XKB_KEY_F6, /* F42 */ MOD_MASK_LOGO, "\033[17;6~", 0, 0, 0},
  538. + { XKB_KEY_F6, /* F54 */ MOD_MASK_ALT, "\033[17;3~", 0, 0, 0},
  539. + { XKB_KEY_F7, MOD_MASK_NONE, "\033[18~", 0, 0, 0},
  540. + { XKB_KEY_F7, /* F19 */ MOD_MASK_SHIFT, "\033[18;2~", 0, 0, 0},
  541. + { XKB_KEY_F7, /* F31 */ MOD_MASK_CTRL, "\033[18;5~", 0, 0, 0},
  542. + { XKB_KEY_F7, /* F43 */ MOD_MASK_LOGO, "\033[18;6~", 0, 0, 0},
  543. + { XKB_KEY_F7, /* F55 */ MOD_MASK_ALT, "\033[18;3~", 0, 0, 0},
  544. + { XKB_KEY_F8, MOD_MASK_NONE, "\033[19~", 0, 0, 0},
  545. + { XKB_KEY_F8, /* F20 */ MOD_MASK_SHIFT, "\033[19;2~", 0, 0, 0},
  546. + { XKB_KEY_F8, /* F32 */ MOD_MASK_CTRL, "\033[19;5~", 0, 0, 0},
  547. + { XKB_KEY_F8, /* F44 */ MOD_MASK_LOGO, "\033[19;6~", 0, 0, 0},
  548. + { XKB_KEY_F8, /* F56 */ MOD_MASK_ALT, "\033[19;3~", 0, 0, 0},
  549. + { XKB_KEY_F9, MOD_MASK_NONE, "\033[20~", 0, 0, 0},
  550. + { XKB_KEY_F9, /* F21 */ MOD_MASK_SHIFT, "\033[20;2~", 0, 0, 0},
  551. + { XKB_KEY_F9, /* F33 */ MOD_MASK_CTRL, "\033[20;5~", 0, 0, 0},
  552. + { XKB_KEY_F9, /* F45 */ MOD_MASK_LOGO, "\033[20;6~", 0, 0, 0},
  553. + { XKB_KEY_F9, /* F57 */ MOD_MASK_ALT, "\033[20;3~", 0, 0, 0},
  554. + { XKB_KEY_F10, MOD_MASK_NONE, "\033[21~", 0, 0, 0},
  555. + { XKB_KEY_F10, /* F22 */ MOD_MASK_SHIFT, "\033[21;2~", 0, 0, 0},
  556. + { XKB_KEY_F10, /* F34 */ MOD_MASK_CTRL, "\033[21;5~", 0, 0, 0},
  557. + { XKB_KEY_F10, /* F46 */ MOD_MASK_LOGO, "\033[21;6~", 0, 0, 0},
  558. + { XKB_KEY_F10, /* F58 */ MOD_MASK_ALT, "\033[21;3~", 0, 0, 0},
  559. + { XKB_KEY_F11, MOD_MASK_NONE, "\033[23~", 0, 0, 0},
  560. + { XKB_KEY_F11, /* F23 */ MOD_MASK_SHIFT, "\033[23;2~", 0, 0, 0},
  561. + { XKB_KEY_F11, /* F35 */ MOD_MASK_CTRL, "\033[23;5~", 0, 0, 0},
  562. + { XKB_KEY_F11, /* F47 */ MOD_MASK_LOGO, "\033[23;6~", 0, 0, 0},
  563. + { XKB_KEY_F11, /* F59 */ MOD_MASK_ALT, "\033[23;3~", 0, 0, 0},
  564. + { XKB_KEY_F12, MOD_MASK_NONE, "\033[24~", 0, 0, 0},
  565. + { XKB_KEY_F12, /* F24 */ MOD_MASK_SHIFT, "\033[24;2~", 0, 0, 0},
  566. + { XKB_KEY_F12, /* F36 */ MOD_MASK_CTRL, "\033[24;5~", 0, 0, 0},
  567. + { XKB_KEY_F12, /* F48 */ MOD_MASK_LOGO, "\033[24;6~", 0, 0, 0},
  568. + { XKB_KEY_F12, /* F60 */ MOD_MASK_ALT, "\033[24;3~", 0, 0, 0},
  569. + { XKB_KEY_F13, MOD_MASK_NONE, "\033[1;2P", 0, 0, 0},
  570. + { XKB_KEY_F14, MOD_MASK_NONE, "\033[1;2Q", 0, 0, 0},
  571. + { XKB_KEY_F15, MOD_MASK_NONE, "\033[1;2R", 0, 0, 0},
  572. + { XKB_KEY_F16, MOD_MASK_NONE, "\033[1;2S", 0, 0, 0},
  573. + { XKB_KEY_F17, MOD_MASK_NONE, "\033[15;2~", 0, 0, 0},
  574. + { XKB_KEY_F18, MOD_MASK_NONE, "\033[17;2~", 0, 0, 0},
  575. + { XKB_KEY_F19, MOD_MASK_NONE, "\033[18;2~", 0, 0, 0},
  576. + { XKB_KEY_F20, MOD_MASK_NONE, "\033[19;2~", 0, 0, 0},
  577. + { XKB_KEY_F21, MOD_MASK_NONE, "\033[20;2~", 0, 0, 0},
  578. + { XKB_KEY_F22, MOD_MASK_NONE, "\033[21;2~", 0, 0, 0},
  579. + { XKB_KEY_F23, MOD_MASK_NONE, "\033[23;2~", 0, 0, 0},
  580. + { XKB_KEY_F24, MOD_MASK_NONE, "\033[24;2~", 0, 0, 0},
  581. + { XKB_KEY_F25, MOD_MASK_NONE, "\033[1;5P", 0, 0, 0},
  582. + { XKB_KEY_F26, MOD_MASK_NONE, "\033[1;5Q", 0, 0, 0},
  583. + { XKB_KEY_F27, MOD_MASK_NONE, "\033[1;5R", 0, 0, 0},
  584. + { XKB_KEY_F28, MOD_MASK_NONE, "\033[1;5S", 0, 0, 0},
  585. + { XKB_KEY_F29, MOD_MASK_NONE, "\033[15;5~", 0, 0, 0},
  586. + { XKB_KEY_F30, MOD_MASK_NONE, "\033[17;5~", 0, 0, 0},
  587. + { XKB_KEY_F31, MOD_MASK_NONE, "\033[18;5~", 0, 0, 0},
  588. + { XKB_KEY_F32, MOD_MASK_NONE, "\033[19;5~", 0, 0, 0},
  589. + { XKB_KEY_F33, MOD_MASK_NONE, "\033[20;5~", 0, 0, 0},
  590. + { XKB_KEY_F34, MOD_MASK_NONE, "\033[21;5~", 0, 0, 0},
  591. + { XKB_KEY_F35, MOD_MASK_NONE, "\033[23;5~", 0, 0, 0},
  592. };
  593. /*
  594. @@ -452,7 +448,7 @@ static Key key[] = {
  595. * If no match is found, regular selection is used.
  596. */
  597. static uint selmasks[] = {
  598. - [SEL_RECTANGULAR] = Mod1Mask,
  599. + [SEL_RECTANGULAR] = MOD_MASK_ALT,
  600. };
  601. /*
  602. diff --git a/config.mk b/config.mk
  603. index c84c5ee..7da06f1 100644
  604. --- a/config.mk
  605. +++ b/config.mk
  606. @@ -7,16 +7,12 @@ VERSION = 0.7
  607. PREFIX = /usr/local
  608. MANPREFIX = ${PREFIX}/share/man
  609. -X11INC = /usr/X11R6/include
  610. -X11LIB = /usr/X11R6/lib
  611. +PKGCFG = fontconfig wayland-client wayland-cursor xkbcommon wld
  612. +XDG_SHELL_PROTO = `pkg-config --variable=pkgdatadir wayland-protocols`/unstable/xdg-shell/xdg-shell-unstable-v5.xml
  613. # includes and libs
  614. -INCS = -I. -I/usr/include -I${X11INC} \
  615. - `pkg-config --cflags fontconfig` \
  616. - `pkg-config --cflags freetype2`
  617. -LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXft \
  618. - `pkg-config --libs fontconfig` \
  619. - `pkg-config --libs freetype2`
  620. +INCS = -I. -I/usr/include `pkg-config --cflags ${PKGCFG}`
  621. +LIBS = -L/usr/lib -lc -lm -lrt -lutil `pkg-config --libs ${PKGCFG}`
  622. # flags
  623. CPPFLAGS = -DVERSION=\"${VERSION}\" -D_XOPEN_SOURCE=600
  624. diff --git a/st.c b/st.c
  625. index fbcd9e0..9ead681 100644
  626. --- a/st.c
  627. +++ b/st.c
  628. @@ -3,6 +3,8 @@
  629. #include <errno.h>
  630. #include <fcntl.h>
  631. #include <limits.h>
  632. +/* for BTN_* definitions */
  633. +#include <linux/input.h>
  634. #include <locale.h>
  635. #include <pwd.h>
  636. #include <stdarg.h>
  637. @@ -12,6 +14,7 @@
  638. #include <signal.h>
  639. #include <stdint.h>
  640. #include <sys/ioctl.h>
  641. +#include <sys/mman.h>
  642. #include <sys/select.h>
  643. #include <sys/stat.h>
  644. #include <sys/time.h>
  645. @@ -21,23 +24,19 @@
  646. #include <time.h>
  647. #include <unistd.h>
  648. #include <libgen.h>
  649. -#include <X11/Xatom.h>
  650. -#include <X11/Xlib.h>
  651. -#include <X11/Xutil.h>
  652. -#include <X11/cursorfont.h>
  653. -#include <X11/keysym.h>
  654. -#include <X11/Xft/Xft.h>
  655. -#include <X11/XKBlib.h>
  656. +#include <wayland-client.h>
  657. +#include <wayland-cursor.h>
  658. +#include <xkbcommon/xkbcommon.h>
  659. +#include <wld/wld.h>
  660. +#include <wld/wayland.h>
  661. #include <fontconfig/fontconfig.h>
  662. #include <wchar.h>
  663. #include "arg.h"
  664. +#include "xdg-shell-client-protocol.h"
  665. char *argv0;
  666. -#define Glyph Glyph_
  667. -#define Font Font_
  668. -
  669. #if defined(__linux)
  670. #include <pty.h>
  671. #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
  672. @@ -47,10 +46,6 @@ char *argv0;
  673. #endif
  674. -/* XEMBED messages */
  675. -#define XEMBED_FOCUS_IN 4
  676. -#define XEMBED_FOCUS_OUT 5
  677. -
  678. /* Arbitrary sizes */
  679. #define UTF_INVALID 0xFFFD
  680. #define UTF_SIZ 4
  681. @@ -58,15 +53,25 @@ char *argv0;
  682. #define ESC_ARG_SIZ 16
  683. #define STR_BUF_SIZ ESC_BUF_SIZ
  684. #define STR_ARG_SIZ ESC_ARG_SIZ
  685. +#define DRAW_BUF_SIZ 20*1024
  686. #define XK_ANY_MOD UINT_MAX
  687. #define XK_NO_MOD 0
  688. #define XK_SWITCH_MOD (1<<13)
  689. +#define MOD_MASK_ANY UINT_MAX
  690. +#define MOD_MASK_NONE 0
  691. +#define MOD_MASK_CTRL (1<<0)
  692. +#define MOD_MASK_ALT (1<<1)
  693. +#define MOD_MASK_SHIFT (1<<2)
  694. +#define MOD_MASK_LOGO (1<<3)
  695. +
  696. +#define AXIS_VERTICAL WL_POINTER_AXIS_VERTICAL_SCROLL
  697. +#define AXIS_HORIZONTAL WL_POINTER_AXIS_HORIZONTAL_SCROLL
  698. +
  699. /* macros */
  700. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  701. #define MAX(a, b) ((a) < (b) ? (b) : (a))
  702. #define LEN(a) (sizeof(a) / sizeof(a)[0])
  703. -#define NUMMAXLEN(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1)
  704. #define DEFAULT(a, b) (a) = (a) ? (a) : (b)
  705. #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
  706. #define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
  707. @@ -89,7 +94,7 @@ char *argv0;
  708. #define TRUEBLUE(x) (((x) & 0xff) << 8)
  709. /* constants */
  710. -#define ISO14755CMD "dmenu -w %lu -p codepoint: </dev/null"
  711. +#define ISO14755CMD "dmenu -p codepoint: </dev/null"
  712. enum glyph_attribute {
  713. ATTR_NULL = 0,
  714. @@ -195,9 +200,6 @@ typedef unsigned short ushort;
  715. typedef uint_least32_t Rune;
  716. -typedef XftDraw *Draw;
  717. -typedef XftColor Color;
  718. -
  719. typedef struct {
  720. Rune u; /* character code */
  721. ushort mode; /* attribute flags */
  722. @@ -242,7 +244,6 @@ typedef struct {
  723. Line *line; /* screen */
  724. Line *alt; /* alternate screen */
  725. int *dirty; /* dirtyness of lines */
  726. - XftGlyphFontSpec *specbuf; /* font spec buffer used for rendering */
  727. TCursor c; /* cursor */
  728. int top; /* top scroll limit */
  729. int bot; /* bottom scroll limit */
  730. @@ -255,29 +256,54 @@ typedef struct {
  731. int *tabs;
  732. } Term;
  733. -/* Purely graphic info */
  734. typedef struct {
  735. - Display *dpy;
  736. - Colormap cmap;
  737. - Window win;
  738. - Drawable buf;
  739. - Atom xembed, wmdeletewin, netwmname, netwmpid;
  740. - XIM xim;
  741. - XIC xic;
  742. - Draw draw;
  743. - Visual *vis;
  744. - XSetWindowAttributes attrs;
  745. - int scr;
  746. - int isfixed; /* is fixed geometry? */
  747. - int l, t; /* left and top offset */
  748. - int gm; /* geometry mask */
  749. + struct xkb_context *ctx;
  750. + struct xkb_keymap *keymap;
  751. + struct xkb_state *state;
  752. + xkb_mod_index_t ctrl, alt, shift, logo;
  753. + unsigned int mods;
  754. +} XKB;
  755. +
  756. +typedef struct {
  757. + struct wl_display *dpy;
  758. + struct wl_compositor *cmp;
  759. + struct wl_shm *shm;
  760. + struct wl_seat *seat;
  761. + struct wl_keyboard *keyboard;
  762. + struct wl_pointer *pointer;
  763. + struct wl_data_device_manager *datadevmanager;
  764. + struct wl_data_device *datadev;
  765. + struct wl_data_offer *seloffer;
  766. + struct wl_surface *surface;
  767. + struct wl_buffer *buffer;
  768. + struct xdg_wm_base *wm;
  769. + struct xdg_surface *xdgsurface;
  770. + struct xdg_toplevel *toplevel;
  771. + XKB xkb;
  772. + bool configured;
  773. + int px, py; /* pointer x and y */
  774. int tw, th; /* tty width and height */
  775. int w, h; /* window width and height */
  776. int ch; /* char height */
  777. int cw; /* char width */
  778. + int vis;
  779. char state; /* focus, redraw, visible */
  780. int cursor; /* cursor style */
  781. -} XWindow;
  782. + struct wl_callback * framecb;
  783. +} Wayland;
  784. +
  785. +typedef struct {
  786. + struct wld_context *ctx;
  787. + struct wld_font_context *fontctx;
  788. + struct wld_renderer *renderer;
  789. + struct wld_buffer *buffer, *oldbuffer;
  790. +} WLD;
  791. +
  792. +typedef struct {
  793. + struct wl_cursor_theme *theme;
  794. + struct wl_cursor *cursor;
  795. + struct wl_surface *surface;
  796. +} Cursor;
  797. typedef struct {
  798. uint b;
  799. @@ -286,7 +312,14 @@ typedef struct {
  800. } MouseShortcut;
  801. typedef struct {
  802. - KeySym k;
  803. + int axis;
  804. + int dir;
  805. + uint mask;
  806. + char s[ESC_BUF_SIZ];
  807. +} Axiskey;
  808. +
  809. +typedef struct {
  810. + xkb_keysym_t k;
  811. uint mask;
  812. char *s;
  813. /* three valued logic variables: 0 indifferent, 1 on, -1 off */
  814. @@ -310,11 +343,10 @@ typedef struct {
  815. int x, y;
  816. } nb, ne, ob, oe;
  817. - char *primary, *clipboard;
  818. - Atom xtarget;
  819. + char *primary;
  820. + struct wl_data_source *source;
  821. int alt;
  822. - struct timespec tclick1;
  823. - struct timespec tclick2;
  824. + uint32_t tclick1, tclick2;
  825. } Selection;
  826. typedef union {
  827. @@ -326,19 +358,25 @@ typedef union {
  828. typedef struct {
  829. uint mod;
  830. - KeySym keysym;
  831. + xkb_keysym_t keysym;
  832. void (*func)(const Arg *);
  833. const Arg arg;
  834. } Shortcut;
  835. +typedef struct {
  836. + char str[32];
  837. + uint32_t key;
  838. + int len;
  839. + bool started;
  840. + struct timespec last;
  841. +} Repeat;
  842. +
  843. /* function definitions used in config.h */
  844. -static void clipcopy(const Arg *);
  845. -static void clippaste(const Arg *);
  846. static void numlock(const Arg *);
  847. static void selpaste(const Arg *);
  848. -static void xzoom(const Arg *);
  849. -static void xzoomabs(const Arg *);
  850. -static void xzoomreset(const Arg *);
  851. +static void wlzoom(const Arg *);
  852. +static void wlzoomabs(const Arg *);
  853. +static void wlzoomreset(const Arg *);
  854. static void printsel(const Arg *);
  855. static void printscreen(const Arg *) ;
  856. static void iso14755(const Arg *);
  857. @@ -358,16 +396,15 @@ typedef struct {
  858. int badweight;
  859. short lbearing;
  860. short rbearing;
  861. - XftFont *match;
  862. + struct wld_font *match;
  863. FcFontSet *set;
  864. FcPattern *pattern;
  865. } Font;
  866. /* Drawing Context */
  867. typedef struct {
  868. - Color col[MAX(LEN(colorname), 256)];
  869. + uint32_t col[MAX(LEN(colorname), 256)];
  870. Font font, bfont, ifont, ibfont;
  871. - GC gc;
  872. } DC;
  873. static void die(const char *, ...);
  874. @@ -378,6 +415,7 @@ static void execsh(void);
  875. static void stty(void);
  876. static void sigchld(int);
  877. static void run(void);
  878. +static void cresize(int, int);
  879. static void csidump(void);
  880. static void csihandle(void);
  881. @@ -433,56 +471,80 @@ static void ttysend(char *, size_t);
  882. static void ttywrite(const char *, size_t);
  883. static void tstrsequence(uchar);
  884. -static inline ushort sixd_to_16bit(int);
  885. -static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, int, int, int);
  886. -static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
  887. -static void xdrawglyph(Glyph, int, int);
  888. -static void xhints(void);
  889. -static void xclear(int, int, int, int);
  890. -static void xdrawcursor(void);
  891. -static void xinit(void);
  892. -static void xloadcols(void);
  893. -static int xsetcolorname(int, const char *);
  894. -static int xgeommasktogravity(int);
  895. -static int xloadfont(Font *, FcPattern *);
  896. -static void xloadfonts(char *, double);
  897. -static void xsettitle(char *);
  898. -static void xresettitle(void);
  899. -static void xsetpointermotion(int);
  900. -static void xseturgency(int);
  901. -static void xsetsel(char *, Time);
  902. -static void xunloadfont(Font *);
  903. -static void xunloadfonts(void);
  904. -static void xresize(int, int);
  905. -
  906. -static void expose(XEvent *);
  907. -static void visibility(XEvent *);
  908. -static void unmap(XEvent *);
  909. -static char *kmap(KeySym, uint);
  910. -static void kpress(XEvent *);
  911. -static void cmessage(XEvent *);
  912. -static void cresize(int, int);
  913. -static void resize(XEvent *);
  914. -static void focus(XEvent *);
  915. -static void brelease(XEvent *);
  916. -static void bpress(XEvent *);
  917. -static void bmotion(XEvent *);
  918. -static void propnotify(XEvent *);
  919. -static void selnotify(XEvent *);
  920. -static void selclear(XEvent *);
  921. -static void selrequest(XEvent *);
  922. +static inline uchar sixd_to_8bit(int);
  923. +static void wldraws(char *, Glyph, int, int, int, int);
  924. +static void wldrawglyph(Glyph, int, int);
  925. +static void wlclear(int, int, int, int);
  926. +static void wldrawcursor(void);
  927. +static void wlinit(void);
  928. +static void wlloadcols(void);
  929. +static int wlsetcolorname(int, const char *);
  930. +static void wlloadcursor(void);
  931. +static int wlloadfont(Font *, FcPattern *);
  932. +static void wlloadfonts(char *, double);
  933. +static void wlsettitle(char *);
  934. +static void wlresettitle(void);
  935. +static void wlseturgency(int);
  936. +static void wlsetsel(char*, uint32_t);
  937. +static void wlunloadfont(Font *f);
  938. +static void wlunloadfonts(void);
  939. +static void wlresize(int, int);
  940. +
  941. +static void regglobal(void *, struct wl_registry *, uint32_t, const char *,
  942. + uint32_t);
  943. +static void regglobalremove(void *, struct wl_registry *, uint32_t);
  944. +static void surfenter(void *, struct wl_surface *, struct wl_output *);
  945. +static void surfleave(void *, struct wl_surface *, struct wl_output *);
  946. +static void framedone(void *, struct wl_callback *, uint32_t);
  947. +static void kbdkeymap(void *, struct wl_keyboard *, uint32_t, int32_t, uint32_t);
  948. +static void kbdenter(void *, struct wl_keyboard *, uint32_t,
  949. + struct wl_surface *, struct wl_array *);
  950. +static void kbdleave(void *, struct wl_keyboard *, uint32_t,
  951. + struct wl_surface *);
  952. +static void kbdkey(void *, struct wl_keyboard *, uint32_t, uint32_t, uint32_t,
  953. + uint32_t);
  954. +static void kbdmodifiers(void *, struct wl_keyboard *, uint32_t, uint32_t,
  955. + uint32_t, uint32_t, uint32_t);
  956. +static void kbdrepeatinfo(void *, struct wl_keyboard *, int32_t, int32_t);
  957. +static void ptrenter(void *, struct wl_pointer *, uint32_t, struct wl_surface *,
  958. + wl_fixed_t, wl_fixed_t);
  959. +static void ptrleave(void *, struct wl_pointer *, uint32_t,
  960. + struct wl_surface *);
  961. +static void ptrmotion(void *, struct wl_pointer *, uint32_t,
  962. + wl_fixed_t, wl_fixed_t);
  963. +static void ptrbutton(void *, struct wl_pointer *, uint32_t, uint32_t,
  964. + uint32_t, uint32_t);
  965. +static void ptraxis(void *, struct wl_pointer *, uint32_t, uint32_t,
  966. + wl_fixed_t);
  967. +static void wmping(void *, struct xdg_wm_base *, uint32_t);
  968. +static void xdgsurfconfigure(void *, struct xdg_surface *, uint32_t);
  969. +static void toplevelconfigure(void *, struct xdg_toplevel *,
  970. + int32_t, int32_t, struct wl_array *);
  971. +static void toplevelclose(void *, struct xdg_toplevel *);
  972. +static void datadevoffer(void *, struct wl_data_device *,
  973. + struct wl_data_offer *);
  974. +static void datadeventer(void *, struct wl_data_device *, uint32_t,
  975. + struct wl_surface *, wl_fixed_t, wl_fixed_t, struct wl_data_offer *);
  976. +static void datadevleave(void *, struct wl_data_device *);
  977. +static void datadevmotion(void *, struct wl_data_device *, uint32_t,
  978. + wl_fixed_t x, wl_fixed_t y);
  979. +static void datadevdrop(void *, struct wl_data_device *);
  980. +static void datadevselection(void *, struct wl_data_device *,
  981. + struct wl_data_offer *);
  982. +static void dataofferoffer(void *, struct wl_data_offer *, const char *);
  983. +static void datasrctarget(void *, struct wl_data_source *, const char *);
  984. +static void datasrcsend(void *, struct wl_data_source *, const char *, int32_t);
  985. +static void datasrccancelled(void *, struct wl_data_source *);
  986. static void selinit(void);
  987. static void selnormalize(void);
  988. static inline int selected(int, int);
  989. static char *getsel(void);
  990. -static void selcopy(Time);
  991. +static void selcopy(uint32_t);
  992. static void selscroll(int, int);
  993. static void selsnap(int *, int *, int);
  994. static int x2col(int);
  995. static int y2row(int);
  996. -static void getbuttoninfo(XEvent *);
  997. -static void mousereport(XEvent *);
  998. static size_t utf8decode(char *, Rune *, size_t);
  999. static Rune utf8decodebyte(char, size_t *);
  1000. @@ -498,41 +560,37 @@ static char *xstrdup(char *);
  1001. static void usage(void);
  1002. -static void (*handler[LASTEvent])(XEvent *) = {
  1003. - [KeyPress] = kpress,
  1004. - [ClientMessage] = cmessage,
  1005. - [ConfigureNotify] = resize,
  1006. - [VisibilityNotify] = visibility,
  1007. - [UnmapNotify] = unmap,
  1008. - [Expose] = expose,
  1009. - [FocusIn] = focus,
  1010. - [FocusOut] = focus,
  1011. - [MotionNotify] = bmotion,
  1012. - [ButtonPress] = bpress,
  1013. - [ButtonRelease] = brelease,
  1014. -/*
  1015. - * Uncomment if you want the selection to disappear when you select something
  1016. - * different in another window.
  1017. - */
  1018. -/* [SelectionClear] = selclear, */
  1019. - [SelectionNotify] = selnotify,
  1020. -/*
  1021. - * PropertyNotify is only turned on when there is some INCR transfer happening
  1022. - * for the selection retrieval.
  1023. - */
  1024. - [PropertyNotify] = propnotify,
  1025. - [SelectionRequest] = selrequest,
  1026. -};
  1027. +static struct wl_registry_listener reglistener = { regglobal, regglobalremove };
  1028. +static struct wl_surface_listener surflistener = { surfenter, surfleave };
  1029. +static struct wl_callback_listener framelistener = { framedone };
  1030. +static struct wl_keyboard_listener kbdlistener =
  1031. + { kbdkeymap, kbdenter, kbdleave, kbdkey, kbdmodifiers, kbdrepeatinfo };
  1032. +static struct wl_pointer_listener ptrlistener =
  1033. + { ptrenter, ptrleave, ptrmotion, ptrbutton, ptraxis };
  1034. +static struct xdg_wm_base_listener wmlistener = { wmping };
  1035. +static struct xdg_surface_listener xdgsurflistener = { xdgsurfconfigure };
  1036. +static struct xdg_toplevel_listener toplevellistener =
  1037. + { toplevelconfigure, toplevelclose };
  1038. +static struct wl_data_device_listener datadevlistener =
  1039. + { datadevoffer, datadeventer, datadevleave, datadevmotion, datadevdrop,
  1040. + datadevselection };
  1041. +static struct wl_data_offer_listener dataofferlistener = { dataofferoffer };
  1042. +static struct wl_data_source_listener datasrclistener =
  1043. + { datasrctarget, datasrcsend, datasrccancelled };
  1044. /* Globals */
  1045. static DC dc;
  1046. -static XWindow xw;
  1047. +static Wayland wl;
  1048. +static WLD wld;
  1049. +static Cursor cursor;
  1050. static Term term;
  1051. static CSIEscape csiescseq;
  1052. static STREscape strescseq;
  1053. static int cmdfd;
  1054. static pid_t pid;
  1055. static Selection sel;
  1056. +static Repeat repeat;
  1057. +static bool needdraw = true;
  1058. static int iofd = 1;
  1059. static char **opt_cmd = NULL;
  1060. static char *opt_class = NULL;
  1061. @@ -543,6 +601,7 @@ static char *opt_line = NULL;
  1062. static char *opt_name = NULL;
  1063. static char *opt_title = NULL;
  1064. static int oldbutton = 3; /* button event on startup: 3 = release */
  1065. +static int oldx, oldy;
  1066. static char *usedfont = NULL;
  1067. static double usedfontsize = 0;
  1068. @@ -562,7 +621,7 @@ enum {
  1069. };
  1070. typedef struct {
  1071. - XftFont *font;
  1072. + struct wld_font *font;
  1073. int flags;
  1074. Rune unicodep;
  1075. } Fontcache;
  1076. @@ -707,23 +766,20 @@ utf8validate(Rune *u, size_t i)
  1077. void
  1078. selinit(void)
  1079. {
  1080. - clock_gettime(CLOCK_MONOTONIC, &sel.tclick1);
  1081. - clock_gettime(CLOCK_MONOTONIC, &sel.tclick2);
  1082. + sel.tclick1 = 0;
  1083. + sel.tclick2 = 0;
  1084. sel.mode = SEL_IDLE;
  1085. sel.snap = 0;
  1086. sel.ob.x = -1;
  1087. sel.primary = NULL;
  1088. - sel.clipboard = NULL;
  1089. - sel.xtarget = XInternAtom(xw.dpy, "UTF8_STRING", 0);
  1090. - if (sel.xtarget == None)
  1091. - sel.xtarget = XA_STRING;
  1092. + sel.source = NULL;
  1093. }
  1094. int
  1095. x2col(int x)
  1096. {
  1097. x -= borderpx;
  1098. - x /= xw.cw;
  1099. + x /= wl.cw;
  1100. return LIMIT(x, 0, term.col-1);
  1101. }
  1102. @@ -732,7 +788,7 @@ int
  1103. y2row(int y)
  1104. {
  1105. y -= borderpx;
  1106. - y /= xw.ch;
  1107. + y /= wl.ch;
  1108. return LIMIT(y, 0, term.row-1);
  1109. }
  1110. @@ -868,15 +924,15 @@ selsnap(int *x, int *y, int direction)
  1111. }
  1112. void
  1113. -getbuttoninfo(XEvent *e)
  1114. +getbuttoninfo(void)
  1115. {
  1116. int type;
  1117. - uint state = e->xbutton.state & ~(Button1Mask | forceselmod);
  1118. + uint state = wl.xkb.mods & ~forceselmod;
  1119. sel.alt = IS_SET(MODE_ALTSCREEN);
  1120. - sel.oe.x = x2col(e->xbutton.x);
  1121. - sel.oe.y = y2row(e->xbutton.y);
  1122. + sel.oe.x = x2col(wl.px);
  1123. + sel.oe.y = y2row(wl.py);
  1124. selnormalize();
  1125. sel.type = SEL_REGULAR;
  1126. @@ -889,59 +945,20 @@ getbuttoninfo(XEvent *e)
  1127. }
  1128. void
  1129. -mousereport(XEvent *e)
  1130. +wlmousereport(int button, bool release, int x, int y)
  1131. {
  1132. - int x = x2col(e->xbutton.x), y = y2row(e->xbutton.y),
  1133. - button = e->xbutton.button, state = e->xbutton.state,
  1134. - len;
  1135. + int len;
  1136. char buf[40];
  1137. - static int ox, oy;
  1138. -
  1139. - /* from urxvt */
  1140. - if (e->xbutton.type == MotionNotify) {
  1141. - if (x == ox && y == oy)
  1142. - return;
  1143. - if (!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY))
  1144. - return;
  1145. - /* MOUSE_MOTION: no reporting if no button is pressed */
  1146. - if (IS_SET(MODE_MOUSEMOTION) && oldbutton == 3)
  1147. - return;
  1148. -
  1149. - button = oldbutton + 32;
  1150. - ox = x;
  1151. - oy = y;
  1152. - } else {
  1153. - if (!IS_SET(MODE_MOUSESGR) && e->xbutton.type == ButtonRelease) {
  1154. - button = 3;
  1155. - } else {
  1156. - button -= Button1;
  1157. - if (button >= 3)
  1158. - button += 64 - 3;
  1159. - }
  1160. - if (e->xbutton.type == ButtonPress) {
  1161. - oldbutton = button;
  1162. - ox = x;
  1163. - oy = y;
  1164. - } else if (e->xbutton.type == ButtonRelease) {
  1165. - oldbutton = 3;
  1166. - /* MODE_MOUSEX10: no button release reporting */
  1167. - if (IS_SET(MODE_MOUSEX10))
  1168. - return;
  1169. - if (button == 64 || button == 65)
  1170. - return;
  1171. - }
  1172. - }
  1173. if (!IS_SET(MODE_MOUSEX10)) {
  1174. - button += ((state & ShiftMask ) ? 4 : 0)
  1175. - + ((state & Mod4Mask ) ? 8 : 0)
  1176. - + ((state & ControlMask) ? 16 : 0);
  1177. + button += ((wl.xkb.mods & MOD_MASK_SHIFT) ? 4 : 0)
  1178. + + ((wl.xkb.mods & MOD_MASK_LOGO ) ? 8 : 0)
  1179. + + ((wl.xkb.mods & MOD_MASK_CTRL ) ? 16 : 0);
  1180. }
  1181. if (IS_SET(MODE_MOUSESGR)) {
  1182. len = snprintf(buf, sizeof(buf), "\033[<%d;%d;%d%c",
  1183. - button, x+1, y+1,
  1184. - e->xbutton.type == ButtonRelease ? 'm' : 'M');
  1185. + button, x+1, y+1, release ? 'm' : 'M');
  1186. } else if (x < 223 && y < 223) {
  1187. len = snprintf(buf, sizeof(buf), "\033[M%c%c%c",
  1188. 32+button, 32+x+1, 32+y+1);
  1189. @@ -953,53 +970,59 @@ mousereport(XEvent *e)
  1190. }
  1191. void
  1192. -bpress(XEvent *e)
  1193. +wlmousereportbutton(uint32_t button, uint32_t state)
  1194. {
  1195. - struct timespec now;
  1196. - MouseShortcut *ms;
  1197. + bool release = state == WL_POINTER_BUTTON_STATE_RELEASED;
  1198. - if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
  1199. - mousereport(e);
  1200. - return;
  1201. + if (!IS_SET(MODE_MOUSESGR) && release) {
  1202. + button = 3;
  1203. + } else {
  1204. + switch (button) {
  1205. + case BTN_LEFT:
  1206. + button = 0;
  1207. + break;
  1208. + case BTN_MIDDLE:
  1209. + button = 1;
  1210. + break;
  1211. + case BTN_RIGHT:
  1212. + button = 2;
  1213. + break;
  1214. + }
  1215. }
  1216. - for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
  1217. - if (e->xbutton.button == ms->b
  1218. - && match(ms->mask, e->xbutton.state)) {
  1219. - ttysend(ms->s, strlen(ms->s));
  1220. - return;
  1221. - }
  1222. + oldbutton = release ? 3 : button;
  1223. +
  1224. + /* don't report release events when in X10 mode */
  1225. + if (IS_SET(MODE_MOUSEX10) && release) {
  1226. + return;
  1227. }
  1228. - if (e->xbutton.button == Button1) {
  1229. - clock_gettime(CLOCK_MONOTONIC, &now);
  1230. + wlmousereport(button, release, oldx, oldy);
  1231. +}
  1232. - /* Clear previous selection, logically and visually. */
  1233. - selclear(NULL);
  1234. - sel.mode = SEL_EMPTY;
  1235. - sel.type = SEL_REGULAR;
  1236. - sel.oe.x = sel.ob.x = x2col(e->xbutton.x);
  1237. - sel.oe.y = sel.ob.y = y2row(e->xbutton.y);
  1238. +void
  1239. +wlmousereportmotion(wl_fixed_t fx, wl_fixed_t fy)
  1240. +{
  1241. + int x = x2col(wl_fixed_to_int(fx)), y = y2row(wl_fixed_to_int(fy));
  1242. - /*
  1243. - * If the user clicks below predefined timeouts specific
  1244. - * snapping behaviour is exposed.
  1245. - */
  1246. - if (TIMEDIFF(now, sel.tclick2) <= tripleclicktimeout) {
  1247. - sel.snap = SNAP_LINE;
  1248. - } else if (TIMEDIFF(now, sel.tclick1) <= doubleclicktimeout) {
  1249. - sel.snap = SNAP_WORD;
  1250. - } else {
  1251. - sel.snap = 0;
  1252. - }
  1253. - selnormalize();
  1254. + if (x == oldx && y == oldy)
  1255. + return;
  1256. + if (!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY))
  1257. + return;
  1258. + /* MOUSE_MOTION: no reporting if no button is pressed */
  1259. + if (IS_SET(MODE_MOUSEMOTION) && oldbutton == 3)
  1260. + return;
  1261. - if (sel.snap != 0)
  1262. - sel.mode = SEL_READY;
  1263. - tsetdirt(sel.nb.y, sel.ne.y);
  1264. - sel.tclick2 = sel.tclick1;
  1265. - sel.tclick1 = now;
  1266. - }
  1267. + oldx = x;
  1268. + oldy = y;
  1269. + wlmousereport(oldbutton + 32, false, x, y);
  1270. +}
  1271. +
  1272. +void
  1273. +wlmousereportaxis(uint32_t axis, wl_fixed_t amount)
  1274. +{
  1275. + wlmousereport(64 + (axis == AXIS_VERTICAL ? 4 : 6)
  1276. + + (amount > 0 ? 1 : 0), false, oldx, oldy);
  1277. }
  1278. char *
  1279. @@ -1057,148 +1080,67 @@ getsel(void)
  1280. }
  1281. void
  1282. -selcopy(Time t)
  1283. -{
  1284. - xsetsel(getsel(), t);
  1285. -}
  1286. -
  1287. -void
  1288. -propnotify(XEvent *e)
  1289. +selcopy(uint32_t serial)
  1290. {
  1291. - XPropertyEvent *xpev;
  1292. - Atom clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
  1293. -
  1294. - xpev = &e->xproperty;
  1295. - if (xpev->state == PropertyNewValue &&
  1296. - (xpev->atom == XA_PRIMARY ||
  1297. - xpev->atom == clipboard)) {
  1298. - selnotify(e);
  1299. - }
  1300. + wlsetsel(getsel(), serial);
  1301. }
  1302. -void
  1303. -selnotify(XEvent *e)
  1304. +static inline void
  1305. +selwritebuf(char *buf, int len)
  1306. {
  1307. - ulong nitems, ofs, rem;
  1308. - int format;
  1309. - uchar *data, *last, *repl;
  1310. - Atom type, incratom, property;
  1311. -
  1312. - incratom = XInternAtom(xw.dpy, "INCR", 0);
  1313. -
  1314. - ofs = 0;
  1315. - if (e->type == SelectionNotify) {
  1316. - property = e->xselection.property;
  1317. - } else if(e->type == PropertyNotify) {
  1318. - property = e->xproperty.atom;
  1319. - } else {
  1320. - return;
  1321. - }
  1322. - if (property == None)
  1323. - return;
  1324. -
  1325. - do {
  1326. - if (XGetWindowProperty(xw.dpy, xw.win, property, ofs,
  1327. - BUFSIZ/4, False, AnyPropertyType,
  1328. - &type, &format, &nitems, &rem,
  1329. - &data)) {
  1330. - fprintf(stderr, "Clipboard allocation failed\n");
  1331. - return;
  1332. - }
  1333. -
  1334. - if (e->type == PropertyNotify && nitems == 0 && rem == 0) {
  1335. - /*
  1336. - * If there is some PropertyNotify with no data, then
  1337. - * this is the signal of the selection owner that all
  1338. - * data has been transferred. We won't need to receive
  1339. - * PropertyNotify events anymore.
  1340. - */
  1341. - MODBIT(xw.attrs.event_mask, 0, PropertyChangeMask);
  1342. - XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask,
  1343. - &xw.attrs);
  1344. - }
  1345. -
  1346. - if (type == incratom) {
  1347. - /*
  1348. - * Activate the PropertyNotify events so we receive
  1349. - * when the selection owner does send us the next
  1350. - * chunk of data.
  1351. - */
  1352. - MODBIT(xw.attrs.event_mask, 1, PropertyChangeMask);
  1353. - XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask,
  1354. - &xw.attrs);
  1355. -
  1356. - /*
  1357. - * Deleting the property is the transfer start signal.
  1358. - */
  1359. - XDeleteProperty(xw.dpy, xw.win, (int)property);
  1360. - continue;
  1361. - }
  1362. -
  1363. - /*
  1364. - * As seen in getsel:
  1365. - * Line endings are inconsistent in the terminal and GUI world
  1366. - * copy and pasting. When receiving some selection data,
  1367. - * replace all '\n' with '\r'.
  1368. - * FIXME: Fix the computer world.
  1369. - */
  1370. - repl = data;
  1371. - last = data + nitems * format / 8;
  1372. - while ((repl = memchr(repl, '\n', last - repl))) {
  1373. - *repl++ = '\r';
  1374. - }
  1375. -
  1376. - if (IS_SET(MODE_BRCKTPASTE) && ofs == 0)
  1377. - ttywrite("\033[200~", 6);
  1378. - ttysend((char *)data, nitems * format / 8);
  1379. - if (IS_SET(MODE_BRCKTPASTE) && rem == 0)
  1380. - ttywrite("\033[201~", 6);
  1381. - XFree(data);
  1382. - /* number of 32-bit chunks returned */
  1383. - ofs += nitems * format / 32;
  1384. - } while (rem > 0);
  1385. + char *repl = buf;
  1386. /*
  1387. - * Deleting the property again tells the selection owner to send the
  1388. - * next data chunk in the property.
  1389. + * As seen in getsel:
  1390. + * Line endings are inconsistent in the terminal and GUI world
  1391. + * copy and pasting. When receiving some selection data,
  1392. + * replace all '\n' with '\r'.
  1393. + * FIXME: Fix the computer world.
  1394. */
  1395. - XDeleteProperty(xw.dpy, xw.win, (int)property);
  1396. -}
  1397. + while ((repl = memchr(repl, '\n', len))) {
  1398. + *repl++ = '\r';
  1399. + }
  1400. -void
  1401. -selpaste(const Arg *dummy)
  1402. -{
  1403. - XConvertSelection(xw.dpy, XA_PRIMARY, sel.xtarget, XA_PRIMARY,
  1404. - xw.win, CurrentTime);
  1405. + ttysend(buf, len);
  1406. }
  1407. void
  1408. -clipcopy(const Arg *dummy)
  1409. +selpaste(const Arg *dummy)
  1410. {
  1411. - Atom clipboard;
  1412. + int fds[2], len, left;
  1413. + char buf[BUFSIZ], *str;
  1414. - if (sel.clipboard != NULL)
  1415. - free(sel.clipboard);
  1416. -
  1417. - if (sel.primary != NULL) {
  1418. - sel.clipboard = xstrdup(sel.primary);
  1419. - clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
  1420. - XSetSelectionOwner(xw.dpy, clipboard, xw.win, CurrentTime);
  1421. + if (wl.seloffer) {
  1422. + if (IS_SET(MODE_BRCKTPASTE))
  1423. + ttywrite("\033[200~", 6);
  1424. + /* check if we are pasting from ourselves */
  1425. + if (sel.source) {
  1426. + str = sel.primary;
  1427. + left = strlen(sel.primary);
  1428. + while (left > 0) {
  1429. + len = MIN(sizeof buf, left);
  1430. + memcpy(buf, str, len);
  1431. + selwritebuf(buf, len);
  1432. + left -= len;
  1433. + str += len;
  1434. + }
  1435. + } else {
  1436. + pipe(fds);
  1437. + wl_data_offer_receive(wl.seloffer, "text/plain", fds[1]);
  1438. + close(fds[1]);
  1439. + wl_display_flush(wl.dpy);
  1440. + while ((len = read(fds[0], buf, sizeof buf)) > 0) {
  1441. + selwritebuf(buf, len);
  1442. + }
  1443. + close(fds[0]);
  1444. + }
  1445. + if (IS_SET(MODE_BRCKTPASTE))
  1446. + ttywrite("\033[201~", 6);
  1447. }
  1448. }
  1449. void
  1450. -clippaste(const Arg *dummy)
  1451. -{
  1452. - Atom clipboard;
  1453. -
  1454. - clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
  1455. - XConvertSelection(xw.dpy, clipboard, sel.xtarget, clipboard,
  1456. - xw.win, CurrentTime);
  1457. -}
  1458. -
  1459. -void
  1460. -selclear(XEvent *e)
  1461. +selclear(void)
  1462. {
  1463. if (sel.ob.x == -1)
  1464. return;
  1465. @@ -1208,117 +1150,19 @@ selclear(XEvent *e)
  1466. }
  1467. void
  1468. -selrequest(XEvent *e)
  1469. -{
  1470. - XSelectionRequestEvent *xsre;
  1471. - XSelectionEvent xev;
  1472. - Atom xa_targets, string, clipboard;
  1473. - char *seltext;
  1474. -
  1475. - xsre = (XSelectionRequestEvent *) e;
  1476. - xev.type = SelectionNotify;
  1477. - xev.requestor = xsre->requestor;
  1478. - xev.selection = xsre->selection;
  1479. - xev.target = xsre->target;
  1480. - xev.time = xsre->time;
  1481. - if (xsre->property == None)
  1482. - xsre->property = xsre->target;
  1483. -
  1484. - /* reject */
  1485. - xev.property = None;
  1486. -
  1487. - xa_targets = XInternAtom(xw.dpy, "TARGETS", 0);
  1488. - if (xsre->target == xa_targets) {
  1489. - /* respond with the supported type */
  1490. - string = sel.xtarget;
  1491. - XChangeProperty(xsre->display, xsre->requestor, xsre->property,
  1492. - XA_ATOM, 32, PropModeReplace,
  1493. - (uchar *) &string, 1);
  1494. - xev.property = xsre->property;
  1495. - } else if (xsre->target == sel.xtarget || xsre->target == XA_STRING) {
  1496. - /*
  1497. - * xith XA_STRING non ascii characters may be incorrect in the
  1498. - * requestor. It is not our problem, use utf8.
  1499. - */
  1500. - clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
  1501. - if (xsre->selection == XA_PRIMARY) {
  1502. - seltext = sel.primary;
  1503. - } else if (xsre->selection == clipboard) {
  1504. - seltext = sel.clipboard;
  1505. - } else {
  1506. - fprintf(stderr,
  1507. - "Unhandled clipboard selection 0x%lx\n",
  1508. - xsre->selection);
  1509. - return;
  1510. - }
  1511. - if (seltext != NULL) {
  1512. - XChangeProperty(xsre->display, xsre->requestor,
  1513. - xsre->property, xsre->target,
  1514. - 8, PropModeReplace,
  1515. - (uchar *)seltext, strlen(seltext));
  1516. - xev.property = xsre->property;
  1517. - }
  1518. - }
  1519. -
  1520. - /* all done, send a notification to the listener */
  1521. - if (!XSendEvent(xsre->display, xsre->requestor, 1, 0, (XEvent *) &xev))
  1522. - fprintf(stderr, "Error sending SelectionNotify event\n");
  1523. -}
  1524. -
  1525. -void
  1526. -xsetsel(char *str, Time t)
  1527. +wlsetsel(char *str, uint32_t serial)
  1528. {
  1529. free(sel.primary);
  1530. sel.primary = str;
  1531. - XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, t);
  1532. - if (XGetSelectionOwner(xw.dpy, XA_PRIMARY) != xw.win)
  1533. - selclear(0);
  1534. -}
  1535. -
  1536. -void
  1537. -brelease(XEvent *e)
  1538. -{
  1539. - if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
  1540. - mousereport(e);
  1541. - return;
  1542. - }
  1543. -
  1544. - if (e->xbutton.button == Button2) {
  1545. - selpaste(NULL);
  1546. - } else if (e->xbutton.button == Button1) {
  1547. - if (sel.mode == SEL_READY) {
  1548. - getbuttoninfo(e);
  1549. - selcopy(e->xbutton.time);
  1550. - } else
  1551. - selclear(NULL);
  1552. - sel.mode = SEL_IDLE;
  1553. - tsetdirt(sel.nb.y, sel.ne.y);
  1554. - }
  1555. -}
  1556. -
  1557. -void
  1558. -bmotion(XEvent *e)
  1559. -{
  1560. - int oldey, oldex, oldsby, oldsey;
  1561. -
  1562. - if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
  1563. - mousereport(e);
  1564. - return;
  1565. + if (str) {
  1566. + sel.source = wl_data_device_manager_create_data_source(wl.datadevmanager);
  1567. + wl_data_source_add_listener(sel.source, &datasrclistener, NULL);
  1568. + wl_data_source_offer(sel.source, "text/plain;charset=utf-8");
  1569. + } else {
  1570. + sel.source = NULL;
  1571. }
  1572. -
  1573. - if (!sel.mode)
  1574. - return;
  1575. -
  1576. - sel.mode = SEL_READY;
  1577. - oldey = sel.oe.y;
  1578. - oldex = sel.oe.x;
  1579. - oldsby = sel.nb.y;
  1580. - oldsey = sel.ne.y;
  1581. - getbuttoninfo(e);
  1582. -
  1583. - if (oldey != sel.oe.y || oldex != sel.oe.x)
  1584. - tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
  1585. + wl_data_device_set_selection(wl.datadev, sel.source, serial);
  1586. }
  1587. void
  1588. @@ -1337,7 +1181,6 @@ execsh(void)
  1589. {
  1590. char **args, *sh, *prog;
  1591. const struct passwd *pw;
  1592. - char buf[sizeof(long) * 8 + 1];
  1593. errno = 0;
  1594. if ((pw = getpwuid(getuid())) == NULL) {
  1595. @@ -1358,8 +1201,6 @@ execsh(void)
  1596. prog = sh;
  1597. args = (opt_cmd) ? opt_cmd : (char *[]) {prog, NULL};
  1598. - snprintf(buf, sizeof(buf), "%lu", xw.win);
  1599. -
  1600. unsetenv("COLUMNS");
  1601. unsetenv("LINES");
  1602. unsetenv("TERMCAP");
  1603. @@ -1368,7 +1209,6 @@ execsh(void)
  1604. setenv("SHELL", sh, 1);
  1605. setenv("HOME", pw->pw_dir, 1);
  1606. setenv("TERM", termname, 1);
  1607. - setenv("WINDOWID", buf, 1);
  1608. signal(SIGCHLD, SIG_DFL);
  1609. signal(SIGHUP, SIG_DFL);
  1610. @@ -1513,6 +1353,7 @@ ttyread(void)
  1611. if (buflen > 0)
  1612. memmove(buf, ptr, buflen);
  1613. + needdraw = true;
  1614. return ret;
  1615. }
  1616. @@ -1606,8 +1447,8 @@ ttyresize(void)
  1617. w.ws_row = term.row;
  1618. w.ws_col = term.col;
  1619. - w.ws_xpixel = xw.tw;
  1620. - w.ws_ypixel = xw.th;
  1621. + w.ws_xpixel = wl.tw;
  1622. + w.ws_ypixel = wl.th;
  1623. if (ioctl(cmdfd, TIOCSWINSZ, &w) < 0)
  1624. fprintf(stderr, "Couldn't set window size: %s\n", strerror(errno));
  1625. }
  1626. @@ -1637,6 +1478,8 @@ tsetdirt(int top, int bot)
  1627. for (i = top; i <= bot; i++)
  1628. term.dirty[i] = 1;
  1629. +
  1630. + needdraw = true;
  1631. }
  1632. void
  1633. @@ -1771,7 +1614,7 @@ selscroll(int orig, int n)
  1634. if (BETWEEN(sel.ob.y, orig, term.bot) || BETWEEN(sel.oe.y, orig, term.bot)) {
  1635. if ((sel.ob.y += n) > term.bot || (sel.oe.y += n) < term.top) {
  1636. - selclear(NULL);
  1637. + selclear();
  1638. return;
  1639. }
  1640. if (sel.type == SEL_RECTANGULAR) {
  1641. @@ -1917,7 +1760,7 @@ tclearregion(int x1, int y1, int x2, int y2)
  1642. for (x = x1; x <= x2; x++) {
  1643. gp = &term.line[y][x];
  1644. if (selected(x, y))
  1645. - selclear(NULL);
  1646. + selclear();
  1647. gp->fg = term.c.attr.fg;
  1648. gp->bg = term.c.attr.bg;
  1649. gp->mode = 0;
  1650. @@ -2180,22 +2023,18 @@ tsetmode(int priv, int set, int *args, int narg)
  1651. MODBIT(term.mode, !set, MODE_HIDE);
  1652. break;
  1653. case 9: /* X10 mouse compatibility mode */
  1654. - xsetpointermotion(0);
  1655. MODBIT(term.mode, 0, MODE_MOUSE);
  1656. MODBIT(term.mode, set, MODE_MOUSEX10);
  1657. break;
  1658. case 1000: /* 1000: report button press */
  1659. - xsetpointermotion(0);
  1660. MODBIT(term.mode, 0, MODE_MOUSE);
  1661. MODBIT(term.mode, set, MODE_MOUSEBTN);
  1662. break;
  1663. case 1002: /* 1002: report motion on button press */
  1664. - xsetpointermotion(0);
  1665. MODBIT(term.mode, 0, MODE_MOUSE);
  1666. MODBIT(term.mode, set, MODE_MOUSEMOTION);
  1667. break;
  1668. case 1003: /* 1003: enable all mouse motions */
  1669. - xsetpointermotion(set);
  1670. MODBIT(term.mode, 0, MODE_MOUSE);
  1671. MODBIT(term.mode, set, MODE_MOUSEMANY);
  1672. break;
  1673. @@ -2368,7 +2207,7 @@ csihandle(void)
  1674. tputtab(csiescseq.arg[0]);
  1675. break;
  1676. case 'J': /* ED -- Clear screen */
  1677. - selclear(NULL);
  1678. + selclear();
  1679. switch (csiescseq.arg[0]) {
  1680. case 0: /* below */
  1681. tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
  1682. @@ -2475,7 +2314,7 @@ csihandle(void)
  1683. if (!BETWEEN(csiescseq.arg[0], 0, 6)) {
  1684. goto unknown;
  1685. }
  1686. - xw.cursor = csiescseq.arg[0];
  1687. + wl.cursor = csiescseq.arg[0];
  1688. break;
  1689. default:
  1690. goto unknown;
  1691. @@ -2531,7 +2370,7 @@ strhandle(void)
  1692. case 1:
  1693. case 2:
  1694. if (narg > 1)
  1695. - xsettitle(strescseq.args[1]);
  1696. + wlsettitle(strescseq.args[1]);
  1697. return;
  1698. case 4: /* color set */
  1699. if (narg < 3)
  1700. @@ -2540,7 +2379,7 @@ strhandle(void)
  1701. /* FALLTHROUGH */
  1702. case 104: /* color reset, here p = NULL */
  1703. j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
  1704. - if (xsetcolorname(j, p)) {
  1705. + if (wlsetcolorname(j, p)) {
  1706. fprintf(stderr, "erresc: invalid color %s\n", p);
  1707. } else {
  1708. /*
  1709. @@ -2553,7 +2392,7 @@ strhandle(void)
  1710. }
  1711. break;
  1712. case 'k': /* old title set compatibility */
  1713. - xsettitle(strescseq.args[0]);
  1714. + wlsettitle(strescseq.args[0]);
  1715. return;
  1716. case 'P': /* DCS -- Device Control String */
  1717. term.mode |= ESC_DCS;
  1718. @@ -2642,13 +2481,11 @@ tprinter(char *s, size_t len)
  1719. void
  1720. iso14755(const Arg *arg)
  1721. {
  1722. - char cmd[sizeof(ISO14755CMD) + NUMMAXLEN(xw.win)];
  1723. FILE *p;
  1724. char *us, *e, codepoint[9], uc[UTF_SIZ];
  1725. unsigned long utf32;
  1726. - snprintf(cmd, sizeof(cmd), ISO14755CMD, xw.win);
  1727. - if (!(p = popen(cmd, "r")))
  1728. + if (!(p = popen(ISO14755CMD, "r")))
  1729. return;
  1730. us = fgets(codepoint, sizeof(codepoint), p);
  1731. @@ -2747,6 +2584,7 @@ techo(Rune u)
  1732. }
  1733. }
  1734. tputc(u);
  1735. + needdraw = true;
  1736. }
  1737. void
  1738. @@ -2833,10 +2671,12 @@ tcontrolcode(uchar ascii)
  1739. /* backwards compatibility to xterm */
  1740. strhandle();
  1741. } else {
  1742. - if (!(xw.state & WIN_FOCUSED))
  1743. - xseturgency(1);
  1744. - if (bellvolume)
  1745. - XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL);
  1746. + if (!(wl.state & WIN_FOCUSED))
  1747. + wlseturgency(1);
  1748. + /* XXX: No bell on wayland
  1749. + * if (bellvolume)
  1750. + * XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL);
  1751. + */
  1752. }
  1753. break;
  1754. case '\033': /* ESC */
  1755. @@ -2968,8 +2808,8 @@ eschandle(uchar ascii)
  1756. break;
  1757. case 'c': /* RIS -- Reset to inital state */
  1758. treset();
  1759. - xresettitle();
  1760. - xloadcols();
  1761. + wlresettitle();
  1762. + wlloadcols();
  1763. break;
  1764. case '=': /* DECPAM -- Application keypad */
  1765. term.mode |= MODE_APPKEYPAD;
  1766. @@ -3026,7 +2866,7 @@ tputc(Rune u)
  1767. */
  1768. if (term.esc & ESC_STR) {
  1769. if (u == '\a' || u == 030 || u == 032 || u == 033 ||
  1770. - ISCONTROLC1(u)) {
  1771. + ISCONTROLC1(u)) {
  1772. term.esc &= ~(ESC_START|ESC_STR|ESC_DCS);
  1773. if (IS_SET(MODE_SIXEL)) {
  1774. /* TODO: render sixel */;
  1775. @@ -3109,7 +2949,7 @@ check_control_code:
  1776. return;
  1777. }
  1778. if (sel.ob.x != -1 && BETWEEN(term.c.y, sel.ob.y, sel.oe.y))
  1779. - selclear(NULL);
  1780. + selclear();
  1781. gp = &term.line[term.c.y][term.c.x];
  1782. if (IS_SET(MODE_WRAP) && (term.c.state & CURSOR_WRAPNEXT)) {
  1783. @@ -3176,9 +3016,6 @@ tresize(int col, int row)
  1784. free(term.alt[i]);
  1785. }
  1786. - /* resize to new width */
  1787. - term.specbuf = xrealloc(term.specbuf, col * sizeof(XftGlyphFontSpec));
  1788. -
  1789. /* resize to new height */
  1790. term.line = xrealloc(term.line, row * sizeof(Line));
  1791. term.alt = xrealloc(term.alt, row * sizeof(Line));
  1792. @@ -3228,155 +3065,107 @@ tresize(int col, int row)
  1793. }
  1794. void
  1795. -xresize(int col, int row)
  1796. +wlresize(int col, int row)
  1797. {
  1798. - xw.tw = MAX(1, col * xw.cw);
  1799. - xw.th = MAX(1, row * xw.ch);
  1800. + union wld_object object;
  1801. +
  1802. + wl.tw = MAX(1, col * wl.cw);
  1803. + wl.th = MAX(1, row * wl.ch);
  1804. - XFreePixmap(xw.dpy, xw.buf);
  1805. - xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h,
  1806. - DefaultDepth(xw.dpy, xw.scr));
  1807. - XftDrawChange(xw.draw, xw.buf);
  1808. - xclear(0, 0, xw.w, xw.h);
  1809. + wld.oldbuffer = wld.buffer;
  1810. + wld.buffer = wld_create_buffer(wld.ctx, wl.w, wl.h,
  1811. + WLD_FORMAT_XRGB8888, 0);
  1812. + wld_export(wld.buffer, WLD_WAYLAND_OBJECT_BUFFER, &object);
  1813. + wl.buffer = object.ptr;
  1814. }
  1815. -ushort
  1816. -sixd_to_16bit(int x)
  1817. +uchar
  1818. +sixd_to_8bit(int x)
  1819. {
  1820. - return x == 0 ? 0 : 0x3737 + 0x2828 * x;
  1821. + return x == 0 ? 0 : 0x37 + 0x28 * x;
  1822. }
  1823. int
  1824. -xloadcolor(int i, const char *name, Color *ncolor)
  1825. +wlloadcolor(int i, const char *name, uint32_t *color)
  1826. {
  1827. - XRenderColor color = { .alpha = 0xffff };
  1828. -
  1829. if (!name) {
  1830. if (BETWEEN(i, 16, 255)) { /* 256 color */
  1831. if (i < 6*6*6+16) { /* same colors as xterm */
  1832. - color.red = sixd_to_16bit( ((i-16)/36)%6 );
  1833. - color.green = sixd_to_16bit( ((i-16)/6) %6 );
  1834. - color.blue = sixd_to_16bit( ((i-16)/1) %6 );
  1835. + *color = 0xff << 24 | sixd_to_8bit(((i-16)/36)%6) << 16
  1836. + | sixd_to_8bit(((i-16)/6)%6) << 8
  1837. + | sixd_to_8bit(((i-16)/1)%6);
  1838. } else { /* greyscale */
  1839. - color.red = 0x0808 + 0x0a0a * (i - (6*6*6+16));
  1840. - color.green = color.blue = color.red;
  1841. + *color = 0xff << 24 | (0x8 + 0xa * (i-(6*6*6+16))) * 0x10101;
  1842. }
  1843. - return XftColorAllocValue(xw.dpy, xw.vis,
  1844. - xw.cmap, &color, ncolor);
  1845. + return true;
  1846. } else
  1847. name = colorname[i];
  1848. }
  1849. - return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
  1850. + return wld_lookup_named_color(name, color);
  1851. }
  1852. void
  1853. -xloadcols(void)
  1854. +wlloadcols(void)
  1855. {
  1856. int i;
  1857. - static int loaded;
  1858. - Color *cp;
  1859. -
  1860. - if (loaded) {
  1861. - for (cp = dc.col; cp < &dc.col[LEN(dc.col)]; ++cp)
  1862. - XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
  1863. - }
  1864. for (i = 0; i < LEN(dc.col); i++)
  1865. - if (!xloadcolor(i, NULL, &dc.col[i])) {
  1866. + if (!wlloadcolor(i, NULL, &dc.col[i])) {
  1867. if (colorname[i])
  1868. die("Could not allocate color '%s'\n", colorname[i]);
  1869. else
  1870. die("Could not allocate color %d\n", i);
  1871. }
  1872. - loaded = 1;
  1873. }
  1874. int
  1875. -xsetcolorname(int x, const char *name)
  1876. +wlsetcolorname(int x, const char *name)
  1877. {
  1878. - Color ncolor;
  1879. + uint32_t color;
  1880. if (!BETWEEN(x, 0, LEN(dc.col)))
  1881. return 1;
  1882. -
  1883. - if (!xloadcolor(x, name, &ncolor))
  1884. + if (!wlloadcolor(x, name, &color))
  1885. return 1;
  1886. - XftColorFree(xw.dpy, xw.vis, xw.cmap, &dc.col[x]);
  1887. - dc.col[x] = ncolor;
  1888. + dc.col[x] = color;
  1889. return 0;
  1890. }
  1891. -/*
  1892. - * Absolute coordinates.
  1893. - */
  1894. -void
  1895. -xclear(int x1, int y1, int x2, int y2)
  1896. +static void wlloadcursor(void)
  1897. {
  1898. - XftDrawRect(xw.draw,
  1899. - &dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg],
  1900. - x1, y1, x2-x1, y2-y1);
  1901. -}
  1902. + char *names[] = { mouseshape, "xterm", "ibeam", "text" };
  1903. + int i;
  1904. -void
  1905. -xhints(void)
  1906. -{
  1907. - XClassHint class = {opt_name ? opt_name : termname,
  1908. - opt_class ? opt_class : termname};
  1909. - XWMHints wm = {.flags = InputHint, .input = 1};
  1910. - XSizeHints *sizeh = NULL;
  1911. -
  1912. - sizeh = XAllocSizeHints();
  1913. -
  1914. - sizeh->flags = PSize | PResizeInc | PBaseSize;
  1915. - sizeh->height = xw.h;
  1916. - sizeh->width = xw.w;
  1917. - sizeh->height_inc = xw.ch;
  1918. - sizeh->width_inc = xw.cw;
  1919. - sizeh->base_height = 2 * borderpx;
  1920. - sizeh->base_width = 2 * borderpx;
  1921. - if (xw.isfixed) {
  1922. - sizeh->flags |= PMaxSize | PMinSize;
  1923. - sizeh->min_width = sizeh->max_width = xw.w;
  1924. - sizeh->min_height = sizeh->max_height = xw.h;
  1925. - }
  1926. - if (xw.gm & (XValue|YValue)) {
  1927. - sizeh->flags |= USPosition | PWinGravity;
  1928. - sizeh->x = xw.l;
  1929. - sizeh->y = xw.t;
  1930. - sizeh->win_gravity = xgeommasktogravity(xw.gm);
  1931. - }
  1932. + cursor.theme = wl_cursor_theme_load(NULL, 32, wl.shm);
  1933. +
  1934. + for (i = 0; !cursor.cursor && i < LEN(names); i++)
  1935. + cursor.cursor = wl_cursor_theme_get_cursor(cursor.theme, names[i]);
  1936. - XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm,
  1937. - &class);
  1938. - XFree(sizeh);
  1939. + cursor.surface = wl_compositor_create_surface(wl.cmp);
  1940. }
  1941. -int
  1942. -xgeommasktogravity(int mask)
  1943. +/*
  1944. + * Absolute coordinates.
  1945. + */
  1946. +void
  1947. +wlclear(int x1, int y1, int x2, int y2)
  1948. {
  1949. - switch (mask & (XNegative|YNegative)) {
  1950. - case 0:
  1951. - return NorthWestGravity;
  1952. - case XNegative:
  1953. - return NorthEastGravity;
  1954. - case YNegative:
  1955. - return SouthWestGravity;
  1956. - }
  1957. + uint32_t color = dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg];
  1958. - return SouthEastGravity;
  1959. + wld_fill_rectangle(wld.renderer, color, x1, y1, x2 - x1, y2 - y1);
  1960. }
  1961. int
  1962. -xloadfont(Font *f, FcPattern *pattern)
  1963. +wlloadfont(Font *f, FcPattern *pattern)
  1964. {
  1965. FcPattern *configured;
  1966. FcPattern *match;
  1967. FcResult result;
  1968. - XGlyphInfo extents;
  1969. + struct wld_extents extents;
  1970. int wantattr, haveattr;
  1971. /*
  1972. @@ -3389,7 +3178,7 @@ xloadfont(Font *f, FcPattern *pattern)
  1973. return 1;
  1974. FcConfigSubstitute(NULL, configured, FcMatchPattern);
  1975. - XftDefaultSubstitute(xw.dpy, xw.scr, configured);
  1976. + FcDefaultSubstitute(configured);
  1977. match = FcFontMatch(NULL, configured, &result);
  1978. if (!match) {
  1979. @@ -3397,37 +3186,36 @@ xloadfont(Font *f, FcPattern *pattern)
  1980. return 1;
  1981. }
  1982. - if (!(f->match = XftFontOpenPattern(xw.dpy, match))) {
  1983. + if (!(f->match = wld_font_open_pattern(wld.fontctx, match))) {
  1984. FcPatternDestroy(configured);
  1985. FcPatternDestroy(match);
  1986. return 1;
  1987. }
  1988. - if ((XftPatternGetInteger(pattern, "slant", 0, &wantattr) ==
  1989. - XftResultMatch)) {
  1990. + if ((FcPatternGetInteger(pattern, "slant", 0, &wantattr) ==
  1991. + FcResultMatch)) {
  1992. /*
  1993. * Check if xft was unable to find a font with the appropriate
  1994. * slant but gave us one anyway. Try to mitigate.
  1995. */
  1996. - if ((XftPatternGetInteger(f->match->pattern, "slant", 0,
  1997. - &haveattr) != XftResultMatch) || haveattr < wantattr) {
  1998. + if ((FcPatternGetInteger(match, "slant", 0,
  1999. + &haveattr) != FcResultMatch) || haveattr < wantattr) {
  2000. f->badslant = 1;
  2001. fputs("st: font slant does not match\n", stderr);
  2002. }
  2003. }
  2004. - if ((XftPatternGetInteger(pattern, "weight", 0, &wantattr) ==
  2005. - XftResultMatch)) {
  2006. - if ((XftPatternGetInteger(f->match->pattern, "weight", 0,
  2007. - &haveattr) != XftResultMatch) || haveattr != wantattr) {
  2008. + if ((FcPatternGetInteger(pattern, "weight", 0, &wantattr) ==
  2009. + FcResultMatch)) {
  2010. + if ((FcPatternGetInteger(match, "weight", 0,
  2011. + &haveattr) != FcResultMatch) || haveattr != wantattr) {
  2012. f->badweight = 1;
  2013. fputs("st: font weight does not match\n", stderr);
  2014. }
  2015. }
  2016. - XftTextExtentsUtf8(xw.dpy, f->match,
  2017. - (const FcChar8 *) ascii_printable,
  2018. - strlen(ascii_printable), &extents);
  2019. +
  2020. + wld_font_text_extents(f->match, ascii_printable, &extents);
  2021. f->set = NULL;
  2022. f->pattern = configured;
  2023. @@ -3435,23 +3223,24 @@ xloadfont(Font *f, FcPattern *pattern)
  2024. f->ascent = f->match->ascent;
  2025. f->descent = f->match->descent;
  2026. f->lbearing = 0;
  2027. - f->rbearing = f->match->max_advance_width;
  2028. + f->rbearing = f->match->max_advance;
  2029. f->height = f->ascent + f->descent;
  2030. - f->width = DIVCEIL(extents.xOff, strlen(ascii_printable));
  2031. + f->width = DIVCEIL(extents.advance, strlen(ascii_printable));
  2032. return 0;
  2033. }
  2034. void
  2035. -xloadfonts(char *fontstr, double fontsize)
  2036. +wlloadfonts(char *fontstr, double fontsize)
  2037. {
  2038. FcPattern *pattern;
  2039. double fontval;
  2040. float ceilf(float);
  2041. if (fontstr[0] == '-') {
  2042. - pattern = XftXlfdParse(fontstr, False, False);
  2043. + /* XXX: need XftXlfdParse equivalent */
  2044. + pattern = NULL;
  2045. } else {
  2046. pattern = FcNameParse((FcChar8 *)fontstr);
  2047. }
  2048. @@ -3482,11 +3271,14 @@ xloadfonts(char *fontstr, double fontsize)
  2049. defaultfontsize = usedfontsize;
  2050. }
  2051. - if (xloadfont(&dc.font, pattern))
  2052. + FcConfigSubstitute(0, pattern, FcMatchPattern);
  2053. + FcDefaultSubstitute(pattern);
  2054. +
  2055. + if (wlloadfont(&dc.font, pattern))
  2056. die("st: can't open font %s\n", fontstr);
  2057. if (usedfontsize < 0) {
  2058. - FcPatternGetDouble(dc.font.match->pattern,
  2059. + FcPatternGetDouble(dc.font.pattern,
  2060. FC_PIXEL_SIZE, 0, &fontval);
  2061. usedfontsize = fontval;
  2062. if (fontsize == 0)
  2063. @@ -3494,282 +3286,339 @@ xloadfonts(char *fontstr, double fontsize)
  2064. }
  2065. /* Setting character width and height. */
  2066. - xw.cw = ceilf(dc.font.width * cwscale);
  2067. - xw.ch = ceilf(dc.font.height * chscale);
  2068. + wl.cw = ceilf(dc.font.width * cwscale);
  2069. + wl.ch = ceilf(dc.font.height * chscale);
  2070. FcPatternDel(pattern, FC_SLANT);
  2071. FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
  2072. - if (xloadfont(&dc.ifont, pattern))
  2073. + if (wlloadfont(&dc.ifont, pattern))
  2074. die("st: can't open font %s\n", fontstr);
  2075. FcPatternDel(pattern, FC_WEIGHT);
  2076. FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
  2077. - if (xloadfont(&dc.ibfont, pattern))
  2078. + if (wlloadfont(&dc.ibfont, pattern))
  2079. die("st: can't open font %s\n", fontstr);
  2080. FcPatternDel(pattern, FC_SLANT);
  2081. FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
  2082. - if (xloadfont(&dc.bfont, pattern))
  2083. + if (wlloadfont(&dc.bfont, pattern))
  2084. die("st: can't open font %s\n", fontstr);
  2085. FcPatternDestroy(pattern);
  2086. }
  2087. void
  2088. -xunloadfont(Font *f)
  2089. +wlunloadfont(Font *f)
  2090. {
  2091. - XftFontClose(xw.dpy, f->match);
  2092. + wld_font_close(f->match);
  2093. FcPatternDestroy(f->pattern);
  2094. if (f->set)
  2095. FcFontSetDestroy(f->set);
  2096. }
  2097. void
  2098. -xunloadfonts(void)
  2099. +wlunloadfonts(void)
  2100. {
  2101. /* Free the loaded fonts in the font cache. */
  2102. while (frclen > 0)
  2103. - XftFontClose(xw.dpy, frc[--frclen].font);
  2104. + wld_font_close(frc[--frclen].font);
  2105. - xunloadfont(&dc.font);
  2106. - xunloadfont(&dc.bfont);
  2107. - xunloadfont(&dc.ifont);
  2108. - xunloadfont(&dc.ibfont);
  2109. + wlunloadfont(&dc.font);
  2110. + wlunloadfont(&dc.bfont);
  2111. + wlunloadfont(&dc.ifont);
  2112. + wlunloadfont(&dc.ibfont);
  2113. }
  2114. void
  2115. -xzoom(const Arg *arg)
  2116. +wlzoom(const Arg *arg)
  2117. {
  2118. Arg larg;
  2119. larg.f = usedfontsize + arg->f;
  2120. - xzoomabs(&larg);
  2121. + wlzoomabs(&larg);
  2122. }
  2123. void
  2124. -xzoomabs(const Arg *arg)
  2125. +wlzoomabs(const Arg *arg)
  2126. {
  2127. - xunloadfonts();
  2128. - xloadfonts(usedfont, arg->f);
  2129. + wlunloadfonts();
  2130. + wlloadfonts(usedfont, arg->f);
  2131. cresize(0, 0);
  2132. ttyresize();
  2133. redraw();
  2134. - xhints();
  2135. + /* XXX: Should the window size be updated here because wayland doesn't
  2136. + * have a notion of hints?
  2137. + * xhints();
  2138. + */
  2139. }
  2140. void
  2141. -xzoomreset(const Arg *arg)
  2142. +wlzoomreset(const Arg *arg)
  2143. {
  2144. Arg larg;
  2145. if (defaultfontsize > 0) {
  2146. larg.f = defaultfontsize;
  2147. - xzoomabs(&larg);
  2148. + wlzoomabs(&larg);
  2149. }
  2150. }
  2151. void
  2152. -xinit(void)
  2153. +wlinit(void)
  2154. {
  2155. - XGCValues gcvalues;
  2156. - Cursor cursor;
  2157. - Window parent;
  2158. - pid_t thispid = getpid();
  2159. - XColor xmousefg, xmousebg;
  2160. + struct wl_registry *registry;
  2161. - if (!(xw.dpy = XOpenDisplay(NULL)))
  2162. + if (!(wl.dpy = wl_display_connect(NULL)))
  2163. die("Can't open display\n");
  2164. - xw.scr = XDefaultScreen(xw.dpy);
  2165. - xw.vis = XDefaultVisual(xw.dpy, xw.scr);
  2166. +
  2167. + registry = wl_display_get_registry(wl.dpy);
  2168. + wl_registry_add_listener(registry, &reglistener, NULL);
  2169. + wld.ctx = wld_wayland_create_context(wl.dpy, WLD_ANY);
  2170. + wld.renderer = wld_create_renderer(wld.ctx);
  2171. +
  2172. + wl_display_roundtrip(wl.dpy);
  2173. +
  2174. + if (!wl.shm)
  2175. + die("Display has no SHM\n");
  2176. + if (!wl.seat)
  2177. + die("Display has no seat\n");
  2178. + if (!wl.datadevmanager)
  2179. + die("Display has no data device manager\n");
  2180. + if (!wl.wm)
  2181. + die("Display has no window manager\n");
  2182. +
  2183. + wl.keyboard = wl_seat_get_keyboard(wl.seat);
  2184. + wl_keyboard_add_listener(wl.keyboard, &kbdlistener, NULL);
  2185. + wl.pointer = wl_seat_get_pointer(wl.seat);
  2186. + wl_pointer_add_listener(wl.pointer, &ptrlistener, NULL);
  2187. + wl.datadev = wl_data_device_manager_get_data_device(wl.datadevmanager,
  2188. + wl.seat);
  2189. + wl_data_device_add_listener(wl.datadev, &datadevlistener, NULL);
  2190. /* font */
  2191. if (!FcInit())
  2192. die("Could not init fontconfig.\n");
  2193. usedfont = (opt_font == NULL)? font : opt_font;
  2194. - xloadfonts(usedfont, 0);
  2195. -
  2196. - /* colors */
  2197. - xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
  2198. - xloadcols();
  2199. -
  2200. - /* adjust fixed window geometry */
  2201. - xw.w = 2 * borderpx + term.col * xw.cw;
  2202. - xw.h = 2 * borderpx + term.row * xw.ch;
  2203. - if (xw.gm & XNegative)
  2204. - xw.l += DisplayWidth(xw.dpy, xw.scr) - xw.w - 2;
  2205. - if (xw.gm & YNegative)
  2206. - xw.t += DisplayHeight(xw.dpy, xw.scr) - xw.h - 2;
  2207. -
  2208. - /* Events */
  2209. - xw.attrs.background_pixel = dc.col[defaultbg].pixel;
  2210. - xw.attrs.border_pixel = dc.col[defaultbg].pixel;
  2211. - xw.attrs.bit_gravity = NorthWestGravity;
  2212. - xw.attrs.event_mask = FocusChangeMask | KeyPressMask
  2213. - | ExposureMask | VisibilityChangeMask | StructureNotifyMask
  2214. - | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
  2215. - xw.attrs.colormap = xw.cmap;
  2216. -
  2217. - if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
  2218. - parent = XRootWindow(xw.dpy, xw.scr);
  2219. - xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
  2220. - xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
  2221. - xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
  2222. - | CWEventMask | CWColormap, &xw.attrs);
  2223. -
  2224. - memset(&gcvalues, 0, sizeof(gcvalues));
  2225. - gcvalues.graphics_exposures = False;
  2226. - dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
  2227. - &gcvalues);
  2228. - xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h,
  2229. - DefaultDepth(xw.dpy, xw.scr));
  2230. - XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
  2231. - XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, xw.w, xw.h);
  2232. -
  2233. - /* Xft rendering context */
  2234. - xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
  2235. -
  2236. - /* input methods */
  2237. - if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
  2238. - XSetLocaleModifiers("@im=local");
  2239. - if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
  2240. - XSetLocaleModifiers("@im=");
  2241. - if ((xw.xim = XOpenIM(xw.dpy,
  2242. - NULL, NULL, NULL)) == NULL) {
  2243. - die("XOpenIM failed. Could not open input"
  2244. - " device.\n");
  2245. - }
  2246. - }
  2247. - }
  2248. - xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing
  2249. - | XIMStatusNothing, XNClientWindow, xw.win,
  2250. - XNFocusWindow, xw.win, NULL);
  2251. - if (xw.xic == NULL)
  2252. - die("XCreateIC failed. Could not obtain input method.\n");
  2253. -
  2254. - /* white cursor, black outline */
  2255. - cursor = XCreateFontCursor(xw.dpy, mouseshape);
  2256. - XDefineCursor(xw.dpy, xw.win, cursor);
  2257. -
  2258. - if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
  2259. - xmousefg.red = 0xffff;
  2260. - xmousefg.green = 0xffff;
  2261. - xmousefg.blue = 0xffff;
  2262. - }
  2263. + wld.fontctx = wld_font_create_context();
  2264. + wlloadfonts(usedfont, 0);
  2265. - if (XParseColor(xw.dpy, xw.cmap, colorname[mousebg], &xmousebg) == 0) {
  2266. - xmousebg.red = 0x0000;
  2267. - xmousebg.green = 0x0000;
  2268. - xmousebg.blue = 0x0000;
  2269. - }
  2270. + wlloadcols();
  2271. + wlloadcursor();
  2272. - XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);
  2273. + wl.vis = 0;
  2274. + wl.h = 2 * borderpx + term.row * wl.ch;
  2275. + wl.w = 2 * borderpx + term.col * wl.cw;
  2276. - xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
  2277. - xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
  2278. - xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False);
  2279. - XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1);
  2280. + wl.surface = wl_compositor_create_surface(wl.cmp);
  2281. + wl_surface_add_listener(wl.surface, &surflistener, NULL);
  2282. - xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False);
  2283. - XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
  2284. - PropModeReplace, (uchar *)&thispid, 1);
  2285. + wl.xdgsurface = xdg_wm_base_get_xdg_surface(wl.wm, wl.surface);
  2286. + xdg_surface_add_listener(wl.xdgsurface, &xdgsurflistener, NULL);
  2287. + wl.toplevel = xdg_surface_get_toplevel(wl.xdgsurface);
  2288. + xdg_toplevel_add_listener(wl.toplevel, &toplevellistener, NULL);
  2289. + xdg_toplevel_set_app_id(wl.toplevel, opt_class ? opt_class : termname);
  2290. + wl_surface_commit(wl.surface);
  2291. - xresettitle();
  2292. - XMapWindow(xw.dpy, xw.win);
  2293. - xhints();
  2294. - XSync(xw.dpy, False);
  2295. + wl.xkb.ctx = xkb_context_new(0);
  2296. + wlresettitle();
  2297. }
  2298. -int
  2299. -xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x, int y)
  2300. +/*
  2301. + * TODO: Implement something like XftDrawGlyphFontSpec in wld, and then apply a
  2302. + * similar patch to ae1923d27533ff46400d93765e971558201ca1ee
  2303. + */
  2304. +
  2305. +void
  2306. +wldraws(char *s, Glyph base, int x, int y, int charlen, int bytelen)
  2307. {
  2308. - float winx = borderpx + x * xw.cw, winy = borderpx + y * xw.ch, xp, yp;
  2309. - ushort mode, prevmode = USHRT_MAX;
  2310. + int winx = borderpx + x * wl.cw, winy = borderpx + y * wl.ch,
  2311. + width = charlen * wl.cw, xp, i;
  2312. + int frcflags, charexists;
  2313. + int u8fl, u8fblen, u8cblen, doesexist;
  2314. + char *u8c, *u8fs;
  2315. + Rune unicodep;
  2316. Font *font = &dc.font;
  2317. - int frcflags = FRC_NORMAL;
  2318. - float runewidth = xw.cw;
  2319. - Rune rune;
  2320. - FT_UInt glyphidx;
  2321. FcResult fcres;
  2322. FcPattern *fcpattern, *fontpattern;
  2323. FcFontSet *fcsets[] = { NULL };
  2324. FcCharSet *fccharset;
  2325. - int i, f, numspecs = 0;
  2326. + uint32_t fg, bg, temp;
  2327. + int oneatatime;
  2328. - for (i = 0, xp = winx, yp = winy + font->ascent; i < len; ++i) {
  2329. - /* Fetch rune and mode for current glyph. */
  2330. - rune = glyphs[i].u;
  2331. - mode = glyphs[i].mode;
  2332. + frcflags = FRC_NORMAL;
  2333. - /* Skip dummy wide-character spacing. */
  2334. - if (mode == ATTR_WDUMMY)
  2335. - continue;
  2336. + /* Fallback on color display for attributes not supported by the font */
  2337. + if (base.mode & ATTR_ITALIC && base.mode & ATTR_BOLD) {
  2338. + if (dc.ibfont.badslant || dc.ibfont.badweight)
  2339. + base.fg = defaultattr;
  2340. + font = &dc.ibfont;
  2341. + frcflags = FRC_ITALICBOLD;
  2342. + } else if (base.mode & ATTR_ITALIC) {
  2343. + if (dc.ifont.badslant)
  2344. + base.fg = defaultattr;
  2345. + font = &dc.ifont;
  2346. + frcflags = FRC_ITALIC;
  2347. + } else if (base.mode & ATTR_BOLD) {
  2348. + if (dc.bfont.badweight)
  2349. + base.fg = defaultattr;
  2350. + font = &dc.ifont;
  2351. + frcflags = FRC_BOLD;
  2352. + }
  2353. - /* Determine font for glyph if different from previous glyph. */
  2354. - if (prevmode != mode) {
  2355. - prevmode = mode;
  2356. - font = &dc.font;
  2357. - frcflags = FRC_NORMAL;
  2358. - runewidth = xw.cw * ((mode & ATTR_WIDE) ? 2.0f : 1.0f);
  2359. - if ((mode & ATTR_ITALIC) && (mode & ATTR_BOLD)) {
  2360. - font = &dc.ibfont;
  2361. - frcflags = FRC_ITALICBOLD;
  2362. - } else if (mode & ATTR_ITALIC) {
  2363. - font = &dc.ifont;
  2364. - frcflags = FRC_ITALIC;
  2365. - } else if (mode & ATTR_BOLD) {
  2366. - font = &dc.bfont;
  2367. - frcflags = FRC_BOLD;
  2368. - }
  2369. - yp = winy + font->ascent;
  2370. + if (IS_TRUECOL(base.fg)) {
  2371. + fg = base.fg | 0xff000000;
  2372. + } else {
  2373. + fg = dc.col[base.fg];
  2374. + }
  2375. +
  2376. + if (IS_TRUECOL(base.bg)) {
  2377. + bg = base.bg | 0xff000000;
  2378. + } else {
  2379. + bg = dc.col[base.bg];
  2380. + }
  2381. +
  2382. + if (base.mode & ATTR_BOLD) {
  2383. + /*
  2384. + * change basic system colors [0-7]
  2385. + * to bright system colors [8-15]
  2386. + */
  2387. + if (BETWEEN(base.fg, 0, 7) && !(base.mode & ATTR_FAINT))
  2388. + fg = dc.col[base.fg + 8];
  2389. +
  2390. + if (base.mode & ATTR_ITALIC) {
  2391. + font = &dc.ibfont;
  2392. + frcflags = FRC_ITALICBOLD;
  2393. + } else {
  2394. + font = &dc.bfont;
  2395. + frcflags = FRC_BOLD;
  2396. }
  2397. + }
  2398. - /* Lookup character index with default font. */
  2399. - glyphidx = XftCharIndex(xw.dpy, font->match, rune);
  2400. - if (glyphidx) {
  2401. - specs[numspecs].font = font->match;
  2402. - specs[numspecs].glyph = glyphidx;
  2403. - specs[numspecs].x = (short)xp;
  2404. - specs[numspecs].y = (short)yp;
  2405. - xp += runewidth;
  2406. - numspecs++;
  2407. - continue;
  2408. + if (IS_SET(MODE_REVERSE)) {
  2409. + if (fg == dc.col[defaultfg]) {
  2410. + fg = dc.col[defaultbg];
  2411. + } else {
  2412. + fg = ~(fg & 0xffffff);
  2413. }
  2414. - /* Fallback on font cache, search the font cache for match. */
  2415. - for (f = 0; f < frclen; f++) {
  2416. - glyphidx = XftCharIndex(xw.dpy, frc[f].font, rune);
  2417. - /* Everything correct. */
  2418. - if (glyphidx && frc[f].flags == frcflags)
  2419. - break;
  2420. - /* We got a default font for a not found glyph. */
  2421. - if (!glyphidx && frc[f].flags == frcflags
  2422. - && frc[f].unicodep == rune) {
  2423. - break;
  2424. - }
  2425. + if (bg == dc.col[defaultbg]) {
  2426. + bg = dc.col[defaultfg];
  2427. + } else {
  2428. + bg = ~(bg & 0xffffff);
  2429. }
  2430. + }
  2431. - /* Nothing was found. Use fontconfig to find matching font. */
  2432. - if (f >= frclen) {
  2433. - if (!font->set)
  2434. - font->set = FcFontSort(0, font->pattern,
  2435. - 1, 0, &fcres);
  2436. - fcsets[0] = font->set;
  2437. + if (base.mode & ATTR_REVERSE) {
  2438. + temp = fg;
  2439. + fg = bg;
  2440. + bg = temp;
  2441. + }
  2442. - /*
  2443. - * Nothing was found in the cache. Now use
  2444. - * some dozen of Fontconfig calls to get the
  2445. - * font for one single character.
  2446. - *
  2447. - * Xft and fontconfig are design failures.
  2448. - */
  2449. - fcpattern = FcPatternDuplicate(font->pattern);
  2450. - fccharset = FcCharSetCreate();
  2451. + if (base.mode & ATTR_FAINT && !(base.mode & ATTR_BOLD)) {
  2452. + fg = (fg & (0xff << 24))
  2453. + | ((((fg >> 16) & 0xff) / 2) << 16)
  2454. + | ((((fg >> 8) & 0xff) / 2) << 8)
  2455. + | ((fg & 0xff) / 2);
  2456. + }
  2457. - FcCharSetAddChar(fccharset, rune);
  2458. - FcPatternAddCharSet(fcpattern, FC_CHARSET,
  2459. - fccharset);
  2460. - FcPatternAddBool(fcpattern, FC_SCALABLE, 1);
  2461. + if (base.mode & ATTR_BLINK && term.mode & MODE_BLINK)
  2462. + fg = bg;
  2463. +
  2464. + if (base.mode & ATTR_INVISIBLE)
  2465. + fg = bg;
  2466. +
  2467. + /* Intelligent cleaning up of the borders. */
  2468. + if (x == 0) {
  2469. + wlclear(0, (y == 0)? 0 : winy, borderpx,
  2470. + ((y >= term.row-1)? wl.h : (winy + wl.ch)));
  2471. + }
  2472. + if (x + charlen >= term.col) {
  2473. + wlclear(winx + width, (y == 0)? 0 : winy, wl.w,
  2474. + ((y >= term.row-1)? wl.h : (winy + wl.ch)));
  2475. + }
  2476. + if (y == 0)
  2477. + wlclear(winx, 0, winx + width, borderpx);
  2478. + if (y == term.row-1)
  2479. + wlclear(winx, winy + wl.ch, winx + width, wl.h);
  2480. +
  2481. + /* Clean up the region we want to draw to. */
  2482. + wld_fill_rectangle(wld.renderer, bg, winx, winy, width, wl.ch);
  2483. +
  2484. + for (xp = winx; bytelen > 0;) {
  2485. + /*
  2486. + * Search for the range in the to be printed string of glyphs
  2487. + * that are in the main font. Then print that range. If
  2488. + * some glyph is found that is not in the font, do the
  2489. + * fallback dance.
  2490. + */
  2491. + u8fs = s;
  2492. + u8fblen = 0;
  2493. + u8fl = 0;
  2494. + oneatatime = font->width != wl.cw;
  2495. + for (;;) {
  2496. + u8c = s;
  2497. + u8cblen = utf8decode(s, &unicodep, UTF_SIZ);
  2498. + s += u8cblen;
  2499. + bytelen -= u8cblen;
  2500. +
  2501. + doesexist = wld_font_ensure_char(font->match, unicodep);
  2502. + if (doesexist) {
  2503. + u8fl++;
  2504. + u8fblen += u8cblen;
  2505. + if (!oneatatime && bytelen > 0)
  2506. + continue;
  2507. + }
  2508. +
  2509. + if (u8fl > 0) {
  2510. + wld_draw_text(wld.renderer,
  2511. + font->match, fg, xp,
  2512. + winy + font->ascent,
  2513. + u8fs, u8fblen, NULL);
  2514. + xp += wl.cw * u8fl;
  2515. + }
  2516. + break;
  2517. + }
  2518. + if (doesexist) {
  2519. + if (oneatatime)
  2520. + continue;
  2521. + break;
  2522. + }
  2523. +
  2524. + /* Search the font cache. */
  2525. + for (i = 0; i < frclen; i++) {
  2526. + charexists = wld_font_ensure_char(frc[i].font, unicodep);
  2527. + /* Everything correct. */
  2528. + if (charexists && frc[i].flags == frcflags)
  2529. + break;
  2530. + /* We got a default font for a not found glyph. */
  2531. + if (!charexists && frc[i].flags == frcflags \
  2532. + && frc[i].unicodep == unicodep) {
  2533. + break;
  2534. + }
  2535. + }
  2536. +
  2537. + /* Nothing was found. */
  2538. + if (i >= frclen) {
  2539. + if (!font->set)
  2540. + font->set = FcFontSort(0, font->pattern,
  2541. + 1, 0, &fcres);
  2542. + fcsets[0] = font->set;
  2543. +
  2544. + /*
  2545. + * Nothing was found in the cache. Now use
  2546. + * some dozen of Fontconfig calls to get the
  2547. + * font for one single character.
  2548. + *
  2549. + * Xft and fontconfig are design failures.
  2550. + */
  2551. + fcpattern = FcPatternDuplicate(font->pattern);
  2552. + fccharset = FcCharSetCreate();
  2553. +
  2554. + FcCharSetAddChar(fccharset, unicodep);
  2555. + FcPatternAddCharSet(fcpattern, FC_CHARSET,
  2556. + fccharset);
  2557. + FcPatternAddBool(fcpattern, FC_SCALABLE, 1);
  2558. FcConfigSubstitute(0, fcpattern,
  2559. FcMatchPattern);
  2560. @@ -3783,186 +3632,58 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
  2561. */
  2562. if (frclen >= LEN(frc)) {
  2563. frclen = LEN(frc) - 1;
  2564. - XftFontClose(xw.dpy, frc[frclen].font);
  2565. + wld_font_close(frc[frclen].font);
  2566. frc[frclen].unicodep = 0;
  2567. }
  2568. - frc[frclen].font = XftFontOpenPattern(xw.dpy,
  2569. + frc[frclen].font = wld_font_open_pattern(wld.fontctx,
  2570. fontpattern);
  2571. frc[frclen].flags = frcflags;
  2572. - frc[frclen].unicodep = rune;
  2573. -
  2574. - glyphidx = XftCharIndex(xw.dpy, frc[frclen].font, rune);
  2575. + frc[frclen].unicodep = unicodep;
  2576. - f = frclen;
  2577. + i = frclen;
  2578. frclen++;
  2579. FcPatternDestroy(fcpattern);
  2580. FcCharSetDestroy(fccharset);
  2581. }
  2582. - specs[numspecs].font = frc[f].font;
  2583. - specs[numspecs].glyph = glyphidx;
  2584. - specs[numspecs].x = (short)xp;
  2585. - specs[numspecs].y = (short)yp;
  2586. - xp += runewidth;
  2587. - numspecs++;
  2588. - }
  2589. -
  2590. - return numspecs;
  2591. -}
  2592. -
  2593. -void
  2594. -xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
  2595. -{
  2596. - int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1);
  2597. - int winx = borderpx + x * xw.cw, winy = borderpx + y * xw.ch,
  2598. - width = charlen * xw.cw;
  2599. - Color *fg, *bg, *temp, revfg, revbg, truefg, truebg;
  2600. - XRenderColor colfg, colbg;
  2601. - XRectangle r;
  2602. -
  2603. - /* Fallback on color display for attributes not supported by the font */
  2604. - if (base.mode & ATTR_ITALIC && base.mode & ATTR_BOLD) {
  2605. - if (dc.ibfont.badslant || dc.ibfont.badweight)
  2606. - base.fg = defaultattr;
  2607. - } else if ((base.mode & ATTR_ITALIC && dc.ifont.badslant) ||
  2608. - (base.mode & ATTR_BOLD && dc.bfont.badweight)) {
  2609. - base.fg = defaultattr;
  2610. - }
  2611. -
  2612. - if (IS_TRUECOL(base.fg)) {
  2613. - colfg.alpha = 0xffff;
  2614. - colfg.red = TRUERED(base.fg);
  2615. - colfg.green = TRUEGREEN(base.fg);
  2616. - colfg.blue = TRUEBLUE(base.fg);
  2617. - XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &truefg);
  2618. - fg = &truefg;
  2619. - } else {
  2620. - fg = &dc.col[base.fg];
  2621. - }
  2622. -
  2623. - if (IS_TRUECOL(base.bg)) {
  2624. - colbg.alpha = 0xffff;
  2625. - colbg.green = TRUEGREEN(base.bg);
  2626. - colbg.red = TRUERED(base.bg);
  2627. - colbg.blue = TRUEBLUE(base.bg);
  2628. - XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg, &truebg);
  2629. - bg = &truebg;
  2630. - } else {
  2631. - bg = &dc.col[base.bg];
  2632. - }
  2633. -
  2634. - /* Change basic system colors [0-7] to bright system colors [8-15] */
  2635. - if ((base.mode & ATTR_BOLD_FAINT) == ATTR_BOLD && BETWEEN(base.fg, 0, 7))
  2636. - fg = &dc.col[base.fg + 8];
  2637. -
  2638. - if (IS_SET(MODE_REVERSE)) {
  2639. - if (fg == &dc.col[defaultfg]) {
  2640. - fg = &dc.col[defaultbg];
  2641. - } else {
  2642. - colfg.red = ~fg->color.red;
  2643. - colfg.green = ~fg->color.green;
  2644. - colfg.blue = ~fg->color.blue;
  2645. - colfg.alpha = fg->color.alpha;
  2646. - XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg,
  2647. - &revfg);
  2648. - fg = &revfg;
  2649. - }
  2650. -
  2651. - if (bg == &dc.col[defaultbg]) {
  2652. - bg = &dc.col[defaultfg];
  2653. - } else {
  2654. - colbg.red = ~bg->color.red;
  2655. - colbg.green = ~bg->color.green;
  2656. - colbg.blue = ~bg->color.blue;
  2657. - colbg.alpha = bg->color.alpha;
  2658. - XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg,
  2659. - &revbg);
  2660. - bg = &revbg;
  2661. - }
  2662. - }
  2663. -
  2664. - if (base.mode & ATTR_REVERSE) {
  2665. - temp = fg;
  2666. - fg = bg;
  2667. - bg = temp;
  2668. - }
  2669. -
  2670. - if ((base.mode & ATTR_BOLD_FAINT) == ATTR_FAINT) {
  2671. - colfg.red = fg->color.red / 2;
  2672. - colfg.green = fg->color.green / 2;
  2673. - colfg.blue = fg->color.blue / 2;
  2674. - XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &revfg);
  2675. - fg = &revfg;
  2676. - }
  2677. -
  2678. - if (base.mode & ATTR_BLINK && term.mode & MODE_BLINK)
  2679. - fg = bg;
  2680. -
  2681. - if (base.mode & ATTR_INVISIBLE)
  2682. - fg = bg;
  2683. + wld_draw_text(wld.renderer, frc[i].font, fg,
  2684. + xp, winy + frc[i].font->ascent,
  2685. + u8c, u8cblen, NULL);
  2686. - /* Intelligent cleaning up of the borders. */
  2687. - if (x == 0) {
  2688. - xclear(0, (y == 0)? 0 : winy, borderpx,
  2689. - winy + xw.ch + ((y >= term.row-1)? xw.h : 0));
  2690. - }
  2691. - if (x + charlen >= term.col) {
  2692. - xclear(winx + width, (y == 0)? 0 : winy, xw.w,
  2693. - ((y >= term.row-1)? xw.h : (winy + xw.ch)));
  2694. + xp += wl.cw * wcwidth(unicodep);
  2695. }
  2696. - if (y == 0)
  2697. - xclear(winx, 0, winx + width, borderpx);
  2698. - if (y == term.row-1)
  2699. - xclear(winx, winy + xw.ch, winx + width, xw.h);
  2700. - /* Clean up the region we want to draw to. */
  2701. - XftDrawRect(xw.draw, bg, winx, winy, width, xw.ch);
  2702. -
  2703. - /* Set the clip region because Xft is sometimes dirty. */
  2704. - r.x = 0;
  2705. - r.y = 0;
  2706. - r.height = xw.ch;
  2707. - r.width = width;
  2708. - XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);
  2709. -
  2710. - /* Render the glyphs. */
  2711. - XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
  2712. -
  2713. - /* Render underline and strikethrough. */
  2714. if (base.mode & ATTR_UNDERLINE) {
  2715. - XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1,
  2716. + wld_fill_rectangle(wld.renderer, fg, winx, winy + font->ascent + 1,
  2717. width, 1);
  2718. }
  2719. if (base.mode & ATTR_STRUCK) {
  2720. - XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3,
  2721. + wld_fill_rectangle(wld.renderer, fg, winx, winy + 2 * font->ascent / 3,
  2722. width, 1);
  2723. }
  2724. -
  2725. - /* Reset clip to none. */
  2726. - XftDrawSetClip(xw.draw, 0);
  2727. }
  2728. void
  2729. -xdrawglyph(Glyph g, int x, int y)
  2730. +wldrawglyph(Glyph g, int x, int y)
  2731. {
  2732. - int numspecs;
  2733. - XftGlyphFontSpec spec;
  2734. + static char buf[UTF_SIZ];
  2735. + size_t len = utf8encode(g.u, buf);
  2736. + int width = g.mode & ATTR_WIDE ? 2 : 1;
  2737. - numspecs = xmakeglyphfontspecs(&spec, &g, 1, x, y);
  2738. - xdrawglyphfontspecs(&spec, g, numspecs, x, y);
  2739. + wldraws(buf, g, x, y, width, len);
  2740. }
  2741. void
  2742. -xdrawcursor(void)
  2743. +wldrawcursor(void)
  2744. {
  2745. static int oldx = 0, oldy = 0;
  2746. int curx;
  2747. Glyph g = {' ', ATTR_NULL, defaultbg, defaultcs}, og;
  2748. int ena_sel = sel.ob.x != -1 && sel.alt == IS_SET(MODE_ALTSCREEN);
  2749. - Color drawcol;
  2750. + uint32_t drawcol;
  2751. LIMIT(oldx, 0, term.col-1);
  2752. LIMIT(oldy, 0, term.row-1);
  2753. @@ -3979,7 +3700,11 @@ xdrawcursor(void)
  2754. og = term.line[oldy][oldx];
  2755. if (ena_sel && selected(oldx, oldy))
  2756. og.mode ^= ATTR_REVERSE;
  2757. - xdrawglyph(og, oldx, oldy);
  2758. + wldrawglyph(og, oldx, oldy);
  2759. + if (oldx != curx || oldy != term.c.y) {
  2760. + wl_surface_damage(wl.surface, borderpx + oldx * wl.cw,
  2761. + borderpx + oldy * wl.ch, wl.cw, wl.ch);
  2762. + }
  2763. g.u = term.line[term.c.y][term.c.x].u;
  2764. @@ -4010,198 +3735,152 @@ xdrawcursor(void)
  2765. return;
  2766. /* draw the new one */
  2767. - if (xw.state & WIN_FOCUSED) {
  2768. - switch (xw.cursor) {
  2769. + if (wl.state & WIN_FOCUSED) {
  2770. + switch (wl.cursor) {
  2771. case 7: /* st extension: snowman */
  2772. utf8decode("☃", &g.u, UTF_SIZ);
  2773. case 0: /* Blinking Block */
  2774. case 1: /* Blinking Block (Default) */
  2775. case 2: /* Steady Block */
  2776. g.mode |= term.line[term.c.y][curx].mode & ATTR_WIDE;
  2777. - xdrawglyph(g, term.c.x, term.c.y);
  2778. + wldrawglyph(g, term.c.x, term.c.y);
  2779. break;
  2780. case 3: /* Blinking Underline */
  2781. case 4: /* Steady Underline */
  2782. - XftDrawRect(xw.draw, &drawcol,
  2783. - borderpx + curx * xw.cw,
  2784. - borderpx + (term.c.y + 1) * xw.ch - \
  2785. + wld_fill_rectangle(wld.renderer, drawcol,
  2786. + borderpx + curx * wl.cw,
  2787. + borderpx + (term.c.y + 1) * wl.ch - \
  2788. cursorthickness,
  2789. - xw.cw, cursorthickness);
  2790. + wl.cw, cursorthickness);
  2791. break;
  2792. case 5: /* Blinking bar */
  2793. case 6: /* Steady bar */
  2794. - XftDrawRect(xw.draw, &drawcol,
  2795. - borderpx + curx * xw.cw,
  2796. - borderpx + term.c.y * xw.ch,
  2797. - cursorthickness, xw.ch);
  2798. + wld_fill_rectangle(wld.renderer, drawcol,
  2799. + borderpx + curx * wl.cw,
  2800. + borderpx + term.c.y * wl.ch,
  2801. + cursorthickness, wl.ch);
  2802. break;
  2803. }
  2804. } else {
  2805. - XftDrawRect(xw.draw, &drawcol,
  2806. - borderpx + curx * xw.cw,
  2807. - borderpx + term.c.y * xw.ch,
  2808. - xw.cw - 1, 1);
  2809. - XftDrawRect(xw.draw, &drawcol,
  2810. - borderpx + curx * xw.cw,
  2811. - borderpx + term.c.y * xw.ch,
  2812. - 1, xw.ch - 1);
  2813. - XftDrawRect(xw.draw, &drawcol,
  2814. - borderpx + (curx + 1) * xw.cw - 1,
  2815. - borderpx + term.c.y * xw.ch,
  2816. - 1, xw.ch - 1);
  2817. - XftDrawRect(xw.draw, &drawcol,
  2818. - borderpx + curx * xw.cw,
  2819. - borderpx + (term.c.y + 1) * xw.ch - 1,
  2820. - xw.cw, 1);
  2821. + wld_fill_rectangle(wld.renderer, drawcol,
  2822. + borderpx + curx * wl.cw,
  2823. + borderpx + term.c.y * wl.ch,
  2824. + wl.cw - 1, 1);
  2825. + wld_fill_rectangle(wld.renderer, drawcol,
  2826. + borderpx + curx * wl.cw,
  2827. + borderpx + term.c.y * wl.ch,
  2828. + 1, wl.ch - 1);
  2829. + wld_fill_rectangle(wld.renderer, drawcol,
  2830. + borderpx + (curx + 1) * wl.cw - 1,
  2831. + borderpx + term.c.y * wl.ch,
  2832. + 1, wl.ch - 1);
  2833. + wld_fill_rectangle(wld.renderer, drawcol,
  2834. + borderpx + curx * wl.cw,
  2835. + borderpx + (term.c.y + 1) * wl.ch - 1,
  2836. + wl.cw, 1);
  2837. }
  2838. + wl_surface_damage(wl.surface, borderpx + curx * wl.cw,
  2839. + borderpx + term.c.y * wl.ch, wl.cw, wl.ch);
  2840. oldx = curx, oldy = term.c.y;
  2841. }
  2842. -
  2843. void
  2844. -xsettitle(char *p)
  2845. +wlsettitle(char *title)
  2846. {
  2847. - XTextProperty prop;
  2848. -
  2849. - Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
  2850. - &prop);
  2851. - XSetWMName(xw.dpy, xw.win, &prop);
  2852. - XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname);
  2853. - XFree(prop.value);
  2854. + xdg_toplevel_set_title(wl.toplevel, title);
  2855. }
  2856. void
  2857. -xresettitle(void)
  2858. +wlresettitle(void)
  2859. {
  2860. - xsettitle(opt_title ? opt_title : "st");
  2861. + wlsettitle(opt_title ? opt_title : "st");
  2862. }
  2863. void
  2864. redraw(void)
  2865. {
  2866. tfulldirt();
  2867. - draw();
  2868. }
  2869. void
  2870. draw(void)
  2871. {
  2872. + int y, y0;
  2873. +
  2874. + for (y = 0; y <= term.bot; ++y) {
  2875. + if (!term.dirty[y])
  2876. + continue;
  2877. + for (y0 = y; y <= term.bot && term.dirty[y]; ++y);
  2878. + wl_surface_damage(wl.surface, 0, borderpx + y0 * wl.ch,
  2879. + wl.w, (y - y0) * wl.ch);
  2880. + }
  2881. +
  2882. + wld_set_target_buffer(wld.renderer, wld.buffer);
  2883. drawregion(0, 0, term.col, term.row);
  2884. - XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.w,
  2885. - xw.h, 0, 0);
  2886. - XSetForeground(xw.dpy, dc.gc,
  2887. - dc.col[IS_SET(MODE_REVERSE)?
  2888. - defaultfg : defaultbg].pixel);
  2889. + wl.framecb = wl_surface_frame(wl.surface);
  2890. + wl_callback_add_listener(wl.framecb, &framelistener, NULL);
  2891. + wld_flush(wld.renderer);
  2892. + wl_surface_attach(wl.surface, wl.buffer, 0, 0);
  2893. + wl_surface_commit(wl.surface);
  2894. + /* need to wait to destroy the old buffer until we commit the new
  2895. + * buffer */
  2896. + if (wld.oldbuffer) {
  2897. + wld_buffer_unreference(wld.oldbuffer);
  2898. + wld.oldbuffer = 0;
  2899. + }
  2900. + needdraw = false;
  2901. }
  2902. void
  2903. drawregion(int x1, int y1, int x2, int y2)
  2904. {
  2905. - int i, x, y, ox, numspecs;
  2906. + int ic, ib, x, y, ox;
  2907. Glyph base, new;
  2908. - XftGlyphFontSpec *specs;
  2909. + char buf[DRAW_BUF_SIZ];
  2910. int ena_sel = sel.ob.x != -1 && sel.alt == IS_SET(MODE_ALTSCREEN);
  2911. - if (!(xw.state & WIN_VISIBLE))
  2912. - return;
  2913. -
  2914. for (y = y1; y < y2; y++) {
  2915. if (!term.dirty[y])
  2916. continue;
  2917. term.dirty[y] = 0;
  2918. -
  2919. - specs = term.specbuf;
  2920. - numspecs = xmakeglyphfontspecs(specs, &term.line[y][x1], x2 - x1, x1, y);
  2921. -
  2922. - i = ox = 0;
  2923. - for (x = x1; x < x2 && i < numspecs; x++) {
  2924. + base = term.line[y][0];
  2925. + ic = ib = ox = 0;
  2926. + for (x = x1; x < x2; x++) {
  2927. new = term.line[y][x];
  2928. if (new.mode == ATTR_WDUMMY)
  2929. continue;
  2930. if (ena_sel && selected(x, y))
  2931. new.mode ^= ATTR_REVERSE;
  2932. - if (i > 0 && ATTRCMP(base, new)) {
  2933. - xdrawglyphfontspecs(specs, base, i, ox, y);
  2934. - specs += i;
  2935. - numspecs -= i;
  2936. - i = 0;
  2937. + if (ib > 0 && (ATTRCMP(base, new)
  2938. + || ib >= DRAW_BUF_SIZ-UTF_SIZ)) {
  2939. + wldraws(buf, base, ox, y, ic, ib);
  2940. + ic = ib = 0;
  2941. }
  2942. - if (i == 0) {
  2943. + if (ib == 0) {
  2944. ox = x;
  2945. base = new;
  2946. }
  2947. - i++;
  2948. +
  2949. + ib += utf8encode(new.u, buf+ib);
  2950. + ic += (new.mode & ATTR_WIDE)? 2 : 1;
  2951. }
  2952. - if (i > 0)
  2953. - xdrawglyphfontspecs(specs, base, i, ox, y);
  2954. + if (ib > 0)
  2955. + wldraws(buf, base, ox, y, ic, ib);
  2956. }
  2957. - xdrawcursor();
  2958. -}
  2959. -
  2960. -void
  2961. -expose(XEvent *ev)
  2962. -{
  2963. - redraw();
  2964. -}
  2965. -
  2966. -void
  2967. -visibility(XEvent *ev)
  2968. -{
  2969. - XVisibilityEvent *e = &ev->xvisibility;
  2970. -
  2971. - MODBIT(xw.state, e->state != VisibilityFullyObscured, WIN_VISIBLE);
  2972. -}
  2973. -
  2974. -void
  2975. -unmap(XEvent *ev)
  2976. -{
  2977. - xw.state &= ~WIN_VISIBLE;
  2978. -}
  2979. -
  2980. -void
  2981. -xsetpointermotion(int set)
  2982. -{
  2983. - MODBIT(xw.attrs.event_mask, set, PointerMotionMask);
  2984. - XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs);
  2985. + wldrawcursor();
  2986. }
  2987. void
  2988. -xseturgency(int add)
  2989. +wlseturgency(int add)
  2990. {
  2991. - XWMHints *h = XGetWMHints(xw.dpy, xw.win);
  2992. -
  2993. - MODBIT(h->flags, add, XUrgencyHint);
  2994. - XSetWMHints(xw.dpy, xw.win, h);
  2995. - XFree(h);
  2996. -}
  2997. -
  2998. -void
  2999. -focus(XEvent *ev)
  3000. -{
  3001. - XFocusChangeEvent *e = &ev->xfocus;
  3002. -
  3003. - if (e->mode == NotifyGrab)
  3004. - return;
  3005. -
  3006. - if (ev->type == FocusIn) {
  3007. - XSetICFocus(xw.xic);
  3008. - xw.state |= WIN_FOCUSED;
  3009. - xseturgency(0);
  3010. - if (IS_SET(MODE_FOCUS))
  3011. - ttywrite("\033[I", 3);
  3012. - } else {
  3013. - XUnsetICFocus(xw.xic);
  3014. - xw.state &= ~WIN_FOCUSED;
  3015. - if (IS_SET(MODE_FOCUS))
  3016. - ttywrite("\033[O", 3);
  3017. - }
  3018. + /* XXX: no urgency equivalent yet in wayland */
  3019. }
  3020. int
  3021. match(uint mask, uint state)
  3022. {
  3023. - return mask == XK_ANY_MOD || mask == (state & ~ignoremod);
  3024. + return mask == MOD_MASK_ANY || mask == (state & ~(ignoremod));
  3025. }
  3026. void
  3027. @@ -4211,7 +3890,7 @@ numlock(const Arg *dummy)
  3028. }
  3029. char*
  3030. -kmap(KeySym k, uint state)
  3031. +kmap(xkb_keysym_t k, uint state)
  3032. {
  3033. Key *kp;
  3034. int i;
  3035. @@ -4251,38 +3930,176 @@ kmap(KeySym k, uint state)
  3036. }
  3037. void
  3038. -kpress(XEvent *ev)
  3039. +cresize(int width, int height)
  3040. +{
  3041. + int col, row;
  3042. +
  3043. + if (width != 0)
  3044. + wl.w = width;
  3045. + if (height != 0)
  3046. + wl.h = height;
  3047. +
  3048. + col = (wl.w - 2 * borderpx) / wl.cw;
  3049. + row = (wl.h - 2 * borderpx) / wl.ch;
  3050. +
  3051. + tresize(col, row);
  3052. + wlresize(col, row);
  3053. +}
  3054. +
  3055. +void
  3056. +regglobal(void *data, struct wl_registry *registry, uint32_t name,
  3057. + const char *interface, uint32_t version)
  3058. +{
  3059. + if (strcmp(interface, "wl_compositor") == 0) {
  3060. + wl.cmp = wl_registry_bind(registry, name,
  3061. + &wl_compositor_interface, 3);
  3062. + } else if (strcmp(interface, "xdg_wm_base") == 0) {
  3063. + wl.wm = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
  3064. + xdg_wm_base_add_listener(wl.wm, &wmlistener, NULL);
  3065. + } else if (strcmp(interface, "wl_shm") == 0) {
  3066. + wl.shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
  3067. + } else if (strcmp(interface, "wl_seat") == 0) {
  3068. + wl.seat = wl_registry_bind(registry, name,
  3069. + &wl_seat_interface, 4);
  3070. + } else if (strcmp(interface, "wl_data_device_manager") == 0) {
  3071. + wl.datadevmanager = wl_registry_bind(registry, name,
  3072. + &wl_data_device_manager_interface, 1);
  3073. + } else if (strcmp(interface, "wl_output") == 0) {
  3074. + /* bind to outputs so we can get surface enter events */
  3075. + wl_registry_bind(registry, name, &wl_output_interface, 2);
  3076. + }
  3077. +}
  3078. +
  3079. +void
  3080. +regglobalremove(void *data, struct wl_registry *registry, uint32_t name)
  3081. +{
  3082. +}
  3083. +
  3084. +void
  3085. +surfenter(void *data, struct wl_surface *surface, struct wl_output *output)
  3086. +{
  3087. + wl.vis++;
  3088. + if (!(wl.state & WIN_VISIBLE))
  3089. + wl.state |= WIN_VISIBLE;
  3090. +}
  3091. +
  3092. +void
  3093. +surfleave(void *data, struct wl_surface *surface, struct wl_output *output)
  3094. +{
  3095. + if (--wl.vis == 0)
  3096. + wl.state &= ~WIN_VISIBLE;
  3097. +}
  3098. +
  3099. +void
  3100. +framedone(void *data, struct wl_callback *callback, uint32_t msecs)
  3101. +{
  3102. + wl_callback_destroy(callback);
  3103. + wl.framecb = NULL;
  3104. + if (needdraw && wl.state & WIN_VISIBLE) {
  3105. + draw();
  3106. + }
  3107. +}
  3108. +
  3109. +void
  3110. +kbdkeymap(void *data, struct wl_keyboard *keyboard, uint32_t format, int32_t fd,
  3111. + uint32_t size)
  3112. {
  3113. - XKeyEvent *e = &ev->xkey;
  3114. - KeySym ksym;
  3115. - char buf[32], *customkey;
  3116. + char *string;
  3117. +
  3118. + if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
  3119. + close(fd);
  3120. + return;
  3121. + }
  3122. +
  3123. + string = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
  3124. +
  3125. + if (string == MAP_FAILED) {
  3126. + close(fd);
  3127. + return;
  3128. + }
  3129. +
  3130. + wl.xkb.keymap = xkb_keymap_new_from_string(wl.xkb.ctx, string,
  3131. + XKB_KEYMAP_FORMAT_TEXT_V1, 0);
  3132. + munmap(string, size);
  3133. + close(fd);
  3134. + wl.xkb.state = xkb_state_new(wl.xkb.keymap);
  3135. +
  3136. + wl.xkb.ctrl = xkb_keymap_mod_get_index(wl.xkb.keymap, XKB_MOD_NAME_CTRL);
  3137. + wl.xkb.alt = xkb_keymap_mod_get_index(wl.xkb.keymap, XKB_MOD_NAME_ALT);
  3138. + wl.xkb.shift = xkb_keymap_mod_get_index(wl.xkb.keymap, XKB_MOD_NAME_SHIFT);
  3139. + wl.xkb.logo = xkb_keymap_mod_get_index(wl.xkb.keymap, XKB_MOD_NAME_LOGO);
  3140. +
  3141. + wl.xkb.mods = 0;
  3142. +}
  3143. +
  3144. +void
  3145. +kbdenter(void *data, struct wl_keyboard *keyboard, uint32_t serial,
  3146. + struct wl_surface *surface, struct wl_array *keys)
  3147. +{
  3148. + wl.state |= WIN_FOCUSED;
  3149. + if (IS_SET(MODE_FOCUS))
  3150. + ttywrite("\033[I", 3);
  3151. + /* need to redraw the cursor */
  3152. + needdraw = true;
  3153. +}
  3154. +
  3155. +void
  3156. +kbdleave(void *data, struct wl_keyboard *keyboard, uint32_t serial,
  3157. + struct wl_surface *surface)
  3158. +{
  3159. + /* selection offers are invalidated when we lose keyboard focus */
  3160. + wl.seloffer = NULL;
  3161. + wl.state &= ~WIN_FOCUSED;
  3162. + if (IS_SET(MODE_FOCUS))
  3163. + ttywrite("\033[O", 3);
  3164. + /* need to redraw the cursor */
  3165. + needdraw = true;
  3166. + /* disable key repeat */
  3167. + repeat.len = 0;
  3168. +}
  3169. +
  3170. +void
  3171. +kbdkey(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time,
  3172. + uint32_t key, uint32_t state)
  3173. +{
  3174. + xkb_keysym_t ksym;
  3175. + char buf[32], *str;
  3176. int len;
  3177. Rune c;
  3178. - Status status;
  3179. Shortcut *bp;
  3180. if (IS_SET(MODE_KBDLOCK))
  3181. return;
  3182. - len = XmbLookupString(xw.xic, e, buf, sizeof buf, &ksym, &status);
  3183. + if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
  3184. + if (repeat.key == key)
  3185. + repeat.len = 0;
  3186. + return;
  3187. + }
  3188. +
  3189. + ksym = xkb_state_key_get_one_sym(wl.xkb.state, key + 8);
  3190. + len = xkb_keysym_to_utf8(ksym, buf, sizeof buf);
  3191. + if (len > 0)
  3192. + --len;
  3193. +
  3194. /* 1. shortcuts */
  3195. for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
  3196. - if (ksym == bp->keysym && match(bp->mod, e->state)) {
  3197. + if (ksym == bp->keysym && match(bp->mod, wl.xkb.mods)) {
  3198. bp->func(&(bp->arg));
  3199. return;
  3200. }
  3201. }
  3202. /* 2. custom keys from config.h */
  3203. - if ((customkey = kmap(ksym, e->state))) {
  3204. - ttysend(customkey, strlen(customkey));
  3205. - return;
  3206. + if ((str = kmap(ksym, wl.xkb.mods))) {
  3207. + len = strlen(str);
  3208. + goto send;
  3209. }
  3210. /* 3. composed string from input method */
  3211. if (len == 0)
  3212. return;
  3213. - if (len == 1 && e->state & Mod1Mask) {
  3214. + if (len == 1 && wl.xkb.mods & MOD_MASK_ALT) {
  3215. if (IS_SET(MODE_8BIT)) {
  3216. if (*buf < 0177) {
  3217. c = *buf | 0x80;
  3218. @@ -4294,101 +4111,334 @@ kpress(XEvent *ev)
  3219. len = 2;
  3220. }
  3221. }
  3222. - ttysend(buf, len);
  3223. + /* convert character to control character */
  3224. + else if (len == 1 && wl.xkb.mods & MOD_MASK_CTRL) {
  3225. + if ((*buf >= '@' && *buf < '\177') || *buf == ' ')
  3226. + *buf &= 0x1F;
  3227. + else if (*buf == '2') *buf = '\000';
  3228. + else if (*buf >= '3' && *buf <= '7')
  3229. + *buf -= ('3' - '\033');
  3230. + else if (*buf == '8') *buf = '\177';
  3231. + else if (*buf == '/') *buf = '_' & 0x1F;
  3232. + }
  3233. +
  3234. + str = buf;
  3235. +
  3236. +send:
  3237. + memcpy(repeat.str, str, len);
  3238. + repeat.key = key;
  3239. + repeat.len = len;
  3240. + repeat.started = false;
  3241. + clock_gettime(CLOCK_MONOTONIC, &repeat.last);
  3242. + ttysend(str, len);
  3243. }
  3244. +void
  3245. +kbdmodifiers(void *data, struct wl_keyboard *keyboard, uint32_t serial,
  3246. + uint32_t dep, uint32_t lat, uint32_t lck, uint32_t group)
  3247. +{
  3248. + xkb_mod_mask_t mod_mask;
  3249. +
  3250. + xkb_state_update_mask(wl.xkb.state, dep, lat, lck, group, 0, 0);
  3251. +
  3252. + mod_mask = xkb_state_serialize_mods(wl.xkb.state, XKB_STATE_MODS_EFFECTIVE);
  3253. + wl.xkb.mods = 0;
  3254. +
  3255. + if (mod_mask & (1 << wl.xkb.ctrl))
  3256. + wl.xkb.mods |= MOD_MASK_CTRL;
  3257. + if (mod_mask & (1 << wl.xkb.alt))
  3258. + wl.xkb.mods |= MOD_MASK_ALT;
  3259. + if (mod_mask & (1 << wl.xkb.shift))
  3260. + wl.xkb.mods |= MOD_MASK_SHIFT;
  3261. + if (mod_mask & (1 << wl.xkb.logo))
  3262. + wl.xkb.mods |= MOD_MASK_LOGO;
  3263. +}
  3264. void
  3265. -cmessage(XEvent *e)
  3266. +kbdrepeatinfo(void *data, struct wl_keyboard *keyboard, int32_t rate,
  3267. + int32_t delay)
  3268. {
  3269. - /*
  3270. - * See xembed specs
  3271. - * http://standards.freedesktop.org/xembed-spec/xembed-spec-latest.html
  3272. - */
  3273. - if (e->xclient.message_type == xw.xembed && e->xclient.format == 32) {
  3274. - if (e->xclient.data.l[1] == XEMBED_FOCUS_IN) {
  3275. - xw.state |= WIN_FOCUSED;
  3276. - xseturgency(0);
  3277. - } else if (e->xclient.data.l[1] == XEMBED_FOCUS_OUT) {
  3278. - xw.state &= ~WIN_FOCUSED;
  3279. + keyrepeatdelay = delay;
  3280. + keyrepeatinterval = 1000 / rate;
  3281. +}
  3282. +
  3283. +void
  3284. +ptrenter(void *data, struct wl_pointer *pointer, uint32_t serial,
  3285. + struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
  3286. +{
  3287. + struct wl_cursor_image *img = cursor.cursor->images[0];
  3288. + struct wl_buffer *buffer;
  3289. +
  3290. + wl_pointer_set_cursor(pointer, serial, cursor.surface,
  3291. + img->hotspot_x, img->hotspot_y);
  3292. + buffer = wl_cursor_image_get_buffer(img);
  3293. + wl_surface_attach(cursor.surface, buffer, 0, 0);
  3294. + wl_surface_damage(cursor.surface, 0, 0, img->width, img->height);
  3295. + wl_surface_commit(cursor.surface);
  3296. +}
  3297. +
  3298. +void
  3299. +ptrleave(void *data, struct wl_pointer *pointer, uint32_t serial,
  3300. + struct wl_surface *surface)
  3301. +{
  3302. +}
  3303. +
  3304. +void
  3305. +ptrmotion(void *data, struct wl_pointer * pointer, uint32_t serial,
  3306. + wl_fixed_t x, wl_fixed_t y)
  3307. +{
  3308. + int oldey, oldex, oldsby, oldsey;
  3309. +
  3310. + if (IS_SET(MODE_MOUSE)) {
  3311. + wlmousereportmotion(x, y);
  3312. + return;
  3313. + }
  3314. +
  3315. + wl.px = wl_fixed_to_int(x);
  3316. + wl.py = wl_fixed_to_int(y);
  3317. +
  3318. + if (!sel.mode)
  3319. + return;
  3320. +
  3321. + sel.mode = SEL_READY;
  3322. + oldey = sel.oe.y;
  3323. + oldex = sel.oe.x;
  3324. + oldsby = sel.nb.y;
  3325. + oldsey = sel.ne.y;
  3326. + getbuttoninfo();
  3327. +
  3328. + if (oldey != sel.oe.y || oldex != sel.oe.x)
  3329. + tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
  3330. +}
  3331. +
  3332. +void
  3333. +ptrbutton(void * data, struct wl_pointer * pointer, uint32_t serial,
  3334. + uint32_t time, uint32_t button, uint32_t state)
  3335. +{
  3336. + MouseShortcut *ms;
  3337. +
  3338. + if (IS_SET(MODE_MOUSE) && !(wl.xkb.mods & forceselmod)) {
  3339. + wlmousereportbutton(button, state);
  3340. + return;
  3341. + }
  3342. +
  3343. + switch (state) {
  3344. + case WL_POINTER_BUTTON_STATE_RELEASED:
  3345. + if (button == BTN_MIDDLE) {
  3346. + selpaste(NULL);
  3347. + } else if (button == BTN_LEFT) {
  3348. + if (sel.mode == SEL_READY) {
  3349. + getbuttoninfo();
  3350. + selcopy(serial);
  3351. + } else
  3352. + selclear();
  3353. + sel.mode = SEL_IDLE;
  3354. + tsetdirt(sel.nb.y, sel.ne.y);
  3355. }
  3356. - } else if (e->xclient.data.l[0] == xw.wmdeletewin) {
  3357. - /* Send SIGHUP to shell */
  3358. - kill(pid, SIGHUP);
  3359. - exit(0);
  3360. + break;
  3361. +
  3362. + case WL_POINTER_BUTTON_STATE_PRESSED:
  3363. + for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
  3364. + if (button == ms->b && match(ms->mask, wl.xkb.mods)) {
  3365. + ttysend(ms->s, strlen(ms->s));
  3366. + return;
  3367. + }
  3368. + }
  3369. +
  3370. + if (button == BTN_LEFT) {
  3371. + /* Clear previous selection, logically and visually. */
  3372. + selclear();
  3373. + sel.mode = SEL_EMPTY;
  3374. + sel.type = SEL_REGULAR;
  3375. + sel.oe.x = sel.ob.x = x2col(wl.px);
  3376. + sel.oe.y = sel.ob.y = y2row(wl.py);
  3377. +
  3378. + /*
  3379. + * If the user clicks below predefined timeouts
  3380. + * specific snapping behaviour is exposed.
  3381. + */
  3382. + if (time - sel.tclick2 <= tripleclicktimeout) {
  3383. + sel.snap = SNAP_LINE;
  3384. + } else if (time - sel.tclick1 <= doubleclicktimeout) {
  3385. + sel.snap = SNAP_WORD;
  3386. + } else {
  3387. + sel.snap = 0;
  3388. + }
  3389. + selnormalize();
  3390. +
  3391. + if (sel.snap != 0)
  3392. + sel.mode = SEL_READY;
  3393. + tsetdirt(sel.nb.y, sel.ne.y);
  3394. + sel.tclick2 = sel.tclick1;
  3395. + sel.tclick1 = time;
  3396. + }
  3397. + break;
  3398. }
  3399. }
  3400. void
  3401. -cresize(int width, int height)
  3402. +ptraxis(void * data, struct wl_pointer * pointer, uint32_t time, uint32_t axis,
  3403. + wl_fixed_t value)
  3404. {
  3405. - int col, row;
  3406. + Axiskey *ak;
  3407. + int dir = value > 0 ? +1 : -1;
  3408. - if (width != 0)
  3409. - xw.w = width;
  3410. - if (height != 0)
  3411. - xw.h = height;
  3412. + if (IS_SET(MODE_MOUSE) && !(wl.xkb.mods & forceselmod)) {
  3413. + wlmousereportaxis(axis, value);
  3414. + return;
  3415. + }
  3416. - col = (xw.w - 2 * borderpx) / xw.cw;
  3417. - row = (xw.h - 2 * borderpx) / xw.ch;
  3418. + for (ak = ashortcuts; ak < ashortcuts + LEN(ashortcuts); ak++) {
  3419. + if (axis == ak->axis && dir == ak->dir
  3420. + && match(ak->mask, wl.xkb.mods)) {
  3421. + ttysend(ak->s, strlen(ak->s));
  3422. + return;
  3423. + }
  3424. + }
  3425. +}
  3426. - tresize(col, row);
  3427. - xresize(col, row);
  3428. +void
  3429. +wmping(void *data, struct xdg_wm_base *wm, uint32_t serial)
  3430. +{
  3431. + xdg_wm_base_pong(wm, serial);
  3432. +}
  3433. +
  3434. +void
  3435. +xdgsurfconfigure(void *data, struct xdg_surface *surf, uint32_t serial)
  3436. +{
  3437. + xdg_surface_ack_configure(surf, serial);
  3438. }
  3439. void
  3440. -resize(XEvent *e)
  3441. +toplevelconfigure(void *data, struct xdg_toplevel *toplevel, int32_t w, int32_t h,
  3442. + struct wl_array *states)
  3443. {
  3444. - if (e->xconfigure.width == xw.w && e->xconfigure.height == xw.h)
  3445. + if (w == wl.w && h == wl.h)
  3446. return;
  3447. + cresize(w, h);
  3448. + if (wl.configured)
  3449. + ttyresize();
  3450. + else
  3451. + wl.configured = true;
  3452. +}
  3453. - cresize(e->xconfigure.width, e->xconfigure.height);
  3454. - ttyresize();
  3455. +void
  3456. +toplevelclose(void *data, struct xdg_toplevel *toplevel)
  3457. +{
  3458. + /* Send SIGHUP to shell */
  3459. + kill(pid, SIGHUP);
  3460. + exit(0);
  3461. +}
  3462. +
  3463. +void
  3464. +datadevoffer(void *data, struct wl_data_device *datadev,
  3465. + struct wl_data_offer *offer)
  3466. +{
  3467. + wl_data_offer_add_listener(offer, &dataofferlistener, NULL);
  3468. +}
  3469. +
  3470. +void
  3471. +datadeventer(void *data, struct wl_data_device *datadev, uint32_t serial,
  3472. + struct wl_surface *surf, wl_fixed_t x, wl_fixed_t y,
  3473. + struct wl_data_offer *offer)
  3474. +{
  3475. +}
  3476. +
  3477. +void
  3478. +datadevleave(void *data, struct wl_data_device *datadev)
  3479. +{
  3480. +}
  3481. +
  3482. +void
  3483. +datadevmotion(void *data, struct wl_data_device *datadev, uint32_t time,
  3484. + wl_fixed_t x, wl_fixed_t y)
  3485. +{
  3486. +}
  3487. +
  3488. +void
  3489. +datadevdrop(void *data, struct wl_data_device *datadev)
  3490. +{
  3491. +}
  3492. +
  3493. +void
  3494. +datadevselection(void *data, struct wl_data_device *datadev,
  3495. + struct wl_data_offer *offer)
  3496. +{
  3497. + if (offer && (uintptr_t) wl_data_offer_get_user_data(offer) == 1)
  3498. + wl.seloffer = offer;
  3499. + else
  3500. + wl.seloffer = NULL;
  3501. +}
  3502. +
  3503. +void
  3504. +dataofferoffer(void *data, struct wl_data_offer *offer, const char *mimetype)
  3505. +{
  3506. + /* mark the offer as usable if it supports plain text */
  3507. + if (strncmp(mimetype, "text/plain", 10) == 0)
  3508. + wl_data_offer_set_user_data(offer, (void *)(uintptr_t) 1);
  3509. +}
  3510. +
  3511. +void
  3512. +datasrctarget(void *data, struct wl_data_source *source, const char *mimetype)
  3513. +{
  3514. +}
  3515. +
  3516. +void
  3517. +datasrcsend(void *data, struct wl_data_source *source, const char *mimetype,
  3518. + int32_t fd)
  3519. +{
  3520. + char *buf = sel.primary;
  3521. + int len = strlen(sel.primary);
  3522. + ssize_t ret;
  3523. + while ((ret = write(fd, buf, MIN(len, BUFSIZ))) > 0) {
  3524. + len -= ret;
  3525. + buf += ret;
  3526. + }
  3527. + close(fd);
  3528. +}
  3529. +
  3530. +void
  3531. +datasrccancelled(void *data, struct wl_data_source *source)
  3532. +{
  3533. + if (sel.source == source) {
  3534. + sel.source = NULL;
  3535. + selclear();
  3536. + }
  3537. + wl_data_source_destroy(source);
  3538. }
  3539. void
  3540. run(void)
  3541. {
  3542. - XEvent ev;
  3543. - int w = xw.w, h = xw.h;
  3544. fd_set rfd;
  3545. - int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0;
  3546. + int wlfd = wl_display_get_fd(wl.dpy), blinkset = 0;
  3547. struct timespec drawtimeout, *tv = NULL, now, last, lastblink;
  3548. - long deltatime;
  3549. + ulong msecs;
  3550. - /* Waiting for window mapping */
  3551. - do {
  3552. - XNextEvent(xw.dpy, &ev);
  3553. - /*
  3554. - * This XFilterEvent call is required because of XOpenIM. It
  3555. - * does filter out the key event and some client message for
  3556. - * the input method too.
  3557. - */
  3558. - if (XFilterEvent(&ev, None))
  3559. - continue;
  3560. - if (ev.type == ConfigureNotify) {
  3561. - w = ev.xconfigure.width;
  3562. - h = ev.xconfigure.height;
  3563. - }
  3564. - } while (ev.type != MapNotify);
  3565. -
  3566. - cresize(w, h);
  3567. ttynew();
  3568. - ttyresize();
  3569. +
  3570. + /* Look for initial configure. */
  3571. + wl_display_roundtrip(wl.dpy);
  3572. + if (!wl.configured) {
  3573. + cresize(wl.w, wl.h);
  3574. + ttyresize();
  3575. + }
  3576. + draw();
  3577. clock_gettime(CLOCK_MONOTONIC, &last);
  3578. lastblink = last;
  3579. - for (xev = actionfps;;) {
  3580. + for (;;) {
  3581. FD_ZERO(&rfd);
  3582. FD_SET(cmdfd, &rfd);
  3583. - FD_SET(xfd, &rfd);
  3584. + FD_SET(wlfd, &rfd);
  3585. - if (pselect(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
  3586. + if (pselect(MAX(wlfd, cmdfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
  3587. if (errno == EINTR)
  3588. continue;
  3589. die("select failed: %s\n", strerror(errno));
  3590. }
  3591. +
  3592. if (FD_ISSET(cmdfd, &rfd)) {
  3593. ttyread();
  3594. if (blinktimeout) {
  3595. @@ -4398,60 +4448,54 @@ run(void)
  3596. }
  3597. }
  3598. - if (FD_ISSET(xfd, &rfd))
  3599. - xev = actionfps;
  3600. + if (FD_ISSET(wlfd, &rfd)) {
  3601. + if (wl_display_dispatch(wl.dpy) == -1)
  3602. + die("Connection error\n");
  3603. + }
  3604. clock_gettime(CLOCK_MONOTONIC, &now);
  3605. - drawtimeout.tv_sec = 0;
  3606. - drawtimeout.tv_nsec = (1000 * 1E6)/ xfps;
  3607. - tv = &drawtimeout;
  3608. -
  3609. - dodraw = 0;
  3610. - if (blinktimeout && TIMEDIFF(now, lastblink) > blinktimeout) {
  3611. - tsetdirtattr(ATTR_BLINK);
  3612. - term.mode ^= MODE_BLINK;
  3613. - lastblink = now;
  3614. - dodraw = 1;
  3615. + msecs = -1;
  3616. +
  3617. + if (blinkset && blinktimeout) {
  3618. + if (TIMEDIFF(now, lastblink) >= blinktimeout) {
  3619. + tsetdirtattr(ATTR_BLINK);
  3620. + term.mode ^= MODE_BLINK;
  3621. + lastblink = now;
  3622. + } else {
  3623. + msecs = MIN(msecs, blinktimeout - \
  3624. + TIMEDIFF(now, lastblink));
  3625. + }
  3626. }
  3627. - deltatime = TIMEDIFF(now, last);
  3628. - if (deltatime > 1000 / (xev ? xfps : actionfps)) {
  3629. - dodraw = 1;
  3630. - last = now;
  3631. + if (repeat.len > 0) {
  3632. + if (TIMEDIFF(now, repeat.last) >= \
  3633. + (repeat.started ? keyrepeatinterval : \
  3634. + keyrepeatdelay)) {
  3635. + repeat.started = true;
  3636. + repeat.last = now;
  3637. + ttysend(repeat.str, repeat.len);
  3638. + } else {
  3639. + msecs = MIN(msecs, (repeat.started ? \
  3640. + keyrepeatinterval : keyrepeatdelay) - \
  3641. + TIMEDIFF(now, repeat.last));
  3642. + }
  3643. }
  3644. - if (dodraw) {
  3645. - while (XPending(xw.dpy)) {
  3646. - XNextEvent(xw.dpy, &ev);
  3647. - if (XFilterEvent(&ev, None))
  3648. - continue;
  3649. - if (handler[ev.type])
  3650. - (handler[ev.type])(&ev);
  3651. + if (needdraw && wl.state & WIN_VISIBLE) {
  3652. + if (!wl.framecb) {
  3653. + draw();
  3654. }
  3655. + }
  3656. - draw();
  3657. - XFlush(xw.dpy);
  3658. -
  3659. - if (xev && !FD_ISSET(xfd, &rfd))
  3660. - xev--;
  3661. - if (!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
  3662. - if (blinkset) {
  3663. - if (TIMEDIFF(now, lastblink) \
  3664. - > blinktimeout) {
  3665. - drawtimeout.tv_nsec = 1000;
  3666. - } else {
  3667. - drawtimeout.tv_nsec = (1E6 * \
  3668. - (blinktimeout - \
  3669. - TIMEDIFF(now,
  3670. - lastblink)));
  3671. - }
  3672. - drawtimeout.tv_sec = \
  3673. - drawtimeout.tv_nsec / 1E9;
  3674. - drawtimeout.tv_nsec %= (long)1E9;
  3675. - } else {
  3676. - tv = NULL;
  3677. - }
  3678. - }
  3679. + if (msecs == -1) {
  3680. + tv = NULL;
  3681. + } else {
  3682. + drawtimeout.tv_nsec = 1E6 * msecs;
  3683. + drawtimeout.tv_sec = 0;
  3684. + tv = &drawtimeout;
  3685. }
  3686. +
  3687. + wl_display_dispatch_pending(wl.dpy);
  3688. + wl_display_flush(wl.dpy);
  3689. }
  3690. }
  3691. @@ -4471,9 +4515,7 @@ usage(void)
  3692. int
  3693. main(int argc, char *argv[])
  3694. {
  3695. - xw.l = xw.t = 0;
  3696. - xw.isfixed = False;
  3697. - xw.cursor = cursorshape;
  3698. + wl.cursor = cursorshape;
  3699. ARGBEGIN {
  3700. case 'a':
  3701. @@ -4489,13 +4531,6 @@ main(int argc, char *argv[])
  3702. case 'f':
  3703. opt_font = EARGF(usage());
  3704. break;
  3705. - case 'g':
  3706. - xw.gm = XParseGeometry(EARGF(usage()),
  3707. - &xw.l, &xw.t, &cols, &rows);
  3708. - break;
  3709. - case 'i':
  3710. - xw.isfixed = 1;
  3711. - break;
  3712. case 'o':
  3713. opt_io = EARGF(usage());
  3714. break;
  3715. @@ -4527,9 +4562,8 @@ run:
  3716. opt_title = basename(xstrdup(argv[0]));
  3717. }
  3718. setlocale(LC_CTYPE, "");
  3719. - XSetLocaleModifiers("");
  3720. tnew(MAX(cols, 1), MAX(rows, 1));
  3721. - xinit();
  3722. + wlinit();
  3723. selinit();
  3724. run();
  3725. --
  3726. 2.37.3