Skip to content

Commit 267368f

Browse files
authored
feat: add workarea getter for monitor (#13276)
1 parent 4e00b27 commit 267368f

File tree

20 files changed

+153
-85
lines changed

20 files changed

+153
-85
lines changed

.changes/monitor-workarea-js.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tauri-apps/api": "minor:feat"
3+
---
4+
5+
Add `Monitor.workArea` field.

.changes/monitor-workarea-rust.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": "minor:feat"
3+
---
4+
5+
Add `Monitor::work_area` getter
6+

.changes/physical-logical-rect.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": "minor:feat"
3+
---
4+
5+
Added `tauri::PhysicalRect` and `tauri::LogicalRect` types.
6+

crates/tauri-bundler/src/bundle/windows/msi/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pub fn build_wix_app_installer(
475475
// when we're performing code signing, we'll sign some WiX DLLs, so we make a local copy
476476
let wix_toolset_path = if settings.can_sign() {
477477
let wix_path = output_path.join("wix");
478-
crate::utils::fs_utils::copy_dir(&wix_toolset_path, &wix_path)
478+
crate::utils::fs_utils::copy_dir(wix_toolset_path, &wix_path)
479479
.context("failed to copy wix directory")?;
480480
wix_path
481481
} else {
@@ -790,7 +790,7 @@ pub fn build_wix_app_installer(
790790
// sign default extensions
791791
if settings.can_sign() {
792792
for path in &fragment_extensions {
793-
try_sign(&path, settings)?;
793+
try_sign(path, settings)?;
794794
}
795795
}
796796

crates/tauri-driver/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn main() {
3333
let job = win32job::Job::create().unwrap();
3434
let mut info = job.query_extended_limit_info().unwrap();
3535
info.limit_kill_on_job_close();
36-
job.set_extended_limit_info(&mut info).unwrap();
36+
job.set_extended_limit_info(&info).unwrap();
3737
job.assign_current_process().unwrap();
3838
job
3939
};

crates/tauri-runtime-wry/src/lib.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/.github/icon.png"
1313
)]
1414

15+
use self::monitor::MonitorExt;
1516
use http::Request;
16-
#[cfg(desktop)]
17-
use monitor::MonitorExt;
1817
use raw_window_handle::{DisplayHandle, HasDisplayHandle, HasWindowHandle};
1918

2019
use tauri_runtime::{
@@ -131,7 +130,6 @@ use std::{
131130
pub type WebviewId = u32;
132131
type IpcHandler = dyn Fn(Request<String>) + 'static;
133132

134-
#[cfg(desktop)]
135133
mod monitor;
136134
#[cfg(any(
137135
windows,
@@ -462,8 +460,8 @@ impl From<DeviceEventFilter> for DeviceEventFilterWrapper {
462460
}
463461

464462
pub struct RectWrapper(pub wry::Rect);
465-
impl From<tauri_runtime::Rect> for RectWrapper {
466-
fn from(value: tauri_runtime::Rect) -> Self {
463+
impl From<tauri_runtime::dpi::Rect> for RectWrapper {
464+
fn from(value: tauri_runtime::dpi::Rect) -> Self {
467465
RectWrapper(wry::Rect {
468466
position: value.position,
469467
size: value.size,
@@ -518,7 +516,7 @@ impl WindowEventWrapper {
518516
if !*focused
519517
&& focused_webview
520518
.as_deref()
521-
.map_or(false, |w| w != FOCUSED_WEBVIEW_MARKER)
519+
.is_some_and(|w| w != FOCUSED_WEBVIEW_MARKER)
522520
{
523521
return Self(None);
524522
}
@@ -586,6 +584,7 @@ impl From<MonitorHandleWrapper> for Monitor {
586584
name: monitor.0.name(),
587585
position: PhysicalPositionWrapper(monitor.0.position()).into(),
588586
size: PhysicalSizeWrapper(monitor.0.size()).into(),
587+
work_area: monitor.0.work_area(),
589588
scale_factor: monitor.0.scale_factor(),
590589
}
591590
}
@@ -1403,7 +1402,7 @@ pub enum WebviewMessage {
14031402
Hide,
14041403
SetPosition(Position),
14051404
SetSize(Size),
1406-
SetBounds(tauri_runtime::Rect),
1405+
SetBounds(tauri_runtime::dpi::Rect),
14071406
SetFocus,
14081407
Reparent(WindowId, Sender<Result<()>>),
14091408
SetAutoResize(bool),
@@ -1412,7 +1411,7 @@ pub enum WebviewMessage {
14121411
ClearAllBrowsingData,
14131412
// Getters
14141413
Url(Sender<Result<String>>),
1415-
Bounds(Sender<Result<tauri_runtime::Rect>>),
1414+
Bounds(Sender<Result<tauri_runtime::dpi::Rect>>),
14161415
Position(Sender<Result<PhysicalPosition<i32>>>),
14171416
Size(Sender<Result<PhysicalSize<u32>>>),
14181417
WithWebview(Box<dyn FnOnce(Webview) + Send>),
@@ -1541,7 +1540,7 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
15411540
webview_getter!(self, WebviewMessage::Url)?
15421541
}
15431542

1544-
fn bounds(&self) -> Result<tauri_runtime::Rect> {
1543+
fn bounds(&self) -> Result<tauri_runtime::dpi::Rect> {
15451544
webview_getter!(self, WebviewMessage::Bounds)?
15461545
}
15471546

@@ -1599,7 +1598,7 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
15991598
)
16001599
}
16011600

1602-
fn set_bounds(&self, bounds: tauri_runtime::Rect) -> Result<()> {
1601+
fn set_bounds(&self, bounds: tauri_runtime::dpi::Rect) -> Result<()> {
16031602
send_user_message(
16041603
&self.context,
16051604
Message::Webview(
@@ -3667,7 +3666,7 @@ fn handle_user_message<T: UserEvent>(
36673666
tx.send(
36683667
webview
36693668
.bounds()
3670-
.map(|bounds| tauri_runtime::Rect {
3669+
.map(|bounds| tauri_runtime::dpi::Rect {
36713670
size: bounds.size,
36723671
position: bounds.position,
36733672
})

crates/tauri-runtime-wry/src/monitor/linux.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use super::PhysicalRect;
65
use gtk::prelude::MonitorExt;
7-
use tao::{
8-
dpi::{PhysicalPosition, PhysicalSize},
9-
platform::unix::MonitorHandleExtUnix,
10-
};
6+
use tao::platform::unix::MonitorHandleExtUnix;
7+
use tauri_runtime::dpi::{PhysicalPosition, PhysicalRect, PhysicalSize};
118

129
impl super::MonitorExt for tao::monitor::MonitorHandle {
13-
fn work_area(&self) -> PhysicalRect {
10+
fn work_area(&self) -> PhysicalRect<i32, u32> {
1411
let rect = self.gdk_monitor().workarea();
1512
PhysicalRect {
1613
size: PhysicalSize::new(rect.width() as u32, rect.height() as u32),

crates/tauri-runtime-wry/src/monitor/macos.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use super::PhysicalRect;
6-
use tao::dpi::{LogicalPosition, LogicalSize, PhysicalPosition};
5+
use tauri_runtime::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalRect};
76

87
impl super::MonitorExt for tao::monitor::MonitorHandle {
9-
fn work_area(&self) -> PhysicalRect {
8+
fn work_area(&self) -> PhysicalRect<i32, u32> {
109
use objc2_app_kit::NSScreen;
1110
use tao::platform::macos::MonitorHandleExtMacOS;
1211
if let Some(ns_screen) = self.ns_screen() {
@@ -20,7 +19,7 @@ impl super::MonitorExt for tao::monitor::MonitorHandle {
2019
} else {
2120
PhysicalRect {
2221
size: self.size(),
23-
position: PhysicalPosition::default(),
22+
position: self.position(),
2423
}
2524
}
2625
}

crates/tauri-runtime-wry/src/monitor/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use tao::dpi::{PhysicalPosition, PhysicalSize};
5+
use tauri_runtime::dpi::PhysicalRect;
66

77
#[cfg(any(
88
target_os = "linux",
@@ -17,16 +17,21 @@ mod macos;
1717
#[cfg(windows)]
1818
mod windows;
1919

20-
pub struct PhysicalRect {
21-
pub size: PhysicalSize<u32>,
22-
pub position: PhysicalPosition<i32>,
23-
}
24-
2520
pub trait MonitorExt {
2621
/// Get the work area of this monitor
2722
///
2823
/// ## Platform-specific:
2924
///
3025
/// - **Android / iOS**: Unsupported.
31-
fn work_area(&self) -> PhysicalRect;
26+
fn work_area(&self) -> PhysicalRect<i32, u32>;
27+
}
28+
29+
#[cfg(mobile)]
30+
impl MonitorExt for tao::monitor::MonitorHandle {
31+
fn work_area(&self) -> PhysicalRect<i32, u32> {
32+
PhysicalRect {
33+
size: self.size(),
34+
position: self.position(),
35+
}
36+
}
3237
}

crates/tauri-runtime-wry/src/monitor/windows.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use super::PhysicalRect;
65
use tao::dpi::{PhysicalPosition, PhysicalSize};
6+
use tauri_runtime::dpi::PhysicalRect;
77

88
impl super::MonitorExt for tao::monitor::MonitorHandle {
9-
fn work_area(&self) -> PhysicalRect {
9+
fn work_area(&self) -> PhysicalRect<i32, u32> {
1010
use tao::platform::windows::MonitorHandleExtWindows;
1111
use windows::Win32::Graphics::Gdi::{GetMonitorInfoW, HMONITOR, MONITORINFO};
1212
let mut monitor_info = MONITORINFO {
@@ -25,7 +25,7 @@ impl super::MonitorExt for tao::monitor::MonitorHandle {
2525
} else {
2626
PhysicalRect {
2727
size: self.size(),
28-
position: PhysicalPosition::default(),
28+
position: self.position(),
2929
}
3030
}
3131
}

0 commit comments

Comments
 (0)