Skip to content
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

Fixed unnecessary window displacement on resize #18004

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

codecat
Copy link

@codecat codecat commented Jan 20, 2025

What does the pull request do?

This fixes unnecessary window displacement on resize introduced by #16608. Also related: #17559. (Edit: It was introduced sometime earlier even, probably..)

What is the current behavior?

When a window on Windows programmatically resizes, it also sets the position for the window placement in workspace coordinates. The coordinates are however fetched from screen coordinates, which causes the window to shift every time the window resizes when the user's taskbar is located on the left or top side of the screen.

Recording.2025-01-20.144204.mp4

For this video, I added a timer to the application that adds 10px to the window height every second using Height += 10.

What is the updated/expected behavior with this PR?

The window should not be moving, and/or be using workspace coordinates instead of screen space coordinates when using SetWindowPlacement.

How was the solution implemented (if it's not obvious)?

The struct that's passed into SetWindowPlacement is already fetched from GetWindowPlacement which returns workspace coordinates. We don't need to assign this at all, as it should already be assigned.

Simply removing the code for left & top assignment is enough to fix this.

Checklist

Fixed issues

This fixes #16217

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054345-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Jan 20, 2025

  • All contributors have signed the CLA.

@codecat
Copy link
Author

codecat commented Jan 20, 2025

@cla-avalonia agree

@maxkatz6 maxkatz6 requested a review from emmauss January 20, 2025 15:13
@codecat
Copy link
Author

codecat commented Jan 20, 2025

Ah, I missed those! Will do.

@codecat codecat force-pushed the fix/resize-workspace-position branch from 3a5cf26 to be913e3 Compare January 21, 2025 09:53
@codecat
Copy link
Author

codecat commented Jan 21, 2025

I've added a new integration test now, and force pushed this PR so the commits are matching the contributor guidelines:

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054375-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@codecat
Copy link
Author

codecat commented Jan 21, 2025

Test was failing. Had to set my Windows resolution to 800x600 to reproduce this one; apparently the test driver was not actually clicking the buttons because they didn't fit in the window, which can not be scrolled. As a workaround, I simply wrapped all buttons in a horizontal stack panel so that they fit inside the window.

The more elegant solution would probably be to make the view scrollable, but that's assuming that the test driver handles that correctly (though it seems to work for the Window page in the test app).

Anyway, hope this works now 🤞

@codecat
Copy link
Author

codecat commented Jan 21, 2025

I'm not sure why the tests are still failing, they pass on my machine, even on 800x600 resolution. Maybe @maxkatz6 has more insights into this?

@MrJul
Copy link
Member

MrJul commented Jan 23, 2025

I'm not sure why the tests are still failing, they pass on my machine, even on 800x600 resolution.

The new integration test passes on Windows, but fails on macOS.
Either the bug is also present on that platform (I'll check), or we need to wait a bit for the new position to be properly reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Window position shifts when size changes with taskbar on left or top
5 participants