From d9ceeb2044f3f2dfa96f1a2989d629d4b965f512 Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Thu, 1 Oct 2015 16:45:36 +0900 Subject: [PATCH] pepper: API for setting pointer clamp area Pointer can never go outside the clamp area. Initial value is infinite area. Change-Id: I832c55791cb499e17c01512fd9052cbd30946dec --- src/lib/pepper/pepper-internal.h | 6 +++ src/lib/pepper/pepper.h | 6 +++ src/lib/pepper/pointer.c | 87 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/src/lib/pepper/pepper-internal.h b/src/lib/pepper/pepper-internal.h index ec0f4f6..e86e80e 100644 --- a/src/lib/pepper/pepper-internal.h +++ b/src/lib/pepper/pepper-internal.h @@ -247,8 +247,14 @@ struct pepper_pointer const pepper_pointer_grab_t *grab; void *data; + uint32_t time; double x, y; double vx, vy; + + struct { + double x0, y0; + double x1, y1; + } clamp; }; pepper_pointer_t * diff --git a/src/lib/pepper/pepper.h b/src/lib/pepper/pepper.h index 36fc400..b355198 100644 --- a/src/lib/pepper/pepper.h +++ b/src/lib/pepper/pepper.h @@ -300,6 +300,12 @@ struct pepper_pointer_grab void (*cancel)(pepper_pointer_t *pointer, void *data); }; +PEPPER_API pepper_bool_t +pepper_pointer_set_clamp(pepper_pointer_t *pointer, double x0, double y0, double x1, double y1); + +PEPPER_API void +pepper_pointer_get_clamp(pepper_pointer_t *pointer, double *x0, double *y0, double *x1, double *y1); + PEPPER_API void pepper_pointer_get_position(pepper_pointer_t *pointer, double *x, double *y); diff --git a/src/lib/pepper/pointer.c b/src/lib/pepper/pointer.c index c761623..4bc0a9d 100644 --- a/src/lib/pepper/pointer.c +++ b/src/lib/pepper/pointer.c @@ -1,4 +1,5 @@ #include "pepper-internal.h" +#include static void pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, uint32_t serial, @@ -68,14 +69,51 @@ static const pepper_pointer_grab_t default_pointer_grab = default_pointer_grab_cancel, }; +static pepper_bool_t +pointer_clamp(pepper_pointer_t *pointer) +{ + pepper_bool_t clamped = PEPPER_FALSE; + + if (pointer->x < pointer->clamp.x0) + { + pointer->x = pointer->clamp.x0; + clamped = PEPPER_TRUE; + } + + if (pointer->x > pointer->clamp.x1) + { + pointer->x = pointer->clamp.x1; + clamped = PEPPER_TRUE; + } + + if (pointer->y < pointer->clamp.y0) + { + pointer->y = pointer->clamp.y0; + clamped = PEPPER_TRUE; + } + + if (pointer->y > pointer->clamp.y1) + { + pointer->y = pointer->clamp.y1; + clamped = PEPPER_TRUE; + } + + return clamped; +} + static void pointer_set_position(pepper_pointer_t *pointer, uint32_t time, double x, double y) { pepper_input_event_t event; + if (x == pointer->x && y == pointer->y) + return; + pointer->x = x; pointer->y = y; + pointer_clamp(pointer); + pointer->grab->motion(pointer, pointer->data, time, x, y); /* Emit motion event. */ @@ -127,6 +165,11 @@ pepper_pointer_create(pepper_seat_t *seat) pepper_input_init(&pointer->input, seat, &pointer->base, pointer_handle_focus_destroy); pointer->grab = &default_pointer_grab; + pointer->clamp.x0 = DBL_MIN; + pointer->clamp.y0 = DBL_MIN; + pointer->clamp.x1 = DBL_MAX; + pointer->clamp.y1 = DBL_MAX; + return pointer; } @@ -163,6 +206,50 @@ pepper_pointer_bind_resource(struct wl_client *client, struct wl_resource *resou } } +PEPPER_API pepper_bool_t +pepper_pointer_set_clamp(pepper_pointer_t *pointer, double x0, double y0, double x1, double y1) +{ + if (x1 < x0 || y1 < y0) + return PEPPER_FALSE; + + pointer->clamp.x0 = x0; + pointer->clamp.y0 = y0; + pointer->clamp.x1 = x1; + pointer->clamp.y1 = y1; + + if (pointer_clamp(pointer)) + { + pepper_input_event_t event; + + pointer->grab->motion(pointer, pointer->data, pointer->time, pointer->x, pointer->y); + + memset(&event, 0x00, sizeof(pepper_input_event_t)); + event.id = PEPPER_EVENT_POINTER_MOTION; + event.time = pointer->time; + event.x = pointer->x; + event.y = pointer->y; + pepper_object_emit_event(&pointer->base, PEPPER_EVENT_POINTER_MOTION, &event); + } + + return PEPPER_TRUE; +} + +PEPPER_API void +pepper_pointer_get_clamp(pepper_pointer_t *pointer, double *x0, double *y0, double *x1, double *y1) +{ + if (x0) + *x0 = pointer->clamp.x0; + + if (y0) + *y0 = pointer->clamp.y0; + + if (x1) + *x1 = pointer->clamp.x1; + + if (y1) + *y1 = pointer->clamp.y1; +} + PEPPER_API void pepper_pointer_get_position(pepper_pointer_t *pointer, double *x, double *y) { -- 2.7.4