Skip to content

Commit

Permalink
Using fork() on Ctrl+Enter (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
geekylthyosaur authored Oct 24, 2022
1 parent 8038f87 commit e71aa55
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased changes

## Features

- Launch multiple apps from one yofi launch based on fork (#24).

## Changes

- Dropped support for font-kit backend.
Expand Down
11 changes: 11 additions & 0 deletions src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ impl Mode {
Self::Dialog(dialog::DialogMode::new())
}

pub fn fork_eval(&mut self, info: EvalInfo<'_>) {
match unsafe { nix::unistd::fork() } {
Ok(v) => {
if v.is_child() {
self.eval(info);
}
}
Err(e) => log::error!("fork() error: {}", e),
}
}

delegate!(pub fn eval(&mut self, info: EvalInfo<'_>) -> std::convert::Infallible);
delegate!(pub fn entries_len(&self) -> usize);
delegate!(pub fn subentries_len(&self, idx: usize) -> usize);
Expand Down
7 changes: 6 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,19 @@ impl State {
}
KeyPress {
keysym: keysyms::XKB_KEY_Return,
ctrl,
..
} => {
let info = EvalInfo {
index: self.filtered_lines.index(self.selected_item),
subindex: self.selected_subitem,
input_value: self.input_buffer.parsed_input(),
};
self.inner.eval(info);
if ctrl {
self.inner.fork_eval(info);
} else {
self.inner.eval(info);
}
}
KeyPress {
keysym: keysyms::XKB_KEY_bracketright,
Expand Down

0 comments on commit e71aa55

Please sign in to comment.