summaryrefslogtreecommitdiff
path: root/tests/x11
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 15:05:06 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 15:05:06 +0300
commit98f0d51157fa2a2b8ccaae54ed4850a88d223d01 (patch)
tree90b03d0930986620d95eb0f45c07b96e1331783c /tests/x11
parent339e1ad7adb8340732ee856d0f6f0d2c7f1455d1 (diff)
Simplify surface state, examples, and library installation
Diffstat (limited to 'tests/x11')
-rw-r--r--tests/x11/test_state.c77
-rw-r--r--tests/x11/test_tablet_native.c49
2 files changed, 123 insertions, 3 deletions
diff --git a/tests/x11/test_state.c b/tests/x11/test_state.c
new file mode 100644
index 0000000..abdda95
--- /dev/null
+++ b/tests/x11/test_state.c
@@ -0,0 +1,77 @@
+/* Supply native window-state properties without requiring an X server. */
+#define XGetWindowProperty state_property
+#include "../../src/platform/x11/window.c"
+#undef XGetWindowProperty
+
+static Atom properties[3];
+static unsigned long property_count;
+static int notifications;
+static uint32_t reported_state;
+
+int state_property(Display *display, Window window, Atom property,
+ long offset, long length, Bool delete_property, Atom type,
+ Atom *actual, int *format, unsigned long *count, unsigned long *left,
+ unsigned char **data)
+{
+ assert(display && window == 42 && property == 10);
+ assert(!offset && length >= 3 && !delete_property && type == XA_ATOM);
+ *actual = XA_ATOM;
+ *format = 32;
+ *count = property_count;
+ *left = 0;
+ *data = NULL;
+ if (property_count) {
+ *data = malloc(property_count * sizeof(*properties));
+ assert(*data);
+ memcpy(*data, properties, property_count * sizeof(*properties));
+ }
+ return Success;
+}
+
+static void state_changed(struct yasl_surface *surface, uint32_t state, void *ud)
+{
+ (void)ud;
+ assert(yasl_surface_state(surface) == state);
+ reported_state = state;
+ notifications++;
+}
+
+int main(void)
+{
+ struct x11_display display = {.base.ops = &yasl_x11_backend,
+ .net_state = 10, .fullscreen = 20, .maximized_h = 21, .maximized_v = 22};
+ display.native = (Display *)&display;
+ struct x11_surface surface = {.base = {.display = &display.base,
+ .state = YASL_STATE_ACTIVATED}, .window = 42};
+ set_callbacks(&surface.base, &(struct yasl_window_cbs){.state = state_changed}, NULL);
+
+ properties[0] = display.fullscreen;
+ property_count = 1;
+ update_state(&surface);
+ assert(notifications == 1);
+ assert(reported_state == (YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED));
+ update_state(&surface);
+ assert(notifications == 1);
+
+ /* Both maximized axes are required; activation survives property changes. */
+ properties[0] = display.maximized_h;
+ update_state(&surface);
+ assert(notifications == 2 && reported_state == YASL_STATE_ACTIVATED);
+ properties[1] = display.maximized_v;
+ property_count = 2;
+ update_state(&surface);
+ assert(notifications == 3);
+ assert(reported_state == (YASL_STATE_MAXIMIZED | YASL_STATE_ACTIVATED));
+ properties[2] = display.fullscreen;
+ property_count = 3;
+ update_state(&surface);
+ assert(notifications == 4);
+ assert(reported_state == (YASL_STATE_FULLSCREEN | YASL_STATE_MAXIMIZED | YASL_STATE_ACTIVATED));
+
+ property_count = 0;
+ update_state(&surface);
+ assert(notifications == 5 && reported_state == YASL_STATE_ACTIVATED);
+ update_state(&surface);
+ assert(notifications == 5);
+ return 0;
+}
diff --git a/tests/x11/test_tablet_native.c b/tests/x11/test_tablet_native.c
index f12ec7f..078606a 100644
--- a/tests/x11/test_tablet_native.c
+++ b/tests/x11/test_tablet_native.c
@@ -55,6 +55,49 @@ static int connect_tool(const char *path)
return fd;
}
+static void native_draw(struct yasl_surface *surface, struct yasl_frame *frame, void *ud)
+{
+ struct yasl_frame_context context = {
+ .surface = surface, .size = frame->target.size,
+ .scale_120 = yasl_surface_geometry(surface).scale_120,
+ .cpu = {.pixels = frame->target.pixels,
+ .stride_bytes = frame->target.size.x * (int)sizeof(uint32_t)},
+ .internal_handle = frame,
+ };
+ draw(ud, surface, &context);
+}
+
+static void native_configure(struct yasl_surface *surface, struct yasl_geometry geometry, void *ud)
+{
+ input(ud, &(struct yasl_event){.surface = surface, .type = YASL_EVENT_WINDOW_RESIZE,
+ .resize = {.size = geometry.size, .scale_120 = geometry.scale_120}});
+}
+
+static void native_input(struct app *app, const struct yasl_input_event *raw)
+{
+ struct yasl_event event = {.surface = raw->surface};
+ if (raw->kind == YASL_INPUT_RESET) event.type = YASL_EVENT_INPUT_RESET;
+ else if (raw->kind == YASL_INPUT_FOCUS) {
+ event.type = YASL_EVENT_WINDOW_FOCUS;
+ event.focus.focused = raw->focus.focused;
+ } else if (raw->kind == YASL_INPUT_MOUSE) {
+ if (raw->mouse.kind == YASL_PTR_MOTION) {
+ event.type = YASL_EVENT_MOUSE_MOTION;
+ event.mouse_motion.pos = raw->mouse.pos;
+ event.mouse_motion.device = raw->mouse.device;
+ event.mouse_motion.pen = raw->mouse.pen;
+ } else if (raw->mouse.kind == YASL_PTR_PRESS || raw->mouse.kind == YASL_PTR_RELEASE) {
+ event.type = YASL_EVENT_MOUSE_BUTTON;
+ event.mouse_button.pos = raw->mouse.pos;
+ event.mouse_button.device = raw->mouse.device;
+ event.mouse_button.button = raw->mouse.button;
+ event.mouse_button.pressed = raw->mouse.kind == YASL_PTR_PRESS;
+ event.mouse_button.pen = raw->mouse.pen;
+ } else if (raw->mouse.kind == YASL_PTR_LEAVE) event.type = YASL_EVENT_MOUSE_LEAVE;
+ }
+ input(app, &event);
+}
+
static void pump(int fd, struct yasl_display *display, struct yasl_surface *surface, struct app *app)
{
xf86ITEventWaitForSync sync = {{sizeof(sync), XF86IT_EVENT_WAIT_FOR_SYNC}};
@@ -68,7 +111,7 @@ static void pump(int fd, struct yasl_display *display, struct yasl_surface *surf
assert(yasl_display_dispatch(display, 0) == 0);
struct yasl_input_event event;
while (yasl_surface_input_poll(surface, &event)) {
- input(app, &event);
+ native_input(app, &event);
yasl_surface_schedule_redraw(surface);
}
yasl_display_flush(display);
@@ -99,14 +142,14 @@ static void set_eraser_property(Display *display)
int main(int argc, char **argv)
{
assert(argc == 3); /* pen socket, eraser socket */
- struct app app = {.running = true, .tablet_supported = true, .backend = YASL_BACKEND_X11};
+ struct app app = {.tablet_supported = true, .backend = YASL_BACKEND_X11};
struct yasl_display_spec ds = {.backend = YASL_BACKEND_X11};
struct yasl_display *display = yasl_display_open(NULL, &ds);
assert(display && (yasl_display_caps(display) & YASL_CAP_TABLET));
struct yasl_window_spec ss = {.title = "YASL native pressure test", .size = {500, 400}};
struct yasl_surface *surface = yasl_surface_create_toplevel(display, &ss);
assert(surface);
- struct yasl_window_cbs cbs = {.draw = draw, .configure = configure};
+ struct yasl_window_cbs cbs = {.draw = native_draw, .configure = native_configure};
yasl_surface_set_callbacks(surface, &cbs, &app);
yasl_surface_schedule_redraw(surface);
Display *x = yasl_display_get_native_handle(display);