-rw-r--r-- src/types.h
1 #ifndef WIMP_TYPES_H 2 #define WIMP_TYPES_H 3 4 #include <cairo/cairo.h> 5 #include <stdlib.h> 6 #include <unistd.h> 7 #include <wlr/backend.h> 8 #include <wlr/render/wlr_renderer.h> 9 #include <wlr/render/wlr_texture.h> 10 #include <wlr/types/wlr_compositor.h> 11 #include <wlr/types/wlr_cursor.h> 12 #include <wlr/types/wlr_output_layout.h> 13 #include <wlr/types/wlr_server_decoration.h> 14 #include <wlr/types/wlr_xcursor_manager.h> 15 #include <wlr/types/wlr_xdg_decoration_v1.h> 16 #include <wlr/types/wlr_xdg_shell.h> 17 #include <wlr/util/log.h> 18 19 #define is_number(s) (strspn(s, "0123456789.-") == strlen(s)) 20 #define is_number_perc(s) (strspn(s, "0123456789.-%") == strlen(s)) 21 22 #define is_readable(p) (access(p, R_OK) != -1) 23 #define is_executable(p) (access(p, R_OK | X_OK) != -1) 24 25 #define CORNER 24 26 27 enum cursor_mode { 28 CURSOR_PASSTHROUGH, 29 CURSOR_MOD, 30 CURSOR_MOVE, 31 CURSOR_RESIZE, 32 }; 33 34 typedef void (*action)(void *data); 35 36 struct mark_indicator { 37 float colour[4]; 38 struct wlr_box box; 39 }; 40 41 struct wimp { 42 struct wl_display *display; 43 struct wlr_backend *backend; 44 struct wlr_renderer *renderer; 45 46 struct wlr_output_layout *output_layout; 47 struct wl_listener output_layout_change_listener; 48 struct wl_list outputs; 49 struct wl_listener new_output_listener; 50 struct wlr_output_manager_v1 *output_manager; 51 struct wl_listener output_manager_apply_listener; 52 struct wl_listener output_manager_test_listener; 53 54 struct wlr_xdg_shell *shell; 55 struct wl_listener new_xdg_surface_listener; 56 struct wl_list desks; 57 int desk_count; 58 struct desk *current_desk; 59 struct wl_list marks; 60 bool mark_waiting; 61 struct mark_indicator mark_indicator; 62 bool bind_marks; 63 64 struct wlr_xdg_decoration_manager_v1 *decoration_manager; 65 struct wl_listener decoration_listener; 66 struct wlr_server_decoration_manager *server_decoration_manager; 67 68 struct wlr_layer_shell_v1 *layer_shell; 69 struct wl_listener layer_shell_surface_listener; 70 struct layer_view *focussed_layer_view; 71 72 struct wlr_cursor *cursor; 73 struct wlr_xcursor_manager *cursor_manager; 74 struct wl_listener cursor_motion_listener; 75 struct wl_listener cursor_motion_absolute_listener; 76 struct wl_listener cursor_button_listener; 77 struct wl_listener cursor_axis_listener; 78 struct wl_listener cursor_frame_listener; 79 struct wlr_pointer_gestures_v1 *pointer_gestures; 80 struct wl_listener pinch_begin_listener; 81 struct wl_listener pinch_update_listener; 82 struct wl_listener pinch_end_listener; 83 struct wl_listener swipe_begin_listener; 84 struct wl_listener swipe_update_listener; 85 struct wl_listener swipe_end_listener; 86 87 struct wlr_seat *seat; 88 struct wl_listener new_input_listener; 89 struct wl_listener request_cursor_listener; 90 struct wl_listener request_set_selection_listener; 91 struct wl_list keyboards; 92 enum wlr_keyboard_modifier mod; 93 struct wl_list key_bindings; 94 struct wl_list mouse_bindings; 95 96 struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard; 97 struct wl_listener new_virtual_keyboard_listener; 98 99 action on_mouse_motion; 100 action on_mouse_scroll; 101 action on_drag1; 102 action on_drag2; 103 action on_drag3; 104 action on_pinch; 105 action on_pinch_begin; 106 107 bool reverse_scrolling; 108 enum cursor_mode cursor_mode; 109 struct view *grabbed_view; 110 double grab_x, grab_y; 111 struct wlr_box grab_geobox; 112 uint32_t resize_edges; 113 double zoom_min, zoom_max; 114 bool auto_focus; 115 116 bool can_snap; 117 struct wlr_box snap_geobox; 118 float snapbox_colour[4]; 119 120 struct wl_list scratchpads; 121 pid_t scratchpad_waiting; 122 }; 123 124 extern struct wimp wimp; 125 126 struct view { 127 struct wl_list link; 128 struct wlr_xdg_surface *surface; 129 struct wl_listener map_listener; 130 struct wl_listener unmap_listener; 131 struct wl_listener commit_listener; 132 struct wl_listener destroy_listener; 133 struct wl_listener request_move_listener; 134 struct wl_listener request_resize_listener; 135 struct wl_listener request_fullscreen_listener; 136 double x, y; 137 int width, height; 138 bool is_scratchpad; 139 }; 140 141 struct output { 142 struct wl_list link; 143 struct wl_list layer_views[4]; 144 struct wlr_output *wlr_output; 145 struct wlr_output_damage *wlr_output_damage; 146 struct wl_listener frame_listener; 147 struct wl_listener destroy_listener; 148 }; 149 150 struct layer_view { 151 struct wl_list link; 152 struct wlr_layer_surface_v1 *surface; 153 struct wl_listener map_listener; 154 struct wl_listener unmap_listener; 155 struct wl_listener commit_listener; 156 struct wl_listener destroy_listener; 157 struct output *output; 158 struct wlr_box geo; 159 }; 160 161 struct keyboard { 162 struct wl_list link; 163 struct wlr_input_device *device; 164 struct wl_listener modifier_listener; 165 struct wl_listener key_listener; 166 struct wl_listener destroy_listener; 167 }; 168 169 struct wallpaper { 170 struct wlr_texture *texture; 171 int width, height; 172 }; 173 174 struct desk { 175 struct wl_list link; 176 struct wl_list views; 177 float background[4]; 178 float border_normal[4]; 179 float border_focus[4]; 180 float corner_normal[4]; 181 float corner_focus[4]; 182 int border_width; 183 struct wallpaper *wallpaper; 184 double panned_x, panned_y; 185 int index; 186 double zoom; 187 struct wlr_xdg_surface *fullscreened; 188 struct wlr_box fullscreened_saved_geo; 189 }; 190 191 struct binding { 192 struct wl_list link; 193 enum wlr_keyboard_modifier mods; 194 uint32_t key; 195 action action; 196 void *data; 197 }; 198 199 struct motion { 200 double dx; 201 double dy; 202 bool is_percentage; 203 }; 204 205 enum mouse_keys { 206 MOTION = 1, 207 SCROLL = 2, 208 DRAG1 = 3, 209 DRAG2 = 4, 210 DRAG3 = 5, 211 PINCH = 6, 212 }; 213 214 struct mark { 215 struct wl_list link; 216 uint32_t key; 217 struct desk *desk; 218 double zoom, x, y; 219 }; 220 221 enum direction { 222 NO_DIRECTION = 0, 223 UP = 1 << 0, 224 RIGHT = 1 << 1, 225 DOWN = 1 << 2, 226 LEFT = 1 << 3, 227 }; 228 229 struct scratchpad { 230 struct wl_list link; 231 char *command; 232 int id; 233 pid_t pid; 234 struct view *view; 235 bool is_mapped; 236 struct wlr_box geo; // negative values represent a percentage of the output's geometry 237 }; 238 239 struct dict { 240 const char *name; 241 const int value; 242 }; 243 244 #endif 245