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
|
/************************************************************
* Copyright (c) 1994 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 "xkbcomp-priv.h"
#include "text.h"
#include "expr.h"
#include "action.h"
#include "keycodes.h"
static const ExprDef constTrue = {
.common = { .type = STMT_EXPR, .next = NULL },
.op = EXPR_VALUE,
.value_type = EXPR_TYPE_BOOLEAN,
.value = { .ival = 1 },
};
static const ExprDef constFalse = {
.common = { .type = STMT_EXPR, .next = NULL },
.op = EXPR_VALUE,
.value_type = EXPR_TYPE_BOOLEAN,
.value = { .ival = 0 },
};
enum action_field {
ACTION_FIELD_CLEAR_LOCKS,
ACTION_FIELD_LATCH_TO_LOCK,
ACTION_FIELD_GEN_KEY_EVENT,
ACTION_FIELD_REPORT,
ACTION_FIELD_DEFAULT,
ACTION_FIELD_AFFECT,
ACTION_FIELD_INCREMENT,
ACTION_FIELD_MODIFIERS,
ACTION_FIELD_GROUP,
ACTION_FIELD_X,
ACTION_FIELD_Y,
ACTION_FIELD_ACCEL,
ACTION_FIELD_BUTTON,
ACTION_FIELD_VALUE,
ACTION_FIELD_CONTROLS,
ACTION_FIELD_TYPE,
ACTION_FIELD_COUNT,
ACTION_FIELD_SCREEN,
ACTION_FIELD_SAME,
ACTION_FIELD_DATA,
ACTION_FIELD_DEVICE,
ACTION_FIELD_KEYCODE,
ACTION_FIELD_MODS_TO_CLEAR,
};
ActionsInfo *
NewActionsInfo(void)
{
unsigned type;
ActionsInfo *info;
info = calloc(1, sizeof(*info));
if (!info)
return NULL;
/* This includes PrivateAction. */
for (type = 0; type < ACTION_TYPE_LAST; type++)
info->actions[type].type = type;
/* Apply some "factory defaults". */
/* Increment default button. */
info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.flags = 0;
info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.value = 1;
return info;
}
void
FreeActionsInfo(ActionsInfo *info)
{
free(info);
}
static const LookupEntry fieldStrings[] = {
{ "clearLocks", ACTION_FIELD_CLEAR_LOCKS },
{ "latchToLock", ACTION_FIELD_LATCH_TO_LOCK },
{ "genKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
{ "generateKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
{ "report", ACTION_FIELD_REPORT },
{ "default", ACTION_FIELD_DEFAULT },
{ "affect", ACTION_FIELD_AFFECT },
{ "increment", ACTION_FIELD_INCREMENT },
{ "modifiers", ACTION_FIELD_MODIFIERS },
{ "mods", ACTION_FIELD_MODIFIERS },
{ "group", ACTION_FIELD_GROUP },
{ "x", ACTION_FIELD_X },
{ "y", ACTION_FIELD_Y },
{ "accel", ACTION_FIELD_ACCEL },
{ "accelerate", ACTION_FIELD_ACCEL },
{ "repeat", ACTION_FIELD_ACCEL },
{ "button", ACTION_FIELD_BUTTON },
{ "value", ACTION_FIELD_VALUE },
{ "controls", ACTION_FIELD_CONTROLS },
{ "ctrls", ACTION_FIELD_CONTROLS },
{ "type", ACTION_FIELD_TYPE },
{ "count", ACTION_FIELD_COUNT },
{ "screen", ACTION_FIELD_SCREEN },
{ "same", ACTION_FIELD_SAME },
{ "sameServer", ACTION_FIELD_SAME },
{ "data", ACTION_FIELD_DATA },
{ "device", ACTION_FIELD_DEVICE },
{ "dev", ACTION_FIELD_DEVICE },
{ "key", ACTION_FIELD_KEYCODE },
{ "keycode", ACTION_FIELD_KEYCODE },
{ "kc", ACTION_FIELD_KEYCODE },
{ "clearmods", ACTION_FIELD_MODS_TO_CLEAR },
{ "clearmodifiers", ACTION_FIELD_MODS_TO_CLEAR },
{ NULL, 0 }
};
static bool
stringToAction(const char *str, unsigned *type_rtrn)
{
return LookupString(actionTypeNames, str, type_rtrn);
}
static bool
stringToField(const char *str, enum action_field *field_rtrn)
{
return LookupString(fieldStrings, str, field_rtrn);
}
static const char *
fieldText(enum action_field field)
{
return LookupValue(fieldStrings, field);
}
/***====================================================================***/
static inline bool
ReportMismatch(struct xkb_keymap *keymap, enum xkb_action_type action,
enum action_field field, const char *type)
{
log_err(keymap->ctx,
"Value of %s field must be of type %s; "
"Action %s definition ignored\n",
fieldText(field), type, ActionTypeText(action));
return false;
}
static inline bool
ReportIllegal(struct xkb_keymap *keymap, enum xkb_action_type action,
enum action_field field)
{
log_err(keymap->ctx,
"Field %s is not defined for an action of type %s; "
"Action definition ignored\n",
fieldText(field), ActionTypeText(action));
return false;
}
static inline bool
ReportActionNotArray(struct xkb_keymap *keymap, enum xkb_action_type action,
enum action_field field)
{
log_err(keymap->ctx,
"The %s field in the %s action is not an array; "
"Action definition ignored\n",
fieldText(field), ActionTypeText(action));
return false;
}
static inline bool
ReportNotFound(struct xkb_keymap *keymap, enum xkb_action_type action,
enum action_field field, const char *what, const char *bad)
{
log_err(keymap->ctx,
"%s named %s not found; "
"Ignoring the %s field of an %s action\n",
what, bad, fieldText(field), ActionTypeText(action));
return false;
}
static bool
HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
return true;
}
static bool
CheckLatchLockFlags(struct xkb_keymap *keymap, enum xkb_action_type action,
enum action_field field, const ExprDef * value,
enum xkb_action_flags *flags_inout)
{
enum xkb_action_flags tmp;
bool result;
if (field == ACTION_FIELD_CLEAR_LOCKS)
tmp = ACTION_LOCK_CLEAR;
else if (field == ACTION_FIELD_LATCH_TO_LOCK)
tmp = ACTION_LATCH_TO_LOCK;
else
return false; /* WSGO! */
if (!ExprResolveBoolean(keymap->ctx, value, &result))
return ReportMismatch(keymap, action, field, "boolean");
if (result)
*flags_inout |= tmp;
else
*flags_inout &= ~tmp;
return true;
}
static bool
CheckModifierField(struct xkb_keymap *keymap, enum xkb_action_type action,
const ExprDef *value, enum xkb_action_flags *flags_inout,
xkb_mod_mask_t *mods_rtrn)
{
if (value->op == EXPR_IDENT) {
const char *valStr;
valStr = xkb_atom_text(keymap->ctx, value->value.str);
if (valStr && (istreq(valStr, "usemodmapmods") ||
istreq(valStr, "modmapmods"))) {
*mods_rtrn = 0;
*flags_inout |= ACTION_MODS_LOOKUP_MODMAP;
return true;
}
}
if (!ExprResolveVModMask(keymap, value, mods_rtrn))
return ReportMismatch(keymap, action,
ACTION_FIELD_MODIFIERS, "modifier mask");
*flags_inout &= ~ACTION_MODS_LOOKUP_MODMAP;
return true;
}
static bool
HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_mod_action *act = &action->mods;
enum xkb_action_flags rtrn, t1;
xkb_mod_mask_t t2;
if (array_ndx != NULL) {
switch (field) {
case ACTION_FIELD_CLEAR_LOCKS:
case ACTION_FIELD_LATCH_TO_LOCK:
case ACTION_FIELD_MODIFIERS:
return ReportActionNotArray(keymap, action->type, field);
default:
break;
}
}
switch (field) {
case ACTION_FIELD_CLEAR_LOCKS:
case ACTION_FIELD_LATCH_TO_LOCK:
rtrn = act->flags;
if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
act->flags = rtrn;
return true;
}
return false;
case ACTION_FIELD_MODIFIERS:
t1 = act->flags;
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1;
act->mods.mods = t2;
return true;
}
return false;
default:
break;
}
return ReportIllegal(keymap, action->type, field);
}
static bool
HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_mod_action *act = &action->mods;
enum xkb_action_flags t1;
xkb_mod_mask_t t2;
if (array_ndx && field == ACTION_FIELD_MODIFIERS)
return ReportActionNotArray(keymap, action->type, field);
switch (field) {
case ACTION_FIELD_MODIFIERS:
t1 = act->flags;
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1;
act->mods.mods = t2;
return true;
}
return false;
default:
break;
}
return ReportIllegal(keymap, action->type, field);
}
static bool
CheckGroupField(struct xkb_keymap *keymap, unsigned action,
const ExprDef *value, enum xkb_action_flags *flags_inout,
xkb_group_index_t *grp_rtrn)
{
const ExprDef *spec;
if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
*flags_inout &= ~ACTION_ABSOLUTE_SWITCH;
spec = value->value.child;
}
else {
*flags_inout |= ACTION_ABSOLUTE_SWITCH;
spec = value;
}
if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
return ReportMismatch(keymap, action, ACTION_FIELD_GROUP,
"integer (range 1..8)");
if (value->op == EXPR_NEGATE)
*grp_rtrn = -*grp_rtrn;
else if (value->op != EXPR_UNARY_PLUS)
(*grp_rtrn)--;
return true;
}
static bool
HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_group_action *act = &action->group;
enum xkb_action_flags rtrn, t1;
xkb_group_index_t t2;
if (array_ndx != NULL) {
switch (field) {
case ACTION_FIELD_CLEAR_LOCKS:
case ACTION_FIELD_LATCH_TO_LOCK:
case ACTION_FIELD_GROUP:
return ReportActionNotArray(keymap, action->type, field);
default:
break;
}
}
switch (field) {
case ACTION_FIELD_CLEAR_LOCKS:
case ACTION_FIELD_LATCH_TO_LOCK:
rtrn = act->flags;
if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
act->flags = rtrn;
return true;
}
return false;
case ACTION_FIELD_GROUP:
t1 = act->flags;
if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1;
act->group = t2;
return true;
}
return false;
default:
break;
}
return ReportIllegal(keymap, action->type, field);
}
static bool
HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_group_action *act = &action->group;
enum xkb_action_flags t1;
xkb_group_index_t t2;
if ((array_ndx != NULL) && (field == ACTION_FIELD_GROUP))
return ReportActionNotArray(keymap, action->type, field);
if (field == ACTION_FIELD_GROUP) {
t1 = act->flags;
if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1;
act->group = t2;
return true;
}
return false;
}
return ReportIllegal(keymap, action->type, field);
}
static bool
HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_pointer_action *act = &action->ptr;
bool absolute;
if (array_ndx && (field == ACTION_FIELD_X || field == ACTION_FIELD_Y))
return ReportActionNotArray(keymap, action->type, field);
if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) {
int val;
if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
absolute = false;
else
absolute = true;
if (!ExprResolveInteger(keymap->ctx, value, &val))
return ReportMismatch(keymap, action->type, field, "integer");
if (field == ACTION_FIELD_X) {
if (absolute)
act->flags |= ACTION_ABSOLUTE_X;
act->x = val;
}
else {
if (absolute)
act->flags |= ACTION_ABSOLUTE_Y;
act->y = val;
}
return true;
}
else if (field == ACTION_FIELD_ACCEL) {
bool set;
if (!ExprResolveBoolean(keymap->ctx, value, &set))
return ReportMismatch(keymap, action->type, field, "boolean");
if (set)
act->flags &= ~ACTION_NO_ACCEL;
else
act->flags |= ACTION_NO_ACCEL;
}
return ReportIllegal(keymap, action->type, field);
}
static const LookupEntry lockWhich[] = {
{ "both", 0 },
{ "lock", ACTION_LOCK_NO_UNLOCK },
{ "neither", (ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK) },
{ "unlock", ACTION_LOCK_NO_LOCK },
{ NULL, 0 }
};
static bool
HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_pointer_button_action *act = &action->btn;
if (field == ACTION_FIELD_BUTTON) {
int btn;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveButton(keymap->ctx, value, &btn))
return ReportMismatch(keymap, action->type, field,
"integer (range 1..5)");
if (btn < 0 || btn > 5) {
log_err(keymap->ctx,
"Button must specify default or be in the range 1..5; "
"Illegal button value %d ignored\n", btn);
return false;
}
act->button = btn;
return true;
}
else if (action->type == ACTION_TYPE_PTR_LOCK &&
field == ACTION_FIELD_AFFECT) {
enum xkb_action_flags val;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
return ReportMismatch(keymap, action->type, field,
"lock or unlock");
act->flags &= ~(ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK);
act->flags |= val;
return true;
}
else if (field == ACTION_FIELD_COUNT) {
int btn;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field);
/* XXX: Should this actually be ResolveButton? */
if (!ExprResolveButton(keymap->ctx, value, &btn))
return ReportMismatch(keymap, action->type, field, "integer");
if (btn < 0 || btn > 255) {
log_err(keymap->ctx,
"The count field must have a value in the range 0..255; "
"Illegal count %d ignored\n", btn);
return false;
}
act->count = btn;
return true;
}
return ReportIllegal(keymap, action->type, field);
}
static const LookupEntry ptrDflts[] = {
{ "dfltbtn", 1 },
{ "defaultbutton", 1 },
{ "button", 1 },
{ NULL, 0 }
};
static bool
HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_pointer_default_action *act = &action->dflt;
if (field == ACTION_FIELD_AFFECT) {
unsigned int val;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
return ReportMismatch(keymap, action->type, field,
"pointer component");
return true;
}
else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
const ExprDef *button;
int btn;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field);
if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
act->flags &= ~ACTION_ABSOLUTE_SWITCH;
button = value->value.child;
}
else {
act->flags |= ACTION_ABSOLUTE_SWITCH;
button = value;
}
if (!ExprResolveButton(keymap->ctx, button, &btn))
return ReportMismatch(keymap, action->type, field,
"integer (range 1..5)");
if (btn < 0 || btn > 5) {
log_err(keymap->ctx,
"New default button value must be in the range 1..5; "
"Illegal default button value %d ignored\n", btn);
return false;
}
if (btn == 0) {
log_err(keymap->ctx,
"Cannot set default pointer button to \"default\"; "
"Illegal default button setting ignored\n");
return false;
}
act->value = (value->op == EXPR_NEGATE ? -btn: btn);
return true;
}
return ReportIllegal(keymap, action->type, field);
}
static bool
HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_switch_screen_action *act = &action->screen;
if (field == ACTION_FIELD_SCREEN) {
const ExprDef *scrn;
int val;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field);
if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
act->flags &= ~ACTION_ABSOLUTE_SWITCH;
scrn = value->value.child;
}
else {
act->flags |= ACTION_ABSOLUTE_SWITCH;
scrn = value;
}
if (!ExprResolveInteger(keymap->ctx, scrn, &val))
return ReportMismatch(keymap, action->type, field,
"integer (0..255)");
if (val < 0 || val > 255) {
log_err(keymap->ctx,
"Screen index must be in the range 1..255; "
"Illegal screen value %d ignored\n", val);
return false;
}
act->screen = (value->op == EXPR_NEGATE ? -val : val);
return true;
}
else if (field == ACTION_FIELD_SAME) {
bool set;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveBoolean(keymap->ctx, value, &set))
return ReportMismatch(keymap, action->type, field, "boolean");
if (set)
act->flags &= ~ACTION_SAME_SCREEN;
else
act->flags |= ACTION_SAME_SCREEN;
return true;
}
return ReportIllegal(keymap, action->type, field);
}
static bool
HandleSetLockControls(struct xkb_keymap *keymap, union xkb_action *action,
enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_controls_action *act = &action->ctrls;
if (field == ACTION_FIELD_CONTROLS) {
unsigned int mask;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlMaskNames))
return ReportMismatch(keymap, action->type, field,
"controls mask");
act->ctrls = mask;
return true;
}
return ReportIllegal(keymap, action->type, field);
}
static bool
HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_private_action *act = &action->priv;
if (field == ACTION_FIELD_TYPE) {
int type;
if (!ExprResolveInteger(keymap->ctx, value, &type))
return ReportMismatch(keymap, ACTION_TYPE_PRIVATE, field, "integer");
if (type < 0 || type > 255) {
log_err(keymap->ctx,
"Private action type must be in the range 0..255; "
"Illegal type %d ignored\n", type);
return false;
}
act->type = (uint8_t) type;
return true;
}
else if (field == ACTION_FIELD_DATA) {
if (array_ndx == NULL) {
xkb_atom_t val;
const char *str;
int len;
if (!ExprResolveString(keymap->ctx, value, &val))
return ReportMismatch(keymap, action->type, field, "string");
str = xkb_atom_text(keymap->ctx, val);
len = strlen(str);
if (len < 1 || len > 7) {
log_warn(keymap->ctx,
"A private action has 7 data bytes; "
"Extra %d bytes ignored\n", len - 6);
return false;
}
strncpy((char *) act->data, str, sizeof(act->data));
return true;
}
else {
int ndx, datum;
if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
log_err(keymap->ctx,
"Array subscript must be integer; "
"Illegal subscript ignored\n");
return false;
}
if (ndx < 0 || ndx >= sizeof(act->data)) {
log_err(keymap->ctx,
"The data for a private action is %zu bytes long; "
"Attempt to use data[%d] ignored\n",
sizeof(act->data), ndx);
return false;
}
if (!ExprResolveInteger(keymap->ctx, value, &datum))
return ReportMismatch(keymap, act->type, field, "integer");
if (datum < 0 || datum > 255) {
log_err(keymap->ctx,
"All data for a private action must be 0..255; "
"Illegal datum %d ignored\n", datum);
return false;
}
act->data[ndx] = (uint8_t) datum;
return true;
}
}
return ReportIllegal(keymap, ACTION_TYPE_NONE, field);
}
typedef bool (*actionHandler)(struct xkb_keymap *keymap,
union xkb_action *action,
enum action_field field,
const ExprDef *array_ndx,
const ExprDef *value);
static const actionHandler handleAction[ACTION_TYPE_LAST] = {
[ACTION_TYPE_NONE] = HandleNoAction,
[ACTION_TYPE_MOD_SET] = HandleSetLatchMods,
[ACTION_TYPE_MOD_LATCH] = HandleSetLatchMods,
[ACTION_TYPE_MOD_LOCK] = HandleLockMods,
[ACTION_TYPE_GROUP_SET] = HandleSetLatchGroup,
[ACTION_TYPE_GROUP_LATCH] = HandleSetLatchGroup,
[ACTION_TYPE_GROUP_LOCK] = HandleLockGroup,
[ACTION_TYPE_PTR_MOVE] = HandleMovePtr,
[ACTION_TYPE_PTR_BUTTON] = HandlePtrBtn,
[ACTION_TYPE_PTR_LOCK] = HandlePtrBtn,
[ACTION_TYPE_PTR_DEFAULT] = HandleSetPtrDflt,
[ACTION_TYPE_TERMINATE] = HandleNoAction,
[ACTION_TYPE_SWITCH_VT] = HandleSwitchScreen,
[ACTION_TYPE_CTRL_SET] = HandleSetLockControls,
[ACTION_TYPE_CTRL_LOCK] = HandleSetLockControls,
[ACTION_TYPE_PRIVATE] = HandlePrivate,
};
/***====================================================================***/
bool
HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
union xkb_action *action, ActionsInfo *info)
{
ExprDef *arg;
const char *str;
unsigned hndlrType;
if (def->op != EXPR_ACTION_DECL) {
log_err(keymap->ctx, "Expected an action definition, found %s\n",
expr_op_type_to_string(def->op));
return false;
}
str = xkb_atom_text(keymap->ctx, def->value.action.name);
if (!stringToAction(str, &hndlrType)) {
log_err(keymap->ctx, "Unknown action %s\n", str);
return false;
}
/*
* Get the default values for this action type, as modified by
* statements such as:
* latchMods.clearLocks = True;
*/
*action = info->actions[hndlrType];
/*
* Now change the action properties as specified for this
* particular instance, e.g. "modifiers" and "clearLocks" in:
* SetMods(modifiers=Alt,clearLocks);
*/
for (arg = def->value.action.args; arg != NULL;
arg = (ExprDef *) arg->common.next) {
const ExprDef *value;
ExprDef *field, *arrayRtrn;
const char *elemRtrn, *fieldRtrn;
enum action_field fieldNdx;
if (arg->op == EXPR_ASSIGN) {
field = arg->value.binary.left;
value = arg->value.binary.right;
}
else if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
field = arg->value.child;
value = &constFalse;
}
else {
field = arg;
value = &constTrue;
}
if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
&arrayRtrn))
return false;
if (elemRtrn) {
log_err(keymap->ctx,
"Cannot change defaults in an action definition; "
"Ignoring attempt to change %s.%s\n",
elemRtrn, fieldRtrn);
return false;
}
if (!stringToField(fieldRtrn, &fieldNdx)) {
log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
return false;
}
if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
value))
return false;
}
return true;
}
bool
SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
ExprDef *array_ndx, ExprDef *value, ActionsInfo *info)
{
unsigned action;
enum action_field action_field;
if (!stringToAction(elem, &action))
return false;
if (!stringToField(field, &action_field)) {
log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
return false;
}
return handleAction[action](keymap, &info->actions[action],
action_field, array_ndx, value);
}
|