Tk Source Code

View Ticket
Login
Ticket UUID: ac7f771957ea4d98639adf89dc8aa82846b8a155
Title: tk panedwindow: cursor changing code does not work well
Type: Bug Version: 8.6.18, 9.0.5, 9.1.1
Submitter: bll Created on: 2020-09-15 00:21:02
Subsystem: 21. [panedwindow] Assigned To: chrstphrchvz
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-11-11 12:02:25
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-11-11 12:02:25
Description:
As reported in: https://core.tcl-lang.org/tk/info/6b51f22bff0548df ,
the tk panedwindow does not handle cursor changes well.

The ttk panedwindow cursor changes can be slightly improved.
User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-11-11 12:02:25:

Serhiy, many thanks for both panedwindow-related branches! Merged branch panedwindow-sash-cursor into main, core-9-0-branch, and core-8-6-branch by commits [f5e8761e], [d6b577ac], and [740eeb89]. Closing the ticket.


serhiy.storchaka added on 2026-10-29 09:24:23:

Marc, panedwindow-identify-bounds was already merged into main by [23aa8b82e3] on 2026-10-09, so the current main should behave as the branch. Only panedwindow-sash-cursor is not merged.

Backported [23aa8b82e3] to 9.0 ([685a4a06de]) and 8.6 ([e17aecfc86]).


marc_culler (claiming to be Marc Culler) added on 2026-10-29 02:25:31:
I tried merging panedwindow-sash-cursor into panedwindow-identify-bounds.
(That required `fossil merge --force` because the panedwindow-identify-bounds
leaf had already been closed.  I think we would be wise not to rusn
too much with these fixes.)

Anyway, that fixed the problem of the cursor reverting to the pointer
during the drag.

The only remaining issue that I saw was that sometimes the push-me-pull-you
cursor reverts to the pointer when I click the mouse button.  And that is
pretty minor.

This is on an M4 macOS 27 macbook air.

marc_culler (claiming to be Marc Culler) added on 2026-10-29 02:13:28:
A tried again after re-reading the ticket to see when the cursor reverts
to the pointer.  I think it is true that it happens when the cursor gets
more than a certain (small) distance from the sash.  And moving the mouse
very slowly prevents this from happening.

Is this the problem fixed by panedwindow-sash-cursor? I will try that
one too.

marc_culler (claiming to be Marc Culler) added on 2026-10-29 02:06:48:
I tested the panedwindow-identify-bounds branch on macOS 27, and compared
against main, using the "Horizontal paned window" demo.  My conclusions
were:

* panedwindow-identify-bounds is a huge improvement;

* there is room for more improvement.

Specifically, with trunk it took me 5 tries to get the push-me-pull-you
cursor to activate.  With panedwindow-identify-bounds I got it on the
first try.  However, when dragging the sash the cursor reverts to the
default arrow cursor at some random point during the drag, and that
default cursor remains until the mouse button is released.  (Well,
actually, I was using a trackpad, so until I lift my finger off of
the pad.)

serhiy.storchaka added on 2026-10-26 18:42:33:

The cursor problems on Windows described on 2026-10-09 are not fixed by [23aa8b82e3]: their fix is in branch panedwindow-sash-cursor, not merged yet. Should the ticket stay open until it is?


oehhar added on 2026-10-26 18:30:51:

Bugfix branch merged by Jan by commit [23aa8b82].

Closing bug.

Thanks, Harald


serhiy.storchaka added on 2026-10-09 17:19:42:

On Windows, two problems remained after panedwindow-identify-bounds:

  • The sash cursor was set only by motion inside the panedwindow, not when the pointer entered on the sash, so on its first pixel the normal cursor was shown although a click started a drag.
  • While dragging, the cursor was restored to the normal one as soon as the pointer got ahead of the sash. They are not reproducible on X11. The delay when leaving the sash does not happen on Windows either.

Proposed fix in branch panedwindow-sash-cursor: the cursor is also set on <Enter>, is kept while a sash is dragged and updated after the release, and the cursor state of a destroyed panedwindow is forgotten, so that a new one with the same name does not inherit it. Tests panedwindow-30.1 to 30.4.

I tested it on Windows. The bindings are not platform-specific, so I expect that it fixes macOS too, but it may need tweaking there. Can someone check it on macOS?


jan.nijtmans added on 2026-10-09 16:36:35:

> Does this fix everything described in this ticket?

My guess is, the answer is "no".

I rebase the bug-ac7f7719 branch to trunk, so it's possible to continue development with it. Anyone?


jan.nijtmans added on 2026-10-09 15:52:03:

The branch "panedwindow-identify-bounds looks good to me. Now merged to trunk.

Does this fix everything described in this ticket?


serhiy.storchaka added on 2026-10-04 11:59:58:

On X11 (8.6.10, 8.6.18, 9.0.5, 9.1) the sash cursor is reset as soon as the pointer enters a pane. But identify reported the sash for the first pixel of the next pane, and with a handle wider than the sash for several more pixels, depending on -handlesize. On such pixels the cursor and the result of a click disagree. Fixed in branch panedwindow-identify-bounds. Can the problem still be reproduced on macOS with it?

To see the difference, run this and move the pointer from the left pane over the sash into the right pane. The line at the bottom turns red where identify reports the sash or handle while the pointer is over a pane (21 pixels of the right pane without the fix):

panedwindow .p -showhandle 1 -handlesize 20 -handlepad 40 \
	-sashwidth 2 -sashpad 2 -bd 0
.p add [frame .p.left -bg lightblue -width 150 -height 120] \
	[frame .p.right -bg lightgreen -width 150 -height 120]
label .info -width 50 -anchor w -font TkFixedFont
pack .p -fill both -expand 1
pack .info -fill x

proc show {X Y} {
    set x [expr {$X - [winfo rootx .p]}]
    set y [expr {$Y - [winfo rooty .p]}]
    set id [.p identify $x $y]
    set w [winfo containing $X $Y]
    set bad [expr {$id ne "" && $w ne ".p"}]
    .info configure -text [format "x=%3d y=%3d  identify: %-9s  under pointer: %s" \
	    $x $y [expr {$id eq "" ? "-" : $id}] $w] \
	    -bg [expr {$bad ? "red" : [. cget -bg]}]
}
bind all <Motion> {show %X %Y}

The branch bug-ac7f7719 is not mergeable as is: it keeps the panedwindow in a single global Priv(panedwindowname).


chrstphrchvz added on 2021-03-04 01:23:21:

After reading through [6b51f22bff] again, I now see that the idea in my previous comment (i.e. make the sash a contained widget with Leave/Enter bindings) was already brought up in Marc's comments @ 2020-09-14 16:38:50 and 2020-09-14 21:12:09. But the idea is arguably unfit for 8.6, because it means introducing a contained widget to panedwindow which it is not documented/implemented as already having. To be truly 8.6 compatible, the sash would have to be inaccessible to Tk programs (e.g. unable to configure or bind to it by ordinary means).

I agree with Marc that the original panedwindow design is flawed. If the Ttk panedwindow is not so flawed, then I personally might prefer that no one bother to salvage the original panedwindow, and that it be avoided in 8.5/8.6 and removed in 8.7.


chrstphrchvz added on 2020-09-18 13:12:46:

Something that occurred to me: the lack of an event for a container widget to detect the pointer entering a contained widget might be considered a non-issue. The standard recipe might be to use additional contained widget(s) adjacent to the one of interest, and set Leave bindings for the adjacent widget(s). In the case of the window pane, that would mean making the sash another contained widget which has its Leave binding check if the pointer has entered one of the paned widgets.


bll added on 2020-09-15 23:38:47:
Ok, that's a different issue.

tk panedwindow has a 
  bind PanedWindow <Motion> ...
so the motion is only applicable to and sent to the PanedWindow class.

I agree, that a general EnterChild/LeaveChild event would would be useful.

chrstphrchvz added on 2020-09-15 21:27:24:

I have not yet tried or reviewed the bug-ac7f7719 work.

To clarify what I meant: using a script like

place [frame .f -background red -width 50 -height 50] -x 75 -y 75
bind all <Enter> {puts {Enter  %W %X %Y}}
bind all <Leave> {puts {Leave  %W %X %Y}}
bind all <Motion> {puts {Motion %W %X %Y}}

(The system "Mouse Keys" feature for exact 1-pixel pointer movement is useful here, avoiding noisy motion events from high-precision hardware which get rounded for Tk.)

On actual X11, I observe that if the pointer moves, there is always a motion event for the widget containing the pointer:

Motion . 91 185
Motion . 92 185
Motion . 93 185
Enter  .f 94 185
Motion .f 94 185
Motion .f 95 185
Motion .f 96 185
Motion .f 95 185
Motion .f 94 185
Leave  .f 93 185
Motion . 93 185
Motion . 92 185
Motion . 91 185

On Aqua and Windows, there is instead no motion event if there was simultaneously any enter/leave events:

Motion . 77 155
Motion . 78 155
Motion . 79 155
Enter  .f 80 155
Motion .f 81 155
Motion .f 82 155
Motion .f 81 155
Motion .f 80 155
Leave  .f 79 155
Motion . 78 155
Motion . 77 155
Motion . 76 185

The non-X11 pointer event abstraction (Tk_UpdatePointer()) could still use some work to address this inconsistency. But to correct myself, there would still be the half of the problem where a container widget needs to detect when the pointer enters a contained widget, even on actual X11.


bll added on 2020-09-15 15:12:40:

I didn't mention that the fix is in branch [bug-ac7f7719]


bll added on 2020-09-15 14:58:03:
The problem is not limited to aqua.

I do not see motion events sent within contained widgets on X11.

- The motion event is only sent to the container widget, not the child
  window panes.  Therefore, the panedwindow widget would only receive 
  motion events at its outside edges (the border) and within the sash, never 
  over the child windows.
- The old panedwindow implementation had no method of knowing when the pointer
  was within a child window.  The implementor used an after statment with
  a time of 150 milliseconds(!) to check where the pointer was.  
  150 milliseconds is a ridiculously long time to check for pointer movement.
- In ttk::panedwindow, someone actually wrote code to create a virtual
  <<EnteredChild>> event to get around the problem.

Perhaps I could have made the simple change of using 10 milliseconds in the
after statement.  But the whole implementation seemed poor and 
inefficient, so a proper rewrite was in order.

I suspect many of the underlying implementation reasons are lost in history.
Enter/Leave for child windows would be useful in general.
Motion for a window and all its children would be useful.

chrstphrchvz added on 2020-09-15 08:12:07:

Subscribing myself, since it appears others have come across the panedwindow cursor issue(s) I alluded to in [08eb057dea] but never reported. My impression of at least one root cause was that the panedwindow cursor handling is using timer events to work around the fact that X11 pointer event abstraction/emulation on non-X11 thought it was correct for a container widget to not be sent motion events when the cursor enters/leaves a contained widget. But I observe such motion events being sent anyways on X11. So I think that the X11 emulation behavior might be incorrect, and the whole panedwindow cursor handling mess could be avoided if non-X11 likewise sent those motion events.


bll added on 2020-09-15 00:27:02:
It appears that the panedwindow tests still work, so maybe I didn't break
anything too badly.

bll added on 2020-09-15 00:24:07:
Proposed code in branch : bug-ac7f7719

Still needs more testing.