Skip to content

Add ability to change the min/max size of windows at runtime - #405

Merged
tomaka merged 12 commits into
rust-windowing:masterfrom
Osspial:size_bounds
Mar 23, 2018
Merged

tomaka merged 12 commits into
rust-windowing:masterfrom
Osspial:size_bounds

Conversation

@Osspial

@Osspial Osspial commented Feb 9, 2018

Copy link
Copy Markdown
Contributor

Adds the ability to change the minimum and maximum sizes of a window, even after it's been created, with set_min_dimensions and set_max_dimensions functions on the Window struct.

I've only tested this on Windows, and I'm pretty sure the OSX and Linux code compiles, but it's much harder for me to test them personally than it is to test the Windows code. I'll probably be able to test the Linux code in the next couple of days but I don't think I can test the OSX code personally.

@francesca64

Copy link
Copy Markdown
Member

Sorry for hijacking your PR; I was originally planning to just give you a review on the X11 portions, but fixing it turned out to be more involved, and I figured you wouldn't enjoy dealing with that.

Since WM_NORMAL_HINTS is just a single window property containing all of the size hints, updating min/max by only setting one causes the other one to be unset, along with any other hints. This revised implementation bases the new hints off of the current value of WM_NORMAL_HINTS.

Some other changes:

  • I removed your usage of unwrap_or for handling None, as the values used were semantically incorrect and no longer necessary for unsetting min/max.
  • I used c_int rather than i32; while ICCCM specifies the latter, the Xlib code uses the former.
  • I dynamically allocated XSizeHints using XAllocSizeHints, as recommended in the lead section of the docs. To facilitate this, I created a wrapper struct named XSmartPointer.
  • I changed XSetNormalHints to XSetWMNormalHints, as the former is obsolete.
  • I applied all of the relevant changes above to the window building code as well.

Note that this still needs to be looked at on Wayland and OSX. While this works fine now on X11, I've found that setting the min/max to the same size tends to permanently disable resizing for me (on XFCE). If I try to change the min/max after the fact, the hints are set correctly according to xwininfo, but the window still can't be resized (occasionally, resizing is re-enabled as expected, but it's very unreliable). However, that doesn't seem to have anything to do with anything introduced here (setting them to the same size during window building causes it to happen as well, it's just we never had a way to try to change it afterwards before), and there's a chance that it's just an issue with my WM. Thus, it would be good for more people to test this on X11.

Anyway, thanks for the contribution!

@tomaka tomaka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to specify what happens when the min/max intersect or when the max is below the min. But since his isn't specified in the builder either, I'm ok with the change as it is.

@Osspial

Osspial commented Feb 28, 2018

Copy link
Copy Markdown
Contributor Author

I got a OSX VM running, and it seems like the code works fine. Would it be possible to merge this, once the changelog conflict is resolved?

@francesca64

Copy link
Copy Markdown
Member

@Osspial I'm in favor of that, since I don't see getting further review as likely, and both the OS X and Wayland code are straightforward and small enough that I don't see any meaningful risk of introducing technical debt.

@tomaka

tomaka commented Mar 6, 2018

Copy link
Copy Markdown
Contributor

Needs a rebase and we're good to go I think.

@Osspial

Osspial commented Mar 21, 2018

Copy link
Copy Markdown
Contributor Author

@tomaka Just rebased. Everything should be good now.

@tomaka
tomaka merged commit bbcd301 into rust-windowing:master Mar 23, 2018
francesca64 pushed a commit to francesca64/winit that referenced this pull request Mar 26, 2018
…ndowing#405)

* Add min/max size setting for win32 and wayland backends

* Implement dynamic min/max size on macos

* Add min/max size setting for x11

* Add empty functions for remaining platforms

* Improved min/max size setting for x11

* Added CHANGELOG entry for new min/max methods

* Added documentation for new min/max methods

* On win32, bound window size to min/max dimensions on window creation

* On win32, force re-check of window size when changing min/max dimensions

* Fix freeze when setting min and max size
tmfink pushed a commit to tmfink/winit that referenced this pull request Jan 5, 2022
tmfink pushed a commit to tmfink/winit that referenced this pull request Jan 5, 2022
Initialize resized mask textures to rgba(0, 0, 0, 0), not rgba(0, 0, 0, 1).

Partially addresses rust-windowing#405.
madsmtm pushed a commit to madsmtm/winit that referenced this pull request Jun 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants