Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: add separate `rect` and `working_rect` getters on native monitor

Lars Bergerc45b028b6ff4
diff --git a/packages/wm/src/common/platform/native_monitor.rs b/packages/wm/src/common/platform/native_monitor.rs
index 1e8f1d5c..4d98cf1b 100644
--- a/packages/wm/src/common/platform/native_monitor.rs
+++ b/packages/wm/src/common/platform/native_monitor.rs
@@ -16,6 +16,8 @@ use windows::{
},
};
+use crate::common::Rect;
+
use super::WindowHandle;
pub type MonitorHandle = HMONITOR;
@@ -31,10 +33,8 @@ struct MonitorInfo {
device_name: String,
device_path: Option<String>,
hardware_id: Option<String>,
- width: i32,
- height: i32,
- x: i32,
- y: i32,
+ rect: Rect,
+ working_rect: Rect,
dpi: f32,
}
@@ -58,20 +58,12 @@ impl NativeMonitor {
self.monitor_info().map(|info| info.hardware_id.as_ref())
}
- pub fn width(&self) -> anyhow::Result<i32> {
- self.monitor_info().map(|info| info.width)
- }
-
- pub fn height(&self) -> anyhow::Result<i32> {
- self.monitor_info().map(|info| info.height)
+ pub fn rect(&self) -> anyhow::Result<&Rect> {
+ self.monitor_info().map(|info| &info.rect)
}
- pub fn x(&self) -> anyhow::Result<i32> {
- self.monitor_info().map(|info| info.x)
- }
-
- pub fn y(&self) -> anyhow::Result<i32> {
- self.monitor_info().map(|info| info.y)
+ pub fn working_rect(&self) -> anyhow::Result<&Rect> {
+ self.monitor_info().map(|info| &info.working_rect)
}
pub fn dpi(&self) -> anyhow::Result<f32> {
@@ -134,16 +126,28 @@ impl NativeMonitor {
let device_name = String::from_utf16_lossy(&monitor_info.szDevice);
let dpi = monitor_dpi(self.handle)?;
+ let rc_monitor = monitor_info.monitorInfo.rcMonitor;
+ let rect = Rect::from_ltrb(
+ rc_monitor.left,
+ rc_monitor.top,
+ rc_monitor.right,
+ rc_monitor.bottom,
+ );
+
+ let rc_work = monitor_info.monitorInfo.rcWork;
+ let working_rect = Rect::from_ltrb(
+ rc_work.left,
+ rc_work.top,
+ rc_work.right,
+ rc_work.bottom,
+ );
+
Ok(MonitorInfo {
device_name,
device_path,
hardware_id,
- width: monitor_info.monitorInfo.rcMonitor.right
- - monitor_info.monitorInfo.rcMonitor.left,
- height: monitor_info.monitorInfo.rcMonitor.bottom
- - monitor_info.monitorInfo.rcMonitor.top,
- x: monitor_info.monitorInfo.rcMonitor.left,
- y: monitor_info.monitorInfo.rcMonitor.top,
+ rect,
+ working_rect,
dpi,
})
})
diff --git a/packages/wm/src/monitors/monitor.rs b/packages/wm/src/monitors/monitor.rs
index 381defe0..7fdd77fd 100644
--- a/packages/wm/src/monitors/monitor.rs
+++ b/packages/wm/src/monitors/monitor.rs
@@ -103,19 +103,19 @@ impl_common_getters!(Monitor, ContainerType::Monitor);
impl PositionGetters for Monitor {
fn width(&self) -> anyhow::Result<i32> {
- Ok(self.0.borrow().native.width()?)
+ Ok(self.0.borrow().native.working_rect()?.width())
}
fn height(&self) -> anyhow::Result<i32> {
- Ok(self.0.borrow().native.height()?)
+ Ok(self.0.borrow().native.working_rect()?.height())
}
fn x(&self) -> anyhow::Result<i32> {
- Ok(self.0.borrow().native.x()?)
+ Ok(self.0.borrow().native.working_rect()?.x())
}
fn y(&self) -> anyhow::Result<i32> {
- Ok(self.0.borrow().native.y()?)
+ Ok(self.0.borrow().native.working_rect()?.y())
}
}