Commit 3b7dd15b authored by Guillaume Desmottes's avatar Guillaume Desmottes 🐐

karapulse: toggle pause when hitting space bar

parent 5c61a66f
Pipeline #106551 passed with stages
in 17 minutes and 26 seconds
......@@ -203,6 +203,14 @@ impl KarapulseInner {
Ok(())
}
fn toggle_pause(&self) -> Result<(), Error> {
match self.state.get() {
State::Playing => self.pause(),
State::Paused => self.play(),
State::Waiting => Ok(()),
}
}
#[allow(dead_code)]
pub fn state(&self) -> State {
self.state.get()
......@@ -308,7 +316,13 @@ impl Karapulse {
Inhibit(false)
});
let inner_weak = Rc::downgrade(&inner);
window.connect_key_press_event(move |window, key| {
let karapulse = match inner_weak.upgrade() {
Some(inner) => inner,
None => return Inhibit(false),
};
let keyval = key.get_keyval();
match keyval {
gdk::enums::key::f => {
......@@ -321,6 +335,9 @@ impl Karapulse {
}
}
gdk::enums::key::Escape => window.unfullscreen(),
gdk::enums::key::space => karapulse
.toggle_pause()
.unwrap_or_else(|e| error!("failed to toggle pause: {}", e.to_string())),
_ => {}
}
Inhibit(false)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment