From 1907381d99ffbc497653809e69ece40fdf3e6863 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Sat, 23 Mar 2024 16:08:51 -0500 Subject: [PATCH] Add scale setting to Rust API --- api/rust/src/output.rs | 50 +++++++++++++++++++++++++++++++++++++++++- src/render.rs | 4 ++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/api/rust/src/output.rs b/api/rust/src/output.rs index 8bf8cf5..2a505ba 100644 --- a/api/rust/src/output.rs +++ b/api/rust/src/output.rs @@ -12,7 +12,10 @@ use futures::FutureExt; use pinnacle_api_defs::pinnacle::output::{ self, - v0alpha1::{output_service_client::OutputServiceClient, SetLocationRequest, SetModeRequest}, + v0alpha1::{ + output_service_client::OutputServiceClient, set_scale_request::AbsoluteOrRelative, + SetLocationRequest, SetModeRequest, SetScaleRequest, + }, }; use tonic::transport::Channel; @@ -390,6 +393,51 @@ impl OutputHandle { .unwrap(); } + /// Set this output's scaling factor. + /// + /// # Examples + /// + /// ``` + /// output.get_focused()?.set_scale(1.5); + /// ``` + pub fn set_scale(&self, scale: f32) { + let mut client = self.output_client.clone(); + block_on_tokio(client.set_scale(SetScaleRequest { + output_name: Some(self.name.clone()), + absolute_or_relative: Some(AbsoluteOrRelative::Absolute(scale)), + })) + .unwrap(); + } + + /// Increase this output's scaling factor by `increase_by`. + /// + /// # Examples + /// + /// ``` + /// output.get_focused()?.increase_scale(0.25); + /// ``` + pub fn increase_scale(&self, increase_by: f32) { + let mut client = self.output_client.clone(); + block_on_tokio(client.set_scale(SetScaleRequest { + output_name: Some(self.name.clone()), + absolute_or_relative: Some(AbsoluteOrRelative::Relative(increase_by)), + })) + .unwrap(); + } + + /// Decrease this output's scaling factor by `decrease_by`. + /// + /// This simply calls [`OutputHandle::increase_scale`] with the negative of `decrease_by`. + /// + /// # Examples + /// + /// ``` + /// output.get_focused()?.decrease_scale(0.25); + /// ``` + pub fn decrease_scale(&self, decrease_by: f32) { + self.increase_scale(-decrease_by); + } + /// Get all properties of this output. /// /// # Examples diff --git a/src/render.rs b/src/render.rs index 3a36990..811e2ee 100644 --- a/src/render.rs +++ b/src/render.rs @@ -148,8 +148,8 @@ where .map(|win| { // subtract win.geometry().loc to align decorations correctly let loc = ( - space.element_location(win) .unwrap_or((0, 0).into()) - - win.geometry().loc + space.element_location(win) .unwrap_or((0, 0).into()) + - win.geometry().loc - output.current_location() ) .to_physical_precise_round(scale);