Skip to content

Commit 6bfac86

Browse files
authored
refactor(core): add window getters, physical & logical sizes/positions (#1723)
1 parent b675469 commit 6bfac86

File tree

15 files changed

+896
-342
lines changed

15 files changed

+896
-342
lines changed
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"api": patch
3+
"tauri": patch
4+
---
5+
6+
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.

.changes/window-getters.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"api": patch
3+
"tauri": patch
4+
---
5+
6+
Adds window getters.

core/tauri/scripts/bundle.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri/src/endpoints/window.rs

+49-67
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
#[cfg(window_create)]
66
use crate::Manager;
7-
use crate::{api::config::WindowConfig, endpoints::InvokeResponse, Params, Window};
7+
use crate::{
8+
api::config::WindowConfig,
9+
endpoints::InvokeResponse,
10+
runtime::window::dpi::{Position, Size},
11+
Params, Window,
12+
};
813
use serde::Deserialize;
914

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

2934
/// The API descriptor.
3035
#[derive(Deserialize)]
31-
#[serde(tag = "cmd", rename_all = "camelCase")]
36+
#[serde(tag = "cmd", content = "data", rename_all = "camelCase")]
3237
pub enum Cmd {
3338
CreateWebview {
3439
options: WindowConfig,
3540
},
36-
SetResizable {
37-
resizable: bool,
38-
},
39-
SetTitle {
40-
title: String,
41-
},
41+
// Getters
42+
ScaleFactor,
43+
InnerPosition,
44+
OuterPosition,
45+
InnerSize,
46+
OuterSize,
47+
IsFullscreen,
48+
IsMaximized,
49+
CurrentMonitor,
50+
PrimaryMonitor,
51+
AvailableMonitors,
52+
// Setters
53+
SetResizable(bool),
54+
SetTitle(String),
4255
Maximize,
4356
Unmaximize,
4457
Minimize,
4558
Unminimize,
4659
Show,
4760
Hide,
4861
Close,
49-
SetDecorations {
50-
decorations: bool,
51-
},
52-
#[serde(rename_all = "camelCase")]
53-
SetAlwaysOnTop {
54-
always_on_top: bool,
55-
},
56-
SetWidth {
57-
width: f64,
58-
},
59-
SetHeight {
60-
height: f64,
61-
},
62-
Resize {
63-
width: f64,
64-
height: f64,
65-
},
62+
SetDecorations(bool),
6663
#[serde(rename_all = "camelCase")]
67-
SetMinSize {
68-
min_width: f64,
69-
min_height: f64,
70-
},
71-
#[serde(rename_all = "camelCase")]
72-
SetMaxSize {
73-
max_width: f64,
74-
max_height: f64,
75-
},
76-
SetX {
77-
x: f64,
78-
},
79-
SetY {
80-
y: f64,
81-
},
82-
SetPosition {
83-
x: f64,
84-
y: f64,
85-
},
86-
SetFullscreen {
87-
fullscreen: bool,
88-
},
64+
SetAlwaysOnTop(bool),
65+
SetSize(Size),
66+
SetMinSize(Option<Size>),
67+
SetMaxSize(Option<Size>),
68+
SetPosition(Position),
69+
SetFullscreen(bool),
8970
SetIcon {
9071
icon: IconDto,
9172
},
@@ -135,33 +116,34 @@ impl Cmd {
135116
}),
136117
)?;
137118
}
138-
139-
Self::SetResizable { resizable } => window.set_resizable(resizable)?,
140-
Self::SetTitle { title } => window.set_title(&title)?,
119+
// Getters
120+
Self::ScaleFactor => return Ok(window.scale_factor()?.into()),
121+
Self::InnerPosition => return Ok(window.inner_position()?.into()),
122+
Self::OuterPosition => return Ok(window.outer_position()?.into()),
123+
Self::InnerSize => return Ok(window.inner_size()?.into()),
124+
Self::OuterSize => return Ok(window.outer_size()?.into()),
125+
Self::IsFullscreen => return Ok(window.is_fullscreen()?.into()),
126+
Self::IsMaximized => return Ok(window.is_maximized()?.into()),
127+
Self::CurrentMonitor => return Ok(window.current_monitor()?.into()),
128+
Self::PrimaryMonitor => return Ok(window.primary_monitor()?.into()),
129+
Self::AvailableMonitors => return Ok(window.available_monitors()?.into()),
130+
// Setters
131+
Self::SetResizable(resizable) => window.set_resizable(resizable)?,
132+
Self::SetTitle(title) => window.set_title(&title)?,
141133
Self::Maximize => window.maximize()?,
142134
Self::Unmaximize => window.unmaximize()?,
143135
Self::Minimize => window.minimize()?,
144136
Self::Unminimize => window.unminimize()?,
145137
Self::Show => window.show()?,
146138
Self::Hide => window.hide()?,
147139
Self::Close => window.close()?,
148-
Self::SetDecorations { decorations } => window.set_decorations(decorations)?,
149-
Self::SetAlwaysOnTop { always_on_top } => window.set_always_on_top(always_on_top)?,
150-
Self::SetWidth { width } => window.set_width(width)?,
151-
Self::SetHeight { height } => window.set_height(height)?,
152-
Self::Resize { width, height } => window.resize(width, height)?,
153-
Self::SetMinSize {
154-
min_width,
155-
min_height,
156-
} => window.set_min_size(min_width, min_height)?,
157-
Self::SetMaxSize {
158-
max_width,
159-
max_height,
160-
} => window.set_max_size(max_width, max_height)?,
161-
Self::SetX { x } => window.set_x(x)?,
162-
Self::SetY { y } => window.set_y(y)?,
163-
Self::SetPosition { x, y } => window.set_position(x, y)?,
164-
Self::SetFullscreen { fullscreen } => window.set_fullscreen(fullscreen)?,
140+
Self::SetDecorations(decorations) => window.set_decorations(decorations)?,
141+
Self::SetAlwaysOnTop(always_on_top) => window.set_always_on_top(always_on_top)?,
142+
Self::SetSize(size) => window.set_size(size)?,
143+
Self::SetMinSize(size) => window.set_min_size(size)?,
144+
Self::SetMaxSize(size) => window.set_max_size(size)?,
145+
Self::SetPosition(position) => window.set_position(position)?,
146+
Self::SetFullscreen(fullscreen) => window.set_fullscreen(fullscreen)?,
165147
Self::SetIcon { icon } => window.set_icon(icon.into())?,
166148
Self::StartDragging => window.start_dragging()?,
167149
}

core/tauri/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ pub use {
6161
},
6262
self::runtime::app::{App, Builder},
6363
self::runtime::flavors::wry::Wry,
64+
self::runtime::monitor::Monitor,
6465
self::runtime::webview::{WebviewAttributes, WindowBuilder},
65-
self::runtime::window::export::Window,
66+
self::runtime::window::export::{
67+
dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Pixel, Position, Size},
68+
Window,
69+
},
6670
self::state::{State, StateManager},
6771
};
6872

0 commit comments

Comments
 (0)