From 5751be3a25a9cf590a35ba9a3d77eb15ad9d4b67 Mon Sep 17 00:00:00 2001 From: Wu Yu Wei Date: Wed, 7 Sep 2022 00:17:41 +0800 Subject: [PATCH 1/6] Try cargo r --example resizable and press space --- examples/resizable.rs | 8 +++++--- src/platform_impl/linux/event_loop.rs | 4 ++-- src/platform_impl/linux/window.rs | 21 ++++++++------------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/examples/resizable.rs b/examples/resizable.rs index 9329f818f..a29d4a097 100644 --- a/examples/resizable.rs +++ b/examples/resizable.rs @@ -39,9 +39,11 @@ fn main() { }, .. } => { - resizable = !resizable; - println!("Resizable: {}", resizable); - window.set_resizable(resizable); + // resizable = !resizable; + // println!("Resizable: {}", resizable); + window.set_resizable(true); + window.set_inner_size(LogicalSize::new(800.0, 600.0)); + window.set_resizable(false); } _ => (), }, diff --git a/src/platform_impl/linux/event_loop.rs b/src/platform_impl/linux/event_loop.rs index 5a651f15e..bff030600 100644 --- a/src/platform_impl/linux/event_loop.rs +++ b/src/platform_impl/linux/event_loop.rs @@ -216,8 +216,8 @@ impl EventLoop { 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()); + // let (alloc, _) = window.allocated_size(); + // window.set_size_request(alloc.width(), alloc.height()); window.set_resizable(resizable) } WindowRequest::Minimized(minimized) => { diff --git a/src/platform_impl/linux/window.rs b/src/platform_impl/linux/window.rs index 6d5e03bd4..7b6464918 100644 --- a/src/platform_impl/linux/window.rs +++ b/src/platform_impl/linux/window.rs @@ -86,21 +86,16 @@ impl Window { .inner_size .map(|size| size.to_logical::(win_scale_factor as f64).into()) .unwrap_or((800, 600)); - if attributes.resizable { - window.set_resizable(attributes.resizable); - window.set_default_size(width, height); + 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 { - 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(width, height); } + window.set_resizable(attributes.resizable); // Set Min/Max Size let geom_mask = (if attributes.min_inner_size.is_some() { From 98f86a649cbd71b8a9695d2f10fd6bf0be1fe7ed Mon Sep 17 00:00:00 2001 From: Wu Yu Wei Date: Wed, 7 Sep 2022 00:30:25 +0800 Subject: [PATCH 2/6] Set dault size to (1, 1) --- examples/resizable.rs | 2 +- src/platform_impl/linux/window.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/resizable.rs b/examples/resizable.rs index a29d4a097..891302c46 100644 --- a/examples/resizable.rs +++ b/examples/resizable.rs @@ -42,7 +42,7 @@ fn main() { // resizable = !resizable; // println!("Resizable: {}", resizable); window.set_resizable(true); - window.set_inner_size(LogicalSize::new(800.0, 600.0)); + window.set_inner_size(LogicalSize::new(100.0, 100.0)); window.set_resizable(false); } _ => (), diff --git a/src/platform_impl/linux/window.rs b/src/platform_impl/linux/window.rs index 7b6464918..f839e8517 100644 --- a/src/platform_impl/linux/window.rs +++ b/src/platform_impl/linux/window.rs @@ -93,7 +93,8 @@ impl Window { // Because if dimension is over window size, maximization does not work correct. window.set_size_request(100, 100); } else { - window.set_default_size(width, height); + window.set_default_size(1, 1); + window.resize(width, height); } window.set_resizable(attributes.resizable); From f65c28c6ead70aa20f2a395d25e2084710adcc2e Mon Sep 17 00:00:00 2001 From: Wu Yu Wei Date: Wed, 7 Sep 2022 19:53:19 +0800 Subject: [PATCH 3/6] Remove all set_size_request --- src/platform_impl/linux/window.rs | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/platform_impl/linux/window.rs b/src/platform_impl/linux/window.rs index f839e8517..eb511a442 100644 --- a/src/platform_impl/linux/window.rs +++ b/src/platform_impl/linux/window.rs @@ -86,16 +86,13 @@ impl Window { .inner_size .map(|size| size.to_logical::(win_scale_factor as f64).into()) .unwrap_or((800, 600)); + window.set_default_size(1, 1); + window.resize(width, height); + 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_default_size(1, 1); - window.resize(width, height); + window.maximize(); } + window.set_resizable(attributes.resizable); // Set Min/Max Size @@ -194,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); From 8e24d3bf1acd089a357350f4e0faaae6a3bdb11f Mon Sep 17 00:00:00 2001 From: Wu Yu Wei Date: Wed, 7 Sep 2022 20:28:42 +0800 Subject: [PATCH 4/6] Add platform-specific note to set_resizable --- src/window.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/window.rs b/src/window.rs index bfb3c5422..13bbb602a 100644 --- a/src/window.rs +++ b/src/window.rs @@ -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) { From 4d6286e7ffa2fc0dfc3c3e607e49fb68ad661d42 Mon Sep 17 00:00:00 2001 From: Wu Yu Wei Date: Wed, 7 Sep 2022 20:34:39 +0800 Subject: [PATCH 5/6] Add change file --- .changes/gtk-resizable.md | 11 +++++++++++ examples/resizable.rs | 8 +++----- src/platform_impl/linux/event_loop.rs | 2 -- 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 .changes/gtk-resizable.md diff --git a/.changes/gtk-resizable.md b/.changes/gtk-resizable.md new file mode 100644 index 000000000..46b7f4104 --- /dev/null +++ b/.changes/gtk-resizable.md @@ -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. diff --git a/examples/resizable.rs b/examples/resizable.rs index 891302c46..9329f818f 100644 --- a/examples/resizable.rs +++ b/examples/resizable.rs @@ -39,11 +39,9 @@ fn main() { }, .. } => { - // resizable = !resizable; - // println!("Resizable: {}", resizable); - window.set_resizable(true); - window.set_inner_size(LogicalSize::new(100.0, 100.0)); - window.set_resizable(false); + resizable = !resizable; + println!("Resizable: {}", resizable); + window.set_resizable(resizable); } _ => (), }, diff --git a/src/platform_impl/linux/event_loop.rs b/src/platform_impl/linux/event_loop.rs index bff030600..ec1176aa6 100644 --- a/src/platform_impl/linux/event_loop.rs +++ b/src/platform_impl/linux/event_loop.rs @@ -216,8 +216,6 @@ impl EventLoop { 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::Minimized(minimized) => { From 6affc89050d1bd3facbe490e543e645b42ff191a Mon Sep 17 00:00:00 2001 From: Wu Yu Wei Date: Wed, 7 Sep 2022 20:39:27 +0800 Subject: [PATCH 6/6] cargo fmt --- src/platform_impl/linux/event_loop.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/platform_impl/linux/event_loop.rs b/src/platform_impl/linux/event_loop.rs index ec1176aa6..05a88e1e8 100644 --- a/src/platform_impl/linux/event_loop.rs +++ b/src/platform_impl/linux/event_loop.rs @@ -215,9 +215,7 @@ impl EventLoop { WindowRequest::Focus => { window.present_with_time(gdk_sys::GDK_CURRENT_TIME as _); } - WindowRequest::Resizable(resizable) => { - window.set_resizable(resizable) - } + WindowRequest::Resizable(resizable) => window.set_resizable(resizable), WindowRequest::Minimized(minimized) => { if minimized { window.iconify();