Skip to content

Commit 3194d24

Browse files
committed
feat: additional keybindings
1 parent b162e33 commit 3194d24

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/key_bind.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
3131
bind!([], Key::Character(".".into()), NextFrame);
3232
bind!([], Key::Character(",".into()), PreviousFrame);
3333
bind!([], Key::Character("a".into()), AbRepeat);
34-
34+
bind!([], Key::Character("m".into()), AudioToggle);
35+
bind!([], Key::Named(Named::PageUp), PlayPrev);
36+
bind!([], Key::Named(Named::PageDown), PlayNext);
3537
key_binds
3638
}

src/main.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ pub enum Action {
187187
NextFrame,
188188
PreviousFrame,
189189
AbRepeat,
190+
AudioToggle,
190191
WindowClose,
191192
}
192193

@@ -212,6 +213,7 @@ impl MenuAction for Action {
212213
Self::NextFrame => Message::NextFrame,
213214
Self::PreviousFrame => Message::PreviousFrame,
214215
Self::AbRepeat => Message::AbRepeat,
216+
Self::AudioToggle => Message::AudioToggle,
215217
Self::WindowClose => Message::WindowClose,
216218
}
217219
}
@@ -321,6 +323,7 @@ pub enum Message {
321323
ShowControls,
322324
SystemThemeModeChange(cosmic_theme::ThemeMode),
323325
WindowClose,
326+
Escape,
324327
}
325328

326329
/// The [`App`] stores application-specific state.
@@ -964,11 +967,7 @@ impl Application for App {
964967
}
965968

966969
fn on_escape(&mut self) -> Task<Self::Message> {
967-
if self.fullscreen {
968-
self.update(Message::Fullscreen)
969-
} else {
970-
Task::none()
971-
}
970+
self.update(Message::Escape)
972971
}
973972

974973
fn on_nav_select(&mut self, id: nav_bar::Id) -> Task<Message> {
@@ -1216,6 +1215,20 @@ impl Application for App {
12161215
);
12171216
}
12181217
}
1218+
Message::Escape => {
1219+
if let Some(window_id) = self.core.main_window_id() {
1220+
if self.fullscreen {
1221+
return self.update(Message::Fullscreen);
1222+
} else {
1223+
1224+
if let Some(video) = &mut self.video_opt {
1225+
video.set_paused(true);
1226+
}
1227+
1228+
return window::minimize(window_id, true);
1229+
}
1230+
}
1231+
}
12191232
Message::Key(modifiers, physical, key) => {
12201233
for (key_bind, action) in self.key_binds.iter() {
12211234
if key_bind.matches(modifiers, &key, Some(&physical)) {

0 commit comments

Comments
 (0)