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

Window does not maintain size after being minimized on Windows #2729

Closed
ProgrammingGoat opened this issue Jul 22, 2024 · 5 comments · Fixed by #2837
Closed

Window does not maintain size after being minimized on Windows #2729

ProgrammingGoat opened this issue Jul 22, 2024 · 5 comments · Fixed by #2837
Labels
bug A crash or error in behavior. good first issue Is this your first time contributing? This could be a good place to start! windows The issue relates to Microsoft Windows support.

Comments

@ProgrammingGoat
Copy link

Describe the bug

Platform tested: Windows
When a window gets minimized and restored, it will be restored to the smallest possible size given its contents, rather than the size it was when minimized.

Steps to reproduce

  1. Create a new briefcase project
  2. Insert a label into the main box
main_box = toga.Box()
label = toga.Label("Hello World")
main_box.add(label)
  1. Run briefcase dev (or briefcase run)
  2. Minimize the window
  3. Restore the window
  4. The window has now been resized to the smallest possible size.

Expected behavior

Window gets restored to the original size before minimizing.

Screenshots

Before:
Default sized window

After:
Tiny window

Environment

  • Operating System: Windows 10
  • Python version: 3.12
  • Software versions:
    • Briefcase: 0.3.19
    • Toga: 0.4.5

Logs

No response

Additional context

No response

@ProgrammingGoat ProgrammingGoat added the bug A crash or error in behavior. label Jul 22, 2024
@freakboy3742 freakboy3742 added the windows The issue relates to Microsoft Windows support. label Jul 23, 2024
@freakboy3742
Copy link
Member

Thanks for the report.

Some further clarifications:

  • This only affects Windows; GTK and macOS don't have the same behavior.
  • It doesn't affect maximizing - only minimising.

Based on some preliminary analysis, I think I've worked out what is happening. The Winforms toga.Window class has a listener on window resizes. When you resize the window, this causes a re-evaluation of the layout; the maximum of the current layout size and the minimum possible layout size is applied as the actual size (effectively imposing a minimum size on the window that matches the minimum possible layout size).

However, on Winforms, minimizing triggers a resize event, with a window size of 0,0. This causes the window size to be set to the minimum possible size of the window content, resulting in the behavior seen here.

From a quick inspection, I think the fix is to check the current window state when the resize event occurs. We don't need to process resize events when the window is minimized; so a if self.native.WindowState != Winforms.FormWindowState.Minimized check in the toga_winforms.Window.winforms_Resize handler should be all that is needed.

By way of testing, there is an existing testbed test that validates window minimisation (tests/window/test_window.py::test_visibility); this check validates the initial size of the window being minimized as part of a check of window resizing, but doesn't validate the size of the window after minimization. An assertion for post-unminimise window size should be sufficient validation.

@freakboy3742 freakboy3742 added the good first issue Is this your first time contributing? This could be a good place to start! label Jul 23, 2024
@yashathwani
Copy link

@freakboy3742 would like to work on this issue could you please assign me this issue to me!!

@freakboy3742
Copy link
Member

@yashathwani We don't formally "assign" issues; dropping a comment that you're working on the topic (as you have already done) is more than enough. I look forward to seeing a PR!

@yashathwani
Copy link

I have made some changes in windows.py . Could you please guide me on how to test these changes to ensure they are working correctly with the Toga framework? Like how to run the application what requirements are required
Thankyou

@freakboy3742
Copy link
Member

@yashathwani The Toga docs have a contribution guide that details how to set up a development environment, and how Toga is tested.

My original reply to this ticket details the extra assertion in the testbed that is required to validate this change.

If you need any additional pointers, let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior. good first issue Is this your first time contributing? This could be a good place to start! windows The issue relates to Microsoft Windows support.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants