-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add XY movement & refactor monitor types #18
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use gnome_randr::display_config::{ | ||
physical_monitor::PhysicalMonitor, ApplyConfig, monitor_models::transform::Displacement, | ||
}; | ||
|
||
use super::{Action}; | ||
|
||
pub struct DisplacementAction { | ||
pub displacement: Displacement | ||
} | ||
|
||
impl Action<'_> for DisplacementAction { | ||
fn apply(&self, config: &mut ApplyConfig, _: &PhysicalMonitor) { | ||
config.transform.displacement = self.displacement; | ||
} | ||
} | ||
|
||
impl std::fmt::Display for DisplacementAction { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "setting displacement to {}", self.displacement) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
use gnome_randr::display_config::{ | ||
logical_monitor::Transform, physical_monitor::PhysicalMonitor, ApplyConfig, | ||
physical_monitor::PhysicalMonitor, ApplyConfig, monitor_models::transform::Orientation, | ||
}; | ||
|
||
use super::{super::Rotation, Action}; | ||
use super::{Action}; | ||
|
||
pub struct RotationAction { | ||
pub rotation: Rotation, | ||
pub struct OrientationAction { | ||
pub orientation: Orientation | ||
} | ||
|
||
impl Action<'_> for RotationAction { | ||
impl Action<'_> for OrientationAction { | ||
fn apply(&self, config: &mut ApplyConfig, _: &PhysicalMonitor) { | ||
config.transform = match self.rotation { | ||
Rotation::Normal => Transform::NORMAL, | ||
Rotation::Left => Transform::R270, | ||
Rotation::Right => Transform::R90, | ||
Rotation::Inverted => Transform::R180, | ||
} | ||
.bits(); | ||
config.transform.orientation = self.orientation; | ||
} | ||
} | ||
|
||
impl std::fmt::Display for RotationAction { | ||
impl std::fmt::Display for OrientationAction { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "setting rotation to {}", self.rotation) | ||
write!(f, "setting rotation to {}", self.orientation) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,20 @@ | ||
mod actions; | ||
|
||
use gnome_randr::{display_config::ApplyConfig, DisplayConfig}; | ||
use gnome_randr::{display_config::{ApplyConfig, monitor_models::transform::{Orientation, Displacement}}, DisplayConfig}; | ||
use structopt::StructOpt; | ||
|
||
use self::actions::{Action, ModeAction, PrimaryAction, RotationAction, ScaleAction}; | ||
use self::actions::{Action, ModeAction, PrimaryAction, OrientationAction, ScaleAction, DisplacementAction}; | ||
|
||
#[derive(Clone, Copy)] | ||
pub enum Rotation { | ||
Normal, | ||
Left, | ||
Right, | ||
Inverted, | ||
} | ||
|
||
impl std::str::FromStr for Rotation { | ||
type Err = std::fmt::Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s.to_lowercase().as_str() { | ||
"normal" => Ok(Rotation::Normal), | ||
"left" => Ok(Rotation::Left), | ||
"right" => Ok(Rotation::Right), | ||
"inverted" => Ok(Rotation::Inverted), | ||
_ => Err(std::fmt::Error), | ||
} | ||
} | ||
} | ||
|
||
impl std::fmt::Display for Rotation { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!( | ||
f, | ||
"{}", | ||
match self { | ||
Rotation::Normal => "normal", | ||
Rotation::Left => "left", | ||
Rotation::Right => "right", | ||
Rotation::Inverted => "inverted", | ||
} | ||
) | ||
} | ||
} | ||
|
||
#[derive(StructOpt)] | ||
pub struct ActionOptions { | ||
#[structopt( | ||
short, | ||
long = "rotate", | ||
help = "One of 'normal', 'left', 'right' or 'inverted'", | ||
long_help = "One of 'normal', 'left', 'right' or 'inverted'. This causes the output contents to be rotated in the specified direction. 'right' specifies a clockwise rotation of the picture and 'left' specifies a counter-clockwise rotation." | ||
long, | ||
help = "A desired orientation of the display.", | ||
long_help = "Any of ('normal', 'left', 'right' or 'inverted'). and optionally 'flipped' joined by ','. EG 'normal,flipped'. This causes the output contents to be rotated in the specified direction. 'right' specifies a 1/4 clockwise rotation of the picture and 'left' specifies a 3/4 clockwise rotation." | ||
)] | ||
pub rotation: Option<Rotation>, | ||
pub rotation: Option<Orientation>, | ||
|
||
#[structopt( | ||
short, | ||
|
@@ -65,6 +29,14 @@ pub struct ActionOptions { | |
|
||
#[structopt(long, help = "Set the scale")] | ||
pub scale: Option<f64>, | ||
|
||
#[structopt( | ||
short, | ||
long, | ||
help = "A desired x,y, and scale.", | ||
long_help = "A comma-separated list of displacement information '100,88,1'. The order is always X, Y, Scale. This does not check whether monitors can be arranged in that way." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like that there's a repetition between Can you make this |
||
)] | ||
pub displacement: Option<Displacement> | ||
} | ||
|
||
#[derive(StructOpt)] | ||
|
@@ -120,8 +92,8 @@ pub fn handle( | |
let primary_is_changing = opts.actions.primary; | ||
|
||
if let Some(rotation) = &opts.actions.rotation { | ||
actions.push(Box::new(RotationAction { | ||
rotation: *rotation, | ||
actions.push(Box::new(OrientationAction { | ||
orientation: *rotation, | ||
})); | ||
} | ||
|
||
|
@@ -137,6 +109,12 @@ pub fn handle( | |
actions.push(Box::new(ScaleAction { scale: *scale })) | ||
} | ||
|
||
if let Some(displacement) = &opts.actions.displacement { | ||
actions.push(Box::new(DisplacementAction { | ||
displacement: *displacement, | ||
})) | ||
} | ||
|
||
if actions.is_empty() { | ||
println!("no changes made."); | ||
return Ok(()); | ||
|
@@ -162,11 +140,11 @@ pub fn handle( | |
.monitors | ||
.iter() | ||
.filter_map(|monitor| { | ||
if monitor.connector == opts.connector { | ||
if monitor.monitor_description.connector == opts.connector { | ||
return Some(apply_config.clone()); | ||
} | ||
|
||
let (logical_monitor, _) = match config.search(&monitor.connector) { | ||
let (logical_monitor, _) = match config.search(&monitor.monitor_description.connector) { | ||
Some(monitors) => monitors, | ||
None => return None, | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like what you've done here with the string parsing, but there are a couple issues with it:
x,y
display_config
directory, which is supposed to be a separate library. I'd rather avoid putting CLI details in the library wherever possible, which is why I had the rotation struct to begin with. This is a relatively minor transgression though so I don't mind much.I would make a
position
struct that gets parsed to an x and y value and use that as the property on this Action.