From 2c41264be7ab081b18b9a7dfb177e5835917c4bc Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 24 Jul 2019 13:31:43 +0000 Subject: (cherry-pick): Patch by Arjen sent to core 2018-09-21 Also, do some renumbering of mouse-buttons, such that at script level the XButtons appear to be at 4/5 while - internally - they are at 8/9. --- doc/bind.n | 4 ---- generic/tkBind.c | 33 ++++++++++++++++++-------------- generic/tkEvent.c | 17 ++++++++++++++++- tests/bind.test | 56 ------------------------------------------------------- 4 files changed, 35 insertions(+), 75 deletions(-) diff --git a/doc/bind.n b/doc/bind.n index 7c39cfc..015bad5 100644 --- a/doc/bind.n +++ b/doc/bind.n @@ -114,10 +114,6 @@ Modifiers consist of any of the following values: \fBButton3\fR, \fBB3\fR \fBTriple\fR \fBButton4\fR, \fBB4\fR \fBQuadruple\fR \fBButton5\fR, \fBB5\fR -\fBButton6\fR, \fBB6\fR -\fBButton7\fR, \fBB7\fR -\fBButton8\fR, \fBB8\fR -\fBButton9\fR, \fBB9\fR .DE Where more than one value is listed, separated by commas, the values are equivalent. diff --git a/generic/tkBind.c b/generic/tkBind.c index 15a66f1..a6bd8ca 100644 --- a/generic/tkBind.c +++ b/generic/tkBind.c @@ -384,18 +384,10 @@ static const ModInfo modArray[] = { {"Button2", Button2Mask, 0}, {"B3", Button3Mask, 0}, {"Button3", Button3Mask, 0}, - {"B4", Button4Mask, 0}, - {"Button4", Button4Mask, 0}, - {"B5", Button5Mask, 0}, - {"Button5", Button5Mask, 0}, - {"B6", Button6Mask, 0}, - {"Button6", Button6Mask, 0}, - {"B7", Button7Mask, 0}, - {"Button7", Button7Mask, 0}, - {"B8", Button8Mask, 0}, - {"Button8", Button8Mask, 0}, - {"B9", Button9Mask, 0}, - {"Button9", Button9Mask, 0}, + {"B4", Button8Mask, 0}, + {"Button4", Button8Mask, 0}, + {"B5", Button9Mask, 0}, + {"Button5", Button9Mask, 0}, {"Mod1", Mod1Mask, 0}, {"M1", Mod1Mask, 0}, {"Command", Mod1Mask, 0}, @@ -1995,6 +1987,9 @@ ExpandPercents( case 'b': if (flags & BUTTON) { number = eventPtr->xbutton.button; + if (eventPtr->xbutton.button >= Button8) { + number += (Button4 - Button8); + } goto doNumber; } goto doString; @@ -3109,6 +3104,9 @@ HandleEventGenerate( return TCL_ERROR; } if (flags & BUTTON) { + if (number >= Button4) { + number += (Button8 - Button4); + } event.general.xbutton.button = number; } else { goto badopt; @@ -3997,7 +3995,7 @@ ParseEventDescription( p = GetField(p, field, FIELD_SIZE); } if (*field != '\0') { - if ((*field >= '1') && (*field <= '9') && (field[1] == '\0')) { + if ((*field >= '1') && (*field <= '5') && (field[1] == '\0')) { if (eventFlags == 0) { patPtr->eventType = ButtonPress; eventMask = ButtonPressMask; @@ -4012,6 +4010,9 @@ ParseEventDescription( goto done; } patPtr->detail.button = (*field - '0'); + if (patPtr->detail.button >= Button4) { + patPtr->detail.button += (Button8 - Button4); + } } else { getKeysym: @@ -4228,7 +4229,11 @@ GetPatternObj( Tcl_AppendToObj(patternObj, string, -1); } } else { - Tcl_AppendPrintfToObj(patternObj, "%d", patPtr->detail.button); + int button = patPtr->detail.button; + if (button >= Button8) { + button += (Button4 - Button8); + } + Tcl_AppendPrintfToObj(patternObj, "%d", button); } } diff --git a/generic/tkEvent.c b/generic/tkEvent.c index d8501c3..02c7de8 100644 --- a/generic/tkEvent.c +++ b/generic/tkEvent.c @@ -580,7 +580,22 @@ UpdateButtonEventState( dispPtr->mouseButtonWindow = eventPtr->xbutton.window; eventPtr->xbutton.state |= dispPtr->mouseButtonState; - dispPtr->mouseButtonState |= TkGetButtonMask(eventPtr->xbutton.button); + if ((eventPtr->xbutton.button >= Button4) && (eventPtr->xbutton.button <= Button7)) { + /* + * Turn the event into a mouse wheel event and queue it + * Note: modelled after the code in tkWinX.c + */ + eventPtr->type = MouseWheelEvent; + eventPtr->xany.send_event = -1; + eventPtr->xkey.nbytes = 0; + eventPtr->xkey.keycode = (eventPtr->xbutton.button & 1) ? 1 : -1; + if (eventPtr->xkey.keycode >= Button6) { + eventPtr->xkey.state |= ShiftMask; + } + Tk_QueueWindowEvent(eventPtr, TCL_QUEUE_TAIL); + } else { + dispPtr->mouseButtonState |= TkGetButtonMask(eventPtr->xbutton.button); + } break; case ButtonRelease: diff --git a/tests/bind.test b/tests/bind.test index ebc39b7..87e8e03 100644 --- a/tests/bind.test +++ b/tests/bind.test @@ -5862,62 +5862,6 @@ test bind-27.7 {button names} -setup { } -cleanup { destroy .t.f } -result { {button 5}} -test bind-27.8 {button names} -setup { - frame .t.f -class Test -width 150 -height 100 - pack .t.f - focus -force .t.f - update -} -body { - bind .t.f {lappend x "button 6"} - set x [bind .t.f] - event generate .t.f - event generate .t.f - set x -} -cleanup { - destroy .t.f -} -result { {button 6}} -test bind-27.9 {button names} -setup { - frame .t.f -class Test -width 150 -height 100 - pack .t.f - focus -force .t.f - update -} -body { - bind .t.f {lappend x "button 7"} - set x [bind .t.f] - event generate .t.f - event generate .t.f - set x -} -cleanup { - destroy .t.f -} -result { {button 7}} -test bind-27.10 {button names} -setup { - frame .t.f -class Test -width 150 -height 100 - pack .t.f - focus -force .t.f - update -} -body { - bind .t.f {lappend x "button 8"} - set x [bind .t.f] - event generate .t.f - event generate .t.f - set x -} -cleanup { - destroy .t.f -} -result { {button 8}} -test bind-27.11 {button names} -setup { - frame .t.f -class Test -width 150 -height 100 - pack .t.f - focus -force .t.f - update -} -body { - bind .t.f {lappend x "button 9"} - set x [bind .t.f] - event generate .t.f - event generate .t.f - set x -} -cleanup { - destroy .t.f -} -result { {button 9}} test bind-28.1 {keysym names} -body { bind .t foo -- cgit v0.12