-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[JEWEL-368] Fix custom title bar mouse event (drag/press) not working correctly #3362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you've made some changes to public APIs, you will need to update the API dumps.
Find the 'ApiCheckTest' (or something similar) in the run configurations from the IDE, run it, and update the dumps accordingly. Feel free to ping me on slack if you need help with it :)
Looks like on Linux it works out of the box with no changes (so probably this is only needed for Windows/MacOS).
Screen.Recording.2026-01-02.at.08.18.00.mp4
| fun updateKey(newKey: String) { | ||
| if (key != newKey) { | ||
| titleBarInfo?.clientRegions?.remove(key) | ||
| key = newKey | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we need to keep the last defined value in the 'clientRegions' map? The code bellow is not correct, but I think you can get the main idea.
| fun updateKey(newKey: String) { | |
| if (key != newKey) { | |
| titleBarInfo?.clientRegions?.remove(key) | |
| key = newKey | |
| } | |
| } | |
| fun updateKey(newKey: String) { | |
| if (key != newKey) { | |
| titleBarInfo?.clientRegions[newKey] = titleBarInfo?.clientRegions?.remove(key) | |
| key = newKey | |
| } | |
| } |
| // Convert from AWT raw pixels to Compose positionInWindow() coordinates | ||
| val x = e.x * scaleX | ||
| val y = e.y * scaleY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked if e.locationOnScreen works?
Also, if you use the Rect suggestion from the other comment, you can convert the event to offset using something like this:
val location = event.locationOnScreen
val offset = Offset(location.x.toFloat(), location.y.toFloat())
| internal data class ClientRegion( | ||
| val x: Float, | ||
| val y: Float, | ||
| val width: Int, | ||
| val height: Int, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using androidx.compose.ui.geometry.Rect instead?
You can get the create it with Rect(it.positionOnScreen(), it.size.toSize()) and use the .contains() method to check if the point is inside the area.
wellingtoncosta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for making sure the api-dump.txt files are properly updated due to the changes in public API. You can just run the ApiCheckTest and apply the changes by clicking on the <Click to see difference> links in the test output.
Evidences
Release notes
New features
clientRegionintroduced to let compose hold the component position and size on custom title barBug fixes
Test
This implementation has been tested on Mac (Tahoe, Ventura) and Windows 11 (25H2) machines.
Links
Youtrack Issue
Slack Thread