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"]
|
features = ["tokio", "winit"]
|
||||||
#path = "../libcosmic"
|
#path = "../libcosmic"
|
||||||
|
|
||||||
|
[dependencies.smol_str]
|
||||||
|
version = "0.2.1"
|
||||||
|
features = ["serde"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["wgpu"]
|
default = ["wgpu"]
|
||||||
wgpu = ["libcosmic/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 serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, fmt};
|
use std::{collections::HashMap, fmt};
|
||||||
|
|
||||||
|
|
@ -15,12 +18,12 @@ pub enum Modifier {
|
||||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
||||||
pub struct KeyBind {
|
pub struct KeyBind {
|
||||||
pub modifiers: Vec<Modifier>,
|
pub modifiers: Vec<Modifier>,
|
||||||
pub key_code: KeyCode,
|
pub key: Key,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyBind {
|
impl KeyBind {
|
||||||
pub fn matches(&self, modifiers: Modifiers, key_code: KeyCode) -> bool {
|
pub fn matches(&self, modifiers: Modifiers, key: &Key) -> bool {
|
||||||
self.key_code == key_code
|
key == &self.key
|
||||||
&& modifiers.logo() == self.modifiers.contains(&Modifier::Super)
|
&& modifiers.logo() == self.modifiers.contains(&Modifier::Super)
|
||||||
&& modifiers.control() == self.modifiers.contains(&Modifier::Ctrl)
|
&& modifiers.control() == self.modifiers.contains(&Modifier::Ctrl)
|
||||||
&& modifiers.alt() == self.modifiers.contains(&Modifier::Alt)
|
&& modifiers.alt() == self.modifiers.contains(&Modifier::Alt)
|
||||||
|
|
@ -33,7 +36,11 @@ impl fmt::Display for KeyBind {
|
||||||
for modifier in self.modifiers.iter() {
|
for modifier in self.modifiers.iter() {
|
||||||
write!(f, "{:?} + ", modifier)?;
|
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();
|
let mut key_binds = HashMap::new();
|
||||||
|
|
||||||
macro_rules! bind {
|
macro_rules! bind {
|
||||||
([$($modifier:ident),* $(,)?], $key_code:ident, $action:ident) => {{
|
([$($modifier:ident),* $(,)?], $key:expr, $action:ident) => {{
|
||||||
key_binds.insert(
|
key_binds.insert(
|
||||||
KeyBind {
|
KeyBind {
|
||||||
modifiers: vec![$(Modifier::$modifier),*],
|
modifiers: vec![$(Modifier::$modifier),*],
|
||||||
key_code: KeyCode::$key_code,
|
key: $key,
|
||||||
},
|
},
|
||||||
Action::$action,
|
Action::$action,
|
||||||
);
|
);
|
||||||
|
|
@ -54,8 +61,8 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: key bindings
|
//TODO: key bindings
|
||||||
bind!([], Left, SeekBackward);
|
bind!([], Key::Named(Named::ArrowLeft), SeekBackward);
|
||||||
bind!([], Right, SeekForward);
|
bind!([], Key::Named(Named::ArrowRight), SeekForward);
|
||||||
|
|
||||||
key_binds
|
key_binds
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
src/main.rs
15
src/main.rs
|
|
@ -7,7 +7,7 @@ use cosmic::{
|
||||||
cosmic_theme, executor,
|
cosmic_theme, executor,
|
||||||
iced::{
|
iced::{
|
||||||
event::{self, Event},
|
event::{self, Event},
|
||||||
keyboard::{Event as KeyEvent, KeyCode, Modifiers},
|
keyboard::{Event as KeyEvent, Key, Modifiers},
|
||||||
subscription::{self, Subscription},
|
subscription::{self, Subscription},
|
||||||
window, Alignment, Length,
|
window, Alignment, Length,
|
||||||
},
|
},
|
||||||
|
|
@ -123,7 +123,7 @@ pub enum Message {
|
||||||
Todo,
|
Todo,
|
||||||
AppTheme(AppTheme),
|
AppTheme(AppTheme),
|
||||||
Config(Config),
|
Config(Config),
|
||||||
Key(Modifiers, KeyCode),
|
Key(Modifiers, Key),
|
||||||
Player(PlayerMessage),
|
Player(PlayerMessage),
|
||||||
SystemThemeModeChange(cosmic_theme::ThemeMode),
|
SystemThemeModeChange(cosmic_theme::ThemeMode),
|
||||||
Tick(Instant),
|
Tick(Instant),
|
||||||
|
|
@ -282,9 +282,9 @@ impl Application for App {
|
||||||
return self.update_config();
|
return self.update_config();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Key(modifiers, key_code) => {
|
Message::Key(modifiers, key) => {
|
||||||
for (key_bind, action) in self.key_binds.iter() {
|
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());
|
return self.update(action.message());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -410,10 +410,9 @@ impl Application for App {
|
||||||
Subscription::batch([
|
Subscription::batch([
|
||||||
window::frames().map(|(_window_id, instant)| Message::Tick(instant)),
|
window::frames().map(|(_window_id, instant)| Message::Tick(instant)),
|
||||||
event::listen_with(|event, _status| match event {
|
event::listen_with(|event, _status| match event {
|
||||||
Event::Keyboard(KeyEvent::KeyPressed {
|
Event::Keyboard(KeyEvent::KeyPressed { key, modifiers, .. }) => {
|
||||||
key_code,
|
Some(Message::Key(modifiers, key))
|
||||||
modifiers,
|
}
|
||||||
}) => Some(Message::Key(modifiers, key_code)),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}),
|
}),
|
||||||
cosmic_config::config_subscription(
|
cosmic_config::config_subscription(
|
||||||
|
|
|
||||||
|
|
@ -567,7 +567,10 @@ fn ffmpeg_thread<P: AsRef<Path>>(
|
||||||
|
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"video: {:?}, {:?} audio: {:?}, {:?}",
|
"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);
|
let min_queue_duration = cmp::min(video_queue_duration, audio_queue_duration);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue