summaryrefslogtreecommitdiff
path: root/dix
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-12-14 14:57:46 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-12-20 13:01:03 +1000
commit5c63dc6dbcbebbb19d79575a9f1ec9878e6537f1 (patch)
tree3344348a4da6ff2af5145a8ab47f7533d741ce8c /dix
parent7f8127d203394cae45c3ded0d063030d7c5fdb70 (diff)
dix: add DIX API to create touchpoints
The DIX touchpoints are the ones used for event processing. Co-authored-by: Daniel Stone <daniel@fooishbar.org> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
Diffstat (limited to 'dix')
-rw-r--r--dix/touch.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/dix/touch.c b/dix/touch.c
index b492e8238..dfb7ff041 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -30,6 +30,7 @@
#include "inputstr.h"
#include "scrnintstr.h"
+#include "dixgrabs.h"
#include "eventstr.h"
#include "exevents.h"
@@ -262,6 +263,9 @@ TouchFreeTouchPoint(DeviceIntPtr device, int index)
return;
ti = &device->touch->touches[index];
+ if (ti->active)
+ TouchEndTouch(device, ti);
+
valuator_mask_free(&ti->valuators);
free(ti->sprite.spriteTrace);
ti->sprite.spriteTrace = NULL;
@@ -273,4 +277,123 @@ TouchFreeTouchPoint(DeviceIntPtr device, int index)
ti->history_elements = 0;
}
+/**
+ * Given a client-facing ID (e.g. DeviceEvent::detail.touch), find the
+ * associated TouchPointInfoRec.
+ */
+TouchPointInfoPtr
+TouchFindByClientID(DeviceIntPtr dev, uint32_t client_id)
+{
+ TouchClassPtr t = dev->touch;
+ TouchPointInfoPtr ti;
+ int i;
+
+ if (!t)
+ return NULL;
+
+ for (i = 0; i < t->num_touches; i++)
+ {
+ ti = &t->touches[i];
+ if (ti->active && ti->client_id == client_id)
+ return ti;
+ }
+
+ return NULL;
+}
+
+
+/**
+ * Given a unique ID for a touchpoint, create a touchpoint record in the
+ * server.
+ *
+ * Returns NULL on failure (i.e. if another touch with that ID is already active,
+ * allocation failure).
+ */
+TouchPointInfoPtr
+TouchBeginTouch(DeviceIntPtr dev, int sourceid, uint32_t touchid,
+ Bool emulate_pointer)
+{
+ int i;
+ TouchClassPtr t = dev->touch;
+ TouchPointInfoPtr ti;
+ void *tmp;
+
+ if (!t)
+ return NULL;
+
+ /* Look for another active touchpoint with the same client ID. It's
+ * technically legitimate for a touchpoint to still exist with the same
+ * ID but only once the 32 bits wrap over and you've used up 4 billion
+ * touch ids without lifting that one finger off once. In which case
+ * you deserve a medal or something, but not error handling code. */
+ if (TouchFindByClientID(dev, touchid))
+ return NULL;
+
+try_find_touch:
+ for (i = 0; i < t->num_touches; i++)
+ {
+ ti = &t->touches[i];
+ if (!ti->active) {
+ ti->active = TRUE;
+ ti->client_id = touchid;
+ ti->sourceid = sourceid;
+ ti->emulate_pointer = emulate_pointer;
+ return ti;
+ }
+ }
+
+ /* If we get here, then we've run out of touches: enlarge dev->touch and
+ * try again. */
+ tmp = realloc(t->touches, (t->num_touches + 1) * sizeof(*ti));
+ if (tmp)
+ {
+ t->touches = tmp;
+ t->num_touches++;
+ if (TouchInitTouchPoint(t, dev->valuator, t->num_touches - 1))
+ goto try_find_touch;
+ }
+
+ return NULL;
+}
+
+/**
+ * Releases a touchpoint for use: this must only be called after all events
+ * related to that touchpoint have been sent and finalised. Called from
+ * ProcessTouchEvent and friends. Not by you.
+ */
+void
+TouchEndTouch(DeviceIntPtr dev, TouchPointInfoPtr ti)
+{
+ if (ti->emulate_pointer)
+ {
+ GrabPtr grab;
+ DeviceEvent ev;
+ memset(&ev, 0, sizeof(ev));
+ ev.type = ET_TouchEnd;
+ ev.detail.button = 1;
+ ev.touchid = ti->client_id;
+ ev.flags = TOUCH_POINTER_EMULATED|TOUCH_END;
+ UpdateDeviceState(dev, &ev);
+
+ if ((grab = dev->deviceGrab.grab))
+ {
+ if (dev->deviceGrab.fromPassiveGrab &&
+ !dev->button->buttonsDown &&
+ !dev->touch->buttonsDown &&
+ GrabIsPointerGrab(grab))
+ (*dev->deviceGrab.DeactivateGrab)(dev);
+ }
+ }
+
+ ti->active = FALSE;
+ ti->pending_finish = FALSE;
+ ti->sprite.spriteTraceGood = 0;
+ free(ti->listeners);
+ ti->listeners = NULL;
+ ti->num_listeners = 0;
+ ti->num_grabs = 0;
+ ti->client_id = 0;
+
+ valuator_mask_zero(ti->valuators);
+}