AtlatestRepositorysigil-wm

sigil-wm / tree / src / croles.h

1/* SPDX-License-Identifier: BSD-3-Clause */
2static struct wlr_surface *view_surface(struct view *view) {
3 if(view->x11) return view->x11->surface;
4 return view->layer ? view->layer->surface : view->native->base->surface;
5}
6static bool view_ready(struct view *view) {
7 if(view->x11) return view->tree && view->x11->surface;
8 return view->layer ? view->layer->initialized : view->native->base->initialized;
9}
10static uint32_t view_serial(struct view *view) {
11 if(view->x11) return 0;
12 return view->layer ? view->layer->current.configure_serial :
13 view->native->base->current.configure_serial;
15static bool view_configured(struct view *view) {
16 if(view->x11) {
17 struct wlr_surface *surface=view_surface(view);
18 return surface && surface->current.width==view->width && surface->current.height==view->height;
19 }
20 return !view->serial || (int32_t)(view_serial(view)-view->serial)>=0;
22static uint32_t configure_view(struct view *view, int x, int y, int width, int height,
23 bool activated, bool fullscreen, uint32_t tiled, bool suspended) {
24 if(view->x11) {
25 wlr_xwayland_surface_configure(view->x11,x,y,width,height);
26 wlr_xwayland_surface_set_fullscreen(view->x11,fullscreen);
27 return 0;
28 }
29 if(view->layer) {
30 if(view->layer->current.actual_width==(uint32_t)width &&
31 view->layer->current.actual_height==(uint32_t)height) return view_serial(view);
32 return wlr_layer_surface_v1_configure(view->layer,width,height);
33 }
34 struct wlr_xdg_toplevel *toplevel=view->native;
35 struct wlr_xdg_toplevel_configure *scheduled=&toplevel->scheduled;
36 uint32_t version=wl_resource_get_version(toplevel->resource);
37 uint32_t pending=view_configured(view) ? 0 : view->serial;
38 uint32_t serial=0;
39 bool resizing=view->width!=width || view->height!=height;
40 if(scheduled->width!=width || scheduled->height!=height)
41 serial=wlr_xdg_toplevel_set_size(toplevel,width,height);
42 if(scheduled->activated!=activated)
43 serial=wlr_xdg_toplevel_set_activated(toplevel,activated);
44 if(version>=6 && scheduled->suspended!=suspended)
45 serial=wlr_xdg_toplevel_set_suspended(toplevel,suspended);
46 if(scheduled->fullscreen!=fullscreen)
47 serial=wlr_xdg_toplevel_set_fullscreen(toplevel,fullscreen);
48 if(version>=2 && scheduled->tiled!=tiled)
49 serial=wlr_xdg_toplevel_set_tiled(toplevel,tiled);
50 if(resizing && !serial) serial=wlr_xdg_surface_schedule_configure(toplevel->base);
51 return resizing ? serial : pending;
53static void close_view(struct view *view) {
54 if(view->x11) wlr_xwayland_surface_close(view->x11);
55 else if (view->layer) wlr_layer_surface_v1_destroy(view->layer);
56 else wlr_xdg_toplevel_send_close(view->native);
58static void view_each_surface(struct view *view, wlr_surface_iterator_func_t iterator, void *data) {
59 if(view->x11) {
60 if(view_surface(view)) wlr_surface_for_each_surface(view_surface(view),iterator,data);
61 }
62 else if (view->layer) wlr_layer_surface_v1_for_each_surface(view->layer, iterator, data);
63 else wlr_xdg_surface_for_each_surface(view->native->base, iterator, data);