aboutsummaryrefslogtreecommitdiff
path: root/examples/touch.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/touch.c')
-rw-r--r--examples/touch.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/examples/touch.c b/examples/touch.c
index f9c496cf..949d209d 100644
--- a/examples/touch.c
+++ b/examples/touch.c
@@ -12,7 +12,6 @@
#include <wayland-server.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
-#include <wlr/render/gles2.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_list.h>
#include <wlr/types/wlr_matrix.h>
@@ -45,10 +44,13 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height);
wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1});
+ int tex_width, tex_height;
+ wlr_texture_get_size(sample->cat_texture, &tex_width, &tex_height);
+
struct touch_point *p;
wl_list_for_each(p, &sample->touch_points, link) {
- int x = (int)(p->x * width) - sample->cat_texture->width / 2;
- int y = (int)(p->y * height) - sample->cat_texture->height / 2;
+ int x = (int)(p->x * width) - tex_width / 2;
+ int y = (int)(p->y * height) - tex_height / 2;
wlr_render_texture(sample->renderer, sample->cat_texture,
wlr_output->transform_matrix, x, y, 1.0f);
}
@@ -57,13 +59,13 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
wlr_output_swap_buffers(wlr_output, NULL, NULL);
}
-static void handle_touch_down(struct touch_state *tstate, int32_t touch_id,
- double x, double y, double width, double height) {
+static void handle_touch_down(struct touch_state *tstate,
+ int32_t touch_id, double x, double y) {
struct sample_state *sample = tstate->compositor->data;
struct touch_point *point = calloc(1, sizeof(struct touch_point));
point->touch_id = touch_id;
- point->x = x / width;
- point->y = y / height;
+ point->x = x;
+ point->y = y;
wl_list_insert(&sample->touch_points, &point->link);
}
@@ -78,14 +80,14 @@ static void handle_touch_up(struct touch_state *tstate, int32_t touch_id) {
}
}
-static void handle_touch_motion(struct touch_state *tstate, int32_t touch_id,
- double x, double y, double width, double height) {
+static void handle_touch_motion(struct touch_state *tstate,
+ int32_t touch_id, double x, double y) {
struct sample_state *sample = tstate->compositor->data;
struct touch_point *point;
wl_list_for_each(point, &sample->touch_points, link) {
if (point->touch_id == touch_id) {
- point->x = x / width;
- point->y = y / height;
+ point->x = x;
+ point->y = y;
break;
}
}
@@ -105,18 +107,18 @@ int main(int argc, char *argv[]) {
};
compositor_init(&compositor);
- state.renderer = wlr_gles2_renderer_create(compositor.backend);
+ state.renderer = wlr_backend_get_renderer(compositor.backend);
if (!state.renderer) {
wlr_log(L_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE);
}
- state.cat_texture = wlr_render_texture_create(state.renderer);
+ state.cat_texture = wlr_texture_from_pixels(state.renderer,
+ WL_SHM_FORMAT_ARGB8888, cat_tex.width * 4, cat_tex.width, cat_tex.height,
+ cat_tex.pixel_data);
if (!state.cat_texture) {
wlr_log(L_ERROR, "Could not start compositor, OOM");
exit(EXIT_FAILURE);
}
- wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ARGB8888,
- cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
if (!wlr_backend_start(compositor.backend)) {
wlr_log(L_ERROR, "Failed to start backend");