switch to using union for *image_capture_tree and *image_capture_scene_surface in screencapture

only image_capture_tree is needed for screensharing single wayland
windows and only image_capture_scene_surface is needed for screensharing
single xwayland windows. Making them into a union makes sense for
reducing memory usage.
This commit is contained in:
Zuki Air 2025-08-05 14:06:52 +01:00
parent 32126eb87b
commit 8b27e5c859

18
dwl.c
View File

@ -126,7 +126,11 @@ typedef struct {
struct wl_listener commit; struct wl_listener commit;
struct wlr_scene *image_capture_scene; struct wlr_scene *image_capture_scene;
struct wlr_ext_image_capture_source_v1 *image_capture_source; struct wlr_ext_image_capture_source_v1 *image_capture_source;
struct wlr_scene_tree *image_capture_tree; struct wlr_ext_foreign_toplevel_handle_v1 *ext_foreign_toplevel;
union {
struct wlr_scene_tree *image_capture_tree;
struct wlr_scene_surface *image_capture_scene_surface;
} capture;
struct wl_listener map; struct wl_listener map;
struct wl_listener maximize; struct wl_listener maximize;
struct wl_listener unmap; struct wl_listener unmap;
@ -136,7 +140,6 @@ typedef struct {
struct wl_listener set_decoration_mode; struct wl_listener set_decoration_mode;
struct wl_listener destroy_decoration; struct wl_listener destroy_decoration;
#ifdef XWAYLAND #ifdef XWAYLAND
struct wlr_scene_surface *image_capture_scene_surface;
struct wl_listener activate; struct wl_listener activate;
struct wl_listener associate; struct wl_listener associate;
struct wl_listener dissociate; struct wl_listener dissociate;
@ -147,7 +150,6 @@ typedef struct {
uint32_t tags; uint32_t tags;
int isfloating, isurgent, isfullscreen; int isfloating, isurgent, isfullscreen;
uint32_t resize; /* configure serial of a pending resize */ uint32_t resize; /* configure serial of a pending resize */
struct wlr_ext_foreign_toplevel_handle_v1 *ext_foreign_toplevel;
} Client; } Client;
typedef struct { typedef struct {
@ -1775,10 +1777,10 @@ mapnotify(struct wl_listener *listener, void *data)
c->ext_foreign_toplevel = wlr_ext_foreign_toplevel_handle_v1_create(foreign_toplevel_list,&foreign_toplevel_state); c->ext_foreign_toplevel = wlr_ext_foreign_toplevel_handle_v1_create(foreign_toplevel_list,&foreign_toplevel_state);
c->ext_foreign_toplevel->data = c; c->ext_foreign_toplevel->data = c;
if (c->type == XDGShell) { if (c->type == XDGShell) {
c->image_capture_tree = wlr_scene_xdg_surface_create(&c->image_capture_scene->tree, c->surface.xdg); c->capture.image_capture_tree = wlr_scene_xdg_surface_create(&c->image_capture_scene->tree, c->surface.xdg);
#ifdef XWAYLAND #ifdef XWAYLAND
} else { /* xwayland */ } else { /* xwayland */
c->image_capture_scene_surface = wlr_scene_surface_create(&c->image_capture_scene->tree, c->surface.xwayland->surface); c->capture.image_capture_scene_surface = wlr_scene_surface_create(&c->image_capture_scene->tree, c->surface.xwayland->surface);
#endif #endif
} }
@ -2886,9 +2888,9 @@ unmapnotify(struct wl_listener *listener, void *data)
wlr_ext_foreign_toplevel_handle_v1_destroy(c->ext_foreign_toplevel); wlr_ext_foreign_toplevel_handle_v1_destroy(c->ext_foreign_toplevel);
} }
#ifdef XWAYLAND #ifdef XWAYLAND
if (c->image_capture_scene_surface) { if (c->type != XDGShell && c->capture.image_capture_scene_surface) {
wlr_scene_node_destroy(&c->image_capture_scene_surface->buffer->node); wlr_scene_node_destroy(&c->capture.image_capture_scene_surface->buffer->node);
c->image_capture_scene_surface = NULL; c->capture.image_capture_scene_surface = NULL;
} }
#endif #endif