commit
This commit is contained in:
parent
521171cf85
commit
026a524c20
8 changed files with 69 additions and 28 deletions
|
@ -17,7 +17,6 @@ mode.playerctl__button.style.inactive.icon = "@ph/skip-forward[alpha=0.4]"
|
|||
[keys.1x2]
|
||||
icon = "@fad/shuffle[alpha=0.4]"
|
||||
mode.playerctl__shuffle.style.on.icon = "@fad/shuffle[color=#58fc11]"
|
||||
mode.playerctl__shuffle.style.off.icon = "@fad/shuffle"
|
||||
|
||||
[keys.2x2]
|
||||
icon = "@fad/repeat[alpha=0.4]"
|
||||
|
|
|
@ -5,24 +5,24 @@ delta = 1
|
|||
|
||||
[keys.4x1]
|
||||
label = "😀"
|
||||
mode.keyboard.key = "😀"
|
||||
mode.command.command = "wtype 😀"
|
||||
|
||||
[keys.4x2]
|
||||
label = "😄"
|
||||
mode.keyboard.key = "😄"
|
||||
mode.command.command = "wtype 😄"
|
||||
|
||||
[keys.4x3]
|
||||
label = "😅"
|
||||
mode.keyboard.key = "😅"
|
||||
mode.command.command = "wtype 😅"
|
||||
|
||||
[keys.4x4]
|
||||
label = "😂"
|
||||
mode.keyboard.key = "😂"
|
||||
mode.command.command = "wtype 😂"
|
||||
|
||||
[keys.4x5]
|
||||
label = "😁"
|
||||
mode.keyboard.key = "😁"
|
||||
mode.command.command = "wtype 😁"
|
||||
|
||||
[keys.4x6]
|
||||
label = "😇"
|
||||
mode.keyboard.key = "😇"
|
||||
mode.command.command = "wtype 😇"
|
|
@ -1,35 +1,35 @@
|
|||
[keys.4x1]
|
||||
label = "9"
|
||||
mode.keyboard.key = "9"
|
||||
mode.command.command = "wtype 9"
|
||||
|
||||
[keys.3x1]
|
||||
label = "8"
|
||||
mode.keyboard.key = "8"
|
||||
mode.command.command = "wtype 8"
|
||||
|
||||
[keys.2x1]
|
||||
label = "7"
|
||||
mode.keyboard.key = "7"
|
||||
mode.command.command = "wtype 7"
|
||||
|
||||
[keys.4x2]
|
||||
label = "6"
|
||||
mode.keyboard.key = "6"
|
||||
mode.command.command = "wtype 6"
|
||||
|
||||
[keys.3x2]
|
||||
label = "5"
|
||||
mode.keyboard.key = "5"
|
||||
mode.command.command = "wtype 5"
|
||||
|
||||
[keys.2x2]
|
||||
label = "4"
|
||||
mode.keyboard.key = "4"
|
||||
mode.command.command = "wtype 4"
|
||||
|
||||
[keys.4x3]
|
||||
label = "3"
|
||||
mode.keyboard.key = "3"
|
||||
mode.command.command = "wtype 3"
|
||||
|
||||
[keys.3x3]
|
||||
label = "2"
|
||||
mode.keyboard.key = "2"
|
||||
mode.command.command = "wtype 2"
|
||||
|
||||
[keys.2x3]
|
||||
label = "1"
|
||||
mode.keyboard.key = "1"
|
||||
mode.command.command = "wtype 1"
|
|
@ -6,24 +6,24 @@ delta = 4
|
|||
|
||||
[keys.1x1]
|
||||
label = "’"
|
||||
mode.keyboard.key = "’"
|
||||
mode.command.command = "wtype ’"
|
||||
|
||||
[keys.2x1]
|
||||
label = "…"
|
||||
mode.keyboard.key = "…"
|
||||
mode.command.command = "wtype …"
|
||||
|
||||
[keys.3x1]
|
||||
label = "—"
|
||||
mode.keyboard.key = "—"
|
||||
mode.command.command = "wtype —"
|
||||
|
||||
[keys.4x1]
|
||||
label = "–"
|
||||
mode.keyboard.key = "–"
|
||||
mode.command.command = "wtype –"
|
||||
|
||||
[keys.5x1]
|
||||
label = "·"
|
||||
mode.keyboard.key = "·"
|
||||
mode.command.command = "wtype ·"
|
||||
|
||||
[keys.6x1]
|
||||
label = "→"
|
||||
mode.keyboard.key = "→"
|
||||
mode.command.command = "wtype →"
|
|
@ -75,12 +75,13 @@ pub struct KeyConfig {
|
|||
#[allow(non_snake_case)]
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
pub struct KeyModes {
|
||||
pub vibrate: Option<Arc<modes::key::vibrate::Config>>,
|
||||
pub command: Option<Arc<modes::key::command::Config>>,
|
||||
pub home_assistant__switch: Option<Arc<modes::key::home_assistant::SwitchConfig>>,
|
||||
pub home_assistant__button: Option<Arc<modes::key::home_assistant::ButtonConfig>>,
|
||||
pub playerctl__button: Option<Arc<modes::key::playerctl::ButtonConfig>>,
|
||||
pub playerctl__shuffle: Option<Arc<modes::key::playerctl::ShuffleConfig>>,
|
||||
pub playerctl__loop: Option<Arc<modes::key::playerctl::LoopConfig>>,
|
||||
pub home_assistant__switch: Option<Arc<modes::key::home_assistant::SwitchConfig>>,
|
||||
pub home_assistant__button: Option<Arc<modes::key::home_assistant::ButtonConfig>>,
|
||||
pub vibrate: Option<Arc<modes::key::vibrate::Config>>,
|
||||
}
|
||||
|
||||
pub type StyleByStateMap<State> = HashMap<State, KeyStyle>;
|
||||
|
|
37
deckster/src/modes/key/command.rs
Normal file
37
deckster/src/modes/key/command.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use std::process::{Command, Stdio};
|
||||
use std::sync::Arc;
|
||||
|
||||
use log::{error, trace, warn};
|
||||
use serde::Deserialize;
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
use crate::modes::key::KeyEvent;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
pub command: String,
|
||||
}
|
||||
|
||||
pub async fn handle(config: Arc<Config>, mut events: broadcast::Receiver<KeyEvent>) {
|
||||
while let Ok(event) = events.recv().await {
|
||||
if let KeyEvent::Press = event {
|
||||
let result = Command::new("sh")
|
||||
.args(["-c", &config.command])
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.stdin(Stdio::null())
|
||||
.status();
|
||||
|
||||
match result {
|
||||
Ok(status) => {
|
||||
if status.success() {
|
||||
trace!("Command `{}` exited with status code 0", config.command);
|
||||
} else {
|
||||
warn!("Command `{}` exited with status code {}", config.command, status);
|
||||
}
|
||||
}
|
||||
Err(error) => error!("Command `{}` could not be executed: {}", config.command, error),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ use crate::model;
|
|||
use crate::model::position::KeyPath;
|
||||
use crate::runner::command::IoWorkerCommand;
|
||||
|
||||
pub mod command;
|
||||
pub mod home_assistant;
|
||||
pub mod playerctl;
|
||||
pub mod timer;
|
||||
|
@ -35,6 +36,10 @@ pub fn start_handlers(
|
|||
let mut events = events.subscribe();
|
||||
let own_events = broadcast::Sender::new(5);
|
||||
|
||||
if let Some(c) = &config.mode.command {
|
||||
tokio::spawn(command::handle(Arc::clone(c), own_events.subscribe()));
|
||||
}
|
||||
|
||||
if let Some(c) = &config.mode.playerctl__button {
|
||||
tokio::spawn(playerctl::handle_button(path.clone(), Arc::clone(c), own_events.subscribe(), commands.clone()));
|
||||
}
|
||||
|
@ -48,7 +53,7 @@ pub fn start_handlers(
|
|||
}
|
||||
|
||||
if let Some(c) = &config.mode.vibrate {
|
||||
tokio::spawn(vibrate::handle(path.clone(), Arc::clone(c), own_events.subscribe(), commands.clone()));
|
||||
tokio::spawn(vibrate::handle(Arc::clone(c), own_events.subscribe(), commands.clone()));
|
||||
}
|
||||
|
||||
tokio::spawn(async move {
|
||||
|
|
|
@ -5,7 +5,6 @@ use tokio::sync::broadcast;
|
|||
|
||||
use loupedeck_serial::commands::VibrationPattern;
|
||||
|
||||
use crate::model::position::KeyPath;
|
||||
use crate::modes::key::{KeyEvent, KeyTouchEventKind};
|
||||
use crate::runner::command::IoWorkerCommand;
|
||||
|
||||
|
@ -14,7 +13,7 @@ pub struct Config {
|
|||
pub pattern: VibrationPattern,
|
||||
}
|
||||
|
||||
pub async fn handle(_: KeyPath, config: Arc<Config>, mut events: broadcast::Receiver<KeyEvent>, commands: flume::Sender<IoWorkerCommand>) {
|
||||
pub async fn handle(config: Arc<Config>, mut events: broadcast::Receiver<KeyEvent>, commands: flume::Sender<IoWorkerCommand>) {
|
||||
while let Ok(event) = events.recv().await {
|
||||
if let KeyEvent::Touch { kind, .. } = event {
|
||||
if kind == KeyTouchEventKind::Start {
|
||||
|
|
Loading…
Add table
Reference in a new issue