From 366d11c3ee1f943fe73cff7f62033ac00b96c2d4 Mon Sep 17 00:00:00 2001 From: "Joscha.Wloch" Date: Mon, 13 May 2024 14:07:15 +0200 Subject: [PATCH] clients: window & keyboard: Be able to set the minimum allocation Function added to be able to set the minimum allocation of the window. Set the minimum allocation of the keyboard window manually. Otherwise, the first call to 'window_schedule_resize' sets 'min_allocation' to the size of the current layout. This means that a layout that requires less space no longer has the chance to use the correct allocation size. Signed-off-by: Joscha.Wloch --- clients/keyboard.c | 5 +++++ clients/window.c | 6 ++++++ clients/window.h | 3 +++ 3 files changed, 14 insertions(+) diff --git a/clients/keyboard.c b/clients/keyboard.c index 3290c2994..0687eebc9 100644 --- a/clients/keyboard.c +++ b/clients/keyboard.c @@ -243,8 +243,12 @@ static const struct layout arabic_layout = { }; #define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define max_count MAX(MAX(sizeof(arabic_keys) / sizeof(*arabic_keys), sizeof(numeric_keys) / sizeof(*numeric_keys) ), sizeof(normal_keys) / sizeof(*normal_keys)) +#define min_columns MIN(MIN(normal_layout.columns, numeric_layout.columns), arabic_layout.columns) +#define min_rows MIN(MIN(normal_layout.rows, numeric_layout.rows), arabic_layout.rows) + static const char *style_labels[] = { "default", "none", @@ -1105,6 +1109,7 @@ keyboard_create(struct virtual_keyboard *virtual_keyboard) window_set_appid(keyboard->window, "org.freedesktop.weston.virtual-keyboard"); window_set_user_data(keyboard->window, keyboard); + window_set_min_allocation(keyboard->window, min_columns * (int32_t)key_width, min_rows * (int32_t)key_height); widget_set_redraw_handler(keyboard->widget, redraw_handler); widget_set_resize_handler(keyboard->widget, resize_handler); diff --git a/clients/window.c b/clients/window.c index 90440c114..d88576856 100644 --- a/clients/window.c +++ b/clients/window.c @@ -4871,6 +4871,12 @@ window_is_resizing(struct window *window) return window->resizing; } +void window_set_min_allocation(struct window *window, int32_t width, int32_t height) +{ + window->min_allocation.width = width; + window->min_allocation.height = height; +} + void window_set_minimized(struct window *window) { diff --git a/clients/window.h b/clients/window.h index 8b3d9d1f3..add6ef601 100644 --- a/clients/window.h +++ b/clients/window.h @@ -481,6 +481,9 @@ window_set_maximized(struct window *window, int maximized); int window_is_resizing(struct window *window); +void +window_set_min_allocation(struct window *window, int32_t width, int32_t height); + void window_set_minimized(struct window *window);