summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--multitouch.c56
1 files changed, 47 insertions, 9 deletions
diff --git a/multitouch.c b/multitouch.c
index b5bcb20..33b5084 100644
--- a/multitouch.c
+++ b/multitouch.c
@@ -24,8 +24,10 @@ static void usage(void)
{
printf("Usage:\n");
printf(" Grey window: normal touch surface\n");
- printf(" Black bar left: grabs the touchpoint, no ownership, accepts\n");
- printf(" White bar left: grabs the touchpoint, no ownership, rejects\n");
+ printf(" Upper black bar left: grabs the touchpoint, no ownership, accepts\n");
+ printf(" Upper White bar left: grabs the touchpoint, no ownership, rejects\n");
+ printf(" Lower black bar left: grabs the touchpoint, with ownership, accepts\n");
+ printf(" Lower White bar left: grabs the touchpoint, with ownership, rejects\n");
}
enum TouchState {
@@ -55,6 +57,8 @@ struct multitouch {
Window win;
Window blackbar;
Window whitebar;
+ Window blackbar_os; /* with ownership */
+ Window whitebar_os; /* with ownership */
GC gc;
Visual *visual;
int xi_opcode;
@@ -121,14 +125,22 @@ static void init_windows(struct multitouch *mt)
0, 0, WhitePixel(mt->dpy, mt->screen_no));
mt->win = win;
- subwin = XCreateSimpleWindow(mt->dpy, win, 0, 0, 50, mt->height/2, 0, 0,
+ subwin = XCreateSimpleWindow(mt->dpy, win, 0, 0, 50, mt->height/4, 0, 0,
BlackPixel(mt->dpy, mt->screen_no));
mt->blackbar = subwin;
- subwin = XCreateSimpleWindow(mt->dpy, win, 0, mt->height/2, 50, mt->height/2, 0, 0,
+ subwin = XCreateSimpleWindow(mt->dpy, win, 0, mt->height/4, 50, mt->height/4, 0, 0,
WhitePixel(mt->dpy, mt->screen_no));
mt->whitebar = subwin;
+ subwin = XCreateSimpleWindow(mt->dpy, win, 0, mt->height/2, 50, mt->height/4, 0, 0,
+ BlackPixel(mt->dpy, mt->screen_no));
+ mt->blackbar_os = subwin;
+
+ subwin = XCreateSimpleWindow(mt->dpy, win, 0, 3 * mt->height/4, 50, mt->height/4, 0, 0,
+ WhitePixel(mt->dpy, mt->screen_no));
+ mt->whitebar_os = subwin;
+
/* select for touch events on main window */
XSelectInput(mt->dpy, win, ExposureMask);
XMapSubwindows(mt->dpy, win);
@@ -157,6 +169,17 @@ static void init_windows(struct multitouch *mt)
XINoOwnerEvents, &evmask, 1, &modifiers) != 0)
error("Failed to establish passive grab on whitebar\n");
+ XISetMask(mask, XI_TouchOwnership);
+ /* grab touch events on blackbar_os with ownership */
+ if (XIGrabTouchBegin(mt->dpy, XIAllMasterDevices, mt->blackbar_os,
+ XINoOwnerEvents, &evmask, 1, &modifiers) != 0)
+ error("Failed to establish passive grab on blackbar_os\n");
+
+ /* grab touch events on whitebar_os with ownership */
+ if (XIGrabTouchBegin(mt->dpy, XIAllMasterDevices, mt->whitebar_os,
+ XINoOwnerEvents, &evmask, 1, &modifiers) != 0)
+ error("Failed to establish passive grab on whitebar_os\n");
+
XSync(mt->dpy, False);
}
@@ -230,6 +253,7 @@ static void print_event(struct multitouch *mt, XIDeviceEvent* event)
case XI_TouchBegin: type = "TouchBegin"; break;
case XI_TouchUpdate: type = "TouchUpdate"; break;
case XI_TouchEnd: type = "TouchEnd"; break;
+ case XI_TouchOwnership: type = "TouchOwnership"; break;
}
msg("Event: %s (%d)\n", type, event->deviceid);
msg("\t%.2f/%.2f (%.2f/%.2f)\n", event->event_x, event->event_y, event->root_x, event->root_y);
@@ -346,10 +370,18 @@ static void paint_grabs(struct multitouch *mt, Window which)
{
r = 0; g = 0; b = 1;
offset = 0;
- } else
+ } else if (which == mt->whitebar)
{
r = 1; g = 0; b = 0;
+ offset = mt->height/4;
+ } else if (which == mt->blackbar_os)
+ {
+ r = 0; g = 1; b = 0;
offset = mt->height/2;
+ } else
+ {
+ r = 0; g = 1; b = 1;
+ offset = 3 * mt->height/2;
}
for (i = 0; i < mt->ngrabs; i++)
@@ -413,9 +445,14 @@ static void handle_grabbed_event(struct multitouch *mt, XIDeviceEvent *event)
switch (event->evtype)
{
case XI_TouchEnd:
- grab->state = TSTATE_END;
- XIAllowTouchEvents(mt->dpy, event->deviceid, event->detail, event->event,
- event->event == mt->blackbar ? XIAcceptTouch : XIRejectTouch);
+ {
+ int mode = XIAcceptTouch;
+ if (event->event == mt->whitebar || event->event == mt->whitebar_os)
+ mode = XIRejectTouch;
+ grab->state = TSTATE_END;
+ XIAllowTouchEvents(mt->dpy, event->deviceid, event->detail,
+ event->event, mode);
+ }
break;
case XI_TouchUpdate:
grab->state = TSTATE_UPDATE;
@@ -425,7 +462,8 @@ static void handle_grabbed_event(struct multitouch *mt, XIDeviceEvent *event)
static void paint_event(struct multitouch *mt, XIDeviceEvent *event)
{
- if (event->event == mt->blackbar || event->event == mt->whitebar)
+ if (event->event == mt->blackbar || event->event == mt->whitebar ||
+ event->event == mt->blackbar_os || event->event == mt->whitebar_os)
{
handle_grabbed_event(mt, event);
return;