You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

368 lines
8.6 KiB

  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <sys/time.h>
  5. #include <wayland-client.h>
  6. #include <xkbcommon/xkbcommon.h>
  7. #include <primary-selection-unstable-v1.h>
  8. #include <presentation-time.h>
  9. #include <tllist.h>
  10. #include "fdm.h"
  11. typedef tll(xkb_keycode_t) xkb_keycode_list_t;
  12. struct key_binding {
  13. xkb_mod_mask_t mods;
  14. xkb_keysym_t sym;
  15. xkb_keycode_list_t key_codes;
  16. };
  17. typedef tll(struct key_binding) key_binding_list_t;
  18. enum bind_action_normal {
  19. BIND_ACTION_NONE,
  20. BIND_ACTION_SCROLLBACK_UP, /* Deprecated, alias for UP_PAGE */
  21. BIND_ACTION_SCROLLBACK_UP_PAGE,
  22. BIND_ACTION_SCROLLBACK_UP_HALF_PAGE,
  23. BIND_ACTION_SCROLLBACK_UP_LINE,
  24. BIND_ACTION_SCROLLBACK_DOWN, /* Deprecated, alias for DOWN_PAGE */
  25. BIND_ACTION_SCROLLBACK_DOWN_PAGE,
  26. BIND_ACTION_SCROLLBACK_DOWN_HALF_PAGE,
  27. BIND_ACTION_SCROLLBACK_DOWN_LINE,
  28. BIND_ACTION_CLIPBOARD_COPY,
  29. BIND_ACTION_CLIPBOARD_PASTE,
  30. BIND_ACTION_PRIMARY_PASTE,
  31. BIND_ACTION_SEARCH_START,
  32. BIND_ACTION_FONT_SIZE_UP,
  33. BIND_ACTION_FONT_SIZE_DOWN,
  34. BIND_ACTION_FONT_SIZE_RESET,
  35. BIND_ACTION_SPAWN_TERMINAL,
  36. BIND_ACTION_MINIMIZE,
  37. BIND_ACTION_MAXIMIZE,
  38. BIND_ACTION_FULLSCREEN,
  39. BIND_ACTION_PIPE_SCROLLBACK,
  40. BIND_ACTION_PIPE_VIEW,
  41. BIND_ACTION_PIPE_SELECTED,
  42. /* Mouse specific actions - i.e. they require a mouse coordinate */
  43. BIND_ACTION_SELECT_BEGIN,
  44. BIND_ACTION_SELECT_BEGIN_BLOCK,
  45. BIND_ACTION_SELECT_EXTEND,
  46. BIND_ACTION_SELECT_WORD,
  47. BIND_ACTION_SELECT_WORD_WS,
  48. BIND_ACTION_SELECT_ROW,
  49. BIND_ACTION_KEY_COUNT = BIND_ACTION_PIPE_SELECTED + 1,
  50. BIND_ACTION_COUNT = BIND_ACTION_SELECT_ROW + 1,
  51. };
  52. struct key_binding_normal {
  53. struct key_binding bind;
  54. enum bind_action_normal action;
  55. char **pipe_argv;
  56. };
  57. struct mouse_binding {
  58. enum bind_action_normal action;
  59. xkb_mod_mask_t mods;
  60. uint32_t button;
  61. int count;
  62. };
  63. typedef tll(struct mouse_binding) mouse_binding_list_t;
  64. enum bind_action_search {
  65. BIND_ACTION_SEARCH_NONE,
  66. BIND_ACTION_SEARCH_CANCEL,
  67. BIND_ACTION_SEARCH_COMMIT,
  68. BIND_ACTION_SEARCH_FIND_PREV,
  69. BIND_ACTION_SEARCH_FIND_NEXT,
  70. BIND_ACTION_SEARCH_EDIT_LEFT,
  71. BIND_ACTION_SEARCH_EDIT_LEFT_WORD,
  72. BIND_ACTION_SEARCH_EDIT_RIGHT,
  73. BIND_ACTION_SEARCH_EDIT_RIGHT_WORD,
  74. BIND_ACTION_SEARCH_EDIT_HOME,
  75. BIND_ACTION_SEARCH_EDIT_END,
  76. BIND_ACTION_SEARCH_DELETE_PREV,
  77. BIND_ACTION_SEARCH_DELETE_PREV_WORD,
  78. BIND_ACTION_SEARCH_DELETE_NEXT,
  79. BIND_ACTION_SEARCH_DELETE_NEXT_WORD,
  80. BIND_ACTION_SEARCH_EXTEND_WORD,
  81. BIND_ACTION_SEARCH_EXTEND_WORD_WS,
  82. BIND_ACTION_SEARCH_COUNT,
  83. };
  84. struct key_binding_search {
  85. struct key_binding bind;
  86. enum bind_action_search action;
  87. };
  88. struct wl_clipboard {
  89. struct wl_data_source *data_source;
  90. struct wl_data_offer *data_offer;
  91. char *text;
  92. uint32_t serial;
  93. };
  94. struct wl_primary {
  95. struct zwp_primary_selection_source_v1 *data_source;
  96. struct zwp_primary_selection_offer_v1 *data_offer;
  97. char *text;
  98. uint32_t serial;
  99. };
  100. struct seat {
  101. struct wayland *wayl;
  102. struct wl_seat *wl_seat;
  103. uint32_t wl_name;
  104. char *name;
  105. /* Focused terminals */
  106. struct terminal *kbd_focus;
  107. struct terminal *mouse_focus;
  108. /* Keyboard state */
  109. struct wl_keyboard *wl_keyboard;
  110. struct {
  111. uint32_t serial;
  112. struct xkb_context *xkb;
  113. struct xkb_keymap *xkb_keymap;
  114. struct xkb_state *xkb_state;
  115. struct xkb_compose_table *xkb_compose_table;
  116. struct xkb_compose_state *xkb_compose_state;
  117. struct {
  118. int fd;
  119. bool dont_re_repeat;
  120. int32_t delay;
  121. int32_t rate;
  122. uint32_t key;
  123. } repeat;
  124. xkb_mod_index_t mod_shift;
  125. xkb_mod_index_t mod_alt;
  126. xkb_mod_index_t mod_ctrl;
  127. xkb_mod_index_t mod_meta;
  128. xkb_keycode_t key_arrow_up;
  129. xkb_keycode_t key_arrow_down;
  130. /* Enabled modifiers */
  131. bool shift;
  132. bool alt;
  133. bool ctrl;
  134. bool meta;
  135. struct {
  136. tll(struct key_binding_normal) key;
  137. tll(struct key_binding_search) search;
  138. } bindings;
  139. } kbd;
  140. /* Pointer state */
  141. struct wl_pointer *wl_pointer;
  142. struct {
  143. uint32_t serial;
  144. struct wl_surface *surface;
  145. struct wl_cursor_theme *theme;
  146. struct wl_cursor *cursor;
  147. int scale;
  148. bool hidden;
  149. const char *xcursor;
  150. struct wl_callback *xcursor_callback;
  151. bool xcursor_pending;
  152. } pointer;
  153. struct {
  154. int x;
  155. int y;
  156. int col;
  157. int row;
  158. int button;
  159. bool consumed; /* True if a button press was consumed - i.e. if a binding claimed it */
  160. int count;
  161. int last_button;
  162. struct timeval last_time;
  163. /* We used a discrete axis event in the current pointer frame */
  164. double axis_aggregated;
  165. bool have_discrete;
  166. mouse_binding_list_t bindings;
  167. } mouse;
  168. /* Clipboard */
  169. struct wl_data_device *data_device;
  170. struct zwp_primary_selection_device_v1 *primary_selection_device;
  171. struct wl_clipboard clipboard;
  172. struct wl_primary primary;
  173. };
  174. enum csd_surface {
  175. CSD_SURF_TITLE,
  176. CSD_SURF_LEFT,
  177. CSD_SURF_RIGHT,
  178. CSD_SURF_TOP,
  179. CSD_SURF_BOTTOM,
  180. CSD_SURF_MINIMIZE,
  181. CSD_SURF_MAXIMIZE,
  182. CSD_SURF_CLOSE,
  183. CSD_SURF_COUNT,
  184. };
  185. struct monitor {
  186. struct wayland *wayl;
  187. struct wl_output *output;
  188. struct zxdg_output_v1 *xdg;
  189. uint32_t wl_name;
  190. int x;
  191. int y;
  192. struct {
  193. /* Physical size, in mm */
  194. struct {
  195. int width;
  196. int height;
  197. } mm;
  198. /* Physical size, in pixels */
  199. struct {
  200. int width;
  201. int height;
  202. } px_real;
  203. /* Scaled size, in pixels */
  204. struct {
  205. int width;
  206. int height;
  207. } px_scaled;
  208. } dim;
  209. struct {
  210. /* PPI, based on physical size */
  211. struct {
  212. int x;
  213. int y;
  214. } real;
  215. /* PPI, logical, based on scaled size */
  216. struct {
  217. int x;
  218. int y;
  219. } scaled;
  220. } ppi;
  221. float dpi;
  222. int scale;
  223. float refresh;
  224. enum wl_output_subpixel subpixel;
  225. /* From wl_output */
  226. char *make;
  227. char *model;
  228. /* From xdg_output */
  229. char *name;
  230. char *description;
  231. float inch; /* e.g. 24" */
  232. };
  233. struct wayland;
  234. struct wl_window {
  235. struct terminal *term;
  236. struct wl_surface *surface;
  237. struct xdg_surface *xdg_surface;
  238. struct xdg_toplevel *xdg_toplevel;
  239. struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration;
  240. enum {CSD_UNKNOWN, CSD_NO, CSD_YES } use_csd;
  241. struct {
  242. struct wl_surface *surface[CSD_SURF_COUNT];
  243. struct wl_subsurface *sub_surface[CSD_SURF_COUNT];
  244. int move_timeout_fd;
  245. uint32_t serial;
  246. } csd;
  247. /* Scrollback search */
  248. struct wl_surface *search_surface;
  249. struct wl_subsurface *search_sub_surface;
  250. struct wl_surface *scrollback_indicator_surface;
  251. struct wl_subsurface *scrollback_indicator_sub_surface;
  252. struct wl_surface *render_timer_surface;
  253. struct wl_subsurface *render_timer_sub_surface;
  254. struct wl_callback *frame_callback;
  255. tll(const struct monitor *) on_outputs; /* Outputs we're mapped on */
  256. bool is_configured;
  257. bool is_fullscreen;
  258. bool is_maximized;
  259. struct {
  260. bool is_activated;
  261. bool is_fullscreen;
  262. bool is_maximized;
  263. int width;
  264. int height;
  265. } configure;
  266. };
  267. struct config;
  268. struct terminal;
  269. struct wayland {
  270. const struct config *conf;
  271. struct fdm *fdm;
  272. int fd;
  273. struct wl_display *display;
  274. struct wl_registry *registry;
  275. struct wl_compositor *compositor;
  276. struct wl_subcompositor *sub_compositor;
  277. struct wl_shm *shm;
  278. struct zxdg_output_manager_v1 *xdg_output_manager;
  279. struct xdg_wm_base *shell;
  280. struct zxdg_decoration_manager_v1 *xdg_decoration_manager;
  281. struct wl_data_device_manager *data_device_manager;
  282. struct zwp_primary_selection_device_manager_v1 *primary_selection_device_manager;
  283. struct wp_presentation *presentation;
  284. uint32_t presentation_clock_id;
  285. bool have_argb8888;
  286. tll(struct monitor) monitors; /* All available outputs */
  287. tll(struct seat) seats;
  288. tll(struct terminal *) terms;
  289. };
  290. struct wayland *wayl_init(const struct config *conf, struct fdm *fdm);
  291. void wayl_destroy(struct wayland *wayl);
  292. void wayl_flush(struct wayland *wayl);
  293. void wayl_roundtrip(struct wayland *wayl);
  294. struct wl_window *wayl_win_init(struct terminal *term);
  295. void wayl_win_destroy(struct wl_window *win);
  296. bool wayl_reload_xcursor_theme(struct seat *seat, int new_scale);