Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Added support for rotation #19

Merged
merged 3 commits into from
Jan 9, 2019
Merged

Added support for rotation #19

merged 3 commits into from
Jan 9, 2019

Conversation

mlbullett
Copy link
Contributor

Done:

  • Rotation (not yet other transforms) now supported in the normal, 90, 180, 270 variety (clockwise).
  • Tested with kanshi store with addition of rotation <0, 90, 180, 270>.
  • Untested with gnome store as I've got version 2 of monitors.xml running and can't find documentation on v1 which seems to be a different build. But should work.

To do:

  • Will have to look into differences between monitors.xml v1 v2 and see how this affects implementing other transforms as the xmltree is quite different in that regard and the swaymsg command is mixed with the rotation command (i.e transform flipped-90)

src/store.rs Outdated
@@ -201,6 +211,13 @@ named!(parse_position<&[u8], OutputArg>, do_parse!(
>> (OutputArg::Position(x, y))
));

named!(parse_rotation<&[u8], OutputArg>, do_parse!(
tag!("rotation")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the same syntax as sway for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I initially did but decided to split it as I was only doing rotation in a first run and sway combines rotation and other transforms into one string whereas monitors.xml doesn't.
If the design philosophy you want is more sway-centric and anything else is just a bonus, I'm more than happy to switch that back. Will probably be able to merge in flipping while I'm at it but I doubt monitors.xml support will be all that simple.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep the kanshi store as close as sway's config as possible, otherwise it'll be confusing for users. It can unpack the transform command into an internal rotation field and leave flipped outputs support for later.

We can ignore monitors.xml support for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okidoki! I'll rewrite it.

@emersion
Copy link
Owner

Yeah, monitors.xml support is old and would need more love. I don't think the current implementation handles v2 at all.

@mlbullett
Copy link
Contributor Author

It doesn't from what I could see. We could do that but then it's a lot of case by case. Maybe it's worth focusing on functionality over input compatibility in a first moment. Your call at the end of the day.

@emersion
Copy link
Owner

It doesn't from what I could see. We could do that but then it's a lot of case by case. Maybe it's worth focusing on functionality over input compatibility in a first moment. Your call at the end of the day.

Yeah, I agree. I'm thinking of removing it for now.

@mlbullett
Copy link
Contributor Author

Ready for review.
I changed the transform argument to match sway's syntax and threw in "flipped", "flipped-90", "flipped-180", and "flipped-270" as it required no effort.
I did not reflect these changes with monitors.xml, normal rotation will still work with v1 configurations though.
One extra I had to add was validation for the transform string as faulty inputs caused lots of trouble in testing. I did this in the frontend but perhaps there's a better way to implement that in the store. This is literally the first time I'm coding in rust though so I wasn't certain how to approach that. Any advice or is my current implementation sufficient?

src/frontend.rs Outdated
@@ -41,9 +41,15 @@ impl SwayFrontend {
if saved.width > 0 && saved.height > 0 {
l += &format!(" resolution {}x{}", saved.width, saved.height);
}
let mut v = ["90".to_string(),"180".into(),"270".into(),"flipped".into(),"flipped-90".into(),"flipped-180".into(),"flipped-270".into()];
if v.contains(&saved.transform) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can replace this with a match?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it most certainly can.

src/frontend.rs Outdated
if saved.scale > 0. {
l += &format!(" scale {}", saved.scale);
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra whitespace here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad.

src/store.rs Outdated
@@ -22,7 +22,7 @@ pub struct SavedOutput {
pub rate: f32,
pub x: i32,
pub y: i32,
//pub rotation: Rotation,
pub transform: String,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be an enum

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow here. This may be my general inexperience talking but since we're parsing the same string we want to output, what is the benefit of transforming this to an enum? Could you briefly explain how you would see this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures the value is valid, and isn't garbage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this redundant with the matching in the frontend?

The way I've got it right now (not committed) is that it matches the string against the valid options and passes through if matched or passes "transform normal" if not. This serves to both handle garbage and reset the output to the normal rotation if transform is absent (something swaymsg doesn't do on it's own if the output already has a rotation prior to passing a new command).

If you'd rather I change this to an enum I'll gladly do so, but then there's little point in matching in the frontend as the parser will silently fail before it gets there in the case of incorrect input.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this redundant with the matching in the frontend?

All frontends and backends may not use the same string.

but then there's little point in matching in the frontend as the parser will silently fail before it gets there in the case of incorrect input.

The parser silently failing is a separate issue that needs to be fixed anyway. See #18

@mlbullett
Copy link
Contributor Author

Hey,
Sorry had a busy December. Will implement your suggestions.

@mlbullett
Copy link
Contributor Author

Updated with your suggestions.

Copy link
Owner

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@emersion emersion merged commit c977157 into emersion:master Jan 9, 2019
@emersion
Copy link
Owner

emersion commented Jan 9, 2019

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants