From b4e9f729c301787239677b1bdd4235436bad99c7 Mon Sep 17 00:00:00 2001 From: qaqland Date: Sun, 11 May 2025 10:42:29 +0800 Subject: [PATCH] output: add "named" to multi-output-modes --- cage.c | 3 +++ output.c | 32 ++++++++++++++++++++++++-------- server.h | 1 + 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cage.c b/cage.c index 40a675d..d0f896c 100644 --- a/cage.c +++ b/cage.c @@ -231,6 +231,7 @@ usage(FILE *file, const char *cage) " -h\t Display this help message\n" " -m extend Extend the display across all connected outputs (default)\n" " -m last Use only the last connected output\n" + " -m named Use the output specified by the environment CAGE_OUTPUT_NAME, or fallback to last\n" " -s\t Allow VT switching\n" " -v\t Show the version number and exit\n" "\n" @@ -258,6 +259,8 @@ parse_args(struct cg_server *server, int argc, char *argv[]) server->output_mode = CAGE_MULTI_OUTPUT_MODE_LAST; } else if (strcmp(optarg, "extend") == 0) { server->output_mode = CAGE_MULTI_OUTPUT_MODE_EXTEND; + } else if (strcmp(optarg, "named") == 0) { + server->output_mode = CAGE_MULTI_OUTPUT_MODE_NAMED; } break; case 's': diff --git a/output.c b/output.c index 5ccc939..4979155 100644 --- a/output.c +++ b/output.c @@ -238,9 +238,12 @@ output_destroy(struct cg_output *output) free(output); - if (wl_list_empty(&server->outputs) && was_nested_output) { - server_terminate(server); - } else if (server->output_mode == CAGE_MULTI_OUTPUT_MODE_LAST && !wl_list_empty(&server->outputs)) { + if (wl_list_empty(&server->outputs)) { + if (was_nested_output) { + server_terminate(server); + } + } else if (server->output_mode == CAGE_MULTI_OUTPUT_MODE_LAST || + server->output_mode == CAGE_MULTI_OUTPUT_MODE_NAMED) { struct cg_output *prev = wl_container_of(server->outputs.next, prev, link); output_enable(prev); view_position_all(server); @@ -314,11 +317,6 @@ handle_new_output(struct wl_listener *listener, void *data) } } - if (server->output_mode == CAGE_MULTI_OUTPUT_MODE_LAST && wl_list_length(&server->outputs) > 1) { - struct cg_output *next = wl_container_of(output->link.next, next, link); - output_disable(next); - } - if (!wlr_xcursor_manager_load(server->seat->xcursor_manager, wlr_output->scale)) { wlr_log(WLR_ERROR, "Cannot load XCursor theme for output '%s' with scale %f", wlr_output->name, wlr_output->scale); @@ -329,6 +327,24 @@ handle_new_output(struct wl_listener *listener, void *data) output_layout_add_auto(output); } + if (wl_list_length(&server->outputs) > 1) { + struct cg_output *next = wl_container_of(output->link.next, next, link); + const char *output_name = getenv("CAGE_OUTPUT_NAME"); + switch (server->output_mode) { + case CAGE_MULTI_OUTPUT_MODE_NAMED: + if (output_name && strcmp(next->wlr_output->name, output_name) == 0) { + wl_list_remove(&next->link); + wl_list_insert(&server->outputs, &next->link); + next = output; + } + // fall through + case CAGE_MULTI_OUTPUT_MODE_LAST: + output_disable(next); + break; + case CAGE_MULTI_OUTPUT_MODE_EXTEND:; + } + } + view_position_all(output->server); update_output_manager_config(output->server); } diff --git a/server.h b/server.h index 00c2a61..7a2f8cb 100644 --- a/server.h +++ b/server.h @@ -18,6 +18,7 @@ enum cg_multi_output_mode { CAGE_MULTI_OUTPUT_MODE_EXTEND, CAGE_MULTI_OUTPUT_MODE_LAST, + CAGE_MULTI_OUTPUT_MODE_NAMED, }; struct cg_server {