summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter@cs.unisa.edu.au>2007-05-02 18:17:34 +0930
committerPeter Hutterer <peter@cs.unisa.edu.au>2007-05-02 18:17:34 +0930
commitd76c4412c9fab7dae6b0283feb847174fb19d1fe (patch)
treed511bdfd45959eb3a635068725b0bdbc21e07d9a
parentfe33724ed6cdaad6b13a7ca1c9f03dbb98d93982 (diff)
Add XFakeDeviceData call.
-rw-r--r--src/Makefile.am1
-rw-r--r--src/XFakeDevData.c81
2 files changed, 82 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8cff802..1f9f0ec 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,6 +18,7 @@ libXi_la_SOURCES = \
XDenyDev.c \
XDevBell.c \
XExtToWire.c \
+ XFakeDevData.c \
XGetBMap.c \
XGetCPtr.c \
XGetDCtl.c \
diff --git a/src/XFakeDevData.c b/src/XFakeDevData.c
new file mode 100644
index 0000000..41a6c6a
--- /dev/null
+++ b/src/XFakeDevData.c
@@ -0,0 +1,81 @@
+/************************************************************
+
+Copyright 2007 Peter Hutterer <peter@cs.unisa.edu.au>
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the author shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the author.
+
+*/
+
+/***********************************************************************
+ *
+ * XFakeDeviceData - fake device data for a given device. The data will appear
+ * as if would come from the device driver.
+ *
+ */
+
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XIproto.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/XInput.h>
+#include <X11/extensions/extutil.h>
+#include "XIint.h"
+
+int XFakeDeviceData(Display* dpy,
+ XDevice* dev,
+ int type,
+ int buttons,
+ int num_valuators,
+ int first_valuator,
+ ValuatorData* valuators)
+{
+ xFakeDeviceDataReq *req;
+
+ XExtDisplayInfo *info = XInput_find_display(dpy);
+ LockDisplay(dpy);
+
+ if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1)
+ return (NoSuchExtension);
+
+ GetReq(FakeDeviceData, req);
+
+ req->reqType = info->codes->major_opcode;
+ req->ReqType = X_FakeDeviceData;
+ req->type = type;
+ req->deviceid = dev->device_id;
+ req->buttons = buttons;
+ req->num_valuators = num_valuators;
+ req->first_valuator = first_valuator;
+ req->length += num_valuators;
+
+ if (num_valuators)
+ {
+ /* note: Data is a macro that uses its arguments multiple
+ * times, so "nvalues" is changed in a separate assignment
+ * statement */
+ num_valuators <<= 2;
+ Data32(dpy, (long*)valuators, num_valuators);
+ }
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return Success;
+}
+