mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 14:31:23 +00:00
feat: add hotkey system (#48)
* feat: add hotkey system for playing individual sounds Slot-based hotkey mappings stored in ~/.config/pwsp/hotkeys.json. Daemon serves hotkey IPC commands for CLI/compositor bindings. GUI supports focused hotkey triggers, a dedicated Hotkeys panel with search and conflict detection, file badges, and a key chord capture dialog. CLI gains play-hotkey, get hotkeys, set hotkey, set hotkey-key, and clear-hotkey subcommands. * feat: add global hotkey support via evdev Listen for keyboard events directly from /dev/input using evdev, enabling hotkeys to work system-wide regardless of window focus or display server (X11, GNOME, KDE Plasma, Hyprland). The daemon spawns async listeners for each keyboard device at startup, tracks modifier state, and triggers playback when a configured chord matches. Requires the user to be in the 'input' group; logs a warning and continues without global hotkeys if devices are inaccessible. * various changes * refactor: route hotkey mutations through daemon IPC GUI no longer writes hotkey config directly to disk. Instead, all mutations (set slot, set key chord, clear chord, remove slot) are sent to the daemon via IPC, which persists the changes. The state thread periodically syncs the hotkey config back from the daemon, so CLI-made changes are reflected in the GUI. New IPC commands: set_hotkey_action (arbitrary action per slot), clear_hotkey_key (remove key chord without removing the slot). Also removes unreachable capture overlay from draw_hotkeys(). * small refactor --------- Co-authored-by: arabian <a.tevg@ya.ru>
This commit is contained in:
+19
-1
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
types::{
|
||||
audio_player::FullState,
|
||||
config::GuiConfig,
|
||||
config::{GuiConfig, HotkeyConfig},
|
||||
gui::AudioPlayerState,
|
||||
socket::{Request, Response},
|
||||
},
|
||||
@@ -10,6 +10,7 @@ use crate::{
|
||||
use std::{
|
||||
error::Error,
|
||||
sync::{Arc, Mutex},
|
||||
time::Instant,
|
||||
};
|
||||
use tokio::time::{Duration, sleep};
|
||||
|
||||
@@ -49,6 +50,7 @@ pub fn format_time_pair(position: f32, duration: f32) -> String {
|
||||
pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerState>>) {
|
||||
tokio::spawn(async move {
|
||||
let sleep_duration = Duration::from_secs_f32(1.0 / 60.0);
|
||||
let mut last_hotkey_poll = Instant::now();
|
||||
|
||||
loop {
|
||||
let is_running = is_daemon_running().unwrap_or(false);
|
||||
@@ -105,6 +107,22 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
|
||||
guard.is_daemon_running = true;
|
||||
}
|
||||
|
||||
// Poll hotkey config at a lower frequency (~every 2 seconds)
|
||||
if last_hotkey_poll.elapsed() >= Duration::from_secs(2) {
|
||||
let hotkey_res = make_request(Request::get_hotkeys())
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
if hotkey_res.status {
|
||||
if let Ok(config) = serde_json::from_str::<HotkeyConfig>(&hotkey_res.message) {
|
||||
let mut guard = audio_player_state_shared
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
guard.hotkey_config = Some(config);
|
||||
}
|
||||
}
|
||||
last_hotkey_poll = Instant::now();
|
||||
}
|
||||
|
||||
sleep(sleep_duration).await;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user