view.h (5265B)
1 /* Copyright (c), Niclas Meyer <niclas@countingsort.com> 2 * 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at https://mozilla.org/MPL/2.0/. 6 */ 7 8 #ifndef KIWMI_DESKTOP_VIEW_H 9 #define KIWMI_DESKTOP_VIEW_H 10 11 #include <stdbool.h> 12 #include <stdlib.h> 13 14 #include <unistd.h> 15 16 #include <wayland-server.h> 17 #include <wlr/types/wlr_xdg_shell.h> 18 #include <wlr/util/edges.h> 19 20 enum kiwmi_view_prop { 21 KIWMI_VIEW_PROP_APP_ID, 22 KIWMI_VIEW_PROP_TITLE, 23 }; 24 25 enum kiwmi_view_type { 26 KIWMI_VIEW_XDG_SHELL, 27 }; 28 29 struct kiwmi_view { 30 struct wl_list link; 31 struct wl_list children; // struct kiwmi_view_child::link 32 33 struct kiwmi_desktop *desktop; 34 35 const struct kiwmi_view_impl *impl; 36 37 enum kiwmi_view_type type; 38 union { 39 struct wlr_xdg_surface *xdg_surface; 40 }; 41 42 struct wlr_surface *wlr_surface; 43 44 struct wlr_box geom; 45 46 struct wl_listener map; 47 struct wl_listener unmap; 48 struct wl_listener commit; 49 struct wl_listener destroy; 50 struct wl_listener new_popup; 51 struct wl_listener new_subsurface; 52 struct wl_listener request_move; 53 struct wl_listener request_resize; 54 55 int x; 56 int y; 57 float matrix[9]; 58 59 bool mapped; 60 bool hidden; 61 62 struct { 63 struct wl_signal unmap; 64 struct wl_signal request_move; 65 struct wl_signal request_resize; 66 struct wl_signal post_render; 67 struct wl_signal pre_render; 68 } events; 69 70 struct kiwmi_xdg_decoration *decoration; 71 }; 72 73 struct kiwmi_view_impl { 74 void (*close)(struct kiwmi_view *view); 75 void (*for_each_surface)( 76 struct kiwmi_view *view, 77 wlr_surface_iterator_func_t callback, 78 void *user_data); 79 pid_t (*get_pid)(struct kiwmi_view *view); 80 void (*set_activated)(struct kiwmi_view *view, bool activated); 81 void (*set_size)(struct kiwmi_view *view, uint32_t width, uint32_t height); 82 const char *( 83 *get_string_prop)(struct kiwmi_view *view, enum kiwmi_view_prop prop); 84 void (*set_tiled)(struct kiwmi_view *view, enum wlr_edges edges); 85 struct wlr_surface *(*surface_at)( 86 struct kiwmi_view *view, 87 double sx, 88 double sy, 89 double *sub_x, 90 double *sub_y); 91 }; 92 93 enum kiwmi_view_child_type { 94 KIWMI_VIEW_CHILD_SUBSURFACE, 95 KIWMI_VIEW_CHILD_XDG_POPUP, 96 }; 97 98 struct kiwmi_view_child { 99 struct wl_list link; 100 struct wl_list children; // struct kiwmi_view_child::link 101 102 struct kiwmi_view *view; 103 struct kiwmi_view_child *parent; 104 105 enum kiwmi_view_child_type type; 106 const struct kiwmi_view_child_impl *impl; 107 108 struct wlr_surface *wlr_surface; 109 union { 110 struct wlr_subsurface *wlr_subsurface; 111 struct wlr_xdg_popup *wlr_xdg_popup; 112 }; 113 114 bool mapped; 115 116 struct wl_listener commit; 117 struct wl_listener map; 118 struct wl_listener unmap; 119 struct wl_listener new_popup; 120 struct wl_listener new_subsurface; 121 struct wl_listener extension_destroy; // the union'ed object destroy 122 struct wl_listener surface_destroy; // wlr_surface::events.destroy 123 }; 124 125 struct kiwmi_view_child_impl { 126 void (*reconfigure)(struct kiwmi_view_child *child); 127 }; 128 129 struct kiwmi_request_resize_event { 130 struct kiwmi_view *view; 131 uint32_t edges; 132 }; 133 134 void view_close(struct kiwmi_view *view); 135 void view_for_each_surface( 136 struct kiwmi_view *view, 137 wlr_surface_iterator_func_t callback, 138 void *user_data); 139 pid_t view_get_pid(struct kiwmi_view *view); 140 void view_get_size(struct kiwmi_view *view, uint32_t *width, uint32_t *height); 141 const char *view_get_app_id(struct kiwmi_view *view); 142 const char *view_get_title(struct kiwmi_view *view); 143 void view_set_activated(struct kiwmi_view *view, bool activated); 144 void view_set_size(struct kiwmi_view *view, uint32_t width, uint32_t height); 145 void view_set_pos(struct kiwmi_view *view, uint32_t x, uint32_t y); 146 void view_set_tiled(struct kiwmi_view *view, enum wlr_edges edges); 147 struct wlr_surface *view_surface_at( 148 struct kiwmi_view *view, 149 double sx, 150 double sy, 151 double *sub_x, 152 double *sub_y); 153 154 void view_focus(struct kiwmi_view *view); 155 struct kiwmi_view *view_at( 156 struct kiwmi_desktop *desktop, 157 double lx, 158 double ly, 159 struct wlr_surface **surface, 160 double *sx, 161 double *sy); 162 void view_move(struct kiwmi_view *view); 163 void view_resize(struct kiwmi_view *view, uint32_t edges); 164 struct kiwmi_view *view_create( 165 struct kiwmi_desktop *desktop, 166 enum kiwmi_view_type type, 167 const struct kiwmi_view_impl *impl); 168 169 void 170 view_init_subsurfaces(struct kiwmi_view_child *child, struct kiwmi_view *view); 171 bool view_child_is_mapped(struct kiwmi_view_child *child); 172 void view_child_damage(struct kiwmi_view_child *child); 173 void view_child_destroy(struct kiwmi_view_child *child); 174 struct kiwmi_view_child *view_child_create( 175 struct kiwmi_view_child *parent, 176 struct kiwmi_view *view, 177 struct wlr_surface *wlr_surface, 178 enum kiwmi_view_child_type type, 179 const struct kiwmi_view_child_impl *impl); 180 struct kiwmi_view_child *view_child_subsurface_create( 181 struct kiwmi_view_child *parent, 182 struct kiwmi_view *view, 183 struct wlr_subsurface *subsurface); 184 185 #endif /* KIWMI_DESKTOP_VIEW_H */