From d3bf3b017b8129ff772ad9c5658ccdfc826d0e51 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Tue, 26 Jul 2022 10:57:33 +0100 Subject: Fix percentage values on rotated monitors. --- src/main.c | 30 ++++++++++++++++++++++++++---- src/tofi.h | 2 ++ 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index a0725fb..ef0dc48 100644 --- a/src/main.c +++ b/src/main.c @@ -430,7 +430,13 @@ static void output_geometry( const char *model, int32_t transform) { - /* Deliberately left blank */ + struct tofi *tofi = data; + struct output_list_element *el; + wl_list_for_each(el, &tofi->output_list, link) { + if (el->wl_output == wl_output) { + el->transform = transform; + } + } } static void output_mode( @@ -656,7 +662,7 @@ static void usage() "Usage: tofi [options]\n" "\n" " -h, --help Print this message and exit.\n" -" -c, --config Specify a config file.\n" +" -c, --config Specify a config file.\n" " --font Font to use.\n" " --font-size Point size of text.\n" " --background-color Color of the background.\n" @@ -998,9 +1004,25 @@ int main(int argc, char *argv[]) */ struct output_list_element *el; el = wl_container_of(tofi.output_list.next, el, link); - tofi.output_width = el->width; - tofi.output_height = el->height; + + /* + * If we're rotated 90 degrees, we need to swap width and + * height to calculate percentages. + */ + switch (el->transform) { + case WL_OUTPUT_TRANSFORM_90: + case WL_OUTPUT_TRANSFORM_270: + case WL_OUTPUT_TRANSFORM_FLIPPED_90: + case WL_OUTPUT_TRANSFORM_FLIPPED_270: + tofi.output_width = el->height; + tofi.output_height = el->width; + break; + default: + tofi.output_width = el->width; + tofi.output_height = el->height; + } tofi.window.scale = el->scale; + tofi.window.transform = el->transform; log_debug("Selected output %s.\n", el->name); } diff --git a/src/tofi.h b/src/tofi.h index 4ad9f75..deea1a2 100644 --- a/src/tofi.h +++ b/src/tofi.h @@ -18,6 +18,7 @@ struct output_list_element { uint32_t width; uint32_t height; int32_t scale; + int32_t transform; }; struct tofi { @@ -53,6 +54,7 @@ struct tofi { uint32_t width; uint32_t height; uint32_t scale; + int32_t transform; int32_t margin_top; int32_t margin_bottom; int32_t margin_left; -- cgit v1.2.3