From 9e6a5ad44fb6e548251fa510fad6b52ba0767d71 Mon Sep 17 00:00:00 2001 From: Tristan Daniel Date: Sun, 14 Apr 2019 01:50:12 +0200 Subject: [PATCH] Cage: implement output transform This commit adds the command line switch -r, which rotates the output 90 degrees clockwise and can be specified up to three times. --- cage.c | 11 +++++++++-- output.c | 10 ++++++---- seat.c | 4 ++++ server.h | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cage.c b/cage.c index 5f537d4..8e1d2e6 100644 --- a/cage.c +++ b/cage.c @@ -87,6 +87,7 @@ usage(FILE *file, const char *cage) fprintf(file, "Usage: %s [OPTIONS] [--] APPLICATION\n" "\n" " -d\t Don't draw client side decorations, when possible\n" + " -r\t Rotate the output 90 degrees clockwise, specify up to three times\n" #ifdef DEBUG " -D\t Turn on damage tracking debugging\n" #endif @@ -101,14 +102,20 @@ parse_args(struct cg_server *server, int argc, char *argv[]) { int c; #ifdef DEBUG - while ((c = getopt(argc, argv, "dDh")) != -1) { + while ((c = getopt(argc, argv, "drDh")) != -1) { #else - while ((c = getopt(argc, argv, "dh")) != -1) { + while ((c = getopt(argc, argv, "drh")) != -1) { #endif switch (c) { case 'd': server->xdg_decoration = true; break; + case 'r': + server->output_transform++; + if (server->output_transform > WL_OUTPUT_TRANSFORM_270) { + server->output_transform = WL_OUTPUT_TRANSFORM_NORMAL; + } + break; #ifdef DEBUG case 'D': server->debug_damage_tracking = true; diff --git a/output.c b/output.c index 3bb7e71..b35fe7b 100644 --- a/output.c +++ b/output.c @@ -211,10 +211,7 @@ handle_output_damage_frame(struct wl_listener *listener, void *data) goto damage_finish; } - int output_width, output_height; - wlr_output_transformed_resolution(output->wlr_output, &output_width, &output_height); - - wlr_renderer_begin(renderer, output_width, output_height); + wlr_renderer_begin(renderer, output->wlr_output->width, output->wlr_output->height); if (!pixman_region32_not_empty(&damage)) { wlr_log(WLR_DEBUG, "Output isn't damaged but needs a buffer swap"); @@ -258,6 +255,9 @@ handle_output_damage_frame(struct wl_listener *listener, void *data) wlr_renderer_scissor(renderer, NULL); wlr_renderer_end(renderer); + int output_width, output_height; + wlr_output_transformed_resolution(output->wlr_output, &output_width, &output_height); + #ifdef DEBUG if (output->server->debug_damage_tracking) { pixman_region32_union_rect(&damage, &damage, 0, 0, output_width, output_height); @@ -366,6 +366,8 @@ handle_new_output(struct wl_listener *listener, void *data) server->output->damage_destroy.notify = handle_output_damage_destroy; wl_signal_add(&server->output->damage->events.destroy, &server->output->damage_destroy); + wlr_output_set_transform(wlr_output, server->output_transform); + wlr_output_layout_add_auto(server->output_layout, wlr_output); /* Disconnect the signal now, because we only use one static output. */ diff --git a/seat.c b/seat.c index 2494ab4..f3731da 100644 --- a/seat.c +++ b/seat.c @@ -157,6 +157,8 @@ handle_new_touch(struct cg_seat *seat, struct wlr_input_device *device) wl_list_insert(&seat->touch, &touch->link); touch->destroy.notify = handle_touch_destroy; wl_signal_add(&touch->device->events.destroy, &touch->destroy); + + wlr_cursor_map_input_to_output(seat->cursor, device, seat->server->output->wlr_output); } static void @@ -189,6 +191,8 @@ handle_new_pointer(struct cg_seat *seat, struct wlr_input_device *device) wl_list_insert(&seat->pointers, &pointer->link); pointer->destroy.notify = handle_pointer_destroy; wl_signal_add(&device->events.destroy, &pointer->destroy); + + wlr_cursor_map_input_to_output(seat->cursor, device, seat->server->output->wlr_output); } static void diff --git a/server.h b/server.h index 213fe09..80e9951 100644 --- a/server.h +++ b/server.h @@ -39,6 +39,7 @@ struct cg_server { #endif bool xdg_decoration; + enum wl_output_transform output_transform; #ifdef DEBUG bool debug_damage_tracking; #endif