From a4b48b60bf27fd36352e42fa6c1fd3f677b9bb85 Mon Sep 17 00:00:00 2001 From: Paul Breugnot Date: Sat, 17 May 2025 11:34:29 +0200 Subject: [PATCH] :white_check_mark: Fixes fixed size window creation --- src/aswm/event_handlers/create.c | 2 +- src/aswm/mapper/mapper.c | 22 ++++++++++++-------- test/aswm/aswm.c | 4 ++-- test/aswm/create_windows/single_fixed_size.c | 13 +++++++++--- test/aswm_log.conf | 2 +- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/aswm/event_handlers/create.c b/src/aswm/event_handlers/create.c index 586f86e..a9e1628 100644 --- a/src/aswm/event_handlers/create.c +++ b/src/aswm/event_handlers/create.c @@ -17,7 +17,7 @@ void OnCreateNotify(Aswm* aswm, const XCreateWindowEvent* e) { } // The WM must subscribe to property changes, notably to implement the - // Extended Window Manager Hints (EWMH) propocol + // ICCM and Extended Window Manager Hints (EWMH) propocol XSelectInput(aswm->display, e->window, PropertyChangeMask); { diff --git a/src/aswm/mapper/mapper.c b/src/aswm/mapper/mapper.c index 49e69ed..dd84480 100644 --- a/src/aswm/mapper/mapper.c +++ b/src/aswm/mapper/mapper.c @@ -144,6 +144,7 @@ void resize_stack(Display* display, Window stack) { for(auto i = 0; i < children_count; i++) { XWindowAttributes child_attributes; XGetWindowAttributes(display, children[i], &child_attributes); + aswm_notice("Resize stack to %lu - %i %i", children[i], child_attributes.width, child_attributes.height); if(child_attributes.map_state != IsUnmapped) { if(child_attributes.width > width) width = child_attributes.width; @@ -168,13 +169,19 @@ void aswm_stack_window(Display* display, Window stack, Window window_to_map, int XWindowAttributes stack_attributes; XGetWindowAttributes(display, stack, &stack_attributes); - XSetWindowAttributes stacked_attributes; - stack_attributes.width = width; - stack_attributes.height = height; - stack_attributes.win_gravity = CenterGravity; + aswm_notice("Stack window %lu with size %i %i", window_to_map, width, height); + XSetWindowAttributes window_to_stack_attributes; + window_to_stack_attributes.win_gravity = CenterGravity; XChangeWindowAttributes(display, window_to_map, - CWWidth | CWHeight | CWWinGravity, - &stacked_attributes); + CWWinGravity, + &window_to_stack_attributes); + // Resize window to its fixed size before stacking it + XResizeWindow(display, window_to_map, width, height); + + + XWindowAttributes child_attributes; + XGetWindowAttributes(display, window_to_map, &child_attributes); + aswm_notice("Map window %lu with size %i %i", window_to_map, child_attributes.width, child_attributes.height); XReparentWindow(display, window_to_map, stack, (stack_attributes.width - width) / 2, (stack_attributes.height - height) / 2 @@ -251,9 +258,6 @@ void aswm_handle_normal_hints(Display* display, Window stack_root, Window window } } else { if(!aswm_is_resizeable(size)) { - // Resize window to its fixed size before stacking it - XResizeWindow(display, window, size->max_width, size->max_height); - // XMapWindow does not trigger a MapRequest for the current // client, so we need to call aswm_stack_window directly. // aswm_stack_window automatically triggers the appropriate diff --git a/test/aswm/aswm.c b/test/aswm/aswm.c index 7f8fc2b..25e239b 100644 --- a/test/aswm/aswm.c +++ b/test/aswm/aswm.c @@ -17,8 +17,8 @@ int main(void) { set_up_test_logger(); if(check_xephyr_available()) { RUN_TEST(run_aswm); - /*RUN_TEST(create_single_resizeable_top_level_window);*/ - /*RUN_TEST(create_multiple_resizeable_top_level_window);*/ + RUN_TEST(create_single_resizeable_top_level_window); + RUN_TEST(create_multiple_resizeable_top_level_window); RUN_TEST(create_single_fixed_size_top_level_window); } tear_down_test_logger(); diff --git a/test/aswm/create_windows/single_fixed_size.c b/test/aswm/create_windows/single_fixed_size.c index 053e493..2cf1b48 100644 --- a/test/aswm/create_windows/single_fixed_size.c +++ b/test/aswm/create_windows/single_fixed_size.c @@ -9,8 +9,7 @@ void create_single_fixed_size_top_level_window(void) { Window child = XCreateSimpleWindow(test_display, window, 0, 0, 25, 30, 0, CopyFromParent, red(1).pixel); - XMapWindow(test_display, child); - + const int fixed_width = 250; const int fixed_height = 75; { @@ -24,7 +23,16 @@ void create_single_fixed_size_top_level_window(void) { XSetWMNormalHints(test_display, window, normal_size); XFree(normal_size); } + + XMapWindow(test_display, child); XMapWindow(test_display, window); + // Even if we called XMapWindow before XSetWindowAttributes, there is NO + // guarante that the property.h event handler for WM_NORMAL_HINTS will be + // triggered AFTER the map. Indeed, the property event can be handled before + // the WM has actually set event handlers on the mapped window. This is not + // an issue as long as the map request handler handles the initial + // WM_NORMAL_HINTS value. Calling XSetWMNormalHints before XMapWindow should + // however ensure that the current test reproduce this situation. int visibility = wait_visibility(test_display, window); @@ -52,5 +60,4 @@ void create_single_fixed_size_top_level_window(void) { TEST_ASSERT_EQUAL_INT(30, child_attributes.height); TEST_ASSERT_EQUAL_INT(0, child_attributes.border_width); TEST_ASSERT_EQUAL_INT(IsViewable, child_attributes.map_state); - } diff --git a/test/aswm_log.conf b/test/aswm_log.conf index 387235e..db00052 100644 --- a/test/aswm_log.conf +++ b/test/aswm_log.conf @@ -4,4 +4,4 @@ simple = "[%c %p] %d(%m-%d %T) %-5V %-8f:%-3L %m%n" [rules] -aswm.NOTICE >stdout; simple +aswm.DEBUG >stdout; simple