inaban.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Copyright 2019-2021 Inaban Authors <https://hacktivis.me/git/inaban>
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Based on wlroots's TinyWL which is distributed under CC0
  4. #ifndef INABAN_H
  5. #define INABAN_H
  6. #include <stdbool.h>
  7. #include <wayland-server.h>
  8. #include <wlr/backend.h>
  9. #include <wlr/render/wlr_renderer.h>
  10. #include <wlr/types/wlr_compositor.h>
  11. #include <wlr/types/wlr_cursor.h>
  12. #include <wlr/types/wlr_data_control_v1.h>
  13. #include <wlr/types/wlr_data_device.h>
  14. #include <wlr/types/wlr_gtk_primary_selection.h>
  15. #include <wlr/types/wlr_input_device.h>
  16. #include <wlr/types/wlr_keyboard.h>
  17. #include <wlr/types/wlr_matrix.h>
  18. #include <wlr/types/wlr_output.h>
  19. #include <wlr/types/wlr_output_layout.h>
  20. #include <wlr/types/wlr_pointer.h>
  21. #include <wlr/types/wlr_primary_selection.h>
  22. #include <wlr/types/wlr_primary_selection_v1.h>
  23. #include <wlr/types/wlr_seat.h>
  24. #include <wlr/types/wlr_server_decoration.h>
  25. #include <wlr/types/wlr_xcursor_manager.h>
  26. #include <wlr/types/wlr_xdg_decoration_v1.h>
  27. #include <wlr/types/wlr_xdg_shell.h>
  28. #include <wlr/util/log.h>
  29. #include <xkbcommon/xkbcommon.h>
  30. enum inaban_input_mode
  31. {
  32. INABAN_INPUT_NORMAL,
  33. INABAN_INPUT_MODKEY,
  34. };
  35. enum inaban_cursor_mode
  36. {
  37. INABAN_CURSOR_NORMAL,
  38. INABAN_CURSOR_MOVE,
  39. INABAN_CURSOR_RESIZE,
  40. };
  41. struct inaban_server
  42. {
  43. struct wl_display *wl_display;
  44. struct wlr_backend *backend;
  45. struct wlr_renderer *renderer;
  46. struct wlr_xdg_shell *xdg_shell;
  47. struct wl_listener new_xdg_surface;
  48. struct wl_list views;
  49. struct wl_listener xdg_toplevel_decoration;
  50. struct wlr_cursor *cursor;
  51. struct wlr_xcursor_manager *cursor_mgr;
  52. struct wl_listener cursor_motion;
  53. struct wl_listener cursor_motion_absolute;
  54. struct wl_listener cursor_button;
  55. struct wl_listener cursor_axis;
  56. struct wl_listener cursor_frame;
  57. struct wlr_seat *seat;
  58. struct wl_listener new_input;
  59. struct wl_listener request_cursor;
  60. struct wl_list keyboards;
  61. struct wlr_output_layout *output_layout;
  62. struct wl_list outputs;
  63. struct wl_listener new_output;
  64. enum inaban_input_mode input_mode;
  65. enum inaban_cursor_mode cursor_mode;
  66. struct inaban_view *grabbed_view;
  67. /* cursor position */
  68. double grab_x, grab_y;
  69. /* window size */
  70. int grab_width, grab_height;
  71. /* clipboard */
  72. struct wl_listener request_set_primary_selection;
  73. struct wl_listener request_set_selection;
  74. };
  75. struct inaban_output
  76. {
  77. struct wl_list link;
  78. struct inaban_server *server;
  79. struct wlr_output *wlr_output;
  80. struct wl_listener frame;
  81. };
  82. struct inaban_view
  83. {
  84. struct wl_list link;
  85. struct inaban_server *server;
  86. struct wlr_xdg_surface *xdg_surface;
  87. struct wl_listener map;
  88. struct wl_listener unmap;
  89. struct wl_listener destroy;
  90. struct wl_listener request_move;
  91. struct wl_listener request_resize;
  92. bool mapped;
  93. int x, y;
  94. };
  95. struct inaban_keyboard
  96. {
  97. struct wl_list link;
  98. struct inaban_server *server;
  99. struct wlr_input_device *device;
  100. struct wl_listener modifiers;
  101. struct wl_listener key;
  102. };
  103. /* Used to move all of the data necessary to render a surface from the top-level
  104. * frame handler to the per-surface render function. */
  105. struct render_data
  106. {
  107. struct wlr_output *output;
  108. struct wlr_renderer *renderer;
  109. struct inaban_view *view;
  110. struct timespec *when;
  111. };
  112. typedef union
  113. {
  114. int i;
  115. unsigned int ui;
  116. float f;
  117. const void *v;
  118. } Arg;
  119. typedef struct
  120. {
  121. uint32_t mod;
  122. xkb_keysym_t keysym;
  123. void (*func)(const Arg *);
  124. const Arg arg;
  125. } Shortcut;
  126. void spawn(const Arg *arg);
  127. void focus_view(struct inaban_view *view, struct wlr_surface *surface);
  128. void quit(const Arg *arg);
  129. #endif /* INABAN_H */