Skip to content

Commit

Permalink
Replace config transform with ipc
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Mar 27, 2024
1 parent cf87a18 commit 9927c15
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 54 deletions.
51 changes: 1 addition & 50 deletions niri-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)]
Expand Down
21 changes: 21 additions & 0 deletions niri-ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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""#
)),
}
}
}
10 changes: 6 additions & 4 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
Expand Down

0 comments on commit 9927c15

Please sign in to comment.