From c60d0f8978d1ebd2ec490caa1464b450c70b9d9f Mon Sep 17 00:00:00 2001 From: marc_culler Date: Mon, 27 Nov 2023 15:31:55 +0000 Subject: Introduce a separate TouchpadScroll event. Avoids Extended-MouseWheel events being handled by MouseWheel bindings. --- doc/bind.n | 20 ++++++++++---------- generic/tk.h | 4 +++- generic/tkBind.c | 6 +++--- generic/tkEvent.c | 3 ++- library/demos/cscroll.tcl | 3 +-- library/demos/items.tcl | 3 +-- library/listbox.tcl | 2 +- library/scrlbar.tcl | 2 +- library/text.tcl | 2 +- library/ttk/scrollbar.tcl | 2 +- macosx/tkMacOSXMouseEvent.c | 4 ++-- 11 files changed, 26 insertions(+), 25 deletions(-) diff --git a/doc/bind.n b/doc/bind.n index 72129d8..518d522 100644 --- a/doc/bind.n +++ b/doc/bind.n @@ -173,11 +173,11 @@ types; where two names appear together, they are synonyms. \fBButton\fR, \fBButtonPress\fR \fBEnter\fR \fBMapRequest\fR \fBButtonRelease\fR \fBExpose\fR \fBMotion\fR \fBCirculate\fR \fBFocusIn\fR \fBMouseWheel\fR -\fBCirculateRequest\fR \fBFocusOut\fR \fBProperty\fR -\fBColormap\fR \fBGravity\fR \fBReparent\fR -\fBConfigure\fR \fBKey\fR, \fBKeyPress\fR \fBResizeRequest\fR -\fBConfigureRequest\fR \fBKeyRelease\fR \fBUnmap\fR -\fBCreate\fR \fBLeave\fR \fBVisibility\fR +\fBTouchpadScroll\fR \fBCirculateRequest\fR \fBFocusOut\fR +\fBProperty\fR \fBColormap\fR \fBGravity\fR +\fBReparent\fR \fBConfigure\fR \fBKey\fR, \fBKeyPress\fR +\fBResizeRequest\fR \fBConfigureRequest\fR \fBKeyRelease\fR +\fBUnmap\fR \fBCreate\fR \fBLeave\fR \fBVisibility\fR \fBDeactivate\fR .DE Most of the above events have the same fields and behaviors as events @@ -198,7 +198,7 @@ active. Likewise, the \fBDeactive\fR event is sent when the window's state changes from active to deactive. There are no useful percent substitutions you would make when binding to these events. .IP \fBMouseWheel\fR 5 -Many contemporary mice support a mouse wheel, which is used +Many contemporary mice include a mouse wheel, which is used for scrolling documents without using the scrollbars. By rolling the wheel, the system will generate \fBMouseWheel\fR events that the application can use to scroll. The event is routed to the @@ -216,19 +216,19 @@ Horizontal scrolling uses \fBShift-MouseWheel\fR events, with positive negative right scrolling. Horizontal scrolling events are generated tilt wheels on some mice. Horizontal scrolling can also be emulated by holding Shift and scrolling vertically. -.PP +.RE +.IP "\fBTouchpadScroll\fR" 5 On some platforms (currently Windows and macOS) there is support for high-resolution scrolling devices, such as touchpads. This is -provided via \fBExtended-MouseWheel\fR events. These events store two +provided via \fBTouchpadScroll\fR events. These events store two 16 bit delta values in the integer provided by the \fB%D\fR -subsstitution. The \fIX\fR delta is in the high order 16 bits and the +substitution. The \fIX\fR delta is in the high order 16 bits and the \fIY\fR delta is in the low order 16 bits. These values can be unpacked by using the tk::PreciseScrollDeltas utility procedure. For example: .CS lassign [tk::PreciseScrollDeltas %D] deltaX deltaY .CE -.RE .IP "\fBKeyPress\fR, \fBKeyRelease\fR" 5 The \fBKeyPress\fR and \fBKeyRelease\fR events are generated whenever a key is pressed or released. \fBKeyPress\fR and \fBKeyRelease\fR diff --git a/generic/tk.h b/generic/tk.h index 481714a..6f59f2c 100644 --- a/generic/tk.h +++ b/generic/tk.h @@ -669,8 +669,10 @@ typedef struct Tk_GeomMgr { #define ActivateNotify (MappingNotify + 2) #define DeactivateNotify (MappingNotify + 3) #define MouseWheelEvent (MappingNotify + 4) -#define TK_LASTEVENT (MappingNotify + 5) +#define TouchpadScroll (MappingNotify + 5) +#define TK_LASTEVENT (MappingNotify + 6) +#define TouchpadScrollMask (1L << 27) #define MouseWheelMask (1L << 28) #define ActivateMask (1L << 29) #define VirtualEventMask (1L << 30) diff --git a/generic/tkBind.c b/generic/tkBind.c index acd982b..6c83dd0 100644 --- a/generic/tkBind.c +++ b/generic/tkBind.c @@ -528,6 +528,7 @@ static const EventInfo eventArray[] = { {"Activate", ActivateNotify, ActivateMask}, {"Deactivate", DeactivateNotify, ActivateMask}, {"MouseWheel", MouseWheelEvent, MouseWheelMask}, + {"TouchpadScroll", TouchpadScroll, TouchpadScrollMask}, {"CirculateRequest", CirculateRequest, SubstructureRedirectMask}, {"ConfigureRequest", ConfigureRequest, SubstructureRedirectMask}, {"Create", CreateNotify, SubstructureNotifyMask}, @@ -632,7 +633,8 @@ static const int flagArray[TK_LASTEVENT] = { /* VirtualEvent */ VIRTUAL, /* Activate */ ACTIVATE, /* Deactivate */ ACTIVATE, - /* MouseWheel */ WHEEL + /* MouseWheel */ WHEEL, + /* TouchpadScroll */ WHEEL }; /* @@ -5016,7 +5018,6 @@ ParseEventDescription( eventFlags = 0; if ((hPtr = Tcl_FindHashEntry(&eventTable, field))) { const EventInfo *eiPtr = (const EventInfo *)Tcl_GetHashValue(hPtr); - patPtr->eventType = eiPtr->type; eventFlags = flagArray[eiPtr->type]; eventMask = eiPtr->eventMask; @@ -5091,7 +5092,6 @@ ParseEventDescription( } else if (patPtr->eventType == MotionNotify) { patPtr->info = ButtonNumberFromState(patPtr->modMask); } - p = SkipFieldDelims(p); if (*p != '>') { diff --git a/generic/tkEvent.c b/generic/tkEvent.c index b6ee204..59b4e49 100644 --- a/generic/tkEvent.c +++ b/generic/tkEvent.c @@ -123,7 +123,8 @@ static const unsigned long eventMasks[TK_LASTEVENT] = { VirtualEventMask, /* VirtualEvents */ ActivateMask, /* ActivateNotify */ ActivateMask, /* DeactivateNotify */ - MouseWheelMask /* MouseWheelEvent */ + MouseWheelMask, /* MouseWheelEvent */ + TouchpadScrollMask /* TouchpadScroll */ }; /* diff --git a/library/demos/cscroll.tcl b/library/demos/cscroll.tcl index bb5e121..9b7f394 100644 --- a/library/demos/cscroll.tcl +++ b/library/demos/cscroll.tcl @@ -108,8 +108,7 @@ if {([tk windowingsystem] eq "aqua") && ![package vsatisfies [package provide Tk %W xview scroll [expr {(%D-2)/-3}] units } } - #Touchpad scrolling - bind $c { + bind $c { lassign [tk::PreciseScrollDeltas %D] deltaX deltaY if {$deltaX != 0 || $deltaY != 0} { tk::CanvasScrollByPixels %W $deltaX $deltaY diff --git a/library/demos/items.tcl b/library/demos/items.tcl index 90eb027..be07916 100644 --- a/library/demos/items.tcl +++ b/library/demos/items.tcl @@ -34,8 +34,7 @@ canvas $c -scrollregion {0c 0c 30c 24c} -width 15c -height 10c \ ttk::scrollbar $w.frame.vscroll -command "$c yview" ttk::scrollbar $w.frame.hscroll -orient horizontal -command "$c xview" -#Touchpad scrolling -bind $c { +bind $c { lassign [tk::PreciseScrollDeltas %D] deltaX deltaY if {$deltaX != 0 || $deltaY != 0} { tk::CanvasScrollByPixels %W $deltaX $deltaY diff --git a/library/listbox.tcl b/library/listbox.tcl index c79be3a..32eea4b 100644 --- a/library/listbox.tcl +++ b/library/listbox.tcl @@ -187,7 +187,7 @@ bind Listbox { bind Listbox { tk::MouseWheel %W x %D -12.0 units } -bind Listbox { +bind Listbox { lassign [tk::PreciseScrollDeltas %D] deltaX deltaY if {$deltaX != 0} { %W xview scroll [expr {-$deltaX}] units diff --git a/library/scrlbar.tcl b/library/scrlbar.tcl index 909d93d..5c4ba72 100644 --- a/library/scrlbar.tcl +++ b/library/scrlbar.tcl @@ -137,7 +137,7 @@ bind Scrollbar { tk::ScrollByUnits %W hv %D -40.0 } -bind Scrollbar { +bind Scrollbar { lassign [tk::PreciseScrollDeltas %D] deltaX deltaY if {$deltaX != 0 && [%W cget -orient] eq "horizontal"} { tk::ScrollbarScrollByPixels %W h $deltaX diff --git a/library/text.tcl b/library/text.tcl index 4e0476d..f2ef83a 100644 --- a/library/text.tcl +++ b/library/text.tcl @@ -456,7 +456,7 @@ bind Text { } set ::tk::Priv(prevPos) {} -bind Text { +bind Text { lassign [tk::PreciseScrollDeltas %D] deltaX deltaY if {$deltaX != 0} { %W xview scroll [expr {-$deltaX}] pixels diff --git a/library/ttk/scrollbar.tcl b/library/ttk/scrollbar.tcl index 0fd4c6a..28c6a84 100644 --- a/library/ttk/scrollbar.tcl +++ b/library/ttk/scrollbar.tcl @@ -21,7 +21,7 @@ bind TScrollbar { ttk::scrollbar::Release %W %x %y } # bind TScrollbar [bind Scrollbar ] bind TScrollbar [bind Scrollbar ] -bind TScrollbar [bind Scrollbar ] +bind TScrollbar [bind Scrollbar ] proc ttk::scrollbar::Scroll {w n units} { set cmd [$w cget -command] diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index e80c4a7..22ae11f 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -559,8 +559,8 @@ enum { int deltaY = [theEvent scrollingDeltaY]; delta = (deltaX << 16) | (deltaY & 0xffff); if (delta != 0) { - xEvent.type = MouseWheelEvent; - xEvent.xbutton.state = state | EXTENDED_MASK; + xEvent.type = TouchpadScroll; + xEvent.xbutton.state = state; xEvent.xkey.keycode = delta; xEvent.xany.serial = LastKnownRequestProcessed(Tk_Display(tkwin)); Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL); -- cgit v0.12