From 9f4cb3c7914b9ac089b6454851fff4f2fcd3bec1 Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Fri, 9 Oct 2020 16:26:10 +0200 Subject: [PATCH] eek-gtk-keyboard: use virtual resolution to check arrangement kind Using the actual monitor width in pixels can lead to unsatisfying results, depending on the display orientation and physical size: on a 10" tablet with a 1280x800 resolution (scale 1), portrait orientation will be using the narrow layout. If the keyboard is sized in an optimal way (i.e. so the layout fills the whole area, with no blanks on the sides) this would result in an unnecessarily huge keyboard being displayed, therefore wasting screen estate. Using the virtual display size gives a hint about the physical size of the device, and can be used to select wide layouts even in portrait mode, while still preserving current behavior on HiDPI devices. This has been tested on PineTab, PinePhone and Librem 5. --- eek/eek-gtk-keyboard.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/eek/eek-gtk-keyboard.c b/eek/eek-gtk-keyboard.c index 3a477668..cdf0571d 100644 --- a/eek/eek-gtk-keyboard.c +++ b/eek/eek-gtk-keyboard.c @@ -104,10 +104,10 @@ eek_gtk_keyboard_real_draw (GtkWidget *self, return FALSE; } -// Units of pixel size +// Units of virtual pixels size static enum squeek_arrangement_kind get_type(uint32_t width, uint32_t height) { (void)height; - if (width < 1080) { + if (width < 540) { return ARRANGEMENT_KIND_BASE; } return ARRANGEMENT_KIND_WIDE; @@ -119,11 +119,10 @@ eek_gtk_keyboard_real_size_allocate (GtkWidget *self, { EekGtkKeyboardPrivate *priv = eek_gtk_keyboard_get_instance_private (EEK_GTK_KEYBOARD (self)); - uint32_t scale = (uint32_t)gtk_widget_get_scale_factor(self); // check if the change would switch types enum squeek_arrangement_kind new_type = get_type( - (uint32_t)(allocation->width - allocation->x) * scale, - (uint32_t)(allocation->height - allocation->y) * scale); + (uint32_t)(allocation->width - allocation->x), + (uint32_t)(allocation->height - allocation->y)); if (priv->layout->arrangement != new_type) { priv->layout->arrangement = new_type; uint32_t time = gdk_event_get_time(NULL);