Tk Source Code

View Ticket
Login
2020-09-07
19:41 Closed ticket [d72abe6b54]: Aqua: toplevel receives button events when resized plus 6 other changes artifact: 4f539964a1 user: marc_culler
18:54
Fix [39cbacb9e8] and revisit [d72abe6b54] both dealing with inappropriate mouse button events. Refactor mouse event code. check-in: e065d1e706 user: marc_culler tags: core-8-6-branch
2020-09-02
21:14 Ticket [d72abe6b54] Aqua: toplevel receives button events when resized status still Open with 4 other changes artifact: ff9a5f0645 user: marc_culler
20:19 Ticket [d72abe6b54]: 4 changes artifact: 1c0736fbac user: marc_culler
19:50 Ticket [d72abe6b54]: 3 changes artifact: d83cd76d29 user: chrstphrchvz
16:33 Ticket [d72abe6b54]: 3 changes artifact: 0b3404e5d8 user: nab
16:10 Open ticket [d72abe6b54]. artifact: ea4a7c7606 user: marc_culler
16:09
Better fix for [d72abe6b54] using NSEvents. check-in: 5ea8262198 user: marc_culler tags: mac_enter_exit
14:36 Ticket [d72abe6b54] Aqua: toplevel receives button events when resized status still Closed with 5 other changes artifact: e74a6a2fd2 user: nab
14:28 Ticket [d72abe6b54]: 6 changes artifact: 5960ed59c8 user: marc_culler
2020-06-02
08:08 New ticket [39cbacb9e8] Aqua: <ButtonRelease-1> sent after closing a toplevel. artifact: 49a75a262a user: chrstphrchvz
2020-04-15
17:09 Ticket [d72abe6b54] Aqua: toplevel receives button events when resized status still Closed with 5 other changes artifact: 1d0c1019a1 user: nab
2020-04-10
19:16 Closed ticket [d72abe6b54]. artifact: 2fc79155b3 user: marc_culler
19:07
Fix [d72abe6b54]: Aqua toplevel receives button events when resizing. check-in: 5b4fb8bd08 user: culler tags: trunk
19:06
Fix [d72abe6b54]: Aqua toplevel receives button events when resizing. check-in: fcdeaa13ab user: culler tags: core-8-6-branch
18:04 Ticket [d72abe6b54] Aqua: toplevel receives button events when resized status still Open with 4 other changes artifact: 219e4be649 user: marc_culler
15:11 Ticket [d72abe6b54]: 3 changes artifact: 7223948529 user: nab
13:05 Ticket [d72abe6b54]: 3 changes artifact: 0f73008d45 user: chrstphrchvz
2020-04-09
19:31 Ticket [d72abe6b54]: 3 changes artifact: cc19891c71 user: nab
16:25 Ticket [d72abe6b54]: 5 changes artifact: ffcbae937e user: marc_culler
16:20
Fix [d72abe6b54]: Aqua toplevel receives button events when resizing. check-in: 142043283e user: marc_culler tags: bug-d72abe6b54
2020-04-08
01:10 New ticket [d72abe6b54] Aqua: toplevel receives button events when resized. artifact: d6258949bf user: chrstphrchvz

Ticket UUID: d72abe6b54dce8b6345507b73d395e7d9aafaf15
Title: Aqua: toplevel receives button events when resized
Type: Bug Version: 8.6.10
Submitter: chrstphrchvz Created on: 2020-04-08 01:10:38
Subsystem: 66. Aqua Window Operations Assigned To: marc_culler
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2020-09-07 19:41:01
Resolution: Fixed Closed By: marc_culler
    Closed on: 2020-09-07 19:41:01
Description:

Resizing a toplevel by dragging a corner or edge causes the toplevel to receive button press and release events, which I do not observe on X11 and Windows.

This poses an annoyance if there is a widget at the edge of the window that responds to a button event. An example is the Tktable demos which have a redundant "Exit" button at the bottom; so on Aqua, just resizing the window tends to close the demo.

The problem might more generally be that the window receives mouse press events when all that is being clicked is the window manager decorations, which doesn't happen on X11 and Windows.

I have not examined the issue enough to have an idea of how to address it. However attempting to filter out button events that are outside of the area of the toplevel would not be sufficient, because the region for resizing windows is still a few pixels within the toplevel.

User Comments: marc_culler (claiming to be Marc Culler) added on 2020-09-07 19:41:01:
This is fixed (again) by the changes that fixed [39cbacb9e8], so I think I
can close the ticket.

marc_culler (claiming to be Marc Culler) added on 2020-09-02 21:14:26:
Unfortunately, it does not work to convert the window coordinates of the mouse
to the contentView coordinates and test if the point is inside the view frame.
It can report yes when the mouse is inside the resize area, which apparently
extends 3 pixels into the contentView.

Also, it turns out that the resize area includes a 15 x 15 square at the lower
right corner of the window where the size grip would have been displayed on an
old mac.  That part of the resize area is detected by the enter / exit events
but was not detected before.

marc_culler (claiming to be Marc Culler) added on 2020-09-02 20:19:19:
You can add an NSTrackingArea for the NSView and then NSMouseEntered and
NSMouseExited events would be generated when the mouse enters or leaves the
NSView.  But that doesn't change the requirement that state be remembered and
it adds additional checking of coordinates.  With the default setting we are
notified when the mouse goes inside or outside of the resizing halo union the
titlebar, which is exactly when we want to ignore the button press events.

However, there is one other thing worth trying, which might be even easier.
Maybe we can just check whether the mouse coordinates are inside the contentView.
I don't really know why that was not tested.

I have tried and tried to reproduce the issue from [39cbacb9e8] and have never
succeeded.  What is the magic trick?

chrstphrchvz added on 2020-09-02 19:50:16:

I reported [39cbacb9e8] a while after this issue had first been fixed. I still observe that issue in core-8-6-branch [3745ef1194] and mac_enter_exit [5ea8262198].

I would be curious if there's an even cleaner way of listening for events only for the contentView, rather than the whole NSWindow and having to filter out events (e.g. based on position and/or by keeping track of state).


nab added on 2020-09-02 16:33:40:
it works better here.

thanks.
++

marc_culler (claiming to be Marc Culler) added on 2020-09-02 16:10:59:
Incidentally, I think that fixing this issue also fixed [d72abe6b54],
which reported that positioning the close button over a link in the demo
and closing the window would launch the demo.

I have reopened this ticket and re-implemented the fix using the
NSMouseExited and NSMouseEntered events.  This eliminates the hard-wired
3-pixel width for the resize halo, so should be more robust with
respect to changes in new operating system releases.

The new branch is called mac_enter_exit.

nab added on 2020-09-02 14:36:01:
Hi Marc,
that's a good news !!

++

marc_culler (claiming to be Marc Culler) added on 2020-09-02 14:28:03:
I just discovered something which looks like it will be helpful here.
It appears that there is an NSTrackingArea which is active for an
NSWindow.  This has the consequence that when the mouse enters the
resizing halo around a window, an NSMouseEntered event is sent to
the window, and when the mouse leaves the resizing halo and enters
either the NSWindow's contentView or the surrounding desktop, an
NSMouseExitedEvent is generated.

This means that we can track whether the mouse is in the resizing halo
of a window and ignore button press events when they are intended for
resizing.  We don't have to make assumptions about the size of the
halo.

nab added on 2020-04-15 17:09:25:
just one more request about this, with the following script 'push' is prompted when I release the size grip.
I personally would much prefer if no event were trigger when releasing the grip of a window.

thanks.

package require Tk
package require Ttk

catch {namespace delete obj}
namespace eval obj {
    array set obj {}
}


proc displayStuff {namespace} {
    for {set x 1} {$x<10} {incr x} {
        set this($x) [\
        ttk::label .b$x -text push\
        ]
        bind .b$x <ButtonRelease-1> {puts "have pushed"}
        grid $this($x) -sticky news
    }
    grid columnconfigure . all -weight 1
    grid rowconfigure . all -weight 1
}

displayStuff obj

marc_culler (claiming to be Marc Culler) added on 2020-04-10 19:16:06:
Closing the ticket.  This has been merged into mac_styles as well.

marc_culler (claiming to be Marc Culler) added on 2020-04-10 18:04:18:
In macOS 10.6 (Snow Leopard) windows had a size grip at the lower left corner
and could not be resized by grabbing an edge of the window.  This was changed
in macOS 10.7 (Lion) which removed the size grip.  So I think this fix should
only be applied in 10.7 and later.  As far as I can tell there has been no
change in the width of the "edge" of a window since 10.7.  Needless to say,
however, there is no Apple documentation about the size of the edge.

Apple does provide a notifications for when "LiveResize" begins and ends.
However my tests showed that the callback for the start of LiveResize is not
called until after the button press event has been generated.  For us, this
means that a ButtonPress event has already been added to the Tcl queue when
the callback is executed.  Most of the time it does not actually get handled
until the resize finishes.  So it might be possible to remove that event from
the Tcl Queue in the LiveResizeWillBegin callback.  But that looks hugely more
complicated and fraught with risks of timing-related errors.  Given that the 3-pixel boundary size has been stable for 8 years now, I am inclined to use
the code as is, except on macOS 10.6.

nab added on 2020-04-10 15:11:20:
Hi,
would it be possible to merge this into mac_styles branch?

++

chrstphrchvz added on 2020-04-10 13:05:23:

Thanks, I have tested on Catalina, and the basic issue seems resolved. I'm not familiar with all of the different ways of making windows non-resizable and checking what differences might exist for those.

I don't think I can come up with a better approach. It would be nice if there was a way to directly check whether the pointer was in the area to perform the resize (rather than indirectly check by hardcoding the size of this area), but I have not found if such an approach is even possible.


nab added on 2020-04-09 19:31:35:
hi,
tested on macOS 10.15.4 and it works great, at least it's much better than before.
before the fix as Christopher have reported trying to resize toplevel when a button was bottom right triggered the button command, now it's not which is better .

thanks,
++

marc_culler (claiming to be Marc Culler) added on 2020-04-09 16:25:42:
The resize zone extends 3 pixels into the window (on Catalina, anyway).  I
pushed a bugfix branch bug-d72abe6b54 which ignores mouse down events in that
zone in the sense that no XEvent is generated for those NSEvents.

Please test!