Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/monitor-workarea-js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": "minor:feat"
---

Add `Monitor.workArea` field.
6 changes: 6 additions & 0 deletions .changes/monitor-workarea-rust.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri": "minor:feat"
---

Add `Monitor::work_area` getter

6 changes: 6 additions & 0 deletions .changes/physical-logical-rect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri": "minor:feat"
---

Added `tauri::PhysicalRect` and `tauri::LogicalRect` types.

4 changes: 2 additions & 2 deletions crates/tauri-bundler/src/bundle/windows/msi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pub fn build_wix_app_installer(
// when we're performing code signing, we'll sign some WiX DLLs, so we make a local copy
let wix_toolset_path = if settings.can_sign() {
let wix_path = output_path.join("wix");
crate::utils::fs_utils::copy_dir(&wix_toolset_path, &wix_path)
crate::utils::fs_utils::copy_dir(wix_toolset_path, &wix_path)
.context("failed to copy wix directory")?;
wix_path
} else {
Expand Down Expand Up @@ -790,7 +790,7 @@ pub fn build_wix_app_installer(
// sign default extensions
if settings.can_sign() {
for path in &fragment_extensions {
try_sign(&path, settings)?;
try_sign(path, settings)?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-driver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() {
let job = win32job::Job::create().unwrap();
let mut info = job.query_extended_limit_info().unwrap();
info.limit_kill_on_job_close();
job.set_extended_limit_info(&mut info).unwrap();
job.set_extended_limit_info(&info).unwrap();
job.assign_current_process().unwrap();
job
};
Expand Down
21 changes: 10 additions & 11 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/.github/icon.png"
)]

use self::monitor::MonitorExt;
use http::Request;
#[cfg(desktop)]
use monitor::MonitorExt;
use raw_window_handle::{DisplayHandle, HasDisplayHandle, HasWindowHandle};

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

#[cfg(desktop)]
mod monitor;
#[cfg(any(
windows,
Expand Down Expand Up @@ -462,8 +460,8 @@ impl From<DeviceEventFilter> for DeviceEventFilterWrapper {
}

pub struct RectWrapper(pub wry::Rect);
impl From<tauri_runtime::Rect> for RectWrapper {
fn from(value: tauri_runtime::Rect) -> Self {
impl From<tauri_runtime::dpi::Rect> for RectWrapper {
fn from(value: tauri_runtime::dpi::Rect) -> Self {
RectWrapper(wry::Rect {
position: value.position,
size: value.size,
Expand Down Expand Up @@ -518,7 +516,7 @@ impl WindowEventWrapper {
if !*focused
&& focused_webview
.as_deref()
.map_or(false, |w| w != FOCUSED_WEBVIEW_MARKER)
.is_some_and(|w| w != FOCUSED_WEBVIEW_MARKER)
{
return Self(None);
}
Expand Down Expand Up @@ -586,6 +584,7 @@ impl From<MonitorHandleWrapper> for Monitor {
name: monitor.0.name(),
position: PhysicalPositionWrapper(monitor.0.position()).into(),
size: PhysicalSizeWrapper(monitor.0.size()).into(),
work_area: monitor.0.work_area(),
scale_factor: monitor.0.scale_factor(),
}
}
Expand Down Expand Up @@ -1403,7 +1402,7 @@ pub enum WebviewMessage {
Hide,
SetPosition(Position),
SetSize(Size),
SetBounds(tauri_runtime::Rect),
SetBounds(tauri_runtime::dpi::Rect),
SetFocus,
Reparent(WindowId, Sender<Result<()>>),
SetAutoResize(bool),
Expand All @@ -1412,7 +1411,7 @@ pub enum WebviewMessage {
ClearAllBrowsingData,
// Getters
Url(Sender<Result<String>>),
Bounds(Sender<Result<tauri_runtime::Rect>>),
Bounds(Sender<Result<tauri_runtime::dpi::Rect>>),
Position(Sender<Result<PhysicalPosition<i32>>>),
Size(Sender<Result<PhysicalSize<u32>>>),
WithWebview(Box<dyn FnOnce(Webview) + Send>),
Expand Down Expand Up @@ -1541,7 +1540,7 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
webview_getter!(self, WebviewMessage::Url)?
}

fn bounds(&self) -> Result<tauri_runtime::Rect> {
fn bounds(&self) -> Result<tauri_runtime::dpi::Rect> {
webview_getter!(self, WebviewMessage::Bounds)?
}

Expand Down Expand Up @@ -1599,7 +1598,7 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
)
}

fn set_bounds(&self, bounds: tauri_runtime::Rect) -> Result<()> {
fn set_bounds(&self, bounds: tauri_runtime::dpi::Rect) -> Result<()> {
send_user_message(
&self.context,
Message::Webview(
Expand Down Expand Up @@ -3667,7 +3666,7 @@ fn handle_user_message<T: UserEvent>(
tx.send(
webview
.bounds()
.map(|bounds| tauri_runtime::Rect {
.map(|bounds| tauri_runtime::dpi::Rect {
size: bounds.size,
position: bounds.position,
})
Expand Down
9 changes: 3 additions & 6 deletions crates/tauri-runtime-wry/src/monitor/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use super::PhysicalRect;
use gtk::prelude::MonitorExt;
use tao::{
dpi::{PhysicalPosition, PhysicalSize},
platform::unix::MonitorHandleExtUnix,
};
use tao::platform::unix::MonitorHandleExtUnix;
use tauri_runtime::dpi::{PhysicalPosition, PhysicalRect, PhysicalSize};

impl super::MonitorExt for tao::monitor::MonitorHandle {
fn work_area(&self) -> PhysicalRect {
fn work_area(&self) -> PhysicalRect<i32, u32> {
let rect = self.gdk_monitor().workarea();
PhysicalRect {
size: PhysicalSize::new(rect.width() as u32, rect.height() as u32),
Expand Down
7 changes: 3 additions & 4 deletions crates/tauri-runtime-wry/src/monitor/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use super::PhysicalRect;
use tao::dpi::{LogicalPosition, LogicalSize, PhysicalPosition};
use tauri_runtime::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalRect};

impl super::MonitorExt for tao::monitor::MonitorHandle {
fn work_area(&self) -> PhysicalRect {
fn work_area(&self) -> PhysicalRect<i32, u32> {
use objc2_app_kit::NSScreen;
use tao::platform::macos::MonitorHandleExtMacOS;
if let Some(ns_screen) = self.ns_screen() {
Expand All @@ -20,7 +19,7 @@ impl super::MonitorExt for tao::monitor::MonitorHandle {
} else {
PhysicalRect {
size: self.size(),
position: PhysicalPosition::default(),
position: self.position(),
}
}
}
Expand Down
19 changes: 12 additions & 7 deletions crates/tauri-runtime-wry/src/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use tao::dpi::{PhysicalPosition, PhysicalSize};
use tauri_runtime::dpi::PhysicalRect;

#[cfg(any(
target_os = "linux",
Expand All @@ -17,16 +17,21 @@ mod macos;
#[cfg(windows)]
mod windows;

pub struct PhysicalRect {
pub size: PhysicalSize<u32>,
pub position: PhysicalPosition<i32>,
}

pub trait MonitorExt {
/// Get the work area of this monitor
///
/// ## Platform-specific:
///
/// - **Android / iOS**: Unsupported.
fn work_area(&self) -> PhysicalRect;
fn work_area(&self) -> PhysicalRect<i32, u32>;
}

#[cfg(mobile)]
impl MonitorExt for tao::monitor::MonitorHandle {
fn work_area(&self) -> PhysicalRect<i32, u32> {
PhysicalRect {
size: self.size(),
position: self.position(),
}
}
}
6 changes: 3 additions & 3 deletions crates/tauri-runtime-wry/src/monitor/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use super::PhysicalRect;
use tao::dpi::{PhysicalPosition, PhysicalSize};
use tauri_runtime::dpi::PhysicalRect;

impl super::MonitorExt for tao::monitor::MonitorHandle {
fn work_area(&self) -> PhysicalRect {
fn work_area(&self) -> PhysicalRect<i32, u32> {
use tao::platform::windows::MonitorHandleExtWindows;
use windows::Win32::Graphics::Gdi::{GetMonitorInfoW, HMONITOR, MONITORINFO};
let mut monitor_info = MONITORINFO {
Expand All @@ -25,7 +25,7 @@ impl super::MonitorExt for tao::monitor::MonitorHandle {
} else {
PhysicalRect {
size: self.size(),
position: PhysicalPosition::default(),
position: self.position(),
}
}
}
Expand Down
21 changes: 5 additions & 16 deletions crates/tauri-runtime-wry/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ mod macos;
#[cfg(windows)]
mod windows;

use crate::monitor::MonitorExt;

pub trait WindowExt {
/// Enable or disable the window
///
Expand Down Expand Up @@ -61,23 +63,10 @@ pub fn calculate_window_center_position(
window_size: tao::dpi::PhysicalSize<u32>,
target_monitor: tao::monitor::MonitorHandle,
) -> tao::dpi::PhysicalPosition<i32> {
let monitor_size: tao::dpi::PhysicalSize<u32>;
let monitor_position: tao::dpi::PhysicalPosition<i32>;
#[cfg(desktop)]
{
use crate::monitor::MonitorExt;
let work_area = target_monitor.work_area();
monitor_size = work_area.size;
monitor_position = work_area.position;
}
#[cfg(mobile)]
{
monitor_size = target_monitor.size();
monitor_position = target_monitor.position();
}
let work_area = target_monitor.work_area();

tao::dpi::PhysicalPosition::new(
(monitor_size.width as i32 - window_size.width as i32) / 2 + monitor_position.x,
(monitor_size.height as i32 - window_size.height as i32) / 2 + monitor_position.y,
(work_area.size.width as i32 - window_size.width as i32) / 2 + work_area.position.x,
(work_area.size.height as i32 - window_size.height as i32) / 2 + work_area.position.y,
)
}
60 changes: 60 additions & 0 deletions crates/tauri-runtime/src/dpi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

pub use dpi::*;
use serde::Serialize;

/// A rectangular region.
#[derive(Clone, Copy, Debug, Serialize)]
pub struct Rect {
/// Rect position.
pub position: dpi::Position,
/// Rect size.
pub size: dpi::Size,
}

impl Default for Rect {
fn default() -> Self {
Self {
position: Position::Logical((0, 0).into()),
size: Size::Logical((0, 0).into()),
}
}
}

/// A rectangular region in physical pixels.
#[derive(Clone, Copy, Debug, Serialize)]
pub struct PhysicalRect<P: dpi::Pixel, S: dpi::Pixel> {
/// Rect position.
pub position: dpi::PhysicalPosition<P>,
/// Rect size.
pub size: dpi::PhysicalSize<S>,
}

impl<P: dpi::Pixel, S: dpi::Pixel> Default for PhysicalRect<P, S> {
fn default() -> Self {
Self {
position: (0, 0).into(),
size: (0, 0).into(),
}
}
}

/// A rectangular region in logical pixels.
#[derive(Clone, Copy, Debug, Serialize)]
pub struct LogicalRect<P: dpi::Pixel, S: dpi::Pixel> {
/// Rect position.
pub position: dpi::LogicalPosition<P>,
/// Rect size.
pub size: dpi::LogicalSize<S>,
}

impl<P: dpi::Pixel, S: dpi::Pixel> Default for LogicalRect<P, S> {
fn default() -> Self {
Self {
position: (0, 0).into(),
size: (0, 0).into(),
}
}
}
27 changes: 4 additions & 23 deletions crates/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
#![cfg_attr(docsrs, feature(doc_cfg))]

use raw_window_handle::DisplayHandle;
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use std::{borrow::Cow, fmt::Debug, sync::mpsc::Sender};
use tauri_utils::config::Color;
use tauri_utils::Theme;
use url::Url;
use webview::{DetachedWebview, PendingWebview};

/// UI scaling utilities.
pub mod dpi;
/// Types useful for interacting with a user's monitors.
pub mod monitor;
pub mod webview;
pub mod window;

use dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use dpi::{PhysicalPosition, PhysicalSize, Position, Rect, Size};
use monitor::Monitor;
use window::{
CursorIcon, DetachedWindow, PendingWindow, RawWindow, WebviewEvent, WindowEvent,
Expand All @@ -40,33 +42,12 @@ use http::{
status::InvalidStatusCode,
};

/// UI scaling utilities.
pub use dpi;

/// Cookie extraction
pub use cookie::Cookie;

pub type WindowEventId = u32;
pub type WebviewEventId = u32;

/// A rectangular region.
#[derive(Clone, Copy, Debug, Serialize)]
pub struct Rect {
/// Rect position.
pub position: dpi::Position,
/// Rect size.
pub size: dpi::Size,
}

impl Default for Rect {
fn default() -> Self {
Self {
position: Position::Logical((0, 0).into()),
size: Size::Logical((0, 0).into()),
}
}
}

/// Progress bar status.
#[derive(Debug, Clone, Copy, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down
Loading