summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorculler <culler>2017-12-05 15:51:53 (GMT)
committerculler <culler>2017-12-05 15:51:53 (GMT)
commitb50aa41fd509b6e0829da869f3e3fbd4f34e1307 (patch)
tree70b2a8cebae6dbc73c981ae78728319ffddd5cdd
parent2bf5f6b8191034e185f6bd6ea8cba07146900649 (diff)
parentde0eaeebac1635a66b66ca05dca003f1dad2243a (diff)
downloadtk-b50aa41fd509b6e0829da869f3e3fbd4f34e1307.zip
tk-b50aa41fd509b6e0829da869f3e3fbd4f34e1307.tar.gz
tk-b50aa41fd509b6e0829da869f3e3fbd4f34e1307.tar.bz2
Merge core-8-6-branch into trunk. Fixes [1088805fff]. See [0feb63f139]
for explanations.
-rw-r--r--generic/tkBind.c9
-rw-r--r--macosx/tkMacOSXKeyboard.c56
-rw-r--r--tests/bind.test29
3 files changed, 77 insertions, 17 deletions
diff --git a/generic/tkBind.c b/generic/tkBind.c
index e0cc1ca..839670a 100644
--- a/generic/tkBind.c
+++ b/generic/tkBind.c
@@ -1738,9 +1738,10 @@ MatchPatterns(
}
if (psPtr->flags & PAT_NEARBY) {
XEvent *firstPtr = &bindPtr->eventRing[bindPtr->curEvent];
- int timeDiff;
+ long timeDiff;
- timeDiff = (Time) firstPtr->xkey.time - eventPtr->xkey.time;
+ timeDiff = ((long)firstPtr->xkey.time -
+ (long)eventPtr->xkey.time);
if ((firstPtr->xkey.x_root
< (eventPtr->xkey.x_root - NEARBY_PIXELS))
|| (firstPtr->xkey.x_root
@@ -3333,9 +3334,9 @@ HandleEventGenerate(
return TCL_ERROR;
}
if (flags & KEY_BUTTON_MOTION_CROSSING) {
- event.general.xkey.time = (Time) number;
+ event.general.xkey.time = number;
} else if (flags & PROP) {
- event.general.xproperty.time = (Time) number;
+ event.general.xproperty.time = number;
} else {
goto badopt;
}
diff --git a/macosx/tkMacOSXKeyboard.c b/macosx/tkMacOSXKeyboard.c
index bbbbf96..1abbbba 100644
--- a/macosx/tkMacOSXKeyboard.c
+++ b/macosx/tkMacOSXKeyboard.c
@@ -96,6 +96,24 @@ static KeyInfo virtualkeyArray[] = {
{0, 0}
};
+#define NUM_MOD_KEYCODES 14
+static KeyCode modKeyArray[NUM_MOD_KEYCODES] = {
+ XK_Shift_L,
+ XK_Shift_R,
+ XK_Control_L,
+ XK_Control_R,
+ XK_Caps_Lock,
+ XK_Shift_Lock,
+ XK_Meta_L,
+ XK_Meta_R,
+ XK_Alt_L,
+ XK_Alt_R,
+ XK_Super_L,
+ XK_Super_R,
+ XK_Hyper_L,
+ XK_Hyper_R,
+};
+
static int initialized = 0;
static Tcl_HashTable keycodeTable; /* keyArray hashed by keycode value. */
static Tcl_HashTable vkeyTable; /* virtualkeyArray hashed by virtual
@@ -457,7 +475,6 @@ XGetModifierMapping(
* MacOSX doesn't use the key codes for the modifiers for anything, and we
* don't generate them either. So there is no modifier map.
*/
-
modmap = ckalloc(sizeof(XModifierKeymap));
modmap->max_keypermod = 0;
modmap->modifiermap = NULL;
@@ -548,7 +565,6 @@ XKeysymToMacKeycode(
KeySym keysym)
{
KeyInfo *kPtr;
-
if (keysym <= LATIN1_MAX) {
/*
* Handle keysyms in the Latin-1 range where keysym and Unicode
@@ -580,6 +596,17 @@ XKeysymToMacKeycode(
}
/*
+ * Modifier keycodes only come from generated events. No translation
+ * is needed.
+ */
+
+ for (int i=0; i < NUM_MOD_KEYCODES; i++) {
+ if (keysym == modKeyArray[i]) {
+ return keysym;
+ }
+ }
+
+ /*
* For other keysyms (not Latin-1 and not special keys), we'd need a
* generic keysym-to-unicode table. We don't have that, so we give up here.
*/
@@ -661,6 +688,13 @@ TkpSetKeycodeAndState(
{
if (keysym == NoSymbol) {
eventPtr->xkey.keycode = 0;
+ } else if ( modKeyArray[0] <= keysym &&
+ keysym <= modKeyArray[NUM_MOD_KEYCODES - 1]) {
+ /*
+ * Keysyms for pure modifiers only arise in generated events.
+ * We should just copy them to the keycode.
+ */
+ eventPtr->xkey.keycode = keysym;
} else {
Display *display = Tk_Display(tkwin);
int macKeycode = XKeysymToMacKeycode(display, keysym);
@@ -668,7 +702,6 @@ TkpSetKeycodeAndState(
/*
* See also XKeysymToKeycode.
*/
-
if ((keysym >= XK_F1) && (keysym <= XK_F35)) {
eventPtr->xkey.keycode = 0x0010;
} else {
@@ -734,7 +767,6 @@ TkpGetKeySym(
*/
if (eventPtr->xany.send_event == -1) {
-
int modifier = eventPtr->xkey.keycode & NSDeviceIndependentModifierFlagsMask;
if (modifier == NSCommandKeyMask) {
@@ -891,18 +923,20 @@ TkpInitKeymapInfo(
#endif
/*
- * MacOSX doesn't use the keycodes for the modifiers for anything, and we
- * don't generate them either (the keycodes actually given in the simulated
- * modifier events are bogus). So there is no modifier map. If we ever want
- * to simulate real modifier keycodes, the list will be constant in the
- * Carbon implementation.
+ * MacOSX doesn't create a key event when a modifier key is pressed or
+ * released. However, it is possible to generate key events for
+ * modifier keys, and this is done in the tests. So we construct an array
+ * containing the keycodes of the standard modifier keys from static data.
*/
if (dispPtr->modKeyCodes != NULL) {
ckfree(dispPtr->modKeyCodes);
}
- dispPtr->numModKeyCodes = 0;
- dispPtr->modKeyCodes = NULL;
+ dispPtr->numModKeyCodes = NUM_MOD_KEYCODES;
+ dispPtr->modKeyCodes = (KeyCode *)ckalloc(NUM_MOD_KEYCODES * sizeof(KeyCode));
+ for (int i = 0; i < NUM_MOD_KEYCODES; i++) {
+ dispPtr->modKeyCodes[i] = modKeyArray[i];
+ }
}
/*
diff --git a/tests/bind.test b/tests/bind.test
index adb802b..788f132 100644
--- a/tests/bind.test
+++ b/tests/bind.test
@@ -34,6 +34,19 @@ proc unsetBindings {} {
bind .t <Enter> {}
}
+# This function fills the pattern matcher's ring buffer with events of
+# the specified type. This can be used when testing with generated
+# events to make sure that there are no stray events in the ring
+# buffer which might cause the pattern matcher to find unintended
+# matches. The size of the ring buffer is EVENT_BUFFER_SIZE, which is
+# currently set to 30. If this changes, the code below will need to
+# change.
+proc clearRingBuffer {{event}} {
+ for {set i 0} {$i < 30} {incr i} {
+ event generate . $event
+ }
+}
+
# move the mouse pointer away of the testing area
# otherwise some spurious events may pollute the tests
toplevel .top
@@ -1382,10 +1395,11 @@ test bind-15.22 {MatchPatterns procedure, time wrap-around} -setup {
pack .t.f
focus -force .t.f
update
+ clearRingBuffer <Key>
} -body {
bind .t.f <Double-1> {set x 1}
set x 0
- event generate .t.f <Button-1> -time [expr -100]
+ event generate .t.f <Button-1> -time -100
event generate .t.f <Button-1> -time 200
event generate .t.f <ButtonRelease-1>
return $x
@@ -1397,6 +1411,7 @@ test bind-15.23 {MatchPatterns procedure, time wrap-around} -setup {
pack .t.f
focus -force .t.f
update
+ clearRingBuffer <Key>
} -body {
bind .t.f <Double-1> {set x 1}
set x 0
@@ -1407,13 +1422,13 @@ test bind-15.23 {MatchPatterns procedure, time wrap-around} -setup {
} -cleanup {
destroy .t.f
} -result {0}
-
test bind-15.24 {MatchPatterns procedure, virtual event} -setup {
frame .t.f -class Test -width 150 -height 100
pack .t.f
focus -force .t.f
update
set x {}
+ clearRingBuffer <Key>
} -body {
event add <<Paste>> <Button-1>
bind .t.f <<Paste>> {lappend x paste}
@@ -1430,6 +1445,7 @@ test bind-15.25 {MatchPatterns procedure, reject a virtual event} -setup {
focus -force .t.f
update
set x {}
+ clearRingBuffer <Key>
} -body {
event add <<Paste>> <Shift-Button-1>
bind .t.f <<Paste>> {lappend x paste}
@@ -1446,6 +1462,7 @@ test bind-15.26 {MatchPatterns procedure, reject a virtual event} -setup {
focus -force .t.f
update
set x {}
+ clearRingBuffer <Key>
} -body {
event add <<V1>> <Button>
event add <<V2>> <Button-1>
@@ -1472,6 +1489,7 @@ test bind-15.27 {MatchPatterns procedure, conflict resolution} -setup {
pack .t.f
focus -force .t.f
update
+ clearRingBuffer <Button>
} -body {
bind .t.f <KeyPress> {set x 0}
bind .t.f 1 {set x 1}
@@ -1486,6 +1504,7 @@ test bind-15.28 {MatchPatterns procedure, conflict resolution} -setup {
pack .t.f
focus -force .t.f
update
+ clearRingBuffer <Button>
} -body {
bind .t.f <KeyPress> {set x 0}
bind .t.f 1 {set x 1}
@@ -1500,6 +1519,7 @@ test bind-15.29 {MatchPatterns procedure, conflict resolution} -setup {
pack .t.f
focus -force .t.f
update
+ clearRingBuffer <Button>
} -body {
bind .t.f <KeyPress> {lappend x 0}
bind .t.f 1 {lappend x 1}
@@ -1517,6 +1537,7 @@ test bind-15.30 {MatchPatterns procedure, conflict resolution} -setup {
pack .t.f
focus -force .t.f
update
+ clearRingBuffer <Key>
} -body {
bind .t.f <ButtonPress> {set x 0}
bind .t.f <1> {set x 1}
@@ -1533,6 +1554,7 @@ test bind-15.31 {MatchPatterns procedure, conflict resolution} -setup {
focus -force .t.f
update
set x {}
+ clearRingBuffer <Button>
} -body {
bind .t.f <M1-Key> {set x 0}
bind .t.f <M2-Key> {set x 1}
@@ -1546,6 +1568,7 @@ test bind-15.32 {MatchPatterns procedure, conflict resolution} -setup {
pack .t.f
focus -force .t.f
update
+ clearRingBuffer <Button>
} -body {
bind .t.f <M2-Key> {set x 0}
bind .t.f <M1-Key> {set x 1}
@@ -1561,6 +1584,7 @@ test bind-15.33 {MatchPatterns procedure, conflict resolution} -setup {
focus -force .t.f
update
set x {}
+ clearRingBuffer <Key>
} -body {
bind .t.f <1> {lappend x single}
bind Test <1> {lappend x single(Test)}
@@ -2208,6 +2232,7 @@ test bind-16.46 {ExpandPercents procedure} -setup {
focus -force .t.e
foreach p [event info] {event delete $p}
update
+ clearRingBuffer <Button>
} -body {
bind all <Key> {set z "%M"}
bind Entry <Key> {set y "%M"}