From fb0e2df285e7f4d070aa88b7c81eba28c6b63f26 Mon Sep 17 00:00:00 2001 From: Joseph <119084558+DerjenigeUberMensch@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:47:18 +0800 Subject: [PATCH] Added more tests, fixed multi test compiling --- tests/centerpixel.c | 8 ----- tests/helper.h | 25 +++++++++----- tests/restack.c | 79 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 16 deletions(-) create mode 100644 tests/restack.c diff --git a/tests/centerpixel.c b/tests/centerpixel.c index f8162ff..687bb45 100644 --- a/tests/centerpixel.c +++ b/tests/centerpixel.c @@ -1,15 +1,7 @@ - - #include #include #include "helper.h" - - - - - - int jnzjmp(void) { diff --git a/tests/helper.h b/tests/helper.h index 7038df5..dc81436 100644 --- a/tests/helper.h +++ b/tests/helper.h @@ -4,15 +4,16 @@ #include #include #include +#include #include -Display *dpy; -int screen; -int sw; -int sh; -Window win; -Window root; +static Display *dpy; +static int screen; +static int sw; +static int sh; +static Window win; +static Window root; static void __test__start_basic(void) @@ -29,14 +30,22 @@ __test__start_basic(void) root = DefaultRootWindow(dpy); + srand(time(NULL)); +} +static Window +__Create_Window(unsigned int color, int bw, int bwcolor) +{ XSetWindowAttributes wa = { .bit_gravity = NorthWestGravity, ///NorthWestGravity, .backing_store = WhenMapped, + .border_pixel = bwcolor, + .background_pixel = color }; - unsigned int mask = CWBitGravity|CWBackingStore; - win = XCreateWindow(dpy, root, 0, 0, sw, sh, 0, DefaultDepth(dpy, screen), InputOutput, 0, mask, &wa); + unsigned long int mask = CWBitGravity|CWBackingStore|CWBorderPixel|CWBorderWidth|CWBackPixel; + win = XCreateWindow(dpy, root, 0, 0, sw, sh, bw, DefaultDepth(dpy, screen), InputOutput, 0, mask, &wa); XMapWindow(dpy, win); + return win; } diff --git a/tests/restack.c b/tests/restack.c new file mode 100644 index 0000000..2f54453 --- /dev/null +++ b/tests/restack.c @@ -0,0 +1,79 @@ +#include "helper.h" + +#include + + +int +jzjmp(void) +{ + __test__start_basic(); + Atom wtype = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); + Atom wstate = XInternAtom(dpy, "_NET_WM_STATE", False); + + Atom above = XInternAtom(dpy, "_NET_WM_STATE_ABOVE", False); + Atom modal = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_MODAL", False); + Atom dialog= XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); + Atom dock = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False); + Atom below = XInternAtom(dpy, "_NET_WM_STATE_BELOW", False); + __test__start_basic(); + + + const int win_count = 5; + Window wins[win_count]; + + + unsigned int red = 255; + unsigned int blue = 255 << 8; + unsigned int green = 255 << 16; + + + unsigned int color = 0; + int i; + for(i = 0; i < win_count; ++i) + { + switch(i % 3) + { + case 0: + color ^= red * rand(); + case 1: + color ^= blue * rand(); + case 2: + color ^= green * rand(); + default: + color ^= rand(); + while(color == UINT32_MAX || color == 0) + { color ^= 255 * rand(); + } + break; + } + Atom atom; + Atom state; + wins[i] = __Create_Window(color, 0, 0); + if((color & red) % 255 > 150) + { + atom = above; + state = wstate; + } + else if((color & blue) % 255 > 100) + { + atom = dock; + state = wtype; + } + else if((color & green) % 255 > 50) + { + atom = below; + state = wstate; + } + else + { + atom = above; + state = wstate; + } + XChangeProperty(dpy, wins[i], state, XA_ATOM, 32, PropModeReplace, (const unsigned char *)&atom, 1); + } + + XEvent ev; + while(!XNextEvent(dpy, &ev)); + + return 0; +}