summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2009-05-25 12:45:52 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2009-05-25 15:22:50 +1000
commit9b9f9373f32ebe9a15f286d16b6ba880b44a9c22 (patch)
tree3682a3a01e54803044089563ca7d001bc5c45ec5
parent13ce4a03824a7c5ac0270198d265b02b18786e1f (diff)
Add XIGetSelectedEvents.
-rw-r--r--include/X11/extensions/XInput2.h6
-rw-r--r--man/Makefile.am3
-rw-r--r--man/XISelectEvents.txt25
-rw-r--r--src/XISelEv.c82
4 files changed, 114 insertions, 2 deletions
diff --git a/include/X11/extensions/XInput2.h b/include/X11/extensions/XInput2.h
index 5ef0892..8b3741a 100644
--- a/include/X11/extensions/XInput2.h
+++ b/include/X11/extensions/XInput2.h
@@ -351,6 +351,12 @@ extern int XISelectEvents(
int num_masks
);
+extern XIEventMask *XIGetSelectedEvents(
+ Display* dpy,
+ Window win,
+ int *num_masks_return
+);
+
extern Status XIQueryVersion(
Display* dpy,
int* major_version_inout,
diff --git a/man/Makefile.am b/man/Makefile.am
index 383c30f..304f993 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -78,7 +78,8 @@ XI2_refpages = \
XIUngrabKeysym.man \
XIUngrabDevice.man \
XIGetClientPointer.man \
- XIGetFocus.man
+ XIGetFocus.man \
+ XIGetSelectedEvents.man
libman_ref = \
XGetDeviceDontPropagateList.man \
diff --git a/man/XISelectEvents.txt b/man/XISelectEvents.txt
index a822fb3..07b3c8e 100644
--- a/man/XISelectEvents.txt
+++ b/man/XISelectEvents.txt
@@ -4,7 +4,7 @@ XISELECTEVENTS(libmansuffix)
NAME
----
- XISelectEvents - select for XI2 events on the window.
+ XISelectEvents, XIGetSelectedEvents - select for or get selected XI2 events on the window.
SYNOPSIS
--------
@@ -28,6 +28,19 @@ SYNOPSIS
win
Specifies the window.
+ XIEventMask *XIGetSelectedEvents( Display *display,
+ Window win,
+ int *num_masks_return);
+
+ display
+ Specifies the connection to the X server.
+
+ num_masks_return
+ Number of masks in the return value.
+
+ win
+ Specifies the window.
+
DESCRIPTION
-----------
@@ -60,6 +73,16 @@ DESCRIPTION
XISelectEvents can generate a BadValue, a BadDevice, and a
BadWindow error.
+ XIGetSelectedEvents returns the events selected by this client on the given
+ window. If no events were selected on this window, XIGetSelectedEvents
+ returns NULL and num_masks_return is set to 0. If an internal error occurs,
+ XIGetSelectedEvents returns NULL and num_masks_return is set to -1.
+ Otherwise, XIGetSelectedEvent returns the selected event masks for all
+ devices including the masks for XIAllDevices and XIAllMasterDevices
+
+ The caller must free the returned data using XFree().
+
+
DIAGNOSTICS
-----------
diff --git a/src/XISelEv.c b/src/XISelEv.c
index fc9f2a2..d76861f 100644
--- a/src/XISelEv.c
+++ b/src/XISelEv.c
@@ -91,3 +91,85 @@ XISelectEvents(Display* dpy, Window win, XIEventMask* masks, int num_masks)
return Success;
}
+
+XIEventMask*
+XIGetSelectedEvents(Display* dpy, Window win, int *num_masks_return)
+{
+ int i, len = 0;
+ unsigned char *mask;
+ XIEventMask *mask_out = NULL;
+ xXIEventMask *mask_in = NULL, *mi;
+ xXIGetSelectedEventsReq *req;
+ xXIGetSelectedEventsReply reply;
+
+ XExtDisplayInfo *info = XInput_find_display(dpy);
+ LockDisplay(dpy);
+ if (_XiCheckExtInit(dpy, XI_2_Major, info) == -1)
+ {
+ *num_masks_return = -1;
+ return NULL;
+ }
+
+ GetReq(XIGetSelectedEvents, req);
+
+ req->reqType = info->codes->major_opcode;
+ req->ReqType = X_XIGetSelectedEvents;
+ req->window = win;
+
+ if (!_XReply(dpy, (xReply *) &reply, 0, xFalse))
+ goto error;
+
+ if (reply.num_masks == 0)
+ {
+ *num_masks_return = 0;
+ return NULL;
+ }
+
+ mask_in = Xmalloc(reply.length * 4);
+ if (!mask_in)
+ goto error;
+
+ _XRead(dpy, (char*)mask_in, reply.length * 4);
+
+ /* Memory layout of the XIEventMask for a 3 mask reply:
+ * [struct a][struct b][struct c][masks a][masks b][masks c]
+ */
+ len = reply.num_masks * sizeof(XIEventMask);
+
+ for (i = 0, mi = mask_in; i < reply.num_masks; i++)
+ {
+ len += mi->mask_len * 4;
+ mi = (xXIEventMask*)((char*)mi + mi->mask_len * 4);
+ mi++;
+ }
+
+ mask_out = Xmalloc(len);
+ if (!mask_out)
+ goto error;
+
+ mi = mask_in;
+ mask = (unsigned char*)&mask_out[reply.num_masks];
+ for (i = 0; i < reply.num_masks; i++)
+ {
+ mask_out[i].deviceid = mi->deviceid;
+ mask_out[i].mask_len = mi->mask_len * 4;
+ mask_out[i].mask = mask;
+ memcpy(mask_out[i].mask, &mi[1], mask_out[i].mask_len);
+ mask += mask_out[i].mask_len;
+ mi = (xXIEventMask*)((char*)mi + mi->mask_len * 4);
+ mi++;
+ }
+
+ *num_masks_return = reply.num_masks;
+
+ return mask_out;
+
+error:
+ if (mask_in)
+ Xfree(mask_in);
+ *num_masks_return = -1;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return NULL;
+
+}