-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial window module functionality.
- Loading branch information
Showing
9 changed files
with
931 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
use serde::Deserialize; | ||
|
||
pub type ScaleFactor = f64; | ||
pub type PixelCount = isize; | ||
|
||
#[derive(Debug)] | ||
pub enum Kind { | ||
Logical, | ||
Physical, | ||
} | ||
|
||
/// A size represented in logical pixels. | ||
#[derive(Deserialize, Clone, Debug)] | ||
pub struct LogicalSize { | ||
width: PixelCount, | ||
height: PixelCount, | ||
} | ||
|
||
impl LogicalSize { | ||
pub fn kind() -> Kind { | ||
Kind::Logical | ||
} | ||
|
||
pub fn width(&self) -> PixelCount { | ||
self.width | ||
} | ||
|
||
pub fn height(&self) -> PixelCount { | ||
self.height | ||
} | ||
} | ||
|
||
/// A size represented in physical pixels. | ||
#[derive(Deserialize, Clone, Debug)] | ||
pub struct PhysicalSize { | ||
width: PixelCount, | ||
height: PixelCount, | ||
} | ||
|
||
impl PhysicalSize { | ||
pub fn kind() -> Kind { | ||
Kind::Physical | ||
} | ||
|
||
pub fn width(&self) -> PixelCount { | ||
self.width | ||
} | ||
|
||
pub fn height(&self) -> PixelCount { | ||
self.height | ||
} | ||
|
||
/// Converts the physical size to a logical one. | ||
pub fn as_logical(&self, scale_factor: ScaleFactor) -> LogicalSize { | ||
LogicalSize { | ||
width: (self.width as f64 / scale_factor) as PixelCount, | ||
height: (self.height as f64 / scale_factor) as PixelCount, | ||
} | ||
} | ||
} | ||
|
||
/// A position represented in logical pixels. | ||
#[derive(Deserialize, Clone, Debug)] | ||
pub struct LogicalPosition { | ||
x: PixelCount, | ||
y: PixelCount, | ||
} | ||
|
||
impl LogicalPosition { | ||
pub fn kind() -> Kind { | ||
Kind::Logical | ||
} | ||
|
||
pub fn x(&self) -> PixelCount { | ||
self.x | ||
} | ||
|
||
pub fn y(&self) -> PixelCount { | ||
self.y | ||
} | ||
} | ||
|
||
/// A position represented in physical pixels. | ||
#[derive(Deserialize, Clone, Debug)] | ||
pub struct PhysicalPosition { | ||
x: PixelCount, | ||
y: PixelCount, | ||
} | ||
|
||
impl PhysicalPosition { | ||
pub fn kind() -> Kind { | ||
Kind::Physical | ||
} | ||
|
||
pub fn x(&self) -> PixelCount { | ||
self.x | ||
} | ||
|
||
pub fn y(&self) -> PixelCount { | ||
self.y | ||
} | ||
|
||
/// Converts the physical position to a logical one. | ||
pub fn as_logical(&self, scale_factor: ScaleFactor) -> LogicalPosition { | ||
LogicalPosition { | ||
x: (self.x as f64 / scale_factor) as PixelCount, | ||
y: (self.y as f64 / scale_factor) as PixelCount, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// tauri/tooling/api/src/core.ts | ||
async function invoke(cmd, args = {}) { | ||
// NB: `options` ignored as not used here. | ||
return window.__TAURI_INTERNALS__.invoke(cmd, args) | ||
} | ||
|
||
// tauri/tooling/api/src/window.ts | ||
function getCurrent() { | ||
return window.__TAURI_INTERNALS__.metadata.currentWindow | ||
} | ||
function getAll() { | ||
return window.__TAURI_INTERNALS__.metadata.windows | ||
} | ||
async function currentMonitor() { | ||
return invoke('plugin:window|current_monitor') | ||
} | ||
async function primaryMonitor() { | ||
return invoke('plugin:window|primary_monitor') | ||
} | ||
async function monitorFromPoint(x, y) { | ||
return invoke('plugin:window|monitor_from_point', { x, y }) | ||
} | ||
async function availableMonitors() { | ||
return invoke('plugin:window|available_monitors') | ||
} | ||
async function cursorPosition() { | ||
return invoke('plugin:window|cursor_position') | ||
} | ||
|
||
export { | ||
getCurrent, | ||
getAll, | ||
currentMonitor, | ||
primaryMonitor, | ||
monitorFromPoint, | ||
availableMonitors, | ||
cursorPosition, | ||
} |
Oops, something went wrong.