From f540cf36fa7173097efa588ee99a7ace69a002a4 Mon Sep 17 00:00:00 2001 From: ArenM Date: Mon, 4 Jul 2022 23:46:18 -0400 Subject: [PATCH] Use output dimensions to detect landscape mode Most displays are in landscape mode by default, so checking to see if it's rotated will produce the exact opposite of the expected results. Signed-off-by: Maarten van Gompel --- main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index 89623cf..dc964e7 100644 --- a/main.c +++ b/main.c @@ -251,21 +251,24 @@ static void display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y, int physical_width, int physical_height, int subpixel, const char *make, const char *model, int transform) { - if (transform % 2 == 0 && keyboard.landscape) { - keyboard.landscape = false; - height = normal_height; - } else if (transform % 2 != 0 && !keyboard.landscape) { - keyboard.landscape = true; - height = landscape_height; - } else { - return; // no changes + // Swap width and height on rotated displays + if (transform % 2 != 0) { + int tmp = physical_width; + physical_width = physical_height; + physical_height = tmp; } + bool landscape = physical_width > physical_height; + if (landscape == keyboard.landscape) return; + keyboard.landscape = landscape; + enum layout_id layer; if (keyboard.landscape) { layer = keyboard.landscape_layers[0]; + height = landscape_height; } else { layer = keyboard.layers[0]; + height = normal_height; } keyboard.layout = &keyboard.layouts[layer];