mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-25 09:59:21 +01:00
Add scale setting to Rust API
This commit is contained in:
parent
dfc7a1351e
commit
1907381d99
2 changed files with 51 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue