From c9b088e3438a0a24aa66913b9fb02cdcd62621bb Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Fri, 12 Dec 2025 04:27:32 +0900 Subject: [PATCH] cycle: add and use get_outputs_by_filter() This function can be reused for filtering windows to cycle through. --- src/cycle/cycle.c | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/src/cycle/cycle.c b/src/cycle/cycle.c index f14bff9d..067c9929 100644 --- a/src/cycle/cycle.c +++ b/src/cycle/cycle.c @@ -266,14 +266,36 @@ get_osd_impl(void) return NULL; } -static void -create_osd_on_output(struct output *output) +static uint64_t +get_outputs_by_filter(struct server *server, + enum cycle_output_filter output_filter) { - if (!output_is_usable(output)) { - return; + struct output *output = NULL; + + switch (output_filter) { + case CYCLE_OUTPUT_ALL: + break; + case CYCLE_OUTPUT_CURSOR: + output = output_nearest_to_cursor(server); + break; + case CYCLE_OUTPUT_FOCUSED: { + struct view *view = server->active_view; + if (view && output_is_usable(view->output)) { + output = view->output; + } else { + /* Fallback to pointer */ + output = output_nearest_to_cursor(server); + } + break; + } + } + + if (output) { + return output->id_bit; + } else { + /* bitmask for all outputs */ + return UINT64_MAX; } - get_osd_impl()->create(output); - assert(output->cycle_osd.tree); } static void @@ -309,28 +331,18 @@ init_cycle(struct server *server) if (rc.window_switcher.osd.show) { /* Create OSD */ - switch (rc.window_switcher.osd.output_filter) { - case CYCLE_OUTPUT_ALL: { - struct output *output; - wl_list_for_each(output, &server->outputs, link) { - create_osd_on_output(output); + uint64_t osd_outputs = get_outputs_by_filter(server, + rc.window_switcher.osd.output_filter); + struct output *output; + wl_list_for_each(output, &server->outputs, link) { + if (!(osd_outputs & output->id_bit)) { + continue; } - break; - } - case CYCLE_OUTPUT_CURSOR: - create_osd_on_output(output_nearest_to_cursor(server)); - break; - case CYCLE_OUTPUT_FOCUSED: { - struct output *output; - if (server->active_view) { - output = server->active_view->output; - } else { - /* Fallback to pointer, if there is no active_view */ - output = output_nearest_to_cursor(server); + if (!output_is_usable(output)) { + continue; } - create_osd_on_output(output); - break; - } + get_osd_impl()->create(output); + assert(output->cycle_osd.tree); } }