winit icon indicating copy to clipboard operation
winit copied to clipboard

Windows: inner_size() reports 0x0 size when window is minimized

Open simast opened this issue 4 years ago • 7 comments

Noticed this weird behavior.

If you minimize the window on Windows and then request window size using inner_size(), the returned value is 0x0. I think the window size should not be zero since you can hover over minimized window taskbar icon and still see the preview of the window (it can continue to render).

Basically if you now want to always render (even when minimized) you have to track and maintain your own window size metrics and not rely on inner_size(). Seems like a bug maybe, but not sure how other platforms behave when minimized?

simast avatar Aug 29 '21 18:08 simast

The behaviour you're expecting seems to match what I'd expect myself. The only (desktop) platform I'd expect to be different in some way is Wayland.

maroider avatar Aug 29 '21 18:08 maroider

I checked and it looks like the problem comes from the Windows API call itself. It's not mentioned in the documentation but GetClientRect reports a 0x0 rectangle when called on a minimized window. This is passed straight through the winapi crate and then into inner_size().

If we want to implement the expected behavior it would require storing the window size somewhere. I'm not sure what the best way to handle that would be.

chelmich avatar Oct 07 '21 06:10 chelmich

Since this was tagged with "platform parity": at least on the systems I tested my code on, in MacOS and Wayland, there is no WindowEvent::Resized triggered on minimizing windows. So, whatever inner_size() returns on these platforms has no consequence for windows minimization.

On the other hand, Windows triggers WM_SIZE when the window is minimized or maximized (https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-size#parameters).

So from a platform parity perspective, I wonder if it would make sense to issue WindowEvent::Resized only if wParam == SIZE_RESTORED and issue separate minimized/maximized events (https://github.com/rust-windowing/winit/issues/1578) in the respective other cases.

supervacuus avatar Apr 22 '22 12:04 supervacuus

On Wayland window doesn't even know that it got minimized iirc or it's minimized, so that's kind of expected that the size doesn't change. It's a pure compositor thing and nothing can be done to know that. But returning the 0x0 size doesn't make any sense, if anything it should be the size before minimization or something?

We can't issue minimized event on Wayland, since there's no information about that, like at all.

For more take a look at https://wayland.app/protocols/xdg-shell#xdg_toplevel:request:set_minimized

kchibisov avatar Apr 22 '22 12:04 kchibisov

I understand and agree. My question is whether minimizing and maximizing events on windows should at all be handled via WindowEvent::Resized because it doesn't happen on any other platform.

supervacuus avatar Apr 22 '22 12:04 supervacuus

Maximized on Wayland should resize the window, and Maximized should issue Resized, however minimize should likely not.

kchibisov avatar Apr 22 '22 12:04 kchibisov

Related to https://github.com/rust-windowing/winit/issues/783.

madsmtm avatar Sep 03 '24 00:09 madsmtm

@kchibisov this was fixed in #4394 too.

dhardy avatar Nov 01 '25 15:11 dhardy