Skip to content

Commit

Permalink
fix(Linux): resize doesn't work when calling with resizable, fix #545 (
Browse files Browse the repository at this point in the history
…#553)

* Try cargo r --example resizable and press space

* Set dault size to (1, 1)

* Remove all set_size_request

* Add platform-specific note to set_resizable

* Add change file

* cargo fmt

Co-authored-by: Wu Yu Wei <wusyong9104@gmail.com>
  • Loading branch information
wusyong and Wu Yu Wei committed Sep 7, 2022
1 parent 0ae71fc commit 4524d5d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
11 changes: 11 additions & 0 deletions .changes/gtk-resizable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"tao": patch
---

Fix resize doesn't work when calling with resizable. Also add platform specific note to `set_resizable`.
On Linux, most size methods like maximized are async and do not work well with calling
sequentailly. For setting inner or outer size, you don't need to set resizable to true before
it. It can resize no matter what. But if you insist to do so, it has a `100, 100` minimum
limitation somehow. For maximizing, it requires resizable is true. If you really want to set
resizable to false after it. You might need a mechanism to check the window is really
maximized.
6 changes: 1 addition & 5 deletions src/platform_impl/linux/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,7 @@ impl<T: 'static> EventLoop<T> {
WindowRequest::Focus => {
window.present_with_time(gdk_sys::GDK_CURRENT_TIME as _);
}
WindowRequest::Resizable(resizable) => {
let (alloc, _) = window.allocated_size();
window.set_size_request(alloc.width(), alloc.height());
window.set_resizable(resizable)
}
WindowRequest::Resizable(resizable) => window.set_resizable(resizable),
WindowRequest::Minimized(minimized) => {
if minimized {
window.iconify();
Expand Down
36 changes: 7 additions & 29 deletions src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,15 @@ impl Window {
.inner_size
.map(|size| size.to_logical::<f64>(win_scale_factor as f64).into())
.unwrap_or((800, 600));
if attributes.resizable {
window.set_resizable(attributes.resizable);
window.set_default_size(width, height);
} else {
if attributes.maximized {
// Set resizable true to maximize window.
window.set_resizable(true);
// Set minimum size to maximize window.
// Because if dimension is over window size, maximization does not work correct.
window.set_size_request(100, 100);
} else {
window.set_resizable(false);
window.set_size_request(width, height);
}
window.set_default_size(1, 1);
window.resize(width, height);

if attributes.maximized {
window.maximize();
}

window.set_resizable(attributes.resizable);

// Set Min/Max Size
let geom_mask = (if attributes.min_inner_size.is_some() {
gdk::WindowHints::MIN_SIZE
Expand Down Expand Up @@ -198,21 +191,6 @@ impl Window {
window.fullscreen();
}
}
if attributes.maximized {
// Set resizable to false after maximizing.
if !attributes.resizable {
let w = app.window_by_id(window.id()).unwrap();
glib::timeout_add_seconds_local(0, move || {
let (alloc, _) = w.allocated_size();
// Window is maximized and set resizable false then error is occurred,
// so we need to set aloccated size to window.
w.set_size_request(alloc.width(), alloc.height());
w.set_resizable(false);
glib::Continue(false)
});
}
window.maximize();
}
window.set_visible(attributes.visible);
window.set_decorated(attributes.decorations);

Expand Down
6 changes: 6 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,12 @@ impl Window {
///
/// ## Platform-specific
///
/// - **Linux:** Most size methods like maximized are async and do not work well with calling
/// sequentailly. For setting inner or outer size, you don't need to set resizable to true before
/// it. It can resize no matter what. But if you insist to do so, it has a `100, 100` minimum
/// limitation somehow. For maximizing, it requires resizable is true. If you really want to set
/// resizable to false after it. You might need a mechanism to check the window is really
/// maximized.
/// - **iOS / Android:** Unsupported.
#[inline]
pub fn set_resizable(&self, resizable: bool) {
Expand Down

0 comments on commit 4524d5d

Please sign in to comment.