Skip to content

Commit

Permalink
refactor(core): add window getters, physical & logical sizes/positions (
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 5, 2021
1 parent b675469 commit 6bfac86
Show file tree
Hide file tree
Showing 15 changed files with 896 additions and 342 deletions.
6 changes: 6 additions & 0 deletions .changes/refactor-window-management.md
@@ -0,0 +1,6 @@
---
"api": patch
"tauri": patch
---

The window management API was refactored: removed `setX`, `setY`, `setWidth`, `setHeight` APIs, renamed `resize` to `setSize` and the size and position APIs now allow defining both logical and physical values.
6 changes: 6 additions & 0 deletions .changes/window-getters.md
@@ -0,0 +1,6 @@
---
"api": patch
"tauri": patch
---

Adds window getters.
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.js

Large diffs are not rendered by default.

116 changes: 49 additions & 67 deletions core/tauri/src/endpoints/window.rs
Expand Up @@ -4,7 +4,12 @@

#[cfg(window_create)]
use crate::Manager;
use crate::{api::config::WindowConfig, endpoints::InvokeResponse, Params, Window};
use crate::{
api::config::WindowConfig,
endpoints::InvokeResponse,
runtime::window::dpi::{Position, Size},
Params, Window,
};
use serde::Deserialize;

use crate::Icon;
Expand All @@ -28,64 +33,40 @@ impl From<IconDto> for Icon {

/// The API descriptor.
#[derive(Deserialize)]
#[serde(tag = "cmd", rename_all = "camelCase")]
#[serde(tag = "cmd", content = "data", rename_all = "camelCase")]
pub enum Cmd {
CreateWebview {
options: WindowConfig,
},
SetResizable {
resizable: bool,
},
SetTitle {
title: String,
},
// Getters
ScaleFactor,
InnerPosition,
OuterPosition,
InnerSize,
OuterSize,
IsFullscreen,
IsMaximized,
CurrentMonitor,
PrimaryMonitor,
AvailableMonitors,
// Setters
SetResizable(bool),
SetTitle(String),
Maximize,
Unmaximize,
Minimize,
Unminimize,
Show,
Hide,
Close,
SetDecorations {
decorations: bool,
},
#[serde(rename_all = "camelCase")]
SetAlwaysOnTop {
always_on_top: bool,
},
SetWidth {
width: f64,
},
SetHeight {
height: f64,
},
Resize {
width: f64,
height: f64,
},
SetDecorations(bool),
#[serde(rename_all = "camelCase")]
SetMinSize {
min_width: f64,
min_height: f64,
},
#[serde(rename_all = "camelCase")]
SetMaxSize {
max_width: f64,
max_height: f64,
},
SetX {
x: f64,
},
SetY {
y: f64,
},
SetPosition {
x: f64,
y: f64,
},
SetFullscreen {
fullscreen: bool,
},
SetAlwaysOnTop(bool),
SetSize(Size),
SetMinSize(Option<Size>),
SetMaxSize(Option<Size>),
SetPosition(Position),
SetFullscreen(bool),
SetIcon {
icon: IconDto,
},
Expand Down Expand Up @@ -135,33 +116,34 @@ impl Cmd {
}),
)?;
}

Self::SetResizable { resizable } => window.set_resizable(resizable)?,
Self::SetTitle { title } => window.set_title(&title)?,
// Getters
Self::ScaleFactor => return Ok(window.scale_factor()?.into()),
Self::InnerPosition => return Ok(window.inner_position()?.into()),
Self::OuterPosition => return Ok(window.outer_position()?.into()),
Self::InnerSize => return Ok(window.inner_size()?.into()),
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::CurrentMonitor => return Ok(window.current_monitor()?.into()),
Self::PrimaryMonitor => return Ok(window.primary_monitor()?.into()),
Self::AvailableMonitors => return Ok(window.available_monitors()?.into()),
// Setters
Self::SetResizable(resizable) => window.set_resizable(resizable)?,
Self::SetTitle(title) => window.set_title(&title)?,
Self::Maximize => window.maximize()?,
Self::Unmaximize => window.unmaximize()?,
Self::Minimize => window.minimize()?,
Self::Unminimize => window.unminimize()?,
Self::Show => window.show()?,
Self::Hide => window.hide()?,
Self::Close => window.close()?,
Self::SetDecorations { decorations } => window.set_decorations(decorations)?,
Self::SetAlwaysOnTop { always_on_top } => window.set_always_on_top(always_on_top)?,
Self::SetWidth { width } => window.set_width(width)?,
Self::SetHeight { height } => window.set_height(height)?,
Self::Resize { width, height } => window.resize(width, height)?,
Self::SetMinSize {
min_width,
min_height,
} => window.set_min_size(min_width, min_height)?,
Self::SetMaxSize {
max_width,
max_height,
} => window.set_max_size(max_width, max_height)?,
Self::SetX { x } => window.set_x(x)?,
Self::SetY { y } => window.set_y(y)?,
Self::SetPosition { x, y } => window.set_position(x, y)?,
Self::SetFullscreen { fullscreen } => window.set_fullscreen(fullscreen)?,
Self::SetDecorations(decorations) => window.set_decorations(decorations)?,
Self::SetAlwaysOnTop(always_on_top) => window.set_always_on_top(always_on_top)?,
Self::SetSize(size) => window.set_size(size)?,
Self::SetMinSize(size) => window.set_min_size(size)?,
Self::SetMaxSize(size) => window.set_max_size(size)?,
Self::SetPosition(position) => window.set_position(position)?,
Self::SetFullscreen(fullscreen) => window.set_fullscreen(fullscreen)?,
Self::SetIcon { icon } => window.set_icon(icon.into())?,
Self::StartDragging => window.start_dragging()?,
}
Expand Down
6 changes: 5 additions & 1 deletion core/tauri/src/lib.rs
Expand Up @@ -61,8 +61,12 @@ pub use {
},
self::runtime::app::{App, Builder},
self::runtime::flavors::wry::Wry,
self::runtime::monitor::Monitor,
self::runtime::webview::{WebviewAttributes, WindowBuilder},
self::runtime::window::export::Window,
self::runtime::window::export::{
dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Pixel, Position, Size},
Window,
},
self::state::{State, StateManager},
};

Expand Down

0 comments on commit 6bfac86

Please sign in to comment.