Skip to content

Commit

Permalink
feat: Add --parent flag for recording/capturing the parent window (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Dec 16, 2020
1 parent 04fd81e commit 5e7b057
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add `--parent` flag for recording/capturing the parent window ([#14](https://github.com/orhun/menyoki/issues/10))

### Changed
- Use architecture compatible types for Xlib calls

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ FLAGS:
-r, --root Record the root window
-f, --focus Record the focused window
--select Select the window to record
--parent Record the parent of the window
--with-alpha Record with the alpha channel
--no-keys Disable the action keys while recording
-h, --help Print help information
Expand Down Expand Up @@ -328,6 +329,7 @@ SUBCOMMANDS:
| `menyoki record --focus --with-alpha` | Record the focused window with the alpha channel (for transparency) |
| `menyoki record --size 200x300 --duration 10` | Record an area of size 200x300 for 10 seconds |
| `menyoki record --padding 20:10:0:10 --timeout 120` | Record an area with given padding and set window selection timeout to 120 seconds |
| `menyoki record --parent` | Record the parent window of the selected window |
| `menyoki record --border 5` | Record the area selected by a border with 5 width |
| `menyoki record --keys LControl-Q/W` | Record with the default settings using custom key bindings |
| `menyoki record gif --fps 15 --quality 90` | Record 15 frames per second with 90% quality |
Expand Down Expand Up @@ -435,6 +437,7 @@ FLAGS:
-r, --root Capture the root window
-f, --focus Capture the focused window
--select Select the window to capture
--parent Record the parent of the window
--with-alpha Capture with the alpha channel
-h, --help Print help information
Expand Down Expand Up @@ -794,6 +797,7 @@ color = 3AA431
root = false
focus = true
select = true
parent = false
with-alpha = false
no-keys = false
keys = LAlt-S/Enter
Expand Down Expand Up @@ -822,6 +826,7 @@ format = gif
root = false
focus = true
select = true
parent = false
with-alpha = false
keys = LAlt-S/Enter
border = 1
Expand Down
8 changes: 4 additions & 4 deletions completions/menyoki.bash

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions completions/menyoki.elvish

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions completions/menyoki.fish

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions completions/menyoki.powershell

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions completions/menyoki.zsh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions config/menyoki.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ root = false
focus = true
# Select the window to record
select = true
# Record the parent of the window
parent = false
# Record with the alpha channel
with-alpha = false
# Disable the action keys while recording
Expand Down Expand Up @@ -64,21 +66,23 @@ repeat = ∞
format = gif

[capture]
# Record the root window
# Capture the root window
root = false
# Record the focused window
# Capture the focused window
focus = true
# Select the window to record
# Select the window to capture
select = true
# Record with the alpha channel
# Capture the parent of the window
parent = false
# Capture with the alpha channel
with-alpha = false
# Set the action keys
keys = LAlt-S/Enter
# Set the border width
border = 1
# Set the record area padding
# Set the capture area padding
#padding = T:R:B:L
# Set the record area size
# Set the capture area size
#size = WxH
# Set the countdown before recording
countdown = 0
Expand Down
2 changes: 2 additions & 0 deletions man/menyoki.1
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ FLAGS:
-r, --root Record the root window
-f, --focus Record the focused window
--select Select the window to record
--parent Record the parent of the window
--with-alpha Record with the alpha channel
--no-keys Disable the action keys while recording
-h, --help Print help information
Expand Down Expand Up @@ -371,6 +372,7 @@ FLAGS:
-r, --root Capture the root window
-f, --focus Capture the focused window
--select Select the window to capture
--parent Record the parent of the window
--with-alpha Capture with the alpha channel
-h, --help Print help information

Expand Down
6 changes: 6 additions & 0 deletions man/menyoki.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Record the focused window
.B select
Select the window to record
.TP
.B parent
Record the parent of the window
.TP
.B with-alpha
Record with the alpha channel
.TP
Expand Down Expand Up @@ -111,6 +114,9 @@ Capture the focused window
.B select
Select the window to capture
.TP
.B parent
Capture the parent of the window
.TP
.B with-alpha
Capture with the alpha channel
.TP
Expand Down
5 changes: 5 additions & 0 deletions src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ where
} else {
"Select the window to record"
}))
.arg(Arg::with_name("parent").long("parent").help(if capture {
"Capture the parent of the window"
} else {
"Record the parent of the window"
}))
.arg(
Arg::with_name("with-alpha")
.long("with-alpha")
Expand Down
8 changes: 4 additions & 4 deletions src/record/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl RecordFlag {
/* Window to record, with geometric properties */
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum RecordWindow {
Focus(Option<Geometry>),
Focus(Option<Geometry>, bool),
Root(Option<Geometry>),
}

Expand All @@ -146,11 +146,11 @@ impl RecordWindow {
None
};
if matches.is_present("focus") {
Self::Focus(size)
Self::Focus(size, matches.is_present("parent"))
} else if matches.is_present("root") {
Self::Root(size)
} else {
Self::Focus(Some(size.unwrap_or_default()))
Self::Focus(Some(size.unwrap_or_default()), matches.is_present("parent"))
}
}
}
Expand All @@ -177,7 +177,7 @@ impl Default for RecordSettings {
padding: Padding::default(),
time: RecordTime::default(),
flag: RecordFlag::default(),
window: RecordWindow::Focus(Some(Geometry::default())),
window: RecordWindow::Focus(Some(Geometry::default()), false),
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ impl<'a> AppSettings<'a> {
fn set_icon_size(&mut self) {
let ico_geometry = Geometry::new(0, 0, 256, 256);
match self.record.window {
RecordWindow::Focus(None) => {
self.record.window = RecordWindow::Focus(Some(ico_geometry))
RecordWindow::Focus(None, parent) => {
self.record.window = RecordWindow::Focus(Some(ico_geometry), parent)
}
RecordWindow::Root(None) => {
self.record.window = RecordWindow::Root(Some(ico_geometry))
}
RecordWindow::Focus(Some(ref mut geometry))
RecordWindow::Focus(Some(ref mut geometry), _)
| RecordWindow::Root(Some(ref mut geometry)) => {
if geometry.width == 0 || geometry.width > ico_geometry.width {
geometry.width = ico_geometry.width;
Expand Down Expand Up @@ -188,7 +188,8 @@ mod tests {
settings.jpg.quality = 0;
settings.anim.quality = 0;
settings.save.file.format = FileFormat::Ico;
settings.record.window = RecordWindow::Focus(Some(Geometry::default()));
settings.record.window =
RecordWindow::Focus(Some(Geometry::default()), false);
settings.check();
}
}
12 changes: 7 additions & 5 deletions src/x11/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ impl Display {
/**
* Get the focused window.
*
* @param parent
* @return Window (Option)
*/
pub fn get_focused_window(&self) -> Option<Window> {
pub fn get_focused_window(&self, parent: bool) -> Option<Window> {
unsafe {
let mut focus_window = MaybeUninit::<c_ulong>::uninit();
let mut focus_state = MaybeUninit::<c_int>::uninit();
Expand All @@ -104,7 +105,7 @@ impl Display {
);
if focus_state.assume_init() != xlib::RevertToNone {
let mut window = Window::new(*focus_window.as_ptr(), *self);
if window.geometry == Geometry::new(0, 0, 1, 1) {
if window.geometry == Geometry::new(0, 0, 1, 1) || parent {
if let Some(parent) = window.get_parent() {
window = parent;
}
Expand Down Expand Up @@ -136,8 +137,9 @@ impl Display {
*/
fn get_window(&self) -> (Window, Geometry) {
match self.settings.window {
RecordWindow::Focus(geometry) => (
self.get_focused_window().expect("Failed to get the window"),
RecordWindow::Focus(geometry, parent) => (
self.get_focused_window(parent)
.expect("Failed to get the window"),
geometry.unwrap_or_default(),
),
RecordWindow::Root(geometry) => {
Expand Down Expand Up @@ -359,7 +361,7 @@ mod tests {
display.update_padding(Geometry::new(0, 0, 10, 10), Geometry::default());
assert_eq!(
display.get_root_window().xid,
display.get_focused_window().unwrap().xid
display.get_focused_window(false).unwrap().xid
);
let input_state = InputState::default();
assert!(display.select_window(&input_state).is_none());
Expand Down
16 changes: 12 additions & 4 deletions src/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ impl<'a> Access<'a, Window> for WindowSystem<'a> {
fn get_window(&mut self) -> Option<Window> {
debug!("Record window: {:?}", self.settings.record.window);
match self.settings.record.window {
RecordWindow::Focus(None) => self.display.get_focused_window(),
RecordWindow::Focus(None, parent) => {
self.display.get_focused_window(parent)
}
RecordWindow::Root(None) => Some(self.display.get_root_window()),
_ => {
if self.settings.record.command.is_some() {
self.display.get_focused_window()
self.display.get_focused_window(
match self.settings.record.window {
RecordWindow::Focus(_, parent) => parent,
_ => false,
},
)
} else {
self.display.select_window(
&self
Expand Down Expand Up @@ -126,13 +133,14 @@ mod tests {
.unwrap()
.get_window()
.is_none());
settings.record.window = RecordWindow::Focus(Some(Geometry::default()));
settings.record.window =
RecordWindow::Focus(Some(Geometry::default()), false);
settings.record.command = Some("test");
assert!(WindowSystem::init(&settings)
.unwrap()
.get_window()
.is_some());
settings.record.window = RecordWindow::Focus(None);
settings.record.window = RecordWindow::Focus(None, false);
let mut window_system = WindowSystem::init(&settings).unwrap();
window_system.display.set_focused_window(
window_system.display.get_root_window().xid,
Expand Down

0 comments on commit 5e7b057

Please sign in to comment.