XKBCtrls.c revision 1ab64890
1/* $Xorg: XKBCtrls.c,v 1.3 2000/08/17 19:45:00 cpqbld Exp $ */ 2/************************************************************ 3Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc. 4 5Permission to use, copy, modify, and distribute this 6software and its documentation for any purpose and without 7fee is hereby granted, provided that the above copyright 8notice appear in all copies and that both that copyright 9notice and this permission notice appear in supporting 10documentation, and that the name of Silicon Graphics not be 11used in advertising or publicity pertaining to distribution 12of the software without specific prior written permission. 13Silicon Graphics makes no representation about the suitability 14of this software for any purpose. It is provided "as is" 15without any express or implied warranty. 16 17SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 18SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 19AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 20GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 21DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 22DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 23OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 24THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 26********************************************************/ 27/* $XFree86: xc/lib/X11/XKBCtrls.c,v 1.4 2002/12/10 04:33:48 dawes Exp $ */ 28 29#ifdef HAVE_CONFIG_H 30#include <config.h> 31#endif 32#include <stdio.h> 33#define NEED_REPLIES 34#define NEED_EVENTS 35#include "Xlibint.h" 36#include <X11/extensions/XKBproto.h> 37#include "XKBlibint.h" 38 39 40static xkbSetControlsReq * 41_XkbGetSetControlsReq(Display *dpy,XkbInfoPtr xkbi,unsigned int deviceSpec) 42{ 43xkbSetControlsReq *req; 44 45 GetReq(kbSetControls,req); 46 bzero(req,SIZEOF(xkbSetControlsReq)); 47 req->reqType = xkbi->codes->major_opcode; 48 req->length = (SIZEOF(xkbSetControlsReq)>>2); 49 req->xkbReqType = X_kbSetControls; 50 req->deviceSpec = deviceSpec; 51 return req; 52} 53 54Bool 55XkbSetAutoRepeatRate( Display *dpy, 56 unsigned int deviceSpec, 57 unsigned int timeout, 58 unsigned int interval) 59{ 60 register xkbSetControlsReq *req; 61 62 if ((dpy->flags & XlibDisplayNoXkb) || 63 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) 64 return False; 65 LockDisplay(dpy); 66 req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); 67 req->changeCtrls = XkbRepeatKeysMask; 68 req->repeatDelay = timeout; 69 req->repeatInterval = interval; 70 UnlockDisplay(dpy); 71 SyncHandle(); 72 return True; 73} 74 75Bool 76XkbGetAutoRepeatRate( Display * dpy, 77 unsigned int deviceSpec, 78 unsigned int * timeoutp, 79 unsigned int * intervalp) 80{ 81 register xkbGetControlsReq *req; 82 xkbGetControlsReply rep; 83 XkbInfoPtr xkbi; 84 85 if ((dpy->flags & XlibDisplayNoXkb) || 86 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) 87 return False; 88 LockDisplay(dpy); 89 xkbi = dpy->xkb_info; 90 GetReq(kbGetControls, req); 91 req->reqType = xkbi->codes->major_opcode; 92 req->xkbReqType = X_kbGetControls; 93 req->deviceSpec = deviceSpec; 94 if (!_XReply(dpy, (xReply *)&rep, 95 (SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) { 96 UnlockDisplay(dpy); 97 SyncHandle(); 98 return False; 99 } 100 UnlockDisplay(dpy); 101 SyncHandle(); 102 *timeoutp = rep.repeatDelay; 103 *intervalp = rep.repeatInterval; 104 return True; 105} 106 107Bool 108XkbSetServerInternalMods( Display * dpy, 109 unsigned deviceSpec, 110 unsigned affectReal, 111 unsigned realValues, 112 unsigned affectVirtual, 113 unsigned virtualValues) 114{ 115 register xkbSetControlsReq *req; 116 117 if ((dpy->flags & XlibDisplayNoXkb) || 118 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) 119 return False; 120 LockDisplay(dpy); 121 req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); 122 req->affectInternalMods = affectReal; 123 req->internalMods = realValues; 124 req->affectInternalVMods= affectVirtual; 125 req->internalVMods= virtualValues; 126 req->changeCtrls = XkbInternalModsMask; 127 UnlockDisplay(dpy); 128 SyncHandle(); 129 return True; 130} 131 132Bool 133XkbSetIgnoreLockMods( Display * dpy, 134 unsigned int deviceSpec, 135 unsigned affectReal, 136 unsigned realValues, 137 unsigned affectVirtual, 138 unsigned virtualValues) 139{ 140 register xkbSetControlsReq *req; 141 142 if ((dpy->flags & XlibDisplayNoXkb) || 143 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) 144 return False; 145 LockDisplay(dpy); 146 req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); 147 req->affectIgnoreLockMods= affectReal; 148 req->ignoreLockMods = realValues; 149 req->affectIgnoreLockVMods= affectVirtual; 150 req->ignoreLockVMods= virtualValues; 151 req->changeCtrls = XkbIgnoreLockModsMask; 152 UnlockDisplay(dpy); 153 SyncHandle(); 154 return True; 155} 156 157Bool 158XkbChangeEnabledControls( Display * dpy, 159 unsigned deviceSpec, 160 unsigned affect, 161 unsigned values) 162{ 163 register xkbSetControlsReq *req; 164 165 if ((dpy->flags & XlibDisplayNoXkb) || 166 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) 167 return False; 168 LockDisplay(dpy); 169 req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec); 170 req->affectEnabledCtrls= affect; 171 req->enabledCtrls= (affect&values); 172 req->changeCtrls = XkbControlsEnabledMask; 173 UnlockDisplay(dpy); 174 SyncHandle(); 175 return True; 176} 177 178Status 179XkbGetControls(Display *dpy, unsigned long which, XkbDescPtr xkb) 180{ 181 register xkbGetControlsReq *req; 182 xkbGetControlsReply rep; 183 XkbControlsPtr ctrls; 184 XkbInfoPtr xkbi; 185 186 if ((dpy->flags & XlibDisplayNoXkb) || 187 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) 188 return BadAccess; 189 if ((!xkb) || (!which)) 190 return BadMatch; 191 192 LockDisplay(dpy); 193 xkbi = dpy->xkb_info; 194 GetReq(kbGetControls, req); 195 if (!xkb->ctrls) { 196 xkb->ctrls = _XkbTypedCalloc(1,XkbControlsRec); 197 if (!xkb->ctrls) { 198 UnlockDisplay(dpy); 199 SyncHandle(); 200 return BadAlloc; 201 } 202 } 203 req->reqType = xkbi->codes->major_opcode; 204 req->xkbReqType = X_kbGetControls; 205 req->deviceSpec = xkb->device_spec; 206 if (!_XReply(dpy, (xReply *)&rep, 207 (SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) { 208 UnlockDisplay(dpy); 209 SyncHandle(); 210 return BadImplementation; 211 } 212 if (xkb->device_spec==XkbUseCoreKbd) 213 xkb->device_spec= rep.deviceID; 214 ctrls= xkb->ctrls; 215 if (which&XkbControlsEnabledMask) 216 ctrls->enabled_ctrls = rep.enabledCtrls; 217 ctrls->num_groups= rep.numGroups; 218 if (which&XkbGroupsWrapMask) 219 ctrls->groups_wrap= rep.groupsWrap; 220 if (which&XkbInternalModsMask) { 221 ctrls->internal.mask = rep.internalMods; 222 ctrls->internal.real_mods = rep.internalRealMods; 223 ctrls->internal.vmods = rep.internalVMods; 224 } 225 if (which&XkbIgnoreLockModsMask) { 226 ctrls->ignore_lock.mask = rep.ignoreLockMods; 227 ctrls->ignore_lock.real_mods = rep.ignoreLockRealMods; 228 ctrls->ignore_lock.vmods = rep.ignoreLockVMods; 229 } 230 if (which&XkbRepeatKeysMask) { 231 ctrls->repeat_delay = rep.repeatDelay; 232 ctrls->repeat_interval = rep.repeatInterval; 233 } 234 if (which&XkbSlowKeysMask) 235 ctrls->slow_keys_delay = rep.slowKeysDelay; 236 if (which&XkbBounceKeysMask) 237 ctrls->debounce_delay = rep.debounceDelay; 238 if (which&XkbMouseKeysMask) { 239 ctrls->mk_dflt_btn = rep.mkDfltBtn; 240 } 241 if (which&XkbMouseKeysAccelMask) { 242 ctrls->mk_delay = rep.mkDelay; 243 ctrls->mk_interval = rep.mkInterval; 244 ctrls->mk_time_to_max = rep.mkTimeToMax; 245 ctrls->mk_max_speed = rep.mkMaxSpeed; 246 ctrls->mk_curve = rep.mkCurve; 247 } 248 if (which&XkbAccessXKeysMask) 249 ctrls->ax_options= rep.axOptions; 250 if (which&XkbStickyKeysMask) { 251 ctrls->ax_options &= ~XkbAX_SKOptionsMask; 252 ctrls->ax_options |= rep.axOptions & XkbAX_SKOptionsMask; 253 } 254 if (which&XkbAccessXFeedbackMask) { 255 ctrls->ax_options &= ~XkbAX_FBOptionsMask; 256 ctrls->ax_options |= rep.axOptions & XkbAX_FBOptionsMask; 257 } 258 if (which&XkbAccessXTimeoutMask) { 259 ctrls->ax_timeout = rep.axTimeout; 260 ctrls->axt_ctrls_mask = rep.axtCtrlsMask; 261 ctrls->axt_ctrls_values = rep.axtCtrlsValues; 262 ctrls->axt_opts_mask = rep.axtOptsMask; 263 ctrls->axt_opts_values= rep.axtOptsValues; 264 } 265 if (which&XkbPerKeyRepeatMask) { 266 memcpy(ctrls->per_key_repeat,rep.perKeyRepeat, 267 XkbPerKeyBitArraySize); 268 } 269 UnlockDisplay(dpy); 270 SyncHandle(); 271 return Success; 272} 273 274Bool 275XkbSetControls(Display *dpy, unsigned long which, XkbDescPtr xkb) 276{ 277 register xkbSetControlsReq *req; 278 XkbControlsPtr ctrls; 279 280 if ((dpy->flags & XlibDisplayNoXkb) || 281 (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) 282 return False; 283 if ((!xkb)||(!xkb->ctrls)) 284 return False; 285 286 ctrls= xkb->ctrls; 287 LockDisplay(dpy); 288 req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,xkb->device_spec); 289 req->changeCtrls = (CARD32)which; 290 if (which&XkbInternalModsMask) { 291 req->affectInternalMods= ~0; 292 req->internalMods= ctrls->internal.real_mods; 293 req->affectInternalVMods = ~0; 294 req->internalVMods= ctrls->internal.vmods; 295 } 296 if (which&XkbIgnoreLockModsMask) { 297 req->affectIgnoreLockMods= ~0; 298 req->ignoreLockMods= ctrls->ignore_lock.real_mods; 299 req->affectIgnoreLockVMods= ~0; 300 req->ignoreLockVMods= ctrls->ignore_lock.vmods; 301 } 302 if (which&XkbControlsEnabledMask) { 303 req->affectEnabledCtrls= XkbAllBooleanCtrlsMask; 304 req->enabledCtrls= ctrls->enabled_ctrls; 305 } 306 if (which&XkbRepeatKeysMask) { 307 req->repeatDelay = ctrls->repeat_delay; 308 req->repeatInterval = ctrls->repeat_interval; 309 } 310 if (which&XkbSlowKeysMask) 311 req->slowKeysDelay = ctrls->slow_keys_delay; 312 if (which&XkbBounceKeysMask) 313 req->debounceDelay = ctrls->debounce_delay; 314 if (which&XkbMouseKeysMask) { 315 req->mkDfltBtn = ctrls->mk_dflt_btn; 316 } 317 if (which&XkbGroupsWrapMask) 318 req->groupsWrap= ctrls->groups_wrap; 319 if (which&(XkbAccessXKeysMask|XkbStickyKeysMask|XkbAccessXFeedbackMask)) 320 req->axOptions= ctrls->ax_options; 321 if (which&XkbMouseKeysAccelMask) { 322 req->mkDelay = ctrls->mk_delay; 323 req->mkInterval = ctrls->mk_interval; 324 req->mkTimeToMax = ctrls->mk_time_to_max; 325 req->mkMaxSpeed = ctrls->mk_max_speed; 326 req->mkCurve = ctrls->mk_curve; 327 } 328 if (which&XkbAccessXTimeoutMask) { 329 req->axTimeout = ctrls->ax_timeout; 330 req->axtCtrlsMask = ctrls->axt_ctrls_mask; 331 req->axtCtrlsValues = ctrls->axt_ctrls_values; 332 req->axtOptsMask = ctrls->axt_opts_mask; 333 req->axtOptsValues=ctrls->axt_opts_values; 334 } 335 if (which&XkbPerKeyRepeatMask) { 336 memcpy(req->perKeyRepeat,ctrls->per_key_repeat, 337 XkbPerKeyBitArraySize); 338 } 339 UnlockDisplay(dpy); 340 SyncHandle(); 341 return True; 342} 343 344/***====================================================================***/ 345 346void 347XkbNoteControlsChanges( XkbControlsChangesPtr old, 348 XkbControlsNotifyEvent * new, 349 unsigned int wanted) 350{ 351 old->changed_ctrls|= (new->changed_ctrls&wanted); 352 if (new->changed_ctrls&XkbControlsEnabledMask&wanted) 353 old->enabled_ctrls_changes^= new->enabled_ctrl_changes; 354 /* num_groups_changed?? */ 355 return; 356} 357