cycle: refactor to aggregate type definitions into cycle.h

We declared `cycle_state` struct in `labwc.h` and `cycle_osd_scene`
struct in `output.h`, which was unclean in terms of separation of
concerns.

So this commit firstly moves `cycle_state` to `cycle.h`, then replaces
`cycle_osd_scene` in `output.h` with `cycle_osd_output` in `cycle.h`
which is dynamically allocated in a similar manner to
`session_lock_output`. This ensures that all states about alt-tabbing
are stored in `server->cycle`.

Also, this commit fixes a rare memory leak in `output->cycle_osd.items`
when an output is destroyed while alt-tabbing, by freeing it when the
osd tree is destroyed.
This commit is contained in:
tokyo4j 2025-12-29 02:50:45 +09:00 committed by Johan Malm
parent 276d4e61f9
commit dfe428ae14
8 changed files with 95 additions and 72 deletions

View file

@ -4,6 +4,7 @@
#include <stdbool.h>
#include <wayland-server-core.h>
#include <wlr/util/box.h>
#include "config/types.h"
struct output;
@ -49,6 +50,27 @@ struct cycle_filter {
enum cycle_app_id_filter app_id;
};
struct cycle_state {
struct view *selected_view;
struct wl_list views;
struct wl_list osd_outputs; /* struct cycle_osd_output.link */
bool preview_was_shaded;
bool preview_was_enabled;
struct wlr_scene_node *preview_node;
struct wlr_scene_node *preview_dummy;
struct lab_scene_rect *preview_outline;
struct cycle_filter filter;
};
struct cycle_osd_output {
struct wl_list link; /* struct cycle_state.osd_outputs */
struct output *output;
struct wl_listener tree_destroy;
struct wl_list items; /* struct cycle_osd_item.link */
struct wlr_scene_tree *tree;
};
struct buf;
struct view;
struct server;
@ -92,15 +114,14 @@ struct cycle_osd_item {
struct cycle_osd_impl {
/*
* Create a scene-tree of OSD for an output.
* This sets output->cycle_osd.{items,tree}.
* Create a scene-tree of OSD for an output and fill
* osd_output->items.
*/
void (*create)(struct output *output);
void (*init)(struct cycle_osd_output *osd_output);
/*
* Update output->cycle_osd.tree to highlight
* server->cycle_state.selected_view.
* Update the OSD to highlight server->cycle.selected_view.
*/
void (*update)(struct output *output);
void (*update)(struct cycle_osd_output *osd_output);
};
extern struct cycle_osd_impl cycle_osd_classic_impl;

View file

@ -303,16 +303,7 @@ struct server {
struct wlr_security_context_manager_v1 *security_context_manager_v1;
/* Set when in cycle (alt-tab) mode */
struct cycle_state {
struct view *selected_view;
struct wl_list views;
bool preview_was_shaded;
bool preview_was_enabled;
struct wlr_scene_node *preview_node;
struct wlr_scene_node *preview_dummy;
struct lab_scene_rect *preview_outline;
struct cycle_filter filter;
} cycle;
struct cycle_state cycle;
struct theme *theme;

View file

@ -19,11 +19,6 @@ struct output {
struct wlr_scene_tree *session_lock_tree;
struct wlr_scene_buffer *workspace_osd;
struct cycle_osd_scene {
struct wl_list items; /* struct cycle_osd_item */
struct wlr_scene_tree *tree;
} cycle_osd;
/* In output-relative scene coordinates */
struct wlr_box usable_area;