Skip to content

Commit

Permalink
feat(core): add is_decorated Window getter
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 30, 2021
1 parent f63925e commit f58a211
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/api-is-decorated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"api": patch
---

Adds `isDecorated` getter on the window API.
7 changes: 7 additions & 0 deletions .changes/is-decorated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch
"tauri-runtime": patch
"tauri-runtime-wry": patch
---

Adds `is_decorated` getter on Window.
7 changes: 7 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ enum WindowMessage {
OuterSize(Sender<PhysicalSize<u32>>),
IsFullscreen(Sender<bool>),
IsMaximized(Sender<bool>),
IsDecorated(Sender<bool>),
CurrentMonitor(Sender<Option<MonitorHandle>>),
PrimaryMonitor(Sender<Option<MonitorHandle>>),
AvailableMonitors(Sender<Vec<MonitorHandle>>),
Expand Down Expand Up @@ -531,6 +532,11 @@ impl Dispatch for WryDispatcher {
Ok(dispatcher_getter!(self, WindowMessage::IsMaximized))
}

/// Gets the window’s current decoration state.
fn is_decorated(&self) -> Result<bool> {
Ok(dispatcher_getter!(self, WindowMessage::IsDecorated))
}

fn current_monitor(&self) -> Result<Option<Monitor>> {
Ok(
dispatcher_getter!(self, WindowMessage::CurrentMonitor)
Expand Down Expand Up @@ -1133,6 +1139,7 @@ fn handle_event_loop(
.unwrap(),
WindowMessage::IsFullscreen(tx) => tx.send(window.fullscreen().is_some()).unwrap(),
WindowMessage::IsMaximized(tx) => tx.send(window.is_maximized()).unwrap(),
WindowMessage::IsDecorated(tx) => tx.send(window.is_decorated()).unwrap(),
WindowMessage::CurrentMonitor(tx) => tx.send(window.current_monitor()).unwrap(),
WindowMessage::PrimaryMonitor(tx) => tx.send(window.primary_monitor()).unwrap(),
WindowMessage::AvailableMonitors(tx) => {
Expand Down
3 changes: 3 additions & 0 deletions core/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ pub trait Dispatch: Clone + Send + Sized + 'static {
/// Gets the window's current maximized state.
fn is_maximized(&self) -> crate::Result<bool>;

/// Gets the window’s current decoration state.
fn is_decorated(&self) -> crate::Result<bool>;

/// Returns the monitor on which the window currently resides.
///
/// Returns None if current monitor can't be detected.
Expand Down
2 changes: 2 additions & 0 deletions core/tauri/src/endpoints/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub enum Cmd {
OuterSize,
IsFullscreen,
IsMaximized,
IsDecorated,
CurrentMonitor,
PrimaryMonitor,
AvailableMonitors,
Expand Down Expand Up @@ -129,6 +130,7 @@ impl Cmd {
Self::OuterSize => return Ok(window.outer_size()?.into()),
Self::IsFullscreen => return Ok(window.is_fullscreen()?.into()),
Self::IsMaximized => return Ok(window.is_maximized()?.into()),
Self::IsDecorated => return Ok(window.is_decorated()?.into()),
Self::CurrentMonitor => return Ok(window.current_monitor()?.into()),
Self::PrimaryMonitor => return Ok(window.primary_monitor()?.into()),
Self::AvailableMonitors => return Ok(window.available_monitors()?.into()),
Expand Down
5 changes: 5 additions & 0 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ impl<P: Params> Window<P> {
self.window.dispatcher.is_maximized().map_err(Into::into)
}

/// Gets the window’s current decoration state.
pub fn is_decorated(&self) -> crate::Result<bool> {
self.window.dispatcher.is_decorated().map_err(Into::into)
}

/// Returns the monitor on which the window currently resides.
///
/// Returns None if current monitor can't be detected.
Expand Down
10 changes: 10 additions & 0 deletions tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,16 @@ class WindowManager {
})
}

/** Gets the window's current decorated state. */
async isDecorated(): Promise<boolean> {
return invokeTauriCommand({
__tauriModule: 'Window',
message: {
cmd: 'isDecorated'
}
})
}

// Setters

/**
Expand Down

0 comments on commit f58a211

Please sign in to comment.