make the Cage multi-monitor layout configurable

This commit is contained in:
Dima Krasner 2021-12-22 08:38:26 +02:00
parent 3321daef98
commit ad0872e33e
4 changed files with 38 additions and 2 deletions

View file

@ -27,6 +27,11 @@ activities outside the scope of the running application are prevented.
*last* Cage uses only the last connected monitor. *last* Cage uses only the last connected monitor.
*extend* Cage extends the display across all connected monitors. *extend* Cage extends the display across all connected monitors.
*-e* <mode>
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* *-r*
Rotate the output 90 degrees clockwise. This can be specified up to three Rotate the output 90 degrees clockwise. This can be specified up to three
times, each resulting in an additional 90 degrees clockwise rotation. times, each resulting in an additional 90 degrees clockwise rotation.

11
cage.c
View file

@ -192,6 +192,8 @@ 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"
" -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" " -r\t Rotate the output 90 degrees clockwise, specify up to three times\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"
@ -204,7 +206,7 @@ static bool
parse_args(struct cg_server *server, int argc, char *argv[]) parse_args(struct cg_server *server, int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "dhm:rsv")) != -1) { while ((c = getopt(argc, argv, "dhm:e:rsv")) != -1) {
switch (c) { switch (c) {
case 'd': case 'd':
server->xdg_decoration = true; 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; server->output_mode = CAGE_MULTI_OUTPUT_MODE_EXTEND;
} }
break; 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': case 'r':
server->output_transform++; server->output_transform++;
if (server->output_transform > WL_OUTPUT_TRANSFORM_270) { if (server->output_transform > WL_OUTPUT_TRANSFORM_270) {

View file

@ -52,7 +52,23 @@ output_enable(struct cg_output *output)
* duplicate the enabled property in cg_output. */ * duplicate the enabled property in cg_output. */
wlr_log(WLR_DEBUG, "Enabling output %s", wlr_output->name); wlr_log(WLR_DEBUG, "Enabling output %s", wlr_output->name);
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_layout_add_auto(output->server->output_layout, wlr_output);
}
wlr_output_enable(wlr_output, true); wlr_output_enable(wlr_output, true);
wlr_output_commit(wlr_output); wlr_output_commit(wlr_output);

View file

@ -21,6 +21,11 @@ enum cg_multi_output_mode {
CAGE_MULTI_OUTPUT_MODE_LAST, CAGE_MULTI_OUTPUT_MODE_LAST,
}; };
enum cg_output_extend_mode {
CAGE_OUTPUT_EXTEND_MODE_AUTO,
CAGE_OUTPUT_EXTEND_MODE_RIGHT,
};
struct cg_server { struct cg_server {
struct wl_display *wl_display; struct wl_display *wl_display;
struct wl_list views; struct wl_list views;
@ -35,6 +40,7 @@ struct cg_server {
struct wl_list inhibitors; struct wl_list inhibitors;
enum cg_multi_output_mode output_mode; enum cg_multi_output_mode output_mode;
enum cg_output_extend_mode output_extend_mode;
struct wlr_output_layout *output_layout; struct wlr_output_layout *output_layout;
struct wlr_scene *scene; struct wlr_scene *scene;
/* Includes disabled outputs; depending on the output_mode /* Includes disabled outputs; depending on the output_mode