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

Allow cancelling/rejecting window resizes #18183

Open
brads55 opened this issue Feb 12, 2025 · 1 comment
Open

Allow cancelling/rejecting window resizes #18183

brads55 opened this issue Feb 12, 2025 · 1 comment

Comments

@brads55
Copy link

brads55 commented Feb 12, 2025

Is your feature request related to a problem? Please describe.

I have a requirement in my application to restrict window sizes to a multiple of a given size, from what I can tell there is no way to directly do this in Avalonia since the resized event cannot be cancelled or rejected. (The desired behaviour is as Windows Terminal behaves, whereby the window size snaps to multiples of the terminal cell size).

Describe the solution you'd like

Either a way to directly cancel/reject a window resize event, or have the relevant methods in Window or WindowBase etc (HandleResized) not be internal so they can be overriden to manually implement the desired behaviour.

Describe alternatives you've considered

The obvious alternative is to simply resize the window if it is not a desired size, and this sort of works, however not only can you see the window borders flickering as the window is rapidly resizing, the layout for the window seems to be affected as you sometimes seem to end up with the window size and the size the layout code used not matching (i.e. window content too large for the window).

Additional context

No response

@maxkatz6
Copy link
Member

In the past, I had requirement to make window follow specific aspect ratio.

In short, it's not really possible in a cross-platform way.
Where on non-windows OS resizing is happening asynchronously.

For platform specific recommendations, I can say:

  • On Windows use Win32Properties.AddWndProcHookCallback. It will allow you to handle WndProc and "cancel" resizing events before Avalonia gets them.
  • On macOS you can get window handle via window.TryGetPlatformHandle(), and set aspectRatio property. But I don't think it would be easily possible to snap to terminal cells
  • On Linux - good luck. You can listen for resizing events, and then change Position property back. Resizing is always async there.

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

No branches or pull requests

2 participants