Add scale setting to Rust API

This commit is contained in:
Ottatop 2024-03-23 16:08:51 -05:00
parent dfc7a1351e
commit 1907381d99
2 changed files with 51 additions and 3 deletions

View file

@ -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

View file

@ -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);