Getting notified on a window being grabbed and moved / resized

Jeremy Wood mickleness at gmail.com
Thu Jul 7 00:34:37 UTC 2022


Kirill,

 > Is there a public / supported way to get notified when an OS-decorated 
window (native title pane from macOS, Windows, etc) is moved around or 
resized by the user grabbing the title bar or the border?

Not that I’m aware of.

 > I want to get notified on that process starting so that I can hide all 
the popups.

Are you OK with just knowing when your JVM’s windows are grabbed?

Attached is a small test app I threw together that I think (?) 
demonstrates what you’re describing. Even if we hide windows when we 
first detect movement, we don’t know exactly when to re-show them… so 
this just uses a timer to wait until movement stops. (We could add 
another layer of pseudoscience to it and look at the mouse location and 
guess if it’s in the title bar? Which is one of those things that will 
probably be right 95+% of the time.)

When testing on my Mac: I don’t observe any delay between moving the 
mouse a pixel and all other windows instantly hiding. What do you 
observe, and what’s your testing environment like?

>From your description my initial assessment would be:
A. What you’re trying to do is not well supported in Java.
B. It may be worth implementing your own window decorations (for Mac, 
Windows, etc.) instead. This would give you complete control over the 
“grabbing” process. It might mean you miss out on some default OS 
behavior, though. (Like nudges the OS might make to auto-align windows, 
or to wrap windows onto other monitors, or to help manage virtual 
monitors.) But if these are small helper popup windows that stay close 
to their parent frame (are they?) that might all be worth it. Plus: if 
they are officially “undecorated” as far as the AWT is considered: you 
can fade them in/out (instead of toggling them on/off).

Regards,
  - Jeremy

------ Original Message ------
>From "Kirill Grouchnikov" <kirill.grouchnikov at gmail.com>
To client-libs-dev at openjdk.org
Date 6/28/2022 11:19:02 AM
Subject Getting notified on a window being grabbed and moved / resized

>Is there a public / supported way to get notified when an OS-decorated 
>window (native title pane from macOS, Windows, etc) is moved around or 
>resized by the user grabbing the title bar or the border?
>
>I want to get notified on that process starting so that I can hide all 
>the popups. What I see is that at [1] this is how Swing's popup menu 
>registers itself to get notified on window grabbing. Note that it's 
>using internal, undocumented and inaccessible event mask. Then at [2] 
>it gets notified that the window has been ungrabbed so that it can hide 
>itself. Again, internal and inaccessible event class. And there's also 
>APIs at [3] to grab / ungrab windows to have the whole process rolling.
>
>Are there alternatives to these internal APIs that have been exposed as 
>part of hiding the implementation details?
>
>The only thing I could find so far is adding a component listener to 
>the frame, but "componentMoved" is called with a noticeable lag, 
>hundreds of milliseconds after the window has started moving.
>
>[1] 
>https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java#L790
>[2] 
>https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java#L861
>[3] 
>https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/sun/awt/SunToolkit.java#L1641
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/client-libs-dev/attachments/20220707/86f61577/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GrabbingTests.java.zip
Type: application/zip
Size: 1162 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/client-libs-dev/attachments/20220707/86f61577/GrabbingTests.java.zip>


More information about the client-libs-dev mailing list