Rebase on new libcosmic
This commit is contained in:
parent
e43008822f
commit
ccee108243
5 changed files with 758 additions and 793 deletions
1502
Cargo.lock
generated
1502
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -24,6 +24,10 @@ default-features = false
|
|||
features = ["tokio", "winit"]
|
||||
#path = "../libcosmic"
|
||||
|
||||
[dependencies.smol_str]
|
||||
version = "0.2.1"
|
||||
features = ["serde"]
|
||||
|
||||
[features]
|
||||
default = ["wgpu"]
|
||||
wgpu = ["libcosmic/wgpu"]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
15
src/main.rs
15
src/main.rs
|
|
@ -7,7 +7,7 @@ use cosmic::{
|
|||
cosmic_theme, executor,
|
||||
iced::{
|
||||
event::{self, Event},
|
||||
keyboard::{Event as KeyEvent, KeyCode, Modifiers},
|
||||
keyboard::{Event as KeyEvent, Key, Modifiers},
|
||||
subscription::{self, Subscription},
|
||||
window, Alignment, Length,
|
||||
},
|
||||
|
|
@ -123,7 +123,7 @@ pub enum Message {
|
|||
Todo,
|
||||
AppTheme(AppTheme),
|
||||
Config(Config),
|
||||
Key(Modifiers, KeyCode),
|
||||
Key(Modifiers, Key),
|
||||
Player(PlayerMessage),
|
||||
SystemThemeModeChange(cosmic_theme::ThemeMode),
|
||||
Tick(Instant),
|
||||
|
|
@ -282,9 +282,9 @@ impl Application for App {
|
|||
return self.update_config();
|
||||
}
|
||||
}
|
||||
Message::Key(modifiers, key_code) => {
|
||||
Message::Key(modifiers, key) => {
|
||||
for (key_bind, action) in self.key_binds.iter() {
|
||||
if key_bind.matches(modifiers, key_code) {
|
||||
if key_bind.matches(modifiers, &key) {
|
||||
return self.update(action.message());
|
||||
}
|
||||
}
|
||||
|
|
@ -410,10 +410,9 @@ impl Application for App {
|
|||
Subscription::batch([
|
||||
window::frames().map(|(_window_id, instant)| Message::Tick(instant)),
|
||||
event::listen_with(|event, _status| match event {
|
||||
Event::Keyboard(KeyEvent::KeyPressed {
|
||||
key_code,
|
||||
modifiers,
|
||||
}) => Some(Message::Key(modifiers, key_code)),
|
||||
Event::Keyboard(KeyEvent::KeyPressed { key, modifiers, .. }) => {
|
||||
Some(Message::Key(modifiers, key))
|
||||
}
|
||||
_ => None,
|
||||
}),
|
||||
cosmic_config::config_subscription(
|
||||
|
|
|
|||
|
|
@ -567,7 +567,10 @@ fn ffmpeg_thread<P: AsRef<Path>>(
|
|||
|
||||
log::debug!(
|
||||
"video: {:?}, {:?} audio: {:?}, {:?}",
|
||||
video_queue_duration, video_queue_delay, audio_queue_duration, audio_queue_delay
|
||||
video_queue_duration,
|
||||
video_queue_delay,
|
||||
audio_queue_duration,
|
||||
audio_queue_delay
|
||||
);
|
||||
|
||||
let min_queue_duration = cmp::min(video_queue_duration, audio_queue_duration);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue