This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository enlightenment.
View the commit online.
commit e25b2c3cacacc8f4d15e3403e6988122de224d86
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Nov 18 17:17:31 2026 -0600
tests - resize a client-side-decorated window on X11
GTK resizes its client-side-decorated windows the way it moves them:
with _NET_WM_MOVERESIZE, here from the bottom-right corner and from the
top-left one. The dragged corner has to follow the pointer and the
opposite one stay put, on one head and on two.
The move and resize tests now share their helpers in x11_testkit.h.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/tests/x11/meson.build | 30 ++++----
src/tests/x11/test_csd_move.c | 143 ++++++------------------------------
src/tests/x11/test_csd_resize.c | 73 +++++++++++++++++++
src/tests/x11/x11_testkit.h | 156 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 268 insertions(+), 134 deletions(-)
diff --git a/src/tests/x11/meson.build b/src/tests/x11/meson.build
index 0df6a613c..5b4b19ecf 100644
--- a/src/tests/x11/meson.build
+++ b/src/tests/x11/meson.build
@@ -15,20 +15,26 @@ if dep_x11.found() and dep_xtst.found()
x11_test_env = environment()
x11_test_env.set('E_TEST_COMPOSITOR', e_test_compositor)
- test_csd_move = executable('test_x11_csd_move', 'test_csd_move.c',
- dependencies: [dep_x11, dep_xtst])
+ x11_tests = [
+ ['x11-csd-move', executable('test_x11_csd_move', 'test_csd_move.c',
+ dependencies: [dep_x11, dep_xtst])],
+ ['x11-csd-resize', executable('test_x11_csd_resize', 'test_csd_resize.c',
+ dependencies: [dep_x11, dep_xtst])],
+ ]
# Two heads as well: a window on the right-hand screen is far from 0,0,
# which is where a drag that lost its starting point puts it.
- foreach heads: ['1', '2']
- env = x11_test_env
- env.set('E_TEST_HEADS', heads)
- test(heads == '1' ? 'x11-csd-move' : 'x11-csd-move-2heads',
- files('run-x11.sh'),
- args: [test_csd_move],
- env: env,
- suite: 'x11',
- timeout: 120,
- )
+ foreach t: x11_tests
+ foreach heads: ['1', '2']
+ env = x11_test_env
+ env.set('E_TEST_HEADS', heads)
+ test(heads == '1' ? t[0] : t[0] + '-2heads',
+ files('run-x11.sh'),
+ args: [t[1]],
+ env: env,
+ suite: 'x11',
+ timeout: 120,
+ )
+ endforeach
endforeach
endif
diff --git a/src/tests/x11/test_csd_move.c b/src/tests/x11/test_csd_move.c
index 064f29745..0fffd33ff 100644
--- a/src/tests/x11/test_csd_move.c
+++ b/src/tests/x11/test_csd_move.c
@@ -1,147 +1,46 @@
/* Move a client-side-decorated window with _NET_WM_MOVERESIZE, the way GTK
* starts a drag from its header bar. E records where the drag starts from
- * the message itself, then runs window_move with no mouse event: the window
- * must follow the pointer by how far the pointer travelled. */
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/extensions/XTest.h>
+ * the message itself: the window must follow the pointer by how far the
+ * pointer travelled. */
+#include "x11_testkit.h"
#define W 300
#define H 200
#define DX 60
#define DY 40
-#define STEPS 10
-
-/* _NET_WM_MOVERESIZE in the EWMH spec */
-#define NET_WM_MOVERESIZE_MOVE 8
-#define NET_WM_SOURCE_APPLICATION 1
-
-static void
-fail(const char *fmt, ...)
-{
- va_list ap;
-
- fprintf(stderr, "test-x11-csd-move: FAIL: ");
- va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
- va_end(ap);
- fputc('\n', stderr);
- exit(1);
-}
-
-static void
-root_pos_get(Display *dpy, Window win, int *x, int *y)
-{
- Window child;
-
- XSync(dpy, False);
- XTranslateCoordinates(dpy, win, DefaultRootWindow(dpy), 0, 0, x, y, &child);
-}
-
-static void
-settle(Display *dpy)
-{
- XSync(dpy, False);
- usleep(300 * 1000);
-}
-
-static void
-pointer_move_to(Display *dpy, int x, int y)
-{
- XTestFakeMotionEvent(dpy, DefaultScreen(dpy), x, y, CurrentTime);
- XSync(dpy, False);
- usleep(50 * 1000);
-}
-
-static void
-moveresize_send(Display *dpy, Window win, int x, int y, int button)
-{
- XEvent ev;
-
- memset(&ev, 0, sizeof(ev));
- ev.xclient.type = ClientMessage;
- ev.xclient.window = win;
- ev.xclient.message_type = XInternAtom(dpy, "_NET_WM_MOVERESIZE", False);
- ev.xclient.format = 32;
- ev.xclient.data.l[0] = x;
- ev.xclient.data.l[1] = y;
- ev.xclient.data.l[2] = NET_WM_MOVERESIZE_MOVE;
- ev.xclient.data.l[3] = button;
- ev.xclient.data.l[4] = NET_WM_SOURCE_APPLICATION;
- XSendEvent(dpy, DefaultRootWindow(dpy), False,
- SubstructureRedirectMask | SubstructureNotifyMask, &ev);
-}
int
main(void)
{
Display *dpy;
Window win;
- XSizeHints *hints;
- XEvent ev;
- Atom motif;
- /* _MOTIF_WM_HINTS: flags = decorations, decorations = none */
- long mwm[5] = { 2, 0, 0, 0, 0 };
- int x0, y0, x1, y1, px, py, i;
+ int x0, y0, x1, y1, px, py;
- dpy = XOpenDisplay(NULL);
- if (!dpy) fail("cannot open the display");
+ dpy = xtk_connect("test-x11-csd-move");
/* Bottom right, which is the right-hand screen with two heads: a drag
* that loses its starting point falls back to 0,0 and has to show. */
- x0 = DisplayWidth(dpy, DefaultScreen(dpy)) - W - 150;
- y0 = DisplayHeight(dpy, DefaultScreen(dpy)) - H - 150;
- win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), x0, y0, W, H, 0,
- 0, 0xffffff);
- hints = XAllocSizeHints();
- hints->flags = USPosition | PPosition;
- hints->x = x0;
- hints->y = y0;
- XSetWMNormalHints(dpy, win, hints);
- XFree(hints);
- XStoreName(dpy, win, "csd move under test");
+ win = xtk_csd_window_new(dpy,
+ DisplayWidth(dpy, DefaultScreen(dpy)) - W - 150,
+ DisplayHeight(dpy, DefaultScreen(dpy)) - H - 150,
+ W, H, "csd move under test");
+ xtk_geometry_get(dpy, win, &x0, &y0, NULL, NULL);
- motif = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
- XChangeProperty(dpy, win, motif, motif, 32, PropModeReplace,
- (unsigned char *)mwm, 5);
-
- XSelectInput(dpy, win, StructureNotifyMask);
- XMapWindow(dpy, win);
- do XNextEvent(dpy, &ev); while (ev.type != MapNotify);
- settle(dpy);
- root_pos_get(dpy, win, &x0, &y0);
-
- /* A press on the header bar; the client then gives up the implicit
- * grab and hands the drag to the window manager. */
+ /* On the header bar. */
px = x0 + (W / 2);
py = y0 + 10;
- pointer_move_to(dpy, px, py);
- settle(dpy);
- XTestFakeButtonEvent(dpy, 1, True, CurrentTime);
- XSync(dpy, False);
- XUngrabPointer(dpy, CurrentTime);
- moveresize_send(dpy, win, px, py, 1);
- settle(dpy);
-
- for (i = 1; i <= STEPS; i++)
- pointer_move_to(dpy, px + (i * DX / STEPS), py + (i * DY / STEPS));
- settle(dpy);
-
- /* E moves only the composited frame during the drag; the X window
- * follows when the button is released. */
- XTestFakeButtonEvent(dpy, 1, False, CurrentTime);
- settle(dpy);
- root_pos_get(dpy, win, &x1, &y1);
+ xtk_pointer_move_to(dpy, px, py);
+ xtk_settle(dpy);
+ xtk_csd_drag_begin(dpy, win, px, py, NET_WM_MOVERESIZE_MOVE);
+ xtk_pointer_drag(dpy, px, py, DX, DY);
+ xtk_settle(dpy);
+ xtk_csd_drag_end(dpy);
+ xtk_geometry_get(dpy, win, &x1, &y1, NULL, NULL);
if ((x1 != x0 + DX) || (y1 != y0 + DY))
- fail("a %d,%d drag from the header bar moved the window from +%d+%d "
- "to +%d+%d, expected +%d+%d", DX, DY, x0, y0, x1, y1,
- x0 + DX, y0 + DY);
+ xtk_fail("a %d,%d drag from the header bar moved the window from "
+ "+%d+%d to +%d+%d, expected +%d+%d", DX, DY, x0, y0, x1, y1,
+ x0 + DX, y0 + DY);
printf("test-x11-csd-move: ok (+%d+%d -> +%d+%d)\n", x0, y0, x1, y1);
XCloseDisplay(dpy);
diff --git a/src/tests/x11/test_csd_resize.c b/src/tests/x11/test_csd_resize.c
new file mode 100644
index 000000000..30c6e6721
--- /dev/null
+++ b/src/tests/x11/test_csd_resize.c
@@ -0,0 +1,73 @@
+/* Resize a client-side-decorated window with _NET_WM_MOVERESIZE, the way
+ * GTK starts a resize from the shadow around its window, from the
+ * bottom-right corner and from the top-left one. The dragged corner must
+ * follow the pointer and the opposite corner must stay where it was. */
+#include "x11_testkit.h"
+
+#define W 300
+#define H 200
+#define DX 60
+#define DY 40
+
+static void
+corner_drag(Display *dpy, Window win, int direction, const char *corner)
+{
+ int x0, y0, w0, h0, x1, y1, w1, h1, px, py, ex, ey, ew, eh;
+
+ xtk_geometry_get(dpy, win, &x0, &y0, &w0, &h0);
+ if (direction == NET_WM_MOVERESIZE_SIZE_TOPLEFT)
+ {
+ px = x0 + 2;
+ py = y0 + 2;
+ ex = x0 + DX;
+ ey = y0 + DY;
+ ew = w0 - DX;
+ eh = h0 - DY;
+ }
+ else
+ {
+ px = x0 + w0 - 2;
+ py = y0 + h0 - 2;
+ ex = x0;
+ ey = y0;
+ ew = w0 + DX;
+ eh = h0 + DY;
+ }
+
+ xtk_pointer_move_to(dpy, px, py);
+ xtk_settle(dpy);
+ xtk_csd_drag_begin(dpy, win, px, py, direction);
+ xtk_pointer_drag(dpy, px, py, DX, DY);
+ xtk_settle(dpy);
+ xtk_csd_drag_end(dpy);
+ xtk_geometry_get(dpy, win, &x1, &y1, &w1, &h1);
+
+ if ((x1 != ex) || (y1 != ey) || (w1 != ew) || (h1 != eh))
+ xtk_fail("a %d,%d drag of the %s corner made %dx%d+%d+%d into "
+ "%dx%d+%d+%d, expected %dx%d+%d+%d", DX, DY, corner,
+ w0, h0, x0, y0, w1, h1, x1, y1, ew, eh, ex, ey);
+ printf("test-x11-csd-resize: %s ok (%dx%d+%d+%d -> %dx%d+%d+%d)\n",
+ corner, w0, h0, x0, y0, w1, h1, x1, y1);
+}
+
+int
+main(void)
+{
+ Display *dpy;
+ Window win;
+
+ dpy = xtk_connect("test-x11-csd-resize");
+
+ /* Bottom right, which is the right-hand screen with two heads: a drag
+ * that loses its starting point falls back to 0,0 and has to show. */
+ win = xtk_csd_window_new(dpy,
+ DisplayWidth(dpy, DefaultScreen(dpy)) - W - 200,
+ DisplayHeight(dpy, DefaultScreen(dpy)) - H - 200,
+ W, H, "csd resize under test");
+
+ corner_drag(dpy, win, NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT, "bottom-right");
+ corner_drag(dpy, win, NET_WM_MOVERESIZE_SIZE_TOPLEFT, "top-left");
+
+ XCloseDisplay(dpy);
+ return 0;
+}
diff --git a/src/tests/x11/x11_testkit.h b/src/tests/x11/x11_testkit.h
new file mode 100644
index 000000000..fd7c97255
--- /dev/null
+++ b/src/tests/x11/x11_testkit.h
@@ -0,0 +1,156 @@
+/* Helpers shared by the X11 tests: each test is a single program, so these
+ * are static and live in the header. */
+#ifndef X11_TESTKIT_H
+#define X11_TESTKIT_H
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/XTest.h>
+
+/* _NET_WM_MOVERESIZE directions and source, from the EWMH spec */
+#define NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
+#define NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
+#define NET_WM_MOVERESIZE_MOVE 8
+#define NET_WM_SOURCE_APPLICATION 1
+
+static const char *xtk_name = "x11-test";
+
+static void
+xtk_fail(const char *fmt, ...)
+{
+ va_list ap;
+
+ fprintf(stderr, "%s: FAIL: ", xtk_name);
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ fputc('\n', stderr);
+ exit(1);
+}
+
+static Display *
+xtk_connect(const char *name)
+{
+ Display *dpy;
+
+ xtk_name = name;
+ dpy = XOpenDisplay(NULL);
+ if (!dpy) xtk_fail("cannot open the display");
+ return dpy;
+}
+
+/* Gives E time to handle what was just sent: X has no round trip that
+ * waits for the window manager. */
+static void
+xtk_settle(Display *dpy)
+{
+ XSync(dpy, False);
+ usleep(300 * 1000);
+}
+
+static void
+xtk_geometry_get(Display *dpy, Window win, int *x, int *y, int *w, int *h)
+{
+ XWindowAttributes attr;
+ Window child;
+
+ XSync(dpy, False);
+ XTranslateCoordinates(dpy, win, DefaultRootWindow(dpy), 0, 0, x, y, &child);
+ XGetWindowAttributes(dpy, win, &attr);
+ if (w) *w = attr.width;
+ if (h) *h = attr.height;
+}
+
+static void
+xtk_pointer_move_to(Display *dpy, int x, int y)
+{
+ XTestFakeMotionEvent(dpy, DefaultScreen(dpy), x, y, CurrentTime);
+ XSync(dpy, False);
+ usleep(50 * 1000);
+}
+
+/* Moves the pointer by dx,dy in steps, as a hand would. */
+static void
+xtk_pointer_drag(Display *dpy, int x, int y, int dx, int dy)
+{
+ int i;
+
+ for (i = 1; i <= 10; i++)
+ xtk_pointer_move_to(dpy, x + (i * dx / 10), y + (i * dy / 10));
+}
+
+/* A window with no server-side frame, as a GTK header bar window asks for,
+ * mapped where it asked to be. Returns once it is mapped. */
+static Window
+xtk_csd_window_new(Display *dpy, int x, int y, int w, int h, const char *title)
+{
+ /* _MOTIF_WM_HINTS: flags = decorations, decorations = none */
+ long mwm[5] = { 2, 0, 0, 0, 0 };
+ XSizeHints *hints;
+ XEvent ev;
+ Window win;
+ Atom motif;
+
+ win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), x, y, w, h, 0,
+ 0, 0xffffff);
+ hints = XAllocSizeHints();
+ hints->flags = USPosition | PPosition;
+ hints->x = x;
+ hints->y = y;
+ XSetWMNormalHints(dpy, win, hints);
+ XFree(hints);
+ XStoreName(dpy, win, title);
+
+ motif = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
+ XChangeProperty(dpy, win, motif, motif, 32, PropModeReplace,
+ (unsigned char *)mwm, 5);
+
+ XSelectInput(dpy, win, StructureNotifyMask);
+ XMapWindow(dpy, win);
+ do XNextEvent(dpy, &ev); while (ev.type != MapNotify);
+ xtk_settle(dpy);
+ return win;
+}
+
+/* What a CSD client does on a press in its own decorations: it gives up
+ * the implicit grab the press took and hands the drag to the window
+ * manager. The pointer must already be at x,y. */
+static void
+xtk_csd_drag_begin(Display *dpy, Window win, int x, int y, int direction)
+{
+ XEvent ev;
+
+ XTestFakeButtonEvent(dpy, 1, True, CurrentTime);
+ XSync(dpy, False);
+ XUngrabPointer(dpy, CurrentTime);
+
+ memset(&ev, 0, sizeof(ev));
+ ev.xclient.type = ClientMessage;
+ ev.xclient.window = win;
+ ev.xclient.message_type = XInternAtom(dpy, "_NET_WM_MOVERESIZE", False);
+ ev.xclient.format = 32;
+ ev.xclient.data.l[0] = x;
+ ev.xclient.data.l[1] = y;
+ ev.xclient.data.l[2] = direction;
+ ev.xclient.data.l[3] = 1;
+ ev.xclient.data.l[4] = NET_WM_SOURCE_APPLICATION;
+ XSendEvent(dpy, DefaultRootWindow(dpy), False,
+ SubstructureRedirectMask | SubstructureNotifyMask, &ev);
+ xtk_settle(dpy);
+}
+
+/* E moves and resizes only the composited frame during a drag; the X
+ * window follows when the button is released. */
+static void
+xtk_csd_drag_end(Display *dpy)
+{
+ XTestFakeButtonEvent(dpy, 1, False, CurrentTime);
+ xtk_settle(dpy);
+}
+
+#endif
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.