use serde::{Deserialize, Serialize};
use std::{fmt::Debug, sync::Arc};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct Hotkey {
pub key: String,
pub ctrl: bool,
pub alt: bool,
pub shift: bool,
pub meta: bool,
}
impl Hotkey {
pub fn new(key: impl Into<String>) -> Self {
Self {
key: key.into(),
ctrl: false,
alt: false,
shift: false,
meta: false,
}
}
pub fn with_ctrl(mut self) -> Self {
self.ctrl = true;
self
}
pub fn with_alt(mut self) -> Self {
self.alt = true;
self
}
pub fn with_shift(mut self) -> Self {
self.shift = true;
self
}
pub fn with_meta(mut self) -> Self {
self.meta = true;
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum HotkeyEvent {
GlobalHotkey(Hotkey),
DoubleCtrl,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum HotkeyEventFilter {
All,
GlobalHotkey(Hotkey),
DoubleCtrl,
}
pub type HotkeyCallback = Arc<dyn Fn(HotkeyEvent) + Send + Sync>;
pub struct CallbackRegistration {
pub id: String,
pub filter: HotkeyEventFilter,
pub callback: HotkeyCallback,
}
impl Debug for CallbackRegistration {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CallbackRegistration")
.field("id", &self.id)
.field("filter", &self.filter)
.finish()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HotkeyRegistration {
pub hotkey: Hotkey,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct HotkeyConfig {
pub hotkeys: Vec<HotkeyRegistration>,
pub double_ctrl_enabled: bool,
}