XGetCPtr.c revision c27c18e8
1c27c18e8Smrg/************************************************************
2c27c18e8Smrg
3c27c18e8SmrgCopyright 2007 Peter Hutterer <peter@cs.unisa.edu.au>
4c27c18e8Smrg
5c27c18e8SmrgPermission to use, copy, modify, distribute, and sell this software and its
6c27c18e8Smrgdocumentation for any purpose is hereby granted without fee, provided that
7c27c18e8Smrgthe above copyright notice appear in all copies and that both that
8c27c18e8Smrgcopyright notice and this permission notice appear in supporting
9c27c18e8Smrgdocumentation.
10c27c18e8Smrg
11c27c18e8SmrgThe above copyright notice and this permission notice shall be included in
12c27c18e8Smrgall copies or substantial portions of the Software.
13c27c18e8Smrg
14c27c18e8SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c27c18e8SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c27c18e8SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17c27c18e8SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18c27c18e8SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19c27c18e8SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20c27c18e8Smrg
21c27c18e8SmrgExcept as contained in this notice, the name of The Open Group shall not be
22c27c18e8Smrgused in advertising or otherwise to promote the sale, use or other dealings
23c27c18e8Smrgin this Software without prior written authorization from The Open Group.
24c27c18e8Smrg
25c27c18e8Smrg*/
26c27c18e8Smrg
27c27c18e8Smrg/***********************************************************************
28c27c18e8Smrg *
29c27c18e8Smrg * XIGetClientPointer - Get the clientPointer setting for a client.
30c27c18e8Smrg *
31c27c18e8Smrg */
32c27c18e8Smrg
33c27c18e8Smrg#include <stdint.h>
34c27c18e8Smrg#include <X11/extensions/XI2proto.h>
35c27c18e8Smrg#include <X11/Xlibint.h>
36c27c18e8Smrg#include <X11/extensions/XInput2.h>
37c27c18e8Smrg#include <X11/extensions/extutil.h>
38c27c18e8Smrg#include "XIint.h"
39c27c18e8Smrg
40c27c18e8SmrgBool
41c27c18e8SmrgXIGetClientPointer(Display* dpy, Window win, int *deviceid)
42c27c18e8Smrg{
43c27c18e8Smrg    xXIGetClientPointerReq *req;
44c27c18e8Smrg    xXIGetClientPointerReply rep;
45c27c18e8Smrg    XExtDisplayInfo *info = XInput_find_display(dpy);
46c27c18e8Smrg
47c27c18e8Smrg    LockDisplay(dpy);
48c27c18e8Smrg    if (_XiCheckExtInit(dpy, Dont_Check, info) == -1)
49c27c18e8Smrg	return (NoSuchExtension);
50c27c18e8Smrg
51c27c18e8Smrg    GetReq(XIGetClientPointer, req);
52c27c18e8Smrg    req->reqType = info->codes->major_opcode;
53c27c18e8Smrg    req->ReqType = X_XIGetClientPointer;
54c27c18e8Smrg    req->win = win;
55c27c18e8Smrg
56c27c18e8Smrg    if (!_XReply(dpy, (xReply*) &rep, 0, xFalse)) {
57c27c18e8Smrg        UnlockDisplay(dpy);
58c27c18e8Smrg        SyncHandle();
59c27c18e8Smrg        return False;
60c27c18e8Smrg    }
61c27c18e8Smrg
62c27c18e8Smrg    *deviceid = rep.deviceid;
63c27c18e8Smrg
64c27c18e8Smrg    UnlockDisplay(dpy);
65c27c18e8Smrg    SyncHandle();
66c27c18e8Smrg    return rep.set;
67c27c18e8Smrg}
68