From 863396aa5260ffccd2d13b1fbcac252345f7d590 Mon Sep 17 00:00:00 2001 From: Muhammad Ragib Hasin Date: Sat, 8 Jan 2022 23:06:12 +0600 Subject: [PATCH 1/3] Add methods WindowHandle::is_resizable etc --- druid-shell/src/backend/gtk/window.rs | 18 ++++++++++++++++++ druid-shell/src/backend/mac/window.rs | 15 +++++++++++++++ druid-shell/src/backend/wayland/window.rs | 15 +++++++++++++++ druid-shell/src/backend/web/window.rs | 15 +++++++++++++++ druid-shell/src/backend/windows/window.rs | 21 +++++++++++++++++++++ druid-shell/src/backend/x11/window.rs | 15 +++++++++++++++ druid-shell/src/window.rs | 15 +++++++++++++++ 7 files changed, 114 insertions(+) diff --git a/druid-shell/src/backend/gtk/window.rs b/druid-shell/src/backend/gtk/window.rs index b82dc93e28..f6ee54edd0 100644 --- a/druid-shell/src/backend/gtk/window.rs +++ b/druid-shell/src/backend/gtk/window.rs @@ -972,12 +972,30 @@ impl WindowHandle { } } + pub fn is_resizable(&self) -> bool { + self.state + .upgrade() + .map(true, |state| state.window.is_resizable()) + } + + pub fn is_transparent(&self) -> bool { + self.state + .upgrade() + .map_or(false, |state| state.is_transparent) + } + pub fn show_titlebar(&self, show_titlebar: bool) { if let Some(state) = self.state.upgrade() { state.window.set_decorated(show_titlebar) } } + pub fn has_titlebar(&self) -> bool { + self.state + .upgrade() + .map(true, |state| state.window.is_decorated()) + } + pub fn set_position(&self, mut position: Point) { if let Some(state) = self.state.upgrade() { if let Some(parent_state) = &state.parent { diff --git a/druid-shell/src/backend/mac/window.rs b/druid-shell/src/backend/mac/window.rs index 6e16b870d9..7a6280100e 100644 --- a/druid-shell/src/backend/mac/window.rs +++ b/druid-shell/src/backend/mac/window.rs @@ -1232,6 +1232,11 @@ impl WindowHandle { // TODO: Implement this pub fn show_titlebar(&self, _show_titlebar: bool) {} + pub fn has_titlebar(&self) -> bool { + tracing::warn!("WindowHandle::has_titlebar is currently unimplemented for Mac."); + true + } + // Need to translate mac y coords, as they start from bottom left pub fn set_position(&self, mut position: Point) { // TODO: Maybe @cmyr can get this into a state where modal windows follow the parent? @@ -1380,6 +1385,16 @@ impl WindowHandle { } } + pub fn is_resizable(&self) -> bool { + tracing::warn!("WindowHandle::is_resizable is currently unimplemented for Mac."); + true + } + + pub fn is_transparent(&self) -> bool { + tracing::warn!("WindowHandle::is_transparent is currently unimplemented for Mac."); + false + } + pub fn set_menu(&self, menu: Menu) { unsafe { NSApp().setMainMenu_(menu.menu); diff --git a/druid-shell/src/backend/wayland/window.rs b/druid-shell/src/backend/wayland/window.rs index 6ad45048ec..122cfb74b5 100644 --- a/druid-shell/src/backend/wayland/window.rs +++ b/druid-shell/src/backend/wayland/window.rs @@ -106,10 +106,25 @@ impl WindowHandle { tracing::warn!("resizable is unimplemented on wayland"); } + pub fn is_resizable(&self) -> bool { + tracing::warn!("is_resizable is unimplemented on wayland"); + true + } + + pub fn is_transparent(&self) -> bool { + tracing::warn!("is_transparent is unimplemented on wayland"); + false + } + pub fn show_titlebar(&self, _show_titlebar: bool) { tracing::warn!("show_titlebar is unimplemented on wayland"); } + pub fn has_titlebar(&self) -> bool { + tracing::warn!("has_titlebar is unimplemented on wayland"); + true + } + pub fn set_position(&self, _position: Point) { tracing::warn!("set_position is unimplemented on wayland"); } diff --git a/druid-shell/src/backend/web/window.rs b/druid-shell/src/backend/web/window.rs index 042d400615..4e7aedbccb 100644 --- a/druid-shell/src/backend/web/window.rs +++ b/druid-shell/src/backend/web/window.rs @@ -384,14 +384,29 @@ impl WindowBuilder { // Ignored } + pub fn is_resizable(&self) -> bool { + warn!("is_resizable is unimplemented on web"); + true + } + pub fn show_titlebar(&mut self, _show_titlebar: bool) { // Ignored } + pub fn has_titlebar(&self) -> bool { + warn!("has_titlebar is unimplemented on web"); + true + } + pub fn set_transparent(&mut self, _transparent: bool) { // Ignored } + pub fn is_transparent(&self) -> bool { + warn!("is_transparent is unimplemented on web"); + true + } + pub fn set_position(&mut self, _position: Point) { // Ignored } diff --git a/druid-shell/src/backend/windows/window.rs b/druid-shell/src/backend/windows/window.rs index d6c692d0f9..0180bafb46 100644 --- a/druid-shell/src/backend/windows/window.rs +++ b/druid-shell/src/backend/windows/window.rs @@ -1926,6 +1926,13 @@ impl WindowHandle { self.defer(DeferredOp::ShowTitlebar(show_titlebar)); } + pub fn has_titlebar(&self) -> bool { + self.state + .upgrade() + .map(|state| state.has_titlebar.get()) + .unwrap_or_default() + } + pub fn set_position(&self, position: Point) { self.defer(DeferredOp::SetWindowState(window::WindowState::Restored)); if let Some(w) = self.state.upgrade() { @@ -2032,6 +2039,20 @@ impl WindowHandle { self.defer(DeferredOp::SetResizable(resizable)); } + pub fn is_resizable(&self) -> bool { + self.state + .upgrade() + .map(|state| state.is_resizable.get()) + .unwrap_or_default() + } + + pub fn is_transparent(&self) -> bool { + self.state + .upgrade() + .map(|state| state.is_transparent.get()) + .unwrap_or_default() + } + /// Sets the window state. pub fn set_window_state(&self, state: window::WindowState) { self.defer(DeferredOp::SetWindowState(state)); diff --git a/druid-shell/src/backend/x11/window.rs b/druid-shell/src/backend/x11/window.rs index e88709dc30..119ead3bce 100644 --- a/druid-shell/src/backend/x11/window.rs +++ b/druid-shell/src/backend/x11/window.rs @@ -1625,6 +1625,16 @@ impl WindowHandle { } } + pub fn is_resizable(&self) -> bool { + warn!("is_resizable is unimplemented on x11"); + true + } + + pub fn is_transparent(&self) -> bool { + warn!("is_transparent is unimplemented on x11"); + false + } + pub fn show_titlebar(&self, show_titlebar: bool) { if let Some(w) = self.window.upgrade() { w.show_titlebar(show_titlebar); @@ -1633,6 +1643,11 @@ impl WindowHandle { } } + pub fn has_titlebar(&self) -> bool { + warn!("has_titlebar is unimplemented on x11"); + true + } + pub fn set_position(&self, position: Point) { if let Some(w) = self.window.upgrade() { w.set_position(position); diff --git a/druid-shell/src/window.rs b/druid-shell/src/window.rs index 32fde8b9df..d28b40e847 100644 --- a/druid-shell/src/window.rs +++ b/druid-shell/src/window.rs @@ -191,6 +191,16 @@ impl WindowHandle { self.0.resizable(resizable) } + /// Get whether the window is resizable + pub fn is_resizable(&self) -> bool { + self.0.is_resizable() + } + + /// Get whether the window is transparent + pub fn is_transparent(&self) -> bool { + self.0.is_transparent() + } + /// Sets the state of the window. pub fn set_window_state(&mut self, state: WindowState) { self.0.set_window_state(state); @@ -216,6 +226,11 @@ impl WindowHandle { self.0.show_titlebar(show_titlebar) } + /// Get whether the window has titlebar. + pub fn has_titlebar(&self) -> bool { + self.0.has_titlebar() + } + /// Sets the position of the window. /// /// The position is given in [display points], measured relative to the parent window if there From d1d908dcc273a9c503ee5d122d69d3f96044d604 Mon Sep 17 00:00:00 2001 From: Muhammad Ragib Hasin Date: Sun, 9 Jan 2022 00:16:48 +0600 Subject: [PATCH 2/3] Implement WindowHandle::is_transparent for wayland As in https://github.com/linebender/druid/pull/2115#discussion_r780690511 --- druid-shell/src/backend/wayland/window.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/druid-shell/src/backend/wayland/window.rs b/druid-shell/src/backend/wayland/window.rs index 122cfb74b5..4606358cdb 100644 --- a/druid-shell/src/backend/wayland/window.rs +++ b/druid-shell/src/backend/wayland/window.rs @@ -112,8 +112,7 @@ impl WindowHandle { } pub fn is_transparent(&self) -> bool { - tracing::warn!("is_transparent is unimplemented on wayland"); - false + true } pub fn show_titlebar(&self, _show_titlebar: bool) { From 15b2f82bb604563892424e589516743553bf0f45 Mon Sep 17 00:00:00 2001 From: Muhammad Ragib Hasin Date: Tue, 11 Jan 2022 10:58:13 +0600 Subject: [PATCH 3/3] Fix build fails on GTK and web --- druid-shell/src/backend/gtk/window.rs | 6 ++--- druid-shell/src/backend/web/window.rs | 33 +++++++++++++-------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/druid-shell/src/backend/gtk/window.rs b/druid-shell/src/backend/gtk/window.rs index f6ee54edd0..fdff1a348a 100644 --- a/druid-shell/src/backend/gtk/window.rs +++ b/druid-shell/src/backend/gtk/window.rs @@ -975,13 +975,13 @@ impl WindowHandle { pub fn is_resizable(&self) -> bool { self.state .upgrade() - .map(true, |state| state.window.is_resizable()) + .map_or(true, |state| state.window.is_resizable()) } pub fn is_transparent(&self) -> bool { self.state .upgrade() - .map_or(false, |state| state.is_transparent) + .map_or(false, |state| state.is_transparent.get()) } pub fn show_titlebar(&self, show_titlebar: bool) { @@ -993,7 +993,7 @@ impl WindowHandle { pub fn has_titlebar(&self) -> bool { self.state .upgrade() - .map(true, |state| state.window.is_decorated()) + .map_or(true, |state| state.window.is_decorated()) } pub fn set_position(&self, mut position: Point) { diff --git a/druid-shell/src/backend/web/window.rs b/druid-shell/src/backend/web/window.rs index 4e7aedbccb..1da3e96121 100644 --- a/druid-shell/src/backend/web/window.rs +++ b/druid-shell/src/backend/web/window.rs @@ -384,29 +384,14 @@ impl WindowBuilder { // Ignored } - pub fn is_resizable(&self) -> bool { - warn!("is_resizable is unimplemented on web"); - true - } - pub fn show_titlebar(&mut self, _show_titlebar: bool) { // Ignored } - pub fn has_titlebar(&self) -> bool { - warn!("has_titlebar is unimplemented on web"); - true - } - pub fn set_transparent(&mut self, _transparent: bool) { // Ignored } - pub fn is_transparent(&self) -> bool { - warn!("is_transparent is unimplemented on web"); - true - } - pub fn set_position(&mut self, _position: Point) { // Ignored } @@ -513,13 +498,27 @@ impl WindowHandle { } pub fn resizable(&self, _resizable: bool) { - warn!("resizable unimplemented for web"); + warn!("WindowHandle::resizable unimplemented for web"); + } + + pub fn is_resizable(&self) -> bool { + warn!("WindowHandle::is_resizable is unimplemented on web"); + true } pub fn show_titlebar(&self, _show_titlebar: bool) { - warn!("show_titlebar unimplemented for web"); + warn!("WindowHandle::show_titlebar unimplemented for web"); } + pub fn has_titlebar(&self) -> bool { + warn!("WindowHandle::has_titlebar is unimplemented on web"); + true + } + + pub fn is_transparent(&self) -> bool { + warn!("WindowHandle::is_transparent is unimplemented on web"); + true + } pub fn set_position(&self, _position: Point) { warn!("WindowHandle::set_position unimplemented for web"); }