swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 5761f826baad7cffdd37dbd84fd87a0cfbe02a3a
parent 45df267d3c6fdc4e2939d8d6dca95f1e0e6066cb
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Tue, 18 May 2021 00:23:10 -0500

touch focus switching

Diffstat:
Mlibswc/compositor.c | 25++++++++++++++++++++++---
Mlibswc/swc.c | 1+
Mlibswc/touch.c | 25++++++++++++++++++++++++-
Mlibswc/touch.h | 9++++++++-
4 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/libswc/compositor.c b/libswc/compositor.c @@ -71,6 +71,7 @@ static struct pointer_handler pointer_handler = { .motion = handle_pointer_motion, }; +/* TODO */ static struct touch_handler touch_handler = { .down = handle_touch_down, }; @@ -734,10 +735,28 @@ handle_pointer_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t } bool -handle_touch_down(struct touch_handler *handler, uint32_t time, int32_t slot, wl_fixed_t x, wl_fixed_t y) +handle_touch_down(struct touch_handler *handler, uint32_t time, int32_t slot, wl_fixed_t fx, wl_fixed_t fy) { - fprintf(stderr, "touch down\n"); - return false; + struct compositor_view *view; + bool found = false; + int32_t x = wl_fixed_to_int(fx), y = wl_fixed_to_int(fy); + struct swc_rectangle *geom; + + wl_list_for_each (view, &compositor.views, link) { + if (!view->visible) + continue; + geom = &view->base.geometry; + if (rectangle_contains_point(geom, x, y)) { + if (pixman_region32_contains_point(&view->surface->state.input, x - geom->x, y - geom->y, NULL)) { + found = true; + break; + } + } + } + + touch_set_focus(swc.seat->touch, found ? view : NULL); + + return false; } static void diff --git a/libswc/swc.c b/libswc/swc.c @@ -79,6 +79,7 @@ setup_compositor(void) wl_list_insert(&swc.seat->pointer->handlers, &screens_pointer_handler.link); wl_signal_add(&swc.seat->pointer->focus.event_signal, &window_enter_listener); wl_list_insert(&swc.seat->touch->handlers, &swc.compositor->touch_handler->link); + wl_signal_add(&swc.seat->touch->focus.event_signal, &window_enter_listener); /* Calculate pointer region */ pixman_region32_init(&pointer_region); diff --git a/libswc/touch.c b/libswc/touch.c @@ -60,6 +60,24 @@ touch_handle_cancel(struct touch *touch, uint32_t time) } void +touch_set_focus(struct touch *touch, struct compositor_view *view) +{ + input_focus_set(&touch->focus, view); +} + +/* TODO these don't really make sense in the context of touch, + * but we need them for input focus for now */ +static void +enter(struct input_focus_handler *handler, struct wl_list *resources, struct compositor_view *view) +{ +} + +static void +leave(struct input_focus_handler *handler, struct wl_list *resources, struct compositor_view *view) +{ +} + +void touch_destroy(struct touch *touch) { wl_array_release(&touch->points); @@ -79,10 +97,14 @@ touch_create() wl_list_init(&touch->handlers); wl_array_init(&touch->points); + touch->focus_handler.enter = enter; + touch->focus_handler.leave = leave; + input_focus_initialize(&touch->focus, &touch->focus_handler); + return touch; error0: - return NULL; + return NULL; } static const struct wl_touch_interface touch_impl = { @@ -99,5 +121,6 @@ touch_bind(struct touch *touch, struct wl_client *client, uint32_t version, uint return NULL; wl_resource_set_implementation(client_resource, &touch_impl, touch, NULL); + input_focus_add_resource(&touch->focus, client_resource); return client_resource; } diff --git a/libswc/touch.h b/libswc/touch.h @@ -1,6 +1,9 @@ #ifndef SWC_TOUCH_H #define SWC_TOUCH_H +#include "input.h" +#include "view.h" + struct touch_handler { bool (*down)(struct touch_handler *handler, uint32_t time, int32_t slot, wl_fixed_t x, wl_fixed_t y); bool (*up)(struct touch_handler *handler, uint32_t time, int32_t slot); @@ -16,7 +19,10 @@ struct point { }; struct touch { - struct wl_list handlers; + struct input_focus focus; + struct input_focus_handler focus_handler; + + struct wl_list handlers; struct wl_array points; }; @@ -25,6 +31,7 @@ void touch_handle_up(struct touch *touch, uint32_t time, int32_t slot); void touch_handle_motion(struct touch *touch, uint32_t time, int32_t slot, uint32_t x, uint32_t y); void touch_handle_frame(struct touch *touch, uint32_t time); void touch_handle_cancel(struct touch *touch, uint32_t time); +void touch_set_focus(struct touch *touch, struct compositor_view *view); void touch_destroy(struct touch *touch); struct touch *touch_create(); struct wl_resource *touch_bind(struct touch *touch, struct wl_client *client, uint32_t version, uint32_t id);