mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-24 02:01:18 +07:00
Replace config transform with ipc
This commit is contained in:
+1
-50
@@ -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)]
|
||||
|
||||
@@ -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""#
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -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;
|
||||
|
||||
@@ -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")?;
|
||||
|
||||
Reference in New Issue
Block a user