Fix window size test (WM_NORMAL_HINTS handling)

This commit is contained in:
Paul Breugnot 2025-05-17 12:13:02 +02:00
parent a4b48b60bf
commit 24a66e41d1
11 changed files with 96 additions and 15 deletions

View file

@ -144,7 +144,6 @@ 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;

View file

@ -8,11 +8,12 @@ FetchContent_MakeAvailable(unity)
add_compile_definitions(ASWM_TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
add_executable(test_aswm
test_set_up.c
utils.c
aswm/aswm.c
aswm/create_windows.c
aswm/create_windows/single_resizeable.c
aswm/create_windows/multiple_resizeable.c
aswm/create_windows/single_fixed_size.c
aswm/property/fix_size.c
)
target_include_directories(test_aswm PUBLIC ${unity_SOURCE_DIR}/src)
target_link_libraries(test_aswm libaswm unity)

View file

@ -3,6 +3,7 @@
#include "../test_set_up.h"
#include "create_windows.h"
#include "property.h"
void run_aswm(void) {
int stat_loc;
@ -20,6 +21,7 @@ int main(void) {
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);
RUN_TEST(fix_size_of_an_existing_single_top_level_window);
}
tear_down_test_logger();
return UNITY_END();

View file

@ -1,20 +1,9 @@
#ifndef TEST_ASWM_CREATE_WINDOWS
#define TEST_ASWM_CREATE_WINDOWS
#include <time.h>
#include "aswm/aswm.h"
#include "../test_set_up.h"
extern clock_t USER_DELAY;
XColor red(float intensity);
XColor blue(float intensity);
Window parent(Display* display, Window window);
int wait_visibility(Display* display, Window window);
void wait_array_visibility(Display* display, int N, Window* windows, int* visibilities);
void create_single_resizeable_top_level_window(void);
void create_multiple_resizeable_top_level_window(void);
void create_single_fixed_size_top_level_window(void);

View file

@ -1,4 +1,5 @@
#include "../create_windows.h"
#include "../../utils.h"
void create_multiple_resizeable_top_level_window(void) {
const int N = 10;

View file

@ -1,4 +1,5 @@
#include "../create_windows.h"
#include "../../utils.h"
void create_single_fixed_size_top_level_window(void) {
Window window = XCreateSimpleWindow(test_display, test_root,
@ -61,3 +62,4 @@ void create_single_fixed_size_top_level_window(void) {
TEST_ASSERT_EQUAL_INT(0, child_attributes.border_width);
TEST_ASSERT_EQUAL_INT(IsViewable, child_attributes.map_state);
}

View file

@ -1,4 +1,5 @@
#include "../create_windows.h"
#include "../../utils.h"
void create_single_resizeable_top_level_window(void) {
Window window = XCreateSimpleWindow(test_display, test_root,

9
test/aswm/property.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef TEST_ASWM_PROPERTY
#define TEST_ASWM_PROPERTY
#include "aswm/aswm.h"
#include "../test_set_up.h"
void fix_size_of_an_existing_single_top_level_window(void);
#endif

View file

@ -0,0 +1,59 @@
#include "../property.h"
#include "../../utils.h"
void fix_size_of_an_existing_single_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);
XMapWindow(test_display, child);
XMapWindow(test_display, window);
// Ensures the window is mapped before setting WM_NORMAL_HINTS
int visibility = wait_visibility(test_display, window);
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);
}
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);
}

View file

@ -1,8 +1,10 @@
#include "create_windows.h"
#include "utils.h"
#include "test_set_up.h"
#define MAX_COLOR 65535
clock_t USER_DELAY = 1 * CLOCKS_PER_SEC;
const time_t USER_DELAY_S = 1;
const clock_t USER_DELAY = USER_DELAY_S * CLOCKS_PER_SEC;
XColor red(float intensity) {
XColor red;

16
test/utils.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef TEST_UTILS
#define TEST_UTILS
#include <time.h>
#include <X11/Xlib.h>
extern const clock_t USER_DELAY;
XColor red(float intensity);
XColor blue(float intensity);
Window parent(Display* display, Window window);
int wait_visibility(Display* display, Window window);
void wait_array_visibility(Display* display, int N, Window* windows, int* visibilities);
#endif