1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
|
/* $XConsortium: xkbLEDs.c /main/3 1996/08/31 12:44:48 kaleb $ */
/************************************************************
Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be
used in advertising or publicity pertaining to distribution
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability
of this software for any purpose. It is provided "as is"
without any express or implied warranty.
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#define NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include "misc.h"
#include "inputstr.h"
#include "XI.h"
#include "XKBsrv.h"
extern InputInfo inputInfo;
/***====================================================================***/
/*
* unsigned
* XkbIndicatorsToUpdate(dev,changed,check_devs_rtrn)
*
* Given a keyboard and a set of state components that have changed,
* this function returns the indicators on the default keyboard
* feedback that might be affected. It also reports whether or not
* any extension devices might be affected in check_devs_rtrn.
*/
unsigned
#if NeedFunctionPrototypes
XkbIndicatorsToUpdate( DeviceIntPtr dev,
unsigned long state_changes,
Bool enable_changes)
#else
XkbIndicatorsToUpdate(dev,state_changes,enable_changes)
DeviceIntPtr dev;
unsigned long state_changes;
Bool enable_changes;
#endif
{
register unsigned update= 0;
XkbSrvLedInfoPtr sli;
sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0);
if (state_changes&(XkbModifierStateMask|XkbGroupStateMask))
update|= sli->usesEffective;
if (state_changes&(XkbModifierBaseMask|XkbGroupBaseMask))
update|= sli->usesBase;
if (state_changes&(XkbModifierLatchMask|XkbGroupLatchMask))
update|= sli->usesLatched;
if (state_changes&(XkbModifierLockMask|XkbGroupLockMask))
update|= sli->usesLocked;
if (state_changes&XkbCompatStateMask)
update|= sli->usesCompat;
if (enable_changes)
update|= sli->usesControls;
return update;
}
/***====================================================================***/
/*
* Bool
* XkbApplyLEDChangeToKeyboard(xkbi,map,on,change)
*
* Some indicators "drive" the keyboard when their state is explicitly
* changed, as described in section 9.2.1 of the XKB protocol spec.
* This function updates the state and controls for the keyboard
* specified by 'xkbi' to reflect any changes that are required
* when the indicator described by 'map' is turned on or off. The
* extent of the changes is reported in change, which must be defined.
*/
Bool
#if NeedFunctionPrototypes
XkbApplyLEDChangeToKeyboard( XkbSrvInfoPtr xkbi,
XkbIndicatorMapPtr map,
Bool on,
XkbChangesPtr change)
#else
XkbApplyLEDChangeToKeyboard(xkbi,map,on,change)
XkbSrvInfoPtr xkbi;
XkbIndicatorMapPtr map;
Bool on;
XkbChangesPtr change;
#endif
{
Bool ctrlChange,stateChange;
XkbStatePtr state;
if ((map->flags&XkbIM_NoExplicit)||((map->flags&XkbIM_LEDDrivesKB)==0))
return False;
ctrlChange= stateChange= False;
if (map->ctrls) {
XkbControlsPtr ctrls= xkbi->desc->ctrls;
unsigned old;
old= ctrls->enabled_ctrls;
if (on) ctrls->enabled_ctrls|= map->ctrls;
else ctrls->enabled_ctrls&= ~map->ctrls;
if (old!=ctrls->enabled_ctrls) {
change->ctrls.changed_ctrls= XkbControlsEnabledMask;
change->ctrls.enabled_ctrls_changes= old^ctrls->enabled_ctrls;
ctrlChange= True;
}
}
state= &xkbi->state;
if ((map->groups)&&((map->which_groups&(~XkbIM_UseBase))!=0)) {
register int i;
register unsigned bit,match;
if (on) match= (map->groups)&XkbAllGroupsMask;
else match= (~map->groups)&XkbAllGroupsMask;
if (map->which_groups&(XkbIM_UseLocked|XkbIM_UseEffective)) {
for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
if (bit&match)
break;
}
if (map->which_groups&XkbIM_UseLatched)
XkbLatchGroup(xkbi->device,0); /* unlatch group */
state->locked_group= i;
stateChange= True;
}
else if (map->which_groups&(XkbIM_UseLatched|XkbIM_UseEffective)) {
for (i=0,bit=1;i<XkbNumKbdGroups;i++,bit<<=1) {
if (bit&match)
break;
}
state->locked_group= 0;
XkbLatchGroup(xkbi->device,i);
stateChange= True;
}
}
if ((map->mods.mask)&&((map->which_mods&(~XkbIM_UseBase))!=0)) {
if (map->which_mods&(XkbIM_UseLocked|XkbIM_UseEffective)) {
register unsigned long old;
old= state->locked_mods;
if (on) state->locked_mods|= map->mods.mask;
else state->locked_mods&= ~map->mods.mask;
if (state->locked_mods!=old)
stateChange= True;
}
if (map->which_mods&(XkbIM_UseLatched|XkbIM_UseEffective)) {
register unsigned long newmods;
newmods= state->latched_mods;
if (on) newmods|= map->mods.mask;
else newmods&= ~map->mods.mask;
if (newmods!=state->locked_mods) {
newmods&= map->mods.mask;
XkbLatchModifiers(xkbi->device,map->mods.mask,newmods);
stateChange= True;
}
}
}
return (stateChange || ctrlChange);
}
/***====================================================================***/
/*
* void
* XkbSetIndicators(dev,affect,values,cause)
*
* Attempts to change the indicators specified in 'affect' to the
* states specified in 'values' for the default keyboard feedback
* on the keyboard specified by 'dev.' Attempts to change indicator
* state might be ignored or have no affect, depending on the XKB
* indicator map for any affected indicators, as described in section
* 9.2 of the XKB protocol specification.
*
* If 'changes' is non-NULL, this function notes any changes to the
* keyboard state, controls, or indicator state that result from this
* attempted change. If 'changes' is NULL, this function generates
* XKB events to report any such changes to interested clients.
*
* If 'cause' is non-NULL, it specifies the reason for the change,
* as reported in some XKB events. If it is NULL, this function
* assumes that the change is the result of a core protocol
* ChangeKeyboardMapping request.
*/
void
#if NeedFunctionPrototypes
XkbSetIndicators( DeviceIntPtr dev,
CARD32 affect,
CARD32 values,
XkbEventCausePtr cause)
#else
XkbSetIndicators(dev,affect,values,cause)
DeviceIntPtr dev;
CARD32 affect;
CARD32 values;
XkbEventCausePtr cause;
#endif
{
XkbSrvLedInfoPtr sli;
XkbChangesRec changes;
xkbExtensionDeviceNotify ed;
unsigned side_affected;
bzero((char *)&changes,sizeof(XkbChangesRec));
bzero((char *)&ed,sizeof(xkbExtensionDeviceNotify));
sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0);
sli->explicitState&= ~affect;
sli->explicitState|= (affect&values);
XkbApplyLedStateChanges(dev,sli,affect,&ed,&changes,cause);
side_affected= 0;
if (changes.state_changes!=0)
side_affected|= XkbIndicatorsToUpdate(dev,changes.state_changes,False);
if (changes.ctrls.enabled_ctrls_changes)
side_affected|= sli->usesControls;
if (side_affected) {
XkbUpdateLedAutoState(dev,sli,side_affected,&ed,&changes,cause);
affect|= side_affected;
}
XkbSendNotification(dev,&changes,cause);
if (ed.reason)
XkbSendExtensionDeviceNotify(dev,cause->client,&ed);
if (changes.state_changes || changes.ctrls.enabled_ctrls_changes)
XkbUpdateAllDeviceIndicators(NULL,cause);
return;
}
/***====================================================================***/
/*
* Bool
* ComputeAutoState(map,state,ctrls)
*
* This function reports the effect of applying the specified
* indicator map given the specified state and controls, as
* described in section 9.2 of the XKB protocol specification.
*/
static Bool
#if NeedFunctionPrototypes
ComputeAutoState( XkbIndicatorMapPtr map,
XkbStatePtr state,
XkbControlsPtr ctrls)
#else
ComputeAutoState(map,state,ctrls)
XkbIndicatorMapPtr map;
XkbStatePtr state;
XkbControlsPtr ctrls;
#endif
{
Bool on;
CARD8 mods,group;
on= False;
mods= group= 0;
if (map->which_mods&XkbIM_UseAnyMods) {
if (map->which_mods&XkbIM_UseBase)
mods|= state->base_mods;
if (map->which_mods&XkbIM_UseLatched)
mods|= state->latched_mods;
if (map->which_mods&XkbIM_UseLocked)
mods|= state->locked_mods;
if (map->which_mods&XkbIM_UseEffective)
mods|= state->mods;
if (map->which_mods&XkbIM_UseCompat)
mods|= state->compat_state;
on = ((map->mods.mask&mods)!=0);
on = on||((mods==0)&&(map->mods.mask==0)&&(map->mods.vmods==0));
}
if (map->which_groups&XkbIM_UseAnyGroup) {
if (map->which_groups&XkbIM_UseBase)
group|= (1L << state->base_group);
if (map->which_groups&XkbIM_UseLatched)
group|= (1L << state->latched_group);
if (map->which_groups&XkbIM_UseLocked)
group|= (1L << state->locked_group);
if (map->which_groups&XkbIM_UseEffective)
group|= (1L << state->group);
on = on||(((map->groups&group)!=0)||(map->groups==0));
}
if (map->ctrls)
on = on||(ctrls->enabled_ctrls&map->ctrls);
return on;
}
/***====================================================================***/
/*
* void
* XkbUpdateIndicators(dev,update,check_edevs,changes,cause)
*
* Applies the indicator maps for any indicators specified in
* 'update' from the default keyboard feedback on the device
* specified by 'dev.'
*
* If 'changes' is NULL, this function generates and XKB events
* required to report the necessary changes, otherwise it simply
* notes the indicators with changed state.
*
* If 'check_edevs' is True, this function also checks the indicator
* maps for any open extension devices that have them, and updates
* the state of any extension device indicators as necessary.
*/
void
#if NeedFunctionPrototypes
XkbUpdateIndicators( DeviceIntPtr dev,
register CARD32 update,
Bool check_edevs,
XkbChangesPtr changes,
XkbEventCausePtr cause)
#else
XkbUpdateIndicators(dev,update,check_edevs,changes,cause)
DeviceIntPtr dev;
register CARD32 update;
Bool check_edevs;
XkbChangesPtr changes;
XkbEventCausePtr cause;
#endif
{
XkbSrvLedInfoPtr sli;
sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0);
XkbUpdateLedAutoState(dev,sli,update,NULL,changes,cause);
if (check_edevs)
XkbUpdateAllDeviceIndicators(changes,cause);
return;
}
/***====================================================================***/
void
#if NeedFunctionPrototypes
XkbUpdateAllDeviceIndicators(XkbChangesPtr changes,XkbEventCausePtr cause)
#else
XkbUpdateAllDeviceIndicators(changes,cause)
XkbChangesPtr changes;
XkbEventCausePtr cause;
#endif
{
DeviceIntPtr edev;
XkbSrvLedInfoPtr sli;
for (edev=inputInfo.devices;edev!=NULL;edev=edev->next) {
if (edev->kbdfeed) {
KbdFeedbackPtr kf;
for (kf=edev->kbdfeed;kf!=NULL;kf=kf->next) {
if ((kf->xkb_sli==NULL)||(kf->xkb_sli->maps==NULL))
continue;
sli= kf->xkb_sli;
XkbUpdateLedAutoState(edev,sli,sli->mapsPresent,NULL,
changes,cause);
}
}
if (edev->leds) {
LedFeedbackPtr lf;
for (lf=edev->leds;lf!=NULL;lf=lf->next) {
if ((lf->xkb_sli==NULL)||(lf->xkb_sli->maps==NULL))
continue;
sli= lf->xkb_sli;
XkbUpdateLedAutoState(edev,sli,sli->mapsPresent,NULL,
changes,cause);
}
}
}
return;
}
/***====================================================================***/
/*
* void
* XkbCheckIndicatorMaps(dev,sli,which)
*
* Updates the 'indicator accelerators' for the indicators specified
* by 'which' in the feedback specified by 'sli.' The indicator
* accelerators are internal to the server and are used to simplify
* and speed up the process of figuring out which indicators might
* be affected by a particular change in keyboard state or controls.
*/
void
#if NeedFunctionPrototypes
XkbCheckIndicatorMaps(DeviceIntPtr dev,XkbSrvLedInfoPtr sli,unsigned which)
#else
XkbCheckIndicatorMaps(dev,sli,which)
DeviceIntPtr dev;
XkbSrvLedInfoPtr sli;
unsigned which;
#endif
{
register unsigned i,bit;
XkbIndicatorMapPtr map;
XkbDescPtr xkb;
if ((sli->flags&XkbSLI_HasOwnState)==0)
dev= (DeviceIntPtr)LookupKeyboardDevice();
sli->usesBase&= ~which;
sli->usesLatched&= ~which;
sli->usesLocked&= ~which;
sli->usesEffective&= ~which;
sli->usesCompat&= ~which;
sli->usesControls&= ~which;
sli->mapsPresent&= ~which;
xkb= dev->key->xkbInfo->desc;
for (i=0,bit=1,map=sli->maps;i<XkbNumIndicators;i++,bit<<=1,map++) {
if (which&bit) {
CARD8 what;
if (!XkbIM_InUse(map))
continue;
sli->mapsPresent|= bit;
what= (map->which_mods|map->which_groups);
if (what&XkbIM_UseBase)
sli->usesBase|= bit;
if (what&XkbIM_UseLatched)
sli->usesLatched|= bit;
if (what&XkbIM_UseLocked)
sli->usesLocked|= bit;
if (what&XkbIM_UseEffective)
sli->usesEffective|= bit;
if (what&XkbIM_UseCompat)
sli->usesCompat|= bit;
if (map->ctrls)
sli->usesControls|= bit;
map->mods.mask= map->mods.real_mods;
if (map->mods.vmods!=0) {
map->mods.mask|= XkbMaskForVMask(xkb,map->mods.vmods);
}
}
}
sli->usedComponents= 0;
if (sli->usesBase)
sli->usedComponents|= XkbModifierBaseMask|XkbGroupBaseMask;
if (sli->usesLatched)
sli->usedComponents|= XkbModifierLatchMask|XkbGroupLatchMask;
if (sli->usesLocked)
sli->usedComponents|= XkbModifierLockMask|XkbGroupLockMask;
if (sli->usesEffective)
sli->usedComponents|= XkbModifierStateMask|XkbGroupStateMask;
if (sli->usesCompat)
sli->usedComponents|= XkbCompatStateMask;
return;
}
/***====================================================================***/
/*
* XkbSrvLedInfoPtr
* XkbAllocSrvLedInfo(dev,kf,lf,needed_parts)
*
* Allocates an XkbSrvLedInfoPtr for the feedback specified by either
* 'kf' or 'lf' on the keyboard specified by 'dev.'
*
* If 'needed_parts' is non-zero, this function makes sure that any
* of the parts speicified therein are allocated.
*/
XkbSrvLedInfoPtr
#if NeedFunctionPrototypes
XkbAllocSrvLedInfo( DeviceIntPtr dev,
KbdFeedbackPtr kf,
LedFeedbackPtr lf,
unsigned needed_parts)
#else
XkbAllocSrvLedInfo(dev,kf,lf,needed_parts)
DeviceIntPtr dev;
KbdFeedbackPtr kf;
LedFeedbackPtr lf;
unsigned needed_parts;
#endif
{
XkbSrvLedInfoPtr sli;
Bool checkAccel;
Bool checkNames;
sli= NULL;
checkAccel= checkNames= False;
if ((kf!=NULL)&&(kf->xkb_sli==NULL)) {
kf->xkb_sli= sli= _XkbTypedCalloc(1,XkbSrvLedInfoRec);
if (sli==NULL)
return NULL; /* ALLOCATION ERROR */
if (dev->key && dev->key->xkbInfo)
sli->flags= XkbSLI_HasOwnState;
else sli->flags= 0;
sli->class= KbdFeedbackClass;
sli->id= kf->ctrl.id;
sli->fb.kf= kf;
sli->autoState= 0;
sli->explicitState= kf->ctrl.leds;
sli->effectiveState= kf->ctrl.leds;
if ((kf==dev->kbdfeed) && (dev->key) && (dev->key->xkbInfo)) {
XkbDescPtr xkb;
xkb= dev->key->xkbInfo->desc;
sli->flags|= XkbSLI_IsDefault;
sli->physIndicators= xkb->indicators->phys_indicators;
sli->names= xkb->names->indicators;
sli->maps= xkb->indicators->maps;
checkNames= checkAccel= True;
}
else {
sli->physIndicators= XkbAllIndicatorsMask;
sli->names= NULL;
sli->maps= NULL;
}
}
else if ((kf!=NULL)&&((kf->xkb_sli->flags&XkbSLI_IsDefault)!=0)) {
XkbDescPtr xkb;
xkb= dev->key->xkbInfo->desc;
sli->physIndicators= xkb->indicators->phys_indicators;
if (xkb->names->indicators!=sli->names) {
checkNames= True;
sli->names= xkb->names->indicators;
}
if (xkb->indicators->maps!=sli->maps) {
checkAccel= True;
sli->maps= xkb->indicators->maps;
}
}
else if ((lf!=NULL)&&(lf->xkb_sli==NULL)) {
lf->xkb_sli= sli= _XkbTypedCalloc(1,XkbSrvLedInfoRec);
if (sli==NULL)
return NULL; /* ALLOCATION ERROR */
if (dev->key && dev->key->xkbInfo)
sli->flags= XkbSLI_HasOwnState;
else sli->flags= 0;
sli->class= LedFeedbackClass;
sli->id= lf->ctrl.id;
sli->fb.lf= lf;
sli->physIndicators= lf->ctrl.led_mask;
sli->autoState= 0;
sli->explicitState= lf->ctrl.led_values;
sli->effectiveState= lf->ctrl.led_values;
sli->maps= NULL;
sli->names= NULL;
}
if ((sli->names==NULL)&&(needed_parts&XkbXI_IndicatorNamesMask))
sli->names= _XkbTypedCalloc(XkbNumIndicators,Atom);
if ((sli->maps==NULL)&&(needed_parts&XkbXI_IndicatorMapsMask))
sli->maps= _XkbTypedCalloc(XkbNumIndicators,XkbIndicatorMapRec);
if (checkNames) {
register unsigned i,bit;
sli->namesPresent= 0;
for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
if (sli->names[i]!=None)
sli->namesPresent|= bit;
}
}
if (checkAccel)
XkbCheckIndicatorMaps(dev,sli,XkbAllIndicatorsMask);
return sli;
}
void
#if NeedFunctionPrototypes
XkbFreeSrvLedInfo(XkbSrvLedInfoPtr sli)
#else
XkbFreeSrvLedInfo(sli)
XkbSrvLedInfoPtr sli;
#endif
{
if ((sli->flags&XkbSLI_IsDefault)==0) {
if (sli->maps) _XkbFree(sli->maps);
if (sli->names) _XkbFree(sli->names);
}
sli->maps= NULL;
sli->names= NULL;
_XkbFree(sli);
return;
}
/***====================================================================***/
/*
* XkbSrvLedInfoPtr
* XkbFindSrvLedInfo(dev,class,id,needed_parts)
*
* Finds the XkbSrvLedInfoPtr for the specified 'class' and 'id'
* on the device specified by 'dev.' If the class and id specify
* a valid device feedback, this function returns the existing
* feedback or allocates a new one.
*
*/
XkbSrvLedInfoPtr
#if NeedFunctionPrototypes
XkbFindSrvLedInfo( DeviceIntPtr dev,
unsigned class,
unsigned id,
unsigned needed_parts)
#else
XkbFindSrvLedInfo(dev,class,id,needed_parts)
DeviceIntPtr dev;
unsigned class;
unsigned id;
unsigned needed_parts;
#endif
{
XkbSrvLedInfoPtr sli;
/* optimization to check for most common case */
if (((class==XkbDfltXIClass)&&(id==XkbDfltXIId))&&(dev->kbdfeed)) {
XkbSrvLedInfoPtr sli;
sli= dev->kbdfeed->xkb_sli;
if (dev->kbdfeed->xkb_sli==NULL) {
sli= XkbAllocSrvLedInfo(dev,dev->kbdfeed,NULL,needed_parts);
dev->kbdfeed->xkb_sli= sli;
}
return dev->kbdfeed->xkb_sli;
}
sli= NULL;
if (class==XkbDfltXIClass) {
if (dev->kbdfeed) class= KbdFeedbackClass;
else if (dev->leds) class= LedFeedbackClass;
else return NULL;
}
if (class==KbdFeedbackClass) {
KbdFeedbackPtr kf;
for (kf=dev->kbdfeed;kf!=NULL;kf=kf->next) {
if ((id==XkbDfltXIId)||(id==kf->ctrl.id)) {
if (kf->xkb_sli==NULL)
kf->xkb_sli= XkbAllocSrvLedInfo(dev,kf,NULL,needed_parts);
sli= kf->xkb_sli;
break;
}
}
}
else if (class==LedFeedbackClass) {
LedFeedbackPtr lf;
for (lf=dev->leds;lf!=NULL;lf=lf->next) {
if ((id==XkbDfltXIId)||(id==lf->ctrl.id)) {
if (lf->xkb_sli==NULL)
lf->xkb_sli= XkbAllocSrvLedInfo(dev,NULL,lf,needed_parts);
sli= lf->xkb_sli;
break;
}
}
}
if ((sli->names==NULL)&&(needed_parts&XkbXI_IndicatorNamesMask))
sli->names= _XkbTypedCalloc(XkbNumIndicators,Atom);
if ((sli->maps==NULL)&&(needed_parts&XkbXI_IndicatorMapsMask))
sli->maps= _XkbTypedCalloc(XkbNumIndicators,XkbIndicatorMapRec);
return sli;
}
/***====================================================================***/
void
#if NeedFunctionPrototypes
XkbFlushLedEvents( DeviceIntPtr dev,
DeviceIntPtr kbd,
XkbSrvLedInfoPtr sli,
xkbExtensionDeviceNotify * ed,
XkbChangesPtr changes,
XkbEventCausePtr cause)
#else
XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause)
DeviceIntPtr dev;
DeviceIntPtr kbd;
XkbSrvLedInfoPtr sli;
xkbExtensionDeviceNotify * ed;
XkbChangesPtr changes;
XkbEventCausePtr cause;
#endif
{
if (changes) {
if (changes->indicators.state_changes)
XkbDDXUpdateDeviceIndicators(dev,sli,sli->effectiveState);
XkbSendNotification(kbd,changes,cause);
bzero((char *)changes,sizeof(XkbChangesRec));
}
if (ed && (ed->reason)) {
if ((dev!=kbd)&&(ed->reason&XkbXI_IndicatorStateMask))
XkbDDXUpdateDeviceIndicators(dev,sli,sli->effectiveState);
XkbSendExtensionDeviceNotify(dev,cause->client,ed);
}
bzero((char *)ed,sizeof(XkbExtensionDeviceNotify));
return;
}
/***====================================================================***/
void
#if NeedFunctionPrototypes
XkbApplyLedNameChanges( DeviceIntPtr dev,
XkbSrvLedInfoPtr sli,
unsigned changed_names,
xkbExtensionDeviceNotify * ed,
XkbChangesPtr changes,
XkbEventCausePtr cause)
#else
XkbApplyLedNameChanges(dev,sli,changed_names,ed,changes,cause)
DeviceIntPtr dev;
XkbSrvLedInfoPtr sli;
unsigned changed_names;
xkbExtensionDeviceNotify * ed;
XkbChangesPtr changes;
XkbEventCausePtr cause;
#endif
{
DeviceIntPtr kbd;
XkbChangesRec my_changes;
xkbExtensionDeviceNotify my_ed;
if (changed_names==0)
return;
if (dev->key && dev->key->xkbInfo)
kbd= dev;
else kbd= (DeviceIntPtr)LookupKeyboardDevice();
if (ed==NULL) {
ed= &my_ed;
bzero((char *)ed,sizeof(xkbExtensionDeviceNotify));
}
else if ((ed->reason&XkbXI_IndicatorsMask)&&
((ed->ledClass!=sli->class)||(ed->ledID!=sli->id))) {
XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
}
if ((kbd==dev)&&(sli->flags&XkbSLI_IsDefault)) {
if (changes==NULL) {
changes= &my_changes;
bzero((char *)changes,sizeof(XkbChangesRec));
}
changes->names.changed|= XkbIndicatorNamesMask;
changes->names.changed_indicators|= changed_names;
}
ed->reason|= (XkbXI_IndicatorNamesMask&(~XkbXIUnsupported));
ed->ledClass= sli->class;
ed->ledID= sli->id;
ed->ledsDefined= sli->namesPresent|sli->mapsPresent;
ed->ledState= sli->effectiveState;
ed->unsupported|= XkbXIUnsupported&XkbXI_IndicatorNamesMask;
ed->supported= XkbXI_AllFeaturesMask&(~XkbXIUnsupported);
if (changes!=&my_changes) changes= NULL;
if (ed!=&my_ed) ed= NULL;
if (changes || ed)
XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
return;
}
/***====================================================================***/
/*
* void
* XkbApplyLedMapChanges(dev,sli,changed_maps,changes,cause)
*
* Handles all of the secondary effects of the changes to the
* feedback specified by 'sli' on the device specified by 'dev.'
*
* If 'changed_maps' specifies any indicators, this function generates
* XkbExtensionDeviceNotify events and possibly IndicatorMapNotify
* events to report the changes, and recalculates the effective
* state of each indicator with a changed map. If any indicators
* change state, the server generates XkbExtensionDeviceNotify and
* XkbIndicatorStateNotify events as appropriate.
*
* If 'changes' is non-NULL, this function updates it to reflect
* any changes to the keyboard state or controls or to the 'core'
* indicator names, maps, or state. If 'changes' is NULL, this
* function generates XKB events as needed to report the changes.
* If 'dev' is not a keyboard device, any changes are reported
* for the core keyboard.
*
* The 'cause' specifies the reason for the event (key event or
* request) for the change, as reported in some XKB events.
*/
void
#if NeedFunctionPrototypes
XkbApplyLedMapChanges( DeviceIntPtr dev,
XkbSrvLedInfoPtr sli,
unsigned changed_maps,
xkbExtensionDeviceNotify * ed,
XkbChangesPtr changes,
XkbEventCausePtr cause)
#else
XkbApplyLedMapChanges(dev,sli,changed_maps,ed,changes,cause)
DeviceIntPtr dev;
XkbSrvLedInfoPtr sli;
unsigned changed_maps;
xkbExtensionDeviceNotify * ed;
XkbChangesPtr changes;
XkbEventCausePtr cause;
#endif
{
DeviceIntPtr kbd;
XkbChangesRec my_changes;
xkbExtensionDeviceNotify my_ed;
if (changed_maps==0)
return;
if (dev->key && dev->key->xkbInfo)
kbd= dev;
else kbd= (DeviceIntPtr)LookupKeyboardDevice();
if (ed==NULL) {
ed= &my_ed;
bzero((char *)ed,sizeof(xkbExtensionDeviceNotify));
}
else if ((ed->reason&XkbXI_IndicatorsMask)&&
((ed->ledClass!=sli->class)||(ed->ledID!=sli->id))) {
XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
}
if ((kbd==dev)&&(sli->flags&XkbSLI_IsDefault)) {
if (changes==NULL) {
changes= &my_changes;
bzero((char *)changes,sizeof(XkbChangesRec));
}
changes->indicators.map_changes|= changed_maps;
}
XkbCheckIndicatorMaps(dev,sli,changed_maps);
ed->reason|= (XkbXI_IndicatorMapsMask&(~XkbXIUnsupported));
ed->ledClass= sli->class;
ed->ledID= sli->id;
ed->ledsDefined= sli->namesPresent|sli->mapsPresent;
ed->ledState= sli->effectiveState;
ed->unsupported|= XkbXIUnsupported&XkbXI_IndicatorMapsMask;
ed->supported= XkbXI_AllFeaturesMask&(~XkbXIUnsupported);
XkbUpdateLedAutoState(dev,sli,changed_maps,ed,changes,cause);
if (changes!=&my_changes) changes= NULL;
if (ed!=&my_ed) ed= NULL;
if (changes || ed)
XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
return;
}
/***====================================================================***/
void
#if NeedFunctionPrototypes
XkbApplyLedStateChanges(DeviceIntPtr dev,
XkbSrvLedInfoPtr sli,
unsigned changed_leds,
xkbExtensionDeviceNotify * ed,
XkbChangesPtr changes,
XkbEventCausePtr cause)
#else
XkbApplyLedStateChanges(dev,sli,changed_leds,ed,changes,cause)
DeviceIntPtr dev;
XkbSrvLedInfoPtr sli;
unsigned changed_leds;
xkbExtensionDeviceNotify * ed;
XkbChangesPtr changes;
XkbEventCausePtr cause;
#endif
{
XkbSrvInfoPtr xkbi;
DeviceIntPtr kbd;
XkbChangesRec my_changes;
xkbExtensionDeviceNotify my_ed;
register unsigned i,bit,affected;
XkbIndicatorMapPtr map;
unsigned oldState;
Bool kb_changed;
if (changed_leds==0)
return;
if (dev->key && dev->key->xkbInfo)
kbd= dev;
else kbd= (DeviceIntPtr)LookupKeyboardDevice();
xkbi= kbd->key->xkbInfo;
if (changes==NULL) {
changes= &my_changes;
bzero((char *)changes,sizeof(XkbChangesRec));
}
kb_changed= False;
affected= changed_leds;
oldState= sli->effectiveState;
for (i=0,bit=1;(i<XkbNumIndicators)&&(affected);i++,bit<<=1) {
if ((affected&bit)==0)
continue;
affected&= ~bit;
map= &sli->maps[i];
if (map->flags&XkbIM_NoExplicit) {
sli->explicitState&= ~bit;
continue;
}
if (map->flags&XkbIM_LEDDrivesKB) {
Bool on= ((sli->explicitState&bit)!=0);
if (XkbApplyLEDChangeToKeyboard(xkbi,map,on,changes))
kb_changed= True;
}
}
sli->effectiveState= (sli->autoState|sli->explicitState);
affected= sli->effectiveState^oldState;
if (ed==NULL) {
ed= &my_ed;
bzero((char *)ed,sizeof(xkbExtensionDeviceNotify));
}
else if (affected&&(ed->reason&XkbXI_IndicatorsMask)&&
((ed->ledClass!=sli->class)||(ed->ledID!=sli->id))) {
XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
}
if ((kbd==dev)&&(sli->flags&XkbSLI_IsDefault))
changes->indicators.state_changes|= affected;
if (affected) {
ed->reason|= (XkbXI_IndicatorStateMask&(~XkbXIUnsupported));
ed->ledClass= sli->class;
ed->ledID= sli->id;
ed->ledsDefined= sli->namesPresent|sli->mapsPresent;
ed->ledState= sli->effectiveState;
ed->unsupported|= XkbXIUnsupported&XkbXI_IndicatorStateMask;
ed->supported= XkbXI_AllFeaturesMask&(~XkbXIUnsupported);
}
if (kb_changed) {
XkbComputeDerivedState(kbd->key->xkbInfo);
XkbUpdateLedAutoState(dev,sli,sli->mapsPresent,ed,changes,cause);
}
if (changes!=&my_changes) changes= NULL;
if (ed!=&my_ed) ed= NULL;
if (changes || ed)
XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
if (kb_changed)
XkbUpdateAllDeviceIndicators(NULL,cause);
return;
}
/***====================================================================***/
void
#if NeedFunctionPrototypes
XkbUpdateLedAutoState( DeviceIntPtr dev,
XkbSrvLedInfoPtr sli,
unsigned maps_to_check,
xkbExtensionDeviceNotify * ed,
XkbChangesPtr changes,
XkbEventCausePtr cause)
#else
XkbUpdateLedAutoState(dev,sli,maps_to_check,ed,changes,cause)
DeviceIntPtr dev;
XkbSrvLedInfoPtr sli;
unsigned maps_to_check;
xkbExtensionDeviceNotify * ed;
XkbChangesPtr changes;
XkbEventCausePtr cause;
#endif
{
DeviceIntPtr kbd;
XkbStatePtr state;
XkbControlsPtr ctrls;
XkbChangesRec my_changes;
xkbExtensionDeviceNotify my_ed;
register unsigned i,bit,affected;
register XkbIndicatorMapPtr map;
unsigned oldState;
if ((maps_to_check==0)||(sli->maps==NULL)||(sli->mapsPresent==0))
return;
if (dev->key && dev->key->xkbInfo)
kbd= dev;
else kbd= (DeviceIntPtr)LookupKeyboardDevice();
state= &kbd->key->xkbInfo->state;
ctrls= kbd->key->xkbInfo->desc->ctrls;
affected= maps_to_check;
oldState= sli->effectiveState;
sli->autoState&= ~affected;
for (i=0,bit=1;(i<XkbNumIndicators)&&(affected);i++,bit<<=1) {
if ((affected&bit)==0)
continue;
affected&= ~bit;
map= &sli->maps[i];
if((!(map->flags&XkbIM_NoAutomatic))&&ComputeAutoState(map,state,ctrls))
sli->autoState|= bit;
}
sli->effectiveState= (sli->autoState|sli->explicitState);
affected= sli->effectiveState^oldState;
if (affected==0)
return;
if (ed==NULL) {
ed= &my_ed;
bzero((char *)ed,sizeof(xkbExtensionDeviceNotify));
}
else if ((ed->reason&XkbXI_IndicatorsMask)&&
((ed->ledClass!=sli->class)||(ed->ledID!=sli->id))) {
XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
}
if ((kbd==dev)&&(sli->flags&XkbSLI_IsDefault)) {
if (changes==NULL) {
changes= &my_changes;
bzero((char *)changes,sizeof(XkbChangesRec));
}
changes->indicators.state_changes|= affected;
}
ed->reason|= (XkbXI_IndicatorStateMask&(~XkbXIUnsupported));
ed->ledClass= sli->class;
ed->ledID= sli->id;
ed->ledsDefined= sli->namesPresent|sli->mapsPresent;
ed->ledState= sli->effectiveState;
ed->unsupported|= XkbXIUnsupported&XkbXI_IndicatorStateMask;
ed->supported= XkbXI_AllFeaturesMask&(~XkbXIUnsupported);
if (changes!=&my_changes) changes= NULL;
if (ed!=&my_ed) ed= NULL;
if (changes || ed)
XkbFlushLedEvents(dev,kbd,sli,ed,changes,cause);
return;
}
/***====================================================================***/
static void
#if NeedFunctionPrototypes
_UpdateButtonVMods( XkbDescPtr xkb,
unsigned num_btns,
XkbAction * acts,
unsigned changed,
xkbExtensionDeviceNotify * ed_inout)
#else
_UpdateButtonVMods(xkb,num_btns,acts,changed,ed_inout)
XkbDescPtr xkb;
unsigned num_btns;
XkbAction * acts;
unsigned changed;
xkbExtensionDeviceNotify * ed_inout;
#endif
{
register int i;
for (i=0;i<num_btns;i++,acts++) {
if ((acts->any.type!=XkbSA_NoAction)&&
XkbUpdateActionVirtualMods(xkb,acts,changed)) {
if ((ed_inout->reason&XkbXI_ButtonActionsMask)==0) {
ed_inout->reason|= XkbXI_ButtonActionsMask;
ed_inout->firstBtn= i;
ed_inout->nBtns= 1;
}
else {
ed_inout->nBtns= (i-ed_inout->firstBtn)+1;
}
}
}
return;
}
static void
#if NeedFunctionPrototypes
_UpdateMapVMods( XkbDescPtr xkb,
register XkbIndicatorMapPtr map,
unsigned changed_vmods,
unsigned * changed_maps_rtrn)
#else
_UpdateMapVMods(xkb,map,changed_vmods,changed_maps_rtrn)
XkbDescPtr xkb;
register XkbIndicatorMapPtr map;
unsigned changed_vmods;
unsigned * changed_maps_rtrn;
#endif
{
register int i;
*changed_maps_rtrn= 0;
for (i=0;i<XkbNumIndicators;i++,map++) {
if (map->mods.vmods&changed_vmods) {
map->mods.mask= map->mods.real_mods;
map->mods.mask|= XkbMaskForVMask(xkb,map->mods.vmods);
*changed_maps_rtrn|= (1L<<i);
}
}
return;
}
static void
#if NeedFunctionPrototypes
_UpdateDeviceVMods( DeviceIntPtr dev,
XkbDescPtr xkb,
unsigned changed,
XkbEventCausePtr cause)
#else
_UpdateDeviceVMods(dev,xkb,changed,cause)
DeviceIntPtr dev;
XkbDescPtr xkb;
unsigned changed;
XkbEventCausePtr cause;
#endif
{
xkbExtensionDeviceNotify ed;
XkbSrvLedInfoPtr sli;
unsigned changed_maps;
bzero((char *)&ed,sizeof(xkbExtensionDeviceNotify));
ed.deviceID= dev->id;
if ((dev->button)&&(dev->button->xkb_acts)) {
_UpdateButtonVMods(xkb,dev->button->numButtons,
dev->button->xkb_acts,changed,&ed);
}
if (dev->kbdfeed) {
KbdFeedbackPtr kf;
for (kf=dev->kbdfeed;kf!=NULL;kf=kf->next) {
if ((kf->xkb_sli==NULL)||(kf->xkb_sli->maps==NULL))
continue;
sli= kf->xkb_sli;
_UpdateMapVMods(xkb,sli->maps,changed,&changed_maps);
if (changed_maps) {
if (ed.reason&XkbXI_IndicatorsMask) {
XkbSendExtensionDeviceNotify(dev,NULL,&ed);
ed.reason= 0;
ed.firstBtn= ed.nBtns;
}
ed.ledClass= sli->class;
ed.ledID= sli->id;
ed.ledsDefined= sli->namesPresent|sli->mapsPresent;
ed.reason|= XkbXI_IndicatorMapsMask;
XkbUpdateLedAutoState(dev,sli,changed_maps,&ed,NULL,cause);
}
}
}
if (dev->leds) {
LedFeedbackPtr lf;
for (lf=dev->leds;lf!=NULL;lf=lf->next) {
if ((lf->xkb_sli==NULL)||(lf->xkb_sli->maps==NULL))
continue;
sli= lf->xkb_sli;
_UpdateMapVMods(xkb,sli->maps,changed,&changed_maps);
if (changed_maps) {
if (ed.reason&XkbXI_IndicatorsMask) {
XkbSendExtensionDeviceNotify(dev,NULL,&ed);
ed.reason= 0;
ed.firstBtn= ed.nBtns;
}
ed.ledClass= sli->class;
ed.ledID= sli->id;
ed.ledsDefined= sli->namesPresent|sli->mapsPresent;
ed.reason|= XkbXI_IndicatorMapsMask;
XkbUpdateLedAutoState(dev,sli,changed_maps,&ed,NULL,cause);
}
}
}
if (ed.reason!=0)
XkbSendExtensionDeviceNotify(dev,NULL,&ed);
return;
}
void
#if NeedFunctionPrototypes
XkbApplyVModChangesToAllDevices( DeviceIntPtr dev,
XkbDescPtr xkb,
unsigned changed,
XkbEventCausePtr cause)
#else
XkbApplyVModChangesToAllDevices(dev,xkb,changed,cause)
DeviceIntPtr dev;
XkbDescPtr xkb;
unsigned changed;
XkbEventCausePtr cause;
#endif
{
DeviceIntPtr edev;
if (dev!=(DeviceIntPtr)LookupKeyboardDevice())
return;
for (edev=inputInfo.devices;edev!=NULL;edev=edev->next) {
if (edev->key)
continue;
_UpdateDeviceVMods(edev,xkb,changed,cause);
}
for (edev=inputInfo.off_devices;edev!=NULL;edev=edev->next) {
if (edev->key)
continue;
_UpdateDeviceVMods(edev,xkb,changed,cause);
}
return;
}
|