This commit is contained in:
Moritz Ruth 2024-01-09 23:16:44 +01:00
parent 521171cf85
commit 026a524c20
Signed by: moritzruth
GPG key ID: C9BBAB79405EE56D
8 changed files with 69 additions and 28 deletions

View file

@ -17,7 +17,6 @@ mode.playerctl__button.style.inactive.icon = "@ph/skip-forward[alpha=0.4]"
[keys.1x2] [keys.1x2]
icon = "@fad/shuffle[alpha=0.4]" icon = "@fad/shuffle[alpha=0.4]"
mode.playerctl__shuffle.style.on.icon = "@fad/shuffle[color=#58fc11]" mode.playerctl__shuffle.style.on.icon = "@fad/shuffle[color=#58fc11]"
mode.playerctl__shuffle.style.off.icon = "@fad/shuffle"
[keys.2x2] [keys.2x2]
icon = "@fad/repeat[alpha=0.4]" icon = "@fad/repeat[alpha=0.4]"

View file

@ -5,24 +5,24 @@ delta = 1
[keys.4x1] [keys.4x1]
label = "😀" label = "😀"
mode.keyboard.key = "😀" mode.command.command = "wtype 😀"
[keys.4x2] [keys.4x2]
label = "😄" label = "😄"
mode.keyboard.key = "😄" mode.command.command = "wtype 😄"
[keys.4x3] [keys.4x3]
label = "😅" label = "😅"
mode.keyboard.key = "😅" mode.command.command = "wtype 😅"
[keys.4x4] [keys.4x4]
label = "😂" label = "😂"
mode.keyboard.key = "😂" mode.command.command = "wtype 😂"
[keys.4x5] [keys.4x5]
label = "😁" label = "😁"
mode.keyboard.key = "😁" mode.command.command = "wtype 😁"
[keys.4x6] [keys.4x6]
label = "😇" label = "😇"
mode.keyboard.key = "😇" mode.command.command = "wtype 😇"

View file

@ -1,35 +1,35 @@
[keys.4x1] [keys.4x1]
label = "9" label = "9"
mode.keyboard.key = "9" mode.command.command = "wtype 9"
[keys.3x1] [keys.3x1]
label = "8" label = "8"
mode.keyboard.key = "8" mode.command.command = "wtype 8"
[keys.2x1] [keys.2x1]
label = "7" label = "7"
mode.keyboard.key = "7" mode.command.command = "wtype 7"
[keys.4x2] [keys.4x2]
label = "6" label = "6"
mode.keyboard.key = "6" mode.command.command = "wtype 6"
[keys.3x2] [keys.3x2]
label = "5" label = "5"
mode.keyboard.key = "5" mode.command.command = "wtype 5"
[keys.2x2] [keys.2x2]
label = "4" label = "4"
mode.keyboard.key = "4" mode.command.command = "wtype 4"
[keys.4x3] [keys.4x3]
label = "3" label = "3"
mode.keyboard.key = "3" mode.command.command = "wtype 3"
[keys.3x3] [keys.3x3]
label = "2" label = "2"
mode.keyboard.key = "2" mode.command.command = "wtype 2"
[keys.2x3] [keys.2x3]
label = "1" label = "1"
mode.keyboard.key = "1" mode.command.command = "wtype 1"

View file

@ -6,24 +6,24 @@ delta = 4
[keys.1x1] [keys.1x1]
label = "" label = ""
mode.keyboard.key = "" mode.command.command = "wtype "
[keys.2x1] [keys.2x1]
label = "…" label = "…"
mode.keyboard.key = "…" mode.command.command = "wtype …"
[keys.3x1] [keys.3x1]
label = "—" label = "—"
mode.keyboard.key = "—" mode.command.command = "wtype —"
[keys.4x1] [keys.4x1]
label = "" label = ""
mode.keyboard.key = "" mode.command.command = "wtype "
[keys.5x1] [keys.5x1]
label = "·" label = "·"
mode.keyboard.key = "·" mode.command.command = "wtype ·"
[keys.6x1] [keys.6x1]
label = "→" label = "→"
mode.keyboard.key = "→" mode.command.command = "wtype →"

View file

@ -75,12 +75,13 @@ pub struct KeyConfig {
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[derive(Debug, Default, Deserialize)] #[derive(Debug, Default, Deserialize)]
pub struct KeyModes { 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__button: Option<Arc<modes::key::playerctl::ButtonConfig>>,
pub playerctl__shuffle: Option<Arc<modes::key::playerctl::ShuffleConfig>>, pub playerctl__shuffle: Option<Arc<modes::key::playerctl::ShuffleConfig>>,
pub playerctl__loop: Option<Arc<modes::key::playerctl::LoopConfig>>, pub playerctl__loop: Option<Arc<modes::key::playerctl::LoopConfig>>,
pub home_assistant__switch: Option<Arc<modes::key::home_assistant::SwitchConfig>>, pub vibrate: Option<Arc<modes::key::vibrate::Config>>,
pub home_assistant__button: Option<Arc<modes::key::home_assistant::ButtonConfig>>,
} }
pub type StyleByStateMap<State> = HashMap<State, KeyStyle>; pub type StyleByStateMap<State> = HashMap<State, KeyStyle>;

View 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),
}
}
}
}

View file

@ -7,6 +7,7 @@ use crate::model;
use crate::model::position::KeyPath; use crate::model::position::KeyPath;
use crate::runner::command::IoWorkerCommand; use crate::runner::command::IoWorkerCommand;
pub mod command;
pub mod home_assistant; pub mod home_assistant;
pub mod playerctl; pub mod playerctl;
pub mod timer; pub mod timer;
@ -35,6 +36,10 @@ pub fn start_handlers(
let mut events = events.subscribe(); let mut events = events.subscribe();
let own_events = broadcast::Sender::new(5); 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 { if let Some(c) = &config.mode.playerctl__button {
tokio::spawn(playerctl::handle_button(path.clone(), Arc::clone(c), own_events.subscribe(), commands.clone())); 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 { 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 { tokio::spawn(async move {

View file

@ -5,7 +5,6 @@ use tokio::sync::broadcast;
use loupedeck_serial::commands::VibrationPattern; use loupedeck_serial::commands::VibrationPattern;
use crate::model::position::KeyPath;
use crate::modes::key::{KeyEvent, KeyTouchEventKind}; use crate::modes::key::{KeyEvent, KeyTouchEventKind};
use crate::runner::command::IoWorkerCommand; use crate::runner::command::IoWorkerCommand;
@ -14,7 +13,7 @@ pub struct Config {
pub pattern: VibrationPattern, 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 { while let Ok(event) = events.recv().await {
if let KeyEvent::Touch { kind, .. } = event { if let KeyEvent::Touch { kind, .. } = event {
if kind == KeyTouchEventKind::Start { if kind == KeyTouchEventKind::Start {