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

fix(Linux): resize doesn't work when calling with resizable, fix #545 #553

Merged
merged 6 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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