output: add "named" to multi-output-modes

This commit is contained in:
qaqland 2025-05-11 10:42:29 +08:00
parent 6efb3b5042
commit b4e9f729c3
3 changed files with 28 additions and 8 deletions

3
cage.c
View file

@ -231,6 +231,7 @@ usage(FILE *file, const char *cage)
" -h\t Display this help message\n" " -h\t Display this help message\n"
" -m extend Extend the display across all connected outputs (default)\n" " -m extend Extend the display across all connected outputs (default)\n"
" -m last Use only the last connected output\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" " -s\t Allow VT switching\n"
" -v\t Show the version number and exit\n" " -v\t Show the version number and exit\n"
"\n" "\n"
@ -258,6 +259,8 @@ parse_args(struct cg_server *server, int argc, char *argv[])
server->output_mode = CAGE_MULTI_OUTPUT_MODE_LAST; server->output_mode = CAGE_MULTI_OUTPUT_MODE_LAST;
} else if (strcmp(optarg, "extend") == 0) { } else if (strcmp(optarg, "extend") == 0) {
server->output_mode = CAGE_MULTI_OUTPUT_MODE_EXTEND; server->output_mode = CAGE_MULTI_OUTPUT_MODE_EXTEND;
} else if (strcmp(optarg, "named") == 0) {
server->output_mode = CAGE_MULTI_OUTPUT_MODE_NAMED;
} }
break; break;
case 's': case 's':

View file

@ -238,9 +238,12 @@ output_destroy(struct cg_output *output)
free(output); free(output);
if (wl_list_empty(&server->outputs) && was_nested_output) { if (wl_list_empty(&server->outputs)) {
server_terminate(server); if (was_nested_output) {
} else if (server->output_mode == CAGE_MULTI_OUTPUT_MODE_LAST && !wl_list_empty(&server->outputs)) { 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); struct cg_output *prev = wl_container_of(server->outputs.next, prev, link);
output_enable(prev); output_enable(prev);
view_position_all(server); 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)) { 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_log(WLR_ERROR, "Cannot load XCursor theme for output '%s' with scale %f", wlr_output->name,
wlr_output->scale); wlr_output->scale);
@ -329,6 +327,24 @@ handle_new_output(struct wl_listener *listener, void *data)
output_layout_add_auto(output); 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); view_position_all(output->server);
update_output_manager_config(output->server); update_output_manager_config(output->server);
} }

View file

@ -18,6 +18,7 @@
enum cg_multi_output_mode { enum cg_multi_output_mode {
CAGE_MULTI_OUTPUT_MODE_EXTEND, CAGE_MULTI_OUTPUT_MODE_EXTEND,
CAGE_MULTI_OUTPUT_MODE_LAST, CAGE_MULTI_OUTPUT_MODE_LAST,
CAGE_MULTI_OUTPUT_MODE_NAMED,
}; };
struct cg_server { struct cg_server {