summaryrefslogtreecommitdiff
path: root/tests/x11/test_tablet_native.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/x11/test_tablet_native.c')
-rw-r--r--tests/x11/test_tablet_native.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/tests/x11/test_tablet_native.c b/tests/x11/test_tablet_native.c
index 66cdd93..bbe39f2 100644
--- a/tests/x11/test_tablet_native.c
+++ b/tests/x11/test_tablet_native.c
@@ -2,7 +2,6 @@
#define main tablet_example_main
#include "../../examples/tablet.c"
#undef main
-#include <yasl/native/x11.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
@@ -59,7 +58,8 @@ static int connect_tool(const char *path)
}
struct canvas_state {
- struct yasl_pen_payload pen;
+ struct yasl_pen_event pen;
+ double x, y;
uint32_t *pixels;
int width, height, painted_width, painted_height;
bool down;
@@ -69,24 +69,24 @@ static void render_event(yasl_surface *surface, struct canvas_state *state, cons
{
if (event->type == YASL_EVENT_PEN) {
state->pen = event->pen;
+ state->x = event->x;
+ state->y = event->y;
state->down = event->pen.in_contact;
}
- struct yasl_cpu_buffer buffer;
free(state->pixels);
- state->pixels = canvas(surface, &state->width, &state->height,
- &state->painted_width, &state->painted_height, false, &buffer);
- assert(state->pixels);
+ uint32_t *pixels = canvas(surface, &state->width, &state->height,
+ &state->painted_width, &state->painted_height, false);
+ assert(pixels);
if (event->type == YASL_EVENT_PEN && state->down &&
- (event->pen.action == YASL_PEN_DOWN || event->pen.action == YASL_PEN_MOVE)) {
- double scale = yasl_surface_get_scale(surface);
- stamp(state->pixels, state->width, state->height,
- event->pen.x * scale, event->pen.y * scale,
+ (event->action == YASL_PEN_DOWN || event->action == YASL_PEN_MOVE)) {
+ double scale = yasl_surface_get_info(surface).scale;
+ stamp(pixels, state->width, state->height, event->x * scale, event->y * scale,
(1.5 + 12 * event->pen.pressure) * scale, event->pen.tool == YASL_PEN_ERASER);
}
uint32_t *snapshot = malloc((size_t)state->width * state->height * sizeof(*snapshot));
assert(snapshot);
- memcpy(snapshot, buffer.pixels, (size_t)state->width * state->height * sizeof(*snapshot));
- assert(yasl_cpu_present(surface, &buffer) == 0);
+ memcpy(snapshot, pixels, (size_t)state->width * state->height * sizeof(*snapshot));
+ assert(yasl_cpu_present(surface) == 0);
state->pixels = snapshot;
}
@@ -107,12 +107,12 @@ static void pump(int fd, yasl_surface *surface, struct canvas_state *state)
receive_all(fd, &response, sizeof(response));
assert(response.type == XF86IT_RESPONSE_SYNC_FINISHED && response.length == sizeof(response));
/* The driver acknowledgment guarantees XI2 processing has finished. */
- struct yasl_x11_handles native;
- assert(yasl_x11_get_native(surface, &native) == 0);
- XSync(native.display, False);
+ struct yasl_native native;
+ assert(yasl_surface_get_native(surface, &native) == 0);
+ XSync(native.x11_display, False);
drain(surface, state);
/* Public polling submits the CPU frame before the native readback. */
- XSync(native.display, False);
+ XSync(native.x11_display, False);
}
static void set_eraser_property(Display *display)
@@ -140,13 +140,13 @@ int main(int argc, char **argv)
{
assert(argc == 3); /* pen socket, eraser socket */
struct canvas_state app = {0};
- assert((yasl_init(&(struct yasl_options){.backend=YASL_BACKEND_X11}) == 0));
- yasl_surface *surface = yasl_surface_create(&(struct yasl_surface_options){.title="YASL native pressure test", .width=500, .height=400, .type=YASL_SURFACE_CPU, .flags=0});
- assert(surface && (yasl_surface_get_features(surface) & YASL_CAP_TABLET));
- struct yasl_x11_handles native;
- assert(yasl_x11_get_native(surface, &native) == 0);
- Display *x = native.display;
- Window window = (Window)native.window;
+ assert(yasl_init(YASL_BACKEND_X11, NULL) == 0);
+ yasl_surface *surface = yasl_surface_create(&(struct yasl_surface_options){.title="YASL native pressure test", .width=500, .height=400});
+ assert(surface && (yasl_get_features() & YASL_FEATURE_TABLET));
+ struct yasl_native native;
+ assert(yasl_surface_get_native(surface, &native) == 0);
+ Display *x = native.x11_display;
+ Window window = (Window)native.x11_window;
XMoveWindow(x, window, 0, 0);
XSetInputFocus(x, window, RevertToParent, CurrentTime);
XSync(x, False);
@@ -163,7 +163,7 @@ int main(int argc, char **argv)
send_all(pen_fd, &motion, sizeof(motion));
pump(pen_fd, surface, &app);
assert(!app.down && app.pen.tool == YASL_PEN_PEN);
- assert(app.pen.x == 150 && app.pen.y == 200);
+ assert(app.x == 150 && app.y == 200);
assert(app.pixels[(size_t)200 * app.width + 150] == PAPER);
xf86ITEventButton button = {.header = {sizeof(button), XF86IT_EVENT_BUTTON},
.is_absolute = 1, .button = 1, .is_press = 1, .valuators = motion.valuators};