| 1 | /************************************************************ |
| 2 | |
| 3 | Copyright 1989, 1998 The Open Group |
| 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 | Copyright 1989 by Hewlett-Packard Company, Palo Alto, California. |
| 26 | |
| 27 | All Rights Reserved |
| 28 | |
| 29 | Permission to use, copy, modify, and distribute this software and its |
| 30 | documentation for any purpose and without fee is hereby granted, |
| 31 | provided that the above copyright notice appear in all copies and that |
| 32 | both that copyright notice and this permission notice appear in |
| 33 | supporting documentation, and that the name of Hewlett-Packard not be |
| 34 | used in advertising or publicity pertaining to distribution of the |
| 35 | software without specific, written prior permission. |
| 36 | |
| 37 | HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING |
| 38 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL |
| 39 | HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR |
| 40 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
| 41 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
| 42 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
| 43 | SOFTWARE. |
| 44 | |
| 45 | ********************************************************/ |
| 46 | |
| 47 | /******************************************************************** |
| 48 | * |
| 49 | * Change Device control attributes for an extension device. |
| 50 | * |
| 51 | */ |
| 52 | |
| 53 | #ifdef HAVE_DIX_CONFIG_H |
| 54 | #include <dix-config.h> |
| 55 | #endif |
| 56 | |
| 57 | #include "inputstr.h" /* DeviceIntPtr */ |
| 58 | #include <X11/extensions/XI.h> |
| 59 | #include <X11/extensions/XIproto.h> /* control constants */ |
| 60 | #include "XIstubs.h" |
| 61 | |
| 62 | #include "exglobals.h" |
| 63 | #include "exevents.h" |
| 64 | |
| 65 | #include "chgdctl.h" |
| 66 | |
| 67 | /*********************************************************************** |
| 68 | * |
| 69 | * This procedure changes the control attributes for an extension device, |
| 70 | * for clients on machines with a different byte ordering than the server. |
| 71 | * |
| 72 | */ |
| 73 | |
| 74 | int |
| 75 | SProcXChangeDeviceControl(ClientPtr client) |
| 76 | { |
| 77 | xDeviceCtl *ctl; |
| 78 | |
| 79 | REQUEST(xChangeDeviceControlReq); |
| 80 | swaps(&stuff->length); |
| 81 | REQUEST_AT_LEAST_SIZE(xChangeDeviceControlReq); |
| 82 | swaps(&stuff->control); |
| 83 | ctl = (xDeviceCtl *) &stuff[1]; |
| 84 | swaps(&ctl->control); |
| 85 | swaps(&ctl->length); |
| 86 | switch (stuff->control) { |
| 87 | case DEVICE_ABS_CALIB: |
| 88 | case DEVICE_ABS_AREA: |
| 89 | case DEVICE_CORE: |
| 90 | case DEVICE_ENABLE: |
| 91 | case DEVICE_RESOLUTION: |
| 92 | /* hmm. beer. *drool* */ |
| 93 | break; |
| 94 | |
| 95 | } |
| 96 | return (ProcXChangeDeviceControl(client)); |
| 97 | } |
| 98 | |
| 99 | /*********************************************************************** |
| 100 | * |
| 101 | * Change the control attributes. |
| 102 | * |
| 103 | */ |
| 104 | |
| 105 | int |
| 106 | ProcXChangeDeviceControl(ClientPtr client) |
| 107 | { |
| 108 | unsigned len; |
| 109 | int i, status, ret = BadValue; |
| 110 | DeviceIntPtr dev; |
| 111 | xDeviceResolutionCtl *r; |
| 112 | xChangeDeviceControlReply rep; |
| 113 | AxisInfoPtr a; |
| 114 | CARD32 *resolution; |
| 115 | xDeviceEnableCtl *e; |
| 116 | |
| 117 | REQUEST(xChangeDeviceControlReq); |
| 118 | REQUEST_AT_LEAST_SIZE(xChangeDeviceControlReq); |
| 119 | |
| 120 | len = stuff->length - bytes_to_int32(sizeof(xChangeDeviceControlReq)); |
| 121 | ret = dixLookupDevice(&dev, stuff->deviceid, client, DixManageAccess); |
| 122 | if (ret != Success) |
| 123 | goto out; |
| 124 | |
| 125 | /* XTest devices are special, none of the below apply to them anyway */ |
| 126 | if (IsXTestDevice(dev, NULL)) { |
| 127 | ret = BadMatch; |
| 128 | goto out; |
| 129 | } |
| 130 | |
| 131 | rep = (xChangeDeviceControlReply) { |
| 132 | .repType = X_Reply, |
| 133 | .RepType = X_ChangeDeviceControl, |
| 134 | .sequenceNumber = client->sequence, |
| 135 | .length = 0, |
| 136 | .status = Success, |
| 137 | }; |
| 138 | |
| 139 | switch (stuff->control) { |
| 140 | case DEVICE_RESOLUTION: |
| 141 | r = (xDeviceResolutionCtl *) &stuff[1]; |
| 142 | if ((len < bytes_to_int32(sizeof(xDeviceResolutionCtl))) || |
| 143 | (len != |
| 144 | bytes_to_int32(sizeof(xDeviceResolutionCtl)) + r->num_valuators)) { |
| 145 | ret = BadLength; |
| 146 | goto out; |
| 147 | } |
| 148 | if (!dev->valuator) { |
| 149 | ret = BadMatch; |
| 150 | goto out; |
| 151 | } |
| 152 | if ((dev->deviceGrab.grab) && !SameClient(dev->deviceGrab.grab, client)) { |
| 153 | rep.status = AlreadyGrabbed; |
| 154 | ret = Success; |
| 155 | goto out; |
| 156 | } |
| 157 | resolution = (CARD32 *) (r + 1); |
| 158 | if (r->first_valuator + r->num_valuators > dev->valuator->numAxes) { |
| 159 | ret = BadValue; |
| 160 | goto out; |
| 161 | } |
| 162 | status = ChangeDeviceControl(client, dev, (xDeviceCtl *) r); |
| 163 | if (status == Success) { |
| 164 | a = &dev->valuator->axes[r->first_valuator]; |
| 165 | for (i = 0; i < r->num_valuators; i++) |
| 166 | if (*(resolution + i) < (a + i)->min_resolution || |
| 167 | *(resolution + i) > (a + i)->max_resolution) |
| 168 | return BadValue; |
| 169 | for (i = 0; i < r->num_valuators; i++) |
| 170 | (a++)->resolution = *resolution++; |
| 171 | |
| 172 | ret = Success; |
| 173 | } |
| 174 | else if (status == DeviceBusy) { |
| 175 | rep.status = DeviceBusy; |
| 176 | ret = Success; |
| 177 | } |
| 178 | else { |
| 179 | ret = BadMatch; |
| 180 | } |
| 181 | break; |
| 182 | case DEVICE_ABS_CALIB: |
| 183 | case DEVICE_ABS_AREA: |
| 184 | /* Calibration is now done through properties, and never had any effect |
| 185 | * on anything (in the open-source world). Thus, be honest. */ |
| 186 | ret = BadMatch; |
| 187 | break; |
| 188 | case DEVICE_CORE: |
| 189 | /* Sorry, no device core switching no more. If you want a device to |
| 190 | * send core events, attach it to a master device */ |
| 191 | ret = BadMatch; |
| 192 | break; |
| 193 | case DEVICE_ENABLE: |
| 194 | e = (xDeviceEnableCtl *) &stuff[1]; |
| 195 | |
| 196 | if (IsXTestDevice(dev, NULL)) |
| 197 | status = !Success; |
| 198 | else |
| 199 | status = ChangeDeviceControl(client, dev, (xDeviceCtl *) e); |
| 200 | |
| 201 | if (status == Success) { |
| 202 | if (e->enable) |
| 203 | EnableDevice(dev, TRUE); |
| 204 | else |
| 205 | DisableDevice(dev, TRUE); |
| 206 | ret = Success; |
| 207 | } |
| 208 | else if (status == DeviceBusy) { |
| 209 | rep.status = DeviceBusy; |
| 210 | ret = Success; |
| 211 | } |
| 212 | else { |
| 213 | ret = BadMatch; |
| 214 | } |
| 215 | |
| 216 | break; |
| 217 | default: |
| 218 | ret = BadValue; |
| 219 | } |
| 220 | |
| 221 | out: |
| 222 | if (ret == Success) { |
| 223 | devicePresenceNotify dpn = { |
| 224 | .type = DevicePresenceNotify, |
| 225 | .time = currentTime.milliseconds, |
| 226 | .devchange = DeviceControlChanged, |
| 227 | .deviceid = dev->id, |
| 228 | .control = stuff->control |
| 229 | }; |
| 230 | SendEventToAllWindows(dev, DevicePresenceNotifyMask, |
| 231 | (xEvent *) &dpn, 1); |
| 232 | |
| 233 | WriteReplyToClient(client, sizeof(xChangeDeviceControlReply), &rep); |
| 234 | } |
| 235 | |
| 236 | return ret; |
| 237 | } |
| 238 | |
| 239 | /*********************************************************************** |
| 240 | * |
| 241 | * This procedure writes the reply for the xChangeDeviceControl function, |
| 242 | * if the client and server have a different byte ordering. |
| 243 | * |
| 244 | */ |
| 245 | |
| 246 | void |
| 247 | SRepXChangeDeviceControl(ClientPtr client, int size, |
| 248 | xChangeDeviceControlReply * rep) |
| 249 | { |
| 250 | swaps(&rep->sequenceNumber); |
| 251 | swapl(&rep->length); |
| 252 | WriteToClient(client, size, rep); |
| 253 | } |