| 1 |
/************************************************************ |
| 2 |
|
| 3 |
Copyright 2006 Peter Hutterer <[email protected]> |
| 4 |
|
| 5 |
Permission to use, copy, modify, distribute, and sell this software and its |
| 6 |
documentation for any purpose is hereby granted without fee, provided that |
| 7 |
the above copyright notice appear in all copies and that both that |
| 8 |
copyright notice and this permission notice appear in supporting |
| 9 |
documentation. |
| 10 |
|
| 11 |
The above copyright notice and this permission notice shall be included in |
| 12 |
all copies or substantial portions of the Software. |
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 |
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 18 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 |
|
| 21 |
Except as contained in this notice, the name of The Open Group shall not be |
| 22 |
used in advertising or otherwise to promote the sale, use or other dealings |
| 23 |
in this Software without prior written authorization from The Open Group. |
| 24 |
|
| 25 |
*/ |
| 26 |
|
| 27 |
/*********************************************************************** |
| 28 |
* |
| 29 |
* XIQueryPointer - Query the pointer of an extension input device. |
| 30 |
* |
| 31 |
*/ |
| 32 |
#ifdef HAVE_CONFIG_H |
| 33 |
#include <config.h> |
| 34 |
#endif |
| 35 |
|
| 36 |
#include <stdint.h> |
| 37 |
#include <X11/extensions/XI2proto.h> |
| 38 |
#include <X11/Xlibint.h> |
| 39 |
#include <X11/extensions/XInput2.h> |
| 40 |
#include <X11/extensions/extutil.h> |
| 41 |
#include "XIint.h" |
| 42 |
|
| 43 |
#define FP1616toDBL(x) ((x) * 1.0 / (1 << 16)) |
| 44 |
|
| 45 |
Bool |
| 46 |
XIQueryPointer(Display *dpy, |
| 47 |
int deviceid, |
| 48 |
Window w, |
| 49 |
Window *root, |
| 50 |
Window *child, |
| 51 |
double *root_x, |
| 52 |
double *root_y, |
| 53 |
double *win_x, |
| 54 |
double *win_y, |
| 55 |
XIButtonState *buttons, |
| 56 |
XIModifierState *mods, |
| 57 |
XIGroupState *group) |
| 58 |
{ |
| 59 |
xXIQueryPointerReq *req; |
| 60 |
xXIQueryPointerReply rep; |
| 61 |
|
| 62 |
XExtDisplayInfo *info = XInput_find_display(dpy); |
| 63 |
|
| 64 |
LockDisplay(dpy); |
| 65 |
if (_XiCheckExtInit(dpy, XInput_2_0, info) == -1) |
| 66 |
return False; |
| 67 |
|
| 68 |
GetReq(XIQueryPointer, req); |
| 69 |
req->reqType = info->codes->major_opcode; |
| 70 |
req->ReqType = X_XIQueryPointer; |
| 71 |
req->deviceid = deviceid; |
| 72 |
req->win = w; |
| 73 |
|
| 74 |
if (!_XReply(dpy, (xReply *)&rep, |
| 75 |
(sizeof(xXIQueryPointerReply) - sizeof(xReply))/4, xFalse)) { |
| 76 |
UnlockDisplay(dpy); |
| 77 |
SyncHandle(); |
| 78 |
return False; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
*root = rep.root; |
| 83 |
*child = rep.child; |
| 84 |
*root_x = FP1616toDBL(cvtINT16toInt(rep.root_x)); |
| 85 |
*root_y = FP1616toDBL(cvtINT16toInt(rep.root_y)); |
| 86 |
*win_x = FP1616toDBL(cvtINT16toInt(rep.win_x)); |
| 87 |
*win_y = FP1616toDBL(cvtINT16toInt(rep.win_y)); |
| 88 |
|
| 89 |
mods->base = rep.mods.base_mods; |
| 90 |
mods->latched = rep.mods.latched_mods; |
| 91 |
mods->locked = rep.mods.locked_mods; |
| 92 |
mods->effective = mods->base | mods->latched | mods->locked; |
| 93 |
|
| 94 |
group->base = rep.group.base_group; |
| 95 |
group->latched = rep.group.latched_group; |
| 96 |
group->locked = rep.group.locked_group; |
| 97 |
group->effective = group->base | group->latched | group->locked; |
| 98 |
|
| 99 |
buttons->mask_len = rep.buttons_len * 4; |
| 100 |
buttons->mask = malloc(buttons->mask_len); |
| 101 |
if (buttons->mask) |
| 102 |
_XRead(dpy, (char*)buttons->mask, buttons->mask_len); |
| 103 |
|
| 104 |
UnlockDisplay(dpy); |
| 105 |
SyncHandle(); |
| 106 |
return rep.same_screen; |
| 107 |
} |