Rebase on new libcosmic
This commit is contained in:
parent
e43008822f
commit
ccee108243
5 changed files with 758 additions and 793 deletions
|
|
@ -1,4 +1,7 @@
|
|||
use cosmic::iced::keyboard::{KeyCode, Modifiers};
|
||||
use cosmic::{
|
||||
iced::keyboard::{Key, Modifiers},
|
||||
iced_core::keyboard::key::Named,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{collections::HashMap, fmt};
|
||||
|
||||
|
|
@ -15,12 +18,12 @@ pub enum Modifier {
|
|||
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
||||
pub struct KeyBind {
|
||||
pub modifiers: Vec<Modifier>,
|
||||
pub key_code: KeyCode,
|
||||
pub key: Key,
|
||||
}
|
||||
|
||||
impl KeyBind {
|
||||
pub fn matches(&self, modifiers: Modifiers, key_code: KeyCode) -> bool {
|
||||
self.key_code == key_code
|
||||
pub fn matches(&self, modifiers: Modifiers, key: &Key) -> bool {
|
||||
key == &self.key
|
||||
&& modifiers.logo() == self.modifiers.contains(&Modifier::Super)
|
||||
&& modifiers.control() == self.modifiers.contains(&Modifier::Ctrl)
|
||||
&& modifiers.alt() == self.modifiers.contains(&Modifier::Alt)
|
||||
|
|
@ -33,7 +36,11 @@ impl fmt::Display for KeyBind {
|
|||
for modifier in self.modifiers.iter() {
|
||||
write!(f, "{:?} + ", modifier)?;
|
||||
}
|
||||
write!(f, "{:?}", self.key_code)
|
||||
match &self.key {
|
||||
Key::Character(c) => write!(f, "{}", c.to_uppercase()),
|
||||
Key::Named(named) => write!(f, "{:?}", named),
|
||||
other => write!(f, "{:?}", other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -42,11 +49,11 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
|
|||
let mut key_binds = HashMap::new();
|
||||
|
||||
macro_rules! bind {
|
||||
([$($modifier:ident),* $(,)?], $key_code:ident, $action:ident) => {{
|
||||
([$($modifier:ident),* $(,)?], $key:expr, $action:ident) => {{
|
||||
key_binds.insert(
|
||||
KeyBind {
|
||||
modifiers: vec![$(Modifier::$modifier),*],
|
||||
key_code: KeyCode::$key_code,
|
||||
key: $key,
|
||||
},
|
||||
Action::$action,
|
||||
);
|
||||
|
|
@ -54,8 +61,8 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
|
|||
}
|
||||
|
||||
//TODO: key bindings
|
||||
bind!([], Left, SeekBackward);
|
||||
bind!([], Right, SeekForward);
|
||||
bind!([], Key::Named(Named::ArrowLeft), SeekBackward);
|
||||
bind!([], Key::Named(Named::ArrowRight), SeekForward);
|
||||
|
||||
key_binds
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue