AtlatestRepositorysigil-wm

sigil-wm / tree / src / cx11.h

1/* SPDX-License-Identifier: BSD-3-Clause
2 * X11 object, metadata and request transport. Placement belongs to Sigil. */
3static void x11_properties(struct view *view) {
4 struct wlr_xwayland_surface *native = view->x11;
5 struct view *parent = native->parent ? native->parent->data : NULL;
6 EVENT(27, view->id, parent ? parent->id : 0, native->pid, native->override_redirect,
7 native->modal, native->decorations, native->x, native->y, native->width, native->height,
8 wlr_xwayland_surface_has_window_type(native, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG));
9}
10static void x11_metadata(struct view *view) {
11 object_text(view->id, 15, view->x11->title);
12 object_text(view->id, 16, view->x11->class);
13 object_text(view->id, 26, view->x11->instance);
14 xcb_size_hints_t *hints = view->x11->size_hints;
15 struct view *parent = view->x11->parent ? view->x11->parent->data : NULL;
16 EVENT(14, view->id,
17 hints && (hints->flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE) ? hints->min_width : 0,
18 hints && (hints->flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE) ? hints->min_height : 0,
19 hints && (hints->flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE) ? hints->max_width : 0,
20 hints && (hints->flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE) ? hints->max_height : 0,
21 parent ? parent->id : 0);
22 x11_properties(view);
24static void x11_map(struct wl_listener *listener, void *data) {
25 (void)data;
26 struct view *view = wl_container_of(listener, view, map);
27 view->mapped = true;
28 foreign_map(view);
29 x11_metadata(view);
30 EVENT(11, view->id);
32static void x11_commit(struct wl_listener *listener, void *data) {
33 (void)data;
34 struct view *view = wl_container_of(listener, view, commit);
35 struct wlr_surface *surface = view_surface(view);
36 if (surface && (view->committed.width != surface->current.width ||
37 view->committed.height != surface->current.height)) {
38 view->committed = (struct wlr_box){0, 0, surface->current.width, surface->current.height};
39 EVENT(18, view->id, 0, 0, surface->current.width, surface->current.height, 0);
40 }
41 check_plan(view->server);
43static void x11_associate(struct wl_listener *listener, void *data) {
44 (void)data;
45 struct view *view = wl_container_of(listener, view, associate);
46 view->tree = wlr_scene_tree_create(view->server->normal);
47 view->live = view->tree ? wlr_scene_subsurface_tree_create(view->tree, view_surface(view)) : NULL;
48 if (!view->live) {
49 if (view->tree) { discard_saved(view); wlr_scene_node_destroy(&view->tree->node); }
50 view->tree = NULL;
51 return;
52 }
53 view->tree->node.data = view;
54 wlr_scene_node_set_enabled(&view->tree->node, false);
55 struct wlr_surface *surface = view_surface(view);
56 refresh_inhibitors(view->server);
57 listen(&surface->events.map, &view->map, x11_map);
58 listen(&surface->events.unmap, &view->unmap, view_unmap);
59 listen(&surface->events.commit, &view->commit, x11_commit);
60 /* Association can follow the buffer commit that would normally map it. */
61 if (!surface->mapped && wlr_surface_has_buffer(surface)) wlr_surface_map(surface);
62 x11_commit(&view->commit, NULL);
64static void x11_dissociate(struct wl_listener *listener, void *data) {
65 (void)data;
66 struct view *view = wl_container_of(listener, view, dissociate);
67 if (!view->tree) return;
68 if (view->mapped) view_unmap(&view->unmap, NULL);
69 wl_list_remove(&view->map.link);
70 wl_list_remove(&view->unmap.link);
71 wl_list_remove(&view->commit.link);
72 discard_saved(view);
73 wlr_scene_node_destroy(&view->tree->node);
74 view->tree = view->live = view->saved = NULL;
76static void x11_destroy(struct wl_listener *listener, void *data) {
77 (void)data;
78 struct view *view = wl_container_of(listener, view, destroy);
79 struct server *server = view->server;
80 foreign_unmap(view);
81 x11_dissociate(&view->dissociate, NULL);
82 wl_list_remove(&view->associate.link);
83 wl_list_remove(&view->dissociate.link);
84 wl_list_remove(&view->destroy.link);
85 wl_list_remove(&view->request_configure.link);
86 wl_list_remove(&view->move.link);
87 wl_list_remove(&view->resize.link);
88 wl_list_remove(&view->set_geometry.link);
89 wl_list_remove(&view->title.link);
90 wl_list_remove(&view->app_id.link);
91 wl_list_remove(&view->request_activate.link);
92 wl_list_remove(&view->fullscreen.link);
93 wl_list_remove(&view->link);
94 view->x11->data = NULL;
95 EVENT(13, view->id);
96 atomic_fetch_sub(&bridge.objects, 1);
97 free(view);
98 check_plan(server);
100static void x11_request_move(struct wl_listener *listener, void *data) {
101 (void)data;
102 struct view *view=wl_container_of(listener,view,move);
103 EVENT(17,view->id,1);
105static void x11_request_resize(struct wl_listener *listener, void *data) {
106 struct view *view=wl_container_of(listener,view,resize);
107 struct wlr_xwayland_resize_event *request=data;
108 EVENT(17,view->id,2,0,request->edges);
110static void x11_request_configure(struct wl_listener *listener, void *data) {
111 struct view *view = wl_container_of(listener, view, request_configure);
112 struct wlr_xwayland_surface_configure_event *request = data;
113 EVENT(17, view->id, 5, request->mask, request->x, request->y, request->width, request->height);
115static void x11_set_geometry(struct wl_listener *listener, void *data) {
116 (void)data;
117 struct view *view = wl_container_of(listener, view, set_geometry);
118 x11_properties(view);
120static void x11_set_title(struct wl_listener *listener, void *data) {
121 (void)data;
122 struct view *view = wl_container_of(listener, view, title);
123 object_text(view->id, 15, view->x11->title);
124 foreign_metadata(view);
126static void x11_set_class(struct wl_listener *listener, void *data) {
127 (void)data;
128 struct view *view = wl_container_of(listener, view, app_id);
129 object_text(view->id, 16, view->x11->class);
130 object_text(view->id, 26, view->x11->instance);
131 foreign_metadata(view);
133static void x11_request_activate(struct wl_listener *listener, void *data) {
134 (void)data;
135 struct view *view = wl_container_of(listener, view, request_activate);
136 EVENT(17, view->id, 6);
138static void x11_request_fullscreen(struct wl_listener *listener, void *data) {
139 (void)data;
140 struct view *view = wl_container_of(listener, view, fullscreen);
141 EVENT(17, view->id, 4, view->x11->fullscreen);
143static void new_x11(struct wl_listener *listener, void *data) {
144 struct server *server = wl_container_of(listener, server, new_x11);
145 struct wlr_xwayland_surface *native = data;
146 struct view *view = calloc(1, sizeof(*view));
147 if (!view) return;
148 view->server = server;
149 view->x11 = native;
150 view->id = ++server->next_id;
151 native->data = view;
152 wl_list_insert(&server->views, &view->link);
153 listen(&native->events.associate, &view->associate, x11_associate);
154 listen(&native->events.dissociate, &view->dissociate, x11_dissociate);
155 listen(&native->events.destroy, &view->destroy, x11_destroy);
156 listen(&native->events.request_configure, &view->request_configure, x11_request_configure);
157 listen(&native->events.request_move, &view->move, x11_request_move);
158 listen(&native->events.request_resize, &view->resize, x11_request_resize);
159 listen(&native->events.set_geometry, &view->set_geometry, x11_set_geometry);
160 listen(&native->events.set_title, &view->title, x11_set_title);
161 listen(&native->events.set_class, &view->app_id, x11_set_class);
162 listen(&native->events.request_activate, &view->request_activate, x11_request_activate);
163 listen(&native->events.request_fullscreen, &view->fullscreen, x11_request_fullscreen);
164 atomic_fetch_add(&bridge.objects, 1);
165 EVENT(10, view->id, 2);
166 x11_properties(view);
168static void x11_manager_ready(struct wl_listener *listener, void *data) {
169 (void)data;
170 struct server *server=wl_container_of(listener,server,x11_ready);
171 object_text(0,9,server->xwayland->display_name);
173static void x11_manager_destroy(struct wl_listener *listener, void *data) {
174 (void)data;
175 struct server *server = wl_container_of(listener, server, x11_destroy);
176 wl_list_remove(&server->new_x11.link);
177 wl_list_remove(&server->x11_destroy.link);
178 wl_list_remove(&server->x11_ready.link);
179 server->xwayland = NULL;