Skip to content

Commit

Permalink
feat(whkd): use win-hotkeys for more win key bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
LGUG2Z committed Dec 28, 2024
1 parent d1b31fe commit a5da95e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 43 deletions.
97 changes: 65 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "whkd"
version = "0.2.3"
authors = ["Jade Iqbal <[email protected]>"]
description = "A simple hotkey daemon for Windows"
categories = ["hotkey-daemon", "windows"]
repository = "https://github.com/LGUG2Z/whkd"
Expand All @@ -18,4 +17,4 @@ color-eyre = "0.6"
dirs = "5"
lazy_static = "1"
parking_lot = "0.12"
windows-hotkeys = "0.2.1"
win-hotkeys = "0.2"
16 changes: 7 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ use std::path::PathBuf;
use std::process::ChildStdin;
use std::process::Command;
use std::process::Stdio;
use windows_hotkeys::error::HkError;
use windows_hotkeys::keys::ModKey;
use windows_hotkeys::keys::VKey;
use windows_hotkeys::HotkeyManager;
use windows_hotkeys::HotkeyManagerImpl;
use win_hotkeys::error::WHKError;
use win_hotkeys::keys::ModKey;
use win_hotkeys::keys::VKey;
use win_hotkeys::HotkeyManager;

mod parser;
mod whkdrc;
Expand Down Expand Up @@ -59,7 +58,7 @@ impl HkmData {
pub fn register(&self, hkm: &mut HotkeyManager<()>, shell: Shell) -> Result<()> {
let cmd = self.command.clone();

if let Err(error) = hkm.register(self.vkey, self.mod_keys.as_slice(), move || {
if let Err(error) = hkm.register_hotkey(self.vkey, self.mod_keys.as_slice(), move || {
if let Some(session_stdin) = SESSION_STDIN.lock().as_mut() {
if matches!(shell, Shell::Pwsh | Shell::Powershell) {
println!("{cmd}");
Expand All @@ -79,7 +78,7 @@ impl HkmData {
}

impl TryFrom<&HotkeyBinding> for HkmData {
type Error = HkError;
type Error = WHKError;

fn try_from(value: &HotkeyBinding) -> Result<Self, Self::Error> {
let (trigger, mods) = value.keys.split_last().unwrap();
Expand Down Expand Up @@ -156,7 +155,6 @@ fn main() -> Result<()> {
}

let mut hkm = HotkeyManager::new();
hkm.set_no_repeat(false);

let mut mapped = HashMap::new();
for (keys, app_bindings) in &whkdrc.app_bindings {
Expand All @@ -174,7 +172,7 @@ fn main() -> Result<()> {
let mod_keys = v[0].mod_keys.as_slice();

let v = v.clone();
hkm.register(vkey, mod_keys, move || {
hkm.register_hotkey(vkey, mod_keys, move || {
if let Some(session_stdin) = SESSION_STDIN.lock().as_mut() {
for e in &v {
let cmd = &e.command;
Expand Down

0 comments on commit a5da95e

Please sign in to comment.