diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-03-27 17:03:17 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-03-27 17:03:17 +0400 |
| commit | 9927c15f68d277daa6de0a13194d25f81226ad2f (patch) | |
| tree | a8af63ae0bebbc0bbf3fbb933b42808a93e5d531 | |
| parent | cf87a185a90aeacf7c15d27ddba23bc493d9c2dd (diff) | |
| download | niri-9927c15f68d277daa6de0a13194d25f81226ad2f.tar.gz niri-9927c15f68d277daa6de0a13194d25f81226ad2f.tar.bz2 niri-9927c15f68d277daa6de0a13194d25f81226ad2f.zip | |
Replace config transform with ipc
| -rw-r--r-- | niri-config/src/lib.rs | 51 | ||||
| -rw-r--r-- | niri-ipc/src/lib.rs | 21 | ||||
| -rw-r--r-- | src/niri.rs | 10 | ||||
| -rw-r--r-- | src/utils/mod.rs | 13 |
4 files changed, 41 insertions, 54 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 0bf3fe0d..d03de0ff 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -10,7 +10,7 @@ use std::time::Duration; use bitflags::bitflags; use knuffel::errors::DecodeError; use miette::{miette, Context, IntoDiagnostic, NarratableReportHandler}; -use niri_ipc::{LayoutSwitchTarget, SizeChange}; +use niri_ipc::{LayoutSwitchTarget, SizeChange, Transform}; use regex::Regex; use smithay::input::keyboard::keysyms::KEY_NoSymbol; use smithay::input::keyboard::xkb::{keysym_from_name, KEYSYM_CASE_INSENSITIVE}; @@ -265,55 +265,6 @@ impl Default for Output { } } -/// Output transform, which goes counter-clockwise. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum Transform { - Normal, - _90, - _180, - _270, - Flipped, - Flipped90, - Flipped180, - Flipped270, -} - -impl FromStr for Transform { - type Err = miette::Error; - - fn from_str(s: &str) -> Result<Self, Self::Err> { - match s { - "normal" => Ok(Self::Normal), - "90" => Ok(Self::_90), - "180" => Ok(Self::_180), - "270" => Ok(Self::_270), - "flipped" => Ok(Self::Flipped), - "flipped-90" => Ok(Self::Flipped90), - "flipped-180" => Ok(Self::Flipped180), - "flipped-270" => Ok(Self::Flipped270), - _ => Err(miette!(concat!( - r#"invalid transform, can be "90", "180", "270", "#, - r#""flipped", "flipped-90", "flipped-180" or "flipped-270""# - ))), - } - } -} - -impl From<Transform> for smithay::utils::Transform { - fn from(value: Transform) -> Self { - match value { - Transform::Normal => Self::Normal, - Transform::_90 => Self::_90, - Transform::_180 => Self::_180, - Transform::_270 => Self::_270, - Transform::Flipped => Self::Flipped, - Transform::Flipped90 => Self::Flipped90, - Transform::Flipped180 => Self::Flipped180, - Transform::Flipped270 => Self::Flipped270, - } - } -} - #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq, Eq)] pub struct Position { #[knuffel(property)] diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index 34a626a6..e43b9437 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -359,3 +359,24 @@ impl FromStr for LayoutSwitchTarget { } } } + +impl FromStr for Transform { + type Err = &'static str; + + fn from_str(s: &str) -> Result<Self, Self::Err> { + match s { + "normal" => Ok(Self::Normal), + "90" => Ok(Self::_90), + "180" => Ok(Self::_180), + "270" => Ok(Self::_270), + "flipped" => Ok(Self::Flipped), + "flipped-90" => Ok(Self::Flipped90), + "flipped-180" => Ok(Self::Flipped180), + "flipped-270" => Ok(Self::Flipped270), + _ => Err(concat!( + r#"invalid transform, can be "90", "180", "270", "#, + r#""flipped", "flipped-90", "flipped-180" or "flipped-270""# + )), + } + } +} diff --git a/src/niri.rs b/src/niri.rs index 05ce00e9..98d714c2 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -115,8 +115,8 @@ use crate::ui::hotkey_overlay::HotkeyOverlay; use crate::ui::screenshot_ui::{ScreenshotUi, ScreenshotUiRenderElement}; use crate::utils::spawning::CHILD_ENV; use crate::utils::{ - center, center_f64, get_monotonic_time, logical_output, make_screenshot_path, output_size, - write_png_rgba8, + center, center_f64, get_monotonic_time, ipc_transform_to_smithay, logical_output, + make_screenshot_path, output_size, write_png_rgba8, }; use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped, WindowRef}; use crate::{animation, niri_render_elements}; @@ -903,7 +903,7 @@ impl State { let scale = scale.clamp(1., 10.).ceil() as i32; let mut transform = config - .map(|c| c.transform.into()) + .map(|c| ipc_transform_to_smithay(c.transform)) .unwrap_or(Transform::Normal); // FIXME: fix winit damage on other transforms. if name == "winit" { @@ -1543,7 +1543,9 @@ impl Niri { let c = config.outputs.iter().find(|o| o.name == name); let scale = c.map(|c| c.scale).unwrap_or(1.); let scale = scale.clamp(1., 10.).ceil() as i32; - let mut transform = c.map(|c| c.transform.into()).unwrap_or(Transform::Normal); + let mut transform = c + .map(|c| ipc_transform_to_smithay(c.transform)) + .unwrap_or(Transform::Normal); // FIXME: fix winit damage on other transforms. if name == "winit" { transform = Transform::Flipped180; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index aef9a8aa..781eec65 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -74,6 +74,19 @@ pub fn logical_output(output: &Output) -> niri_ipc::LogicalOutput { } } +pub fn ipc_transform_to_smithay(transform: niri_ipc::Transform) -> Transform { + match transform { + niri_ipc::Transform::Normal => Transform::Normal, + niri_ipc::Transform::_90 => Transform::_90, + niri_ipc::Transform::_180 => Transform::_180, + niri_ipc::Transform::_270 => Transform::_270, + niri_ipc::Transform::Flipped => Transform::Flipped, + niri_ipc::Transform::Flipped90 => Transform::Flipped90, + niri_ipc::Transform::Flipped180 => Transform::Flipped180, + niri_ipc::Transform::Flipped270 => Transform::Flipped270, + } +} + pub fn expand_home(path: &Path) -> anyhow::Result<Option<PathBuf>> { if let Ok(rest) = path.strip_prefix("~") { let dirs = UserDirs::new().context("error retrieving home directory")?; |
