diff --git a/cage.1.scd b/cage.1.scd index 4ca1bea..c541e4f 100644 --- a/cage.1.scd +++ b/cage.1.scd @@ -27,6 +27,11 @@ activities outside the scope of the running application are prevented. *last* Cage uses only the last connected monitor. *extend* Cage extends the display across all connected monitors. +*-e* + Set the monitor addition mode, if display is extended across all connected monitors. + *auto* Cage places monitors automatically. + *right* Cage places each newly-connected monitor on the right of the rightmost connected monitor. + *-r* Rotate the output 90 degrees clockwise. This can be specified up to three times, each resulting in an additional 90 degrees clockwise rotation. diff --git a/cage.c b/cage.c index 95f0cc7..41f8d62 100644 --- a/cage.c +++ b/cage.c @@ -192,6 +192,8 @@ 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" + " -e auto Automatically place newly connected outputs (default)\n" + " -e right Place newly connected outputs on the right\n" " -r\t Rotate the output 90 degrees clockwise, specify up to three times\n" " -s\t Allow VT switching\n" " -v\t Show the version number and exit\n" @@ -204,7 +206,7 @@ static bool parse_args(struct cg_server *server, int argc, char *argv[]) { int c; - while ((c = getopt(argc, argv, "dhm:rsv")) != -1) { + while ((c = getopt(argc, argv, "dhm:e:rsv")) != -1) { switch (c) { case 'd': server->xdg_decoration = true; @@ -219,6 +221,13 @@ parse_args(struct cg_server *server, int argc, char *argv[]) server->output_mode = CAGE_MULTI_OUTPUT_MODE_EXTEND; } break; + case 'e': + if (strcmp(optarg, "right") == 0) { + server->output_extend_mode = CAGE_OUTPUT_EXTEND_MODE_RIGHT; + } else if (strcmp(optarg, "auto") == 0) { + server->output_extend_mode = CAGE_OUTPUT_EXTEND_MODE_AUTO; + } + break; case 'r': server->output_transform++; if (server->output_transform > WL_OUTPUT_TRANSFORM_270) { diff --git a/output.c b/output.c index 0577c0d..57e0863 100644 --- a/output.c +++ b/output.c @@ -52,7 +52,23 @@ output_enable(struct cg_output *output) * duplicate the enabled property in cg_output. */ wlr_log(WLR_DEBUG, "Enabling output %s", wlr_output->name); - wlr_output_layout_add_auto(output->server->output_layout, wlr_output); + if (output->server->output_extend_mode == CAGE_OUTPUT_EXTEND_MODE_RIGHT) { + int max_x = 0, max_x_y = 0; + struct wlr_output_layout_output *l_output; + wl_list_for_each (l_output, &output->server->output_layout->outputs, link) { + int width, height; + wlr_output_effective_resolution(l_output->output, &width, &height); + if (l_output->x + width > max_x) { + max_x = l_output->x + width; + max_x_y = l_output->y; + } + } + + wlr_output_layout_add(output->server->output_layout, wlr_output, max_x, max_x_y); + } else { + wlr_output_layout_add_auto(output->server->output_layout, wlr_output); + } + wlr_output_enable(wlr_output, true); wlr_output_commit(wlr_output); diff --git a/server.h b/server.h index bb7f3c1..0d6f6ab 100644 --- a/server.h +++ b/server.h @@ -21,6 +21,11 @@ enum cg_multi_output_mode { CAGE_MULTI_OUTPUT_MODE_LAST, }; +enum cg_output_extend_mode { + CAGE_OUTPUT_EXTEND_MODE_AUTO, + CAGE_OUTPUT_EXTEND_MODE_RIGHT, +}; + struct cg_server { struct wl_display *wl_display; struct wl_list views; @@ -35,6 +40,7 @@ struct cg_server { struct wl_list inhibitors; enum cg_multi_output_mode output_mode; + enum cg_output_extend_mode output_extend_mode; struct wlr_output_layout *output_layout; struct wlr_scene *scene; /* Includes disabled outputs; depending on the output_mode