xserver

xserver with xephyr scale patch
git clone https://git.neptards.moe/u3shit/xserver.git
Log | Files | Refs | README | LICENSE

protocol-xiquerypointer.c (5824B)


      1 /**
      2  * Copyright © 2009 Red Hat, Inc.
      3  *
      4  *  Permission is hereby granted, free of charge, to any person obtaining a
      5  *  copy of this software and associated documentation files (the "Software"),
      6  *  to deal in the Software without restriction, including without limitation
      7  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8  *  and/or sell copies of the Software, and to permit persons to whom the
      9  *  Software is furnished to do so, subject to the following conditions:
     10  *
     11  *  The above copyright notice and this permission notice (including the next
     12  *  paragraph) shall be included in all copies or substantial portions of the
     13  *  Software.
     14  *
     15  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     18  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     20  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     21  *  DEALINGS IN THE SOFTWARE.
     22  */
     23 
     24 /* Test relies on assert() */
     25 #undef NDEBUG
     26 
     27 #ifdef HAVE_DIX_CONFIG_H
     28 #include <dix-config.h>
     29 #endif
     30 
     31 /*
     32  * Protocol testing for XIQueryPointer request.
     33  */
     34 #include <stdint.h>
     35 #include <X11/X.h>
     36 #include <X11/Xproto.h>
     37 #include <X11/extensions/XI2proto.h>
     38 #include "inputstr.h"
     39 #include "windowstr.h"
     40 #include "scrnintstr.h"
     41 #include "xiquerypointer.h"
     42 #include "exevents.h"
     43 #include "exglobals.h"
     44 
     45 #include "protocol-common.h"
     46 
     47 extern ClientRec client_window;
     48 static ClientRec client_request;
     49 static void reply_XIQueryPointer_data(ClientPtr client, int len,
     50                                       char *data, void *closure);
     51 
     52 static struct {
     53     DeviceIntPtr dev;
     54     WindowPtr win;
     55 } test_data;
     56 
     57 static void
     58 reply_XIQueryPointer(ClientPtr client, int len, char *data, void *closure)
     59 {
     60     xXIQueryPointerReply *rep = (xXIQueryPointerReply *) data;
     61     SpritePtr sprite;
     62 
     63     if (!rep->repType)
     64         return;
     65 
     66     if (client->swapped) {
     67         swapl(&rep->length);
     68         swaps(&rep->sequenceNumber);
     69         swapl(&rep->root);
     70         swapl(&rep->child);
     71         swapl(&rep->root_x);
     72         swapl(&rep->root_y);
     73         swapl(&rep->win_x);
     74         swapl(&rep->win_y);
     75         swaps(&rep->buttons_len);
     76     }
     77 
     78     reply_check_defaults(rep, len, XIQueryPointer);
     79 
     80     assert(rep->root == root.drawable.id);
     81     assert(rep->same_screen == xTrue);
     82 
     83     sprite = test_data.dev->spriteInfo->sprite;
     84     assert((rep->root_x >> 16) == sprite->hot.x);
     85     assert((rep->root_y >> 16) == sprite->hot.y);
     86 
     87     if (test_data.win == &root) {
     88         assert(rep->root_x == rep->win_x);
     89         assert(rep->root_y == rep->win_y);
     90         assert(rep->child == window.drawable.id);
     91     }
     92     else {
     93         int x, y;
     94 
     95         x = sprite->hot.x - window.drawable.x;
     96         y = sprite->hot.y - window.drawable.y;
     97 
     98         assert((rep->win_x >> 16) == x);
     99         assert((rep->win_y >> 16) == y);
    100         assert(rep->child == None);
    101     }
    102 
    103     assert(rep->same_screen == xTrue);
    104 
    105     reply_handler = reply_XIQueryPointer_data;
    106 }
    107 
    108 static void
    109 reply_XIQueryPointer_data(ClientPtr client, int len, char *data, void *closure)
    110 {
    111     reply_handler = reply_XIQueryPointer;
    112 }
    113 
    114 static void
    115 request_XIQueryPointer(ClientPtr client, xXIQueryPointerReq * req, int error)
    116 {
    117     int rc;
    118 
    119     rc = ProcXIQueryPointer(&client_request);
    120     assert(rc == error);
    121 
    122     if (rc == BadDevice)
    123         assert(client_request.errorValue == req->deviceid);
    124 
    125     client_request.swapped = TRUE;
    126     swaps(&req->deviceid);
    127     swapl(&req->win);
    128     swaps(&req->length);
    129     rc = SProcXIQueryPointer(&client_request);
    130     assert(rc == error);
    131 
    132     if (rc == BadDevice)
    133         assert(client_request.errorValue == req->deviceid);
    134 }
    135 
    136 static void
    137 test_XIQueryPointer(void)
    138 {
    139     int i;
    140     xXIQueryPointerReq request;
    141 
    142     memset(&request, 0, sizeof(request));
    143 
    144     request_init(&request, XIQueryPointer);
    145 
    146     reply_handler = reply_XIQueryPointer;
    147 
    148     client_request = init_client(request.length, &request);
    149 
    150     request.deviceid = XIAllDevices;
    151     request_XIQueryPointer(&client_request, &request, BadDevice);
    152 
    153     request.deviceid = XIAllMasterDevices;
    154     request_XIQueryPointer(&client_request, &request, BadDevice);
    155 
    156     request.win = root.drawable.id;
    157     test_data.win = &root;
    158 
    159     test_data.dev = devices.vcp;
    160     request.deviceid = devices.vcp->id;
    161     request_XIQueryPointer(&client_request, &request, Success);
    162     request.deviceid = devices.vck->id;
    163     request_XIQueryPointer(&client_request, &request, BadDevice);
    164     request.deviceid = devices.mouse->id;
    165     request_XIQueryPointer(&client_request, &request, BadDevice);
    166     request.deviceid = devices.kbd->id;
    167     request_XIQueryPointer(&client_request, &request, BadDevice);
    168 
    169     test_data.dev = devices.mouse;
    170     devices.mouse->master = NULL;       /* Float, kind-of */
    171     request.deviceid = devices.mouse->id;
    172     request_XIQueryPointer(&client_request, &request, Success);
    173 
    174     for (i = devices.kbd->id + 1; i <= 0xFFFF; i++) {
    175         request.deviceid = i;
    176         request_XIQueryPointer(&client_request, &request, BadDevice);
    177     }
    178 
    179     request.win = window.drawable.id;
    180 
    181     test_data.dev = devices.vcp;
    182     test_data.win = &window;
    183     request.deviceid = devices.vcp->id;
    184     request_XIQueryPointer(&client_request, &request, Success);
    185 
    186     test_data.dev = devices.mouse;
    187     request.deviceid = devices.mouse->id;
    188     request_XIQueryPointer(&client_request, &request, Success);
    189 
    190     /* test REQUEST_SIZE_MATCH */
    191     client_request.req_len -= 4;
    192     request_XIQueryPointer(&client_request, &request, BadLength);
    193 }
    194 
    195 int
    196 protocol_xiquerypointer_test(void)
    197 {
    198     init_simple();
    199 
    200     test_XIQueryPointer();
    201 
    202     return 0;
    203 }