From 1f11ad113d88457059a44431dea635e50f7a13d6 Mon Sep 17 00:00:00 2001 From: Jente Hidskes Date: Sun, 31 May 2020 16:04:01 +0200 Subject: [PATCH] output: implement CAGE_MULTI_OUTPUT_MODE_LAST In this mode, only the last connected output will be used. If that one is unplugged, the previously last connected output will be enabled. This for example allows one to switch between two outputs, e.g. on a handheld device such as a mobile phone. --- output.c | 21 ++++++++++++++++----- server.h | 4 +++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/output.c b/output.c index 97f02d6..d6e34aa 100644 --- a/output.c +++ b/output.c @@ -404,15 +404,20 @@ output_destroy(struct cg_output *output) wlr_output_layout_remove(server->output_layout, output->wlr_output); - struct cg_view *view; - wl_list_for_each (view, &output->server->views, link) { - view_position(view); - } - free(output); if (wl_list_empty(&server->outputs)) { wl_display_terminate(server->wl_display); + } else if (server->output_mode == CAGE_MULTI_OUTPUT_MODE_LAST) { + struct cg_output *prev = wl_container_of(server->outputs.next, prev, link); + if (prev) { + output_enable(prev); + + struct cg_view *view; + wl_list_for_each (view, &server->views, link) { + view_position(view); + } + } } } @@ -465,6 +470,12 @@ handle_new_output(struct wl_listener *listener, void *data) } wlr_output_set_transform(wlr_output, output->server->output_transform); + if (server->output_mode == CAGE_MULTI_OUTPUT_MODE_LAST) { + struct cg_output *next = wl_container_of(output->link.next, next, link); + if (next) { + 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, diff --git a/server.h b/server.h index 401dd55..1469802 100644 --- a/server.h +++ b/server.h @@ -33,7 +33,9 @@ struct cg_server { enum cg_multi_output_mode output_mode; struct wlr_output_layout *output_layout; - struct wl_list outputs; + /* Includes disabled outputs; depending on the output_mode + * some outputs may be disabled. */ + struct wl_list outputs; // cg_output::link struct wl_listener new_output; struct wl_listener xdg_toplevel_decoration;