Skip to content
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

Introduce '--pos clone' to clone output to second monitor #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
It uses `xrandr` under the hood and works great with window managers like i3, bspwm, and others.

Use cases:
- a laptop and an abritrary secondary monitor (e.g. at work, home, etc.)
- a laptop and an arbitrary secondary monitor (e.g. at work, home, etc.)
- a desktop with two monitors

## Install
Expand All @@ -31,7 +31,7 @@ enact --pos top --watch &
You can also select which monitor will be the new primary one

```sh
enact --pos top --new_primary 1
enact --pos top --new-primary 1
```

## Comparison With Similar Tools
Expand Down
15 changes: 10 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum Placement {
Bottom,
Left,
Right,
Clone,
}

impl Placement {
Expand All @@ -47,6 +48,7 @@ impl Placement {
Self::Bottom => Self::Top,
Self::Right => Self::Left,
Self::Left => Self::Right,
Self::Clone => Self::Clone,
}
}
}
Expand All @@ -60,6 +62,7 @@ impl std::str::FromStr for Placement {
"bottom" => Ok(Self::Bottom),
"left" => Ok(Self::Left),
"right" => Ok(Self::Right),
"clone" => Ok(Self::Clone),
_ => anyhow::bail!("Invalid placement"),
}
}
Expand All @@ -83,6 +86,7 @@ impl Rect {
self.width - monitor.width,
(self.height - monitor.height) / 2,
),
Placement::Clone => (0,0,),
};
format!("{}x{}", offset_width, offset_height)
}
Expand Down Expand Up @@ -135,16 +139,17 @@ impl Xrandr {

for (i, monitor) in self.monitors.iter().enumerate() {
cmd.args(&["--output", &monitor.name])
.args(&["--mode", &monitor.resolution()])
.arg("--pos");
.args(&["--mode", &monitor.resolution()]);

if i == 0 {
cmd.arg(&rect.place(monitor, &self.placement.invert()));
cmd.args(&["--pos", &rect.place(monitor, &self.placement.invert())]);
} else if self.placement == Placement::Clone {
cmd.args(&["--same-as", &self.monitors[0].name]);
} else {
cmd.arg(&rect.place(monitor, &self.placement));
cmd.args(&["--pos", &rect.place(monitor, &self.placement)]);
}

if self.new_primary == i {
if self.new_primary == i || self.monitors.len() == 1 {
cmd.arg("--primary");
}
}
Expand Down