aswm/test/aswm/create_windows/single_fixed_size.c
2025-05-17 12:14:31 +02:00

65 lines
2.6 KiB
C

#include "../create_windows.h"
#include "../../utils.h"
void create_single_fixed_size_top_level_window(void) {
Window window = XCreateSimpleWindow(test_display, test_root,
10 /*x*/, 10 /*y*/, 128 /*w*/, 128 /*h*/,
0 /*TODO: border width*/, CopyFromParent /*depth*/, blue(1).pixel /* background */);
// The top level window might have children. Those must **not** be altered
// by the Window Manager
Window child = XCreateSimpleWindow(test_display, window,
0, 0, 25, 30,
0, CopyFromParent, red(1).pixel);
const int fixed_width = 250;
const int fixed_height = 75;
{
XSizeHints* normal_size = XAllocSizeHints();
normal_size->flags = PMinSize | PMaxSize;
normal_size->min_width = fixed_width;
normal_size->max_width = fixed_width;
normal_size->min_height = fixed_height;
normal_size->max_height = fixed_height;
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);
// The top level window if fully visible
XWindowAttributes attributes;
XGetWindowAttributes(test_display, window, &attributes);
TEST_ASSERT_EQUAL_INT(VisibilityUnobscured, visibility);
TEST_ASSERT_EQUAL_INT(IsViewable, attributes.map_state);
// The top level window has its size preserved
XWindowAttributes window_attributes;
XGetWindowAttributes(test_display, window, &window_attributes);
TEST_ASSERT_EQUAL_INT(fixed_width, window_attributes.width);
TEST_ASSERT_EQUAL_INT(fixed_height, window_attributes.height);
// Check the child structure is unaltered
TEST_ASSERT_EQUAL(parent(test_display, child), window);
XWindowAttributes child_attributes;
XGetWindowAttributes(test_display, child, &child_attributes);
TEST_ASSERT_EQUAL_INT(0, child_attributes.x);
TEST_ASSERT_EQUAL_INT(0, child_attributes.y);
TEST_ASSERT_EQUAL_INT(25, child_attributes.width);
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);
}