Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: 2024 edition #1545

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ homepage = "https://github.com/jtroo/kanata"
repository = "https://github.com/jtroo/kanata"
readme = "README.md"
license = "LGPL-3.0-only"
edition = "2021"
edition = "2024"
default-run = "kanata"

[lib]
Expand Down
4 changes: 2 additions & 2 deletions example_tcp_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "kanata_example_tcp_client"
description = "Example kanata TCP client"
version = "1.1.0"
edition = "2021"
edition = "2024"
license = "LGPL-3.0"
authors = ["jtroo <[email protected]>"]

Expand All @@ -12,4 +12,4 @@ clap = { version = "4", features = [ "derive" ] }
kanata-tcp-protocol = { path = "../tcp_protocol" }
log = "0.4.8"
simplelog = "0.12"
serde_json = "1"
serde_json = "1"
2 changes: 1 addition & 1 deletion example_tcp_client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::Parser;
use kanata_tcp_protocol::*;
use simplelog::*;
use std::io::{stdin, BufRead, BufReader, Write};
use std::io::{BufRead, BufReader, Write, stdin};
use std::net::{SocketAddr, TcpStream};
use std::process::exit;
use std::time::Duration;
Expand Down
58 changes: 38 additions & 20 deletions src/gui/win.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::Kanata;
use anyhow::{bail, Result};
use anyhow::{Result, bail};
use core::cell::RefCell;
use kanata_parser::cfg::CfgOptionsGui;
use log::Level::*;
Expand All @@ -17,14 +17,14 @@ use std::ffi::OsStr;
use std::iter::once;
use std::os::windows::ffi::OsStrExt;
use std::path::{Path, PathBuf};
use std::sync::mpsc::{Receiver, Sender as ASender, TryRecvError};
use std::sync::OnceLock;
use std::sync::mpsc::{Receiver, Sender as ASender, TryRecvError};
use std::time::Duration;
use winapi::shared::minwindef::{BYTE, DWORD};
use winapi::shared::windef::COLORREF;
use windows_sys::Wdk::System::SystemServices::RtlGetVersion;
use windows_sys::Win32::Foundation::{ERROR_FILE_NOT_FOUND, ERROR_SUCCESS, POINT, RECT, SIZE};
use windows_sys::Win32::System::Registry::{RegGetValueW, HKEY_CURRENT_USER, RRF_RT_REG_DWORD};
use windows_sys::Win32::System::Registry::{HKEY_CURRENT_USER, RRF_RT_REG_DWORD, RegGetValueW};
use windows_sys::Win32::System::SystemInformation::OSVERSIONINFOW;
use windows_sys::Win32::UI::HiDpi::GetSystemMetricsForDpi;
use windows_sys::Win32::UI::WindowsAndMessaging::{
Expand Down Expand Up @@ -126,7 +126,7 @@ pub fn get_xdg_home() -> Option<PathBuf> {
}

const CFG_FD: [&str; 3] = ["", "kanata", "kanata-tray"]; // blank "" allow checking directly for
// user passed values
// user passed values
const ASSET_FD: [&str; 4] = ["", "icon", "img", "icons"];
const IMG_EXT: [&str; 7] = ["ico", "jpg", "jpeg", "png", "bmp", "dds", "tiff"];
const PRE_LAYER: &str = "\n🗍: "; // : invalid path marker, so should be safe to use as a separator
Expand Down Expand Up @@ -255,7 +255,7 @@ fn get_icon_p_impl(
&app_data,
&user_cfg,
]; // empty path to allow no prefixes when icon path is explictily set in case it's a full
// path already
// path already

for (i, nm) in f_name.enumerate() {
trace!("{}nm={:?}", "", nm);
Expand Down Expand Up @@ -324,7 +324,10 @@ fn get_icon_p_impl(
icon_file.clear();
if p_par == blank_p && p_kan.is_empty() && p_icn.is_empty() && is_full_p
{
trace!("skipping further sub-iters on an empty parent with user config {:?}",nm);
trace!(
"skipping further sub-iters on an empty parent with user config {:?}",
nm
);
continue 'p;
}
} else {
Expand Down Expand Up @@ -561,8 +564,14 @@ impl SystemTray {
// TODO: somehow still shown a bit too far off from the pointer
if log_enabled!(Trace) {
let (mx, my) = MXY.get();
trace!("🖰 @{mx}⋅{my} ↔{mouse_ptr_w}↕{mouse_ptr_h} (upd={}) {x}⋅{y} @ dpi={dpi} → {xx}⋅{yy} {win_ver:?} flags={flags} ex←{}→{}↑{}↓{}"
,ret != 0,excluderect.left,excluderect.right,excluderect.top,excluderect.bottom);
trace!(
"🖰 @{mx}⋅{my} ↔{mouse_ptr_w}↕{mouse_ptr_h} (upd={}) {x}⋅{y} @ dpi={dpi} → {xx}⋅{yy} {win_ver:?} flags={flags} ex←{}→{}↑{}↓{}",
ret != 0,
excluderect.left,
excluderect.right,
excluderect.top,
excluderect.bottom
);
}
}
/// Spawn a thread with a new 🖰 pointer watcher
Expand Down Expand Up @@ -630,7 +639,7 @@ impl SystemTray {
let mut m_ptr_wh = self.m_ptr_wh.borrow_mut();
*m_ptr_wh = get_mouse_ptr_size(false);
} // 🖰 pointer size so tooltip doesn't overlap
// don't adjust for dpi in internal calculations
// don't adjust for dpi in internal calculations
self.update_tooltip_pos();
self.win_tt.set_visible(true);
if app_data.gui_opts.tooltip_duration != 0 {
Expand All @@ -651,7 +660,9 @@ impl SystemTray {
error!("internal: couldn't send a signal to the 🖰 pointer watcher!")
});
} else {
debug!("no message and no m2tt_sender_o, so no thread should be running, launch a new thread!");
debug!(
"no message and no m2tt_sender_o, so no thread should be running, launch a new thread!"
);
start = true;
}
}
Expand Down Expand Up @@ -744,13 +755,15 @@ impl SystemTray {
let mut img_dyn = self.img_dyn.borrow_mut();
img_dyn.insert(cfg_p.clone(), None);
self.tray_1cfg_m.set_bitmap(None); // can't update menu, so remove combo
// menu icon
// menu icon
};
} else {
debug!("gui cfg selection matches active config");
};
} else {
debug!("✗ kanata config is locked, can't get current config (likely the gui changed the layer and is still holding the lock, it will update the icon)");
debug!(
"✗ kanata config is locked, can't get current config (likely the gui changed the layer and is still holding the lock, it will update the icon)"
);
}
};
}
Expand Down Expand Up @@ -928,8 +941,8 @@ impl SystemTray {
let mut cfg_layer_pkey = PathBuf::new(); // path key
cfg_layer_pkey.push(path_cur_cc.clone());
cfg_layer_pkey.push(PRE_LAYER.to_owned() + layer_name); //:invalid path marker,
// so should be safe to use as
// a separator
// so should be safe to use as
// a separator
let cfg_layer_pkey_s = cfg_layer_pkey.display().to_string();
if log_enabled!(Debug) {
let layer_icon_s = layer_icon.clone().unwrap_or("✗".to_string());
Expand Down Expand Up @@ -1038,8 +1051,8 @@ impl SystemTray {
let mut cfg_layer_pkey = PathBuf::new(); // path key
cfg_layer_pkey.push(path_cur_cc.clone());
cfg_layer_pkey.push(PRE_LAYER.to_owned() + layer_name); //:invalid path marker,
// so should be safe
// to use as a separator
// so should be safe
// to use as a separator
let cfg_layer_pkey_s = cfg_layer_pkey.display().to_string();
if log_enabled!(Debug) {
let cfg_name = &path_cur
Expand Down Expand Up @@ -1092,7 +1105,9 @@ impl SystemTray {
clear,
)
} else {
debug!("✗ kanata config is locked, can't get current layer (likely the gui changed the layer and is still holding the lock, it will update the icon)");
debug!(
"✗ kanata config is locked, can't get current layer (likely the gui changed the layer and is still holding the lock, it will update the icon)"
);
}
} else {
warn!("✗ Layer indicator NOT changed, no CFG");
Expand Down Expand Up @@ -1486,7 +1501,10 @@ pub mod system_tray_ui {
main_tray_icon_is = true;
let _ = img_dyn.insert(cfg_layer_pkey, Some(icn));
} else {
info!("✗ main 0 icon ✓ icon path, will be using DEFAULT icon for {:?}",cfg_p);
info!(
"✗ main 0 icon ✓ icon path, will be using DEFAULT icon for {:?}",
cfg_p
);
let _ = img_dyn.insert(cfg_layer_pkey, None);
}
} else {
Expand Down Expand Up @@ -1677,9 +1695,9 @@ pub fn build_tray(cfg: &Arc<Mutex<Kanata>>) -> Result<system_tray_ui::SystemTray
}

pub use log::*;
pub use std::io::{stdout, IsTerminal};
pub use std::io::{IsTerminal, stdout};
pub use winapi::shared::minwindef::BOOL;
pub use winapi::um::wincon::{AttachConsole, FreeConsole, ATTACH_PARENT_PROCESS};
pub use winapi::um::wincon::{ATTACH_PARENT_PROCESS, AttachConsole, FreeConsole};

use once_cell::sync::Lazy;
pub static IS_TERM: Lazy<bool> = Lazy::new(|| stdout().is_terminal());
Expand Down
10 changes: 6 additions & 4 deletions src/gui/win_nwg_ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use winapi::shared::windef::HWND;
use windows_sys::Win32::Foundation::HANDLE;
use windows_sys::Win32::Graphics::Gdi::DeleteObject;
use windows_sys::Win32::UI::Shell::{
SHGetStockIconInfo, SHGSI_ICON, SHGSI_SMALLICON, SHSTOCKICONID, SHSTOCKICONINFO,
SHGSI_ICON, SHGSI_SMALLICON, SHGetStockIconInfo, SHSTOCKICONID, SHSTOCKICONINFO,
};
use windows_sys::Win32::UI::WindowsAndMessaging::{
CopyImage, DestroyIcon, GetIconInfoExW, SetMenuItemInfoW, HMENU, ICONINFOEXW, IMAGE_BITMAP,
LR_CREATEDIBSECTION, MENUITEMINFOW, MF_BYCOMMAND, MIIM_BITMAP,
CopyImage, DestroyIcon, GetIconInfoExW, HMENU, ICONINFOEXW, IMAGE_BITMAP, LR_CREATEDIBSECTION,
MENUITEMINFOW, MF_BYCOMMAND, MIIM_BITMAP, SetMenuItemInfoW,
};

/// Extends [`nwg::Bitmap`] with additional functionality.
Expand Down Expand Up @@ -225,7 +225,9 @@ pub fn check_hwnd(handle: &ControlHandle, not_bound: &str, bad_handle: &str) ->
match handle.hwnd() {
Some(hwnd) => match unsafe { IsWindow(hwnd) } {
0 => {
panic!("The window handle is no longer valid. This usually means the control was freed by the OS");
panic!(
"The window handle is no longer valid. This usually means the control was freed by the OS"
);
}
_ => hwnd,
},
Expand Down
2 changes: 1 addition & 1 deletion src/kanata/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub(super) enum KeyAction {
Release(OsCode),
Delay(u16),
}
use kanata_keyberon::key_code::KeyCode;
use KeyAction::*;
use kanata_keyberon::key_code::KeyCode;

fn empty() -> std::vec::IntoIter<Item> {
vec![].into_iter()
Expand Down
4 changes: 2 additions & 2 deletions src/kanata/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
allow(dead_code, unused_imports, unused_variables, unused_mut)
)]

use anyhow::{anyhow, bail, Result};
use anyhow::{Result, anyhow, bail};
use evdev::{InputEvent, InputEventKind, RelativeAxisType};
use log::info;
use parking_lot::Mutex;
use std::convert::TryFrom;
use std::sync::mpsc::SyncSender as Sender;
use std::sync::Arc;
use std::sync::mpsc::SyncSender as Sender;

use super::*;

Expand Down
4 changes: 2 additions & 2 deletions src/kanata/macos.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::*;
use anyhow::{anyhow, bail, Result};
use anyhow::{Result, anyhow, bail};
use log::info;
use parking_lot::Mutex;
use std::convert::TryFrom;
use std::sync::mpsc::SyncSender as Sender;
use std::sync::Arc;
use std::sync::mpsc::SyncSender as Sender;

pub(crate) static PRESSED_KEYS: Lazy<Mutex<HashSet<OsCode>>> =
Lazy::new(|| Mutex::new(HashSet::default()));
Expand Down
22 changes: 13 additions & 9 deletions src/kanata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#[cfg(all(target_os = "windows", feature = "gui"))]
use crate::gui::win::*;
use anyhow::{bail, Result};
use anyhow::{Result, bail};
use kanata_parser::sequences::*;
use log::{error, info};
use parking_lot::Mutex;
Expand All @@ -19,12 +19,12 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::time;

use crate::oskbd::{KeyEvent, *};
#[cfg(feature = "tcp_server")]
use crate::tcp_server::simple_sexpr_to_json_array;
#[cfg(feature = "tcp_server")]
use crate::SocketAddrWrapper;
use crate::ValidatedArgs;
use crate::oskbd::{KeyEvent, *};
#[cfg(feature = "tcp_server")]
use crate::tcp_server::simple_sexpr_to_json_array;
use kanata_parser::cfg;
use kanata_parser::cfg::list_actions::*;
use kanata_parser::cfg::*;
Expand Down Expand Up @@ -317,7 +317,9 @@ impl Kanata {
) {
Ok(kbd_out) => kbd_out,
Err(err) => {
error!("Failed to open the output uinput device. Make sure you've added the user executing kanata to the `uinput` group");
error!(
"Failed to open the output uinput device. Make sure you've added the user executing kanata to the `uinput` group"
);
bail!(err)
}
};
Expand Down Expand Up @@ -475,7 +477,9 @@ impl Kanata {
) {
Ok(kbd_out) => kbd_out,
Err(err) => {
error!("Failed to open the output uinput device. Make sure you've added the user executing kanata to the `uinput` group");
error!(
"Failed to open the output uinput device. Make sure you've added the user executing kanata to the `uinput` group"
);
bail!(err)
}
};
Expand Down Expand Up @@ -2305,9 +2309,9 @@ fn check_for_exit(_event: &KeyEvent) {
native_windows_gui::stop_thread_dispatch();
#[cfg(feature = "interception_driver")]
send_gui_exit_notice(); // interception driver is running in another thread to allow
// GUI take the main one, so it's calling check_for_exit
// from a thread that has no access to the main one, so
// can't stop main thread's dispatch
// GUI take the main one, so it's calling check_for_exit
// from a thread that has no access to the main one, so
// can't stop main thread's dispatch
}
#[cfg(all(
not(target_os = "linux"),
Expand Down
7 changes: 5 additions & 2 deletions src/kanata/windows/exthook.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use parking_lot::Mutex;
use std::convert::TryFrom;
use std::sync::mpsc::{sync_channel, Receiver, SyncSender as Sender, TryRecvError};
use std::sync::Arc;
use std::sync::mpsc::{Receiver, SyncSender as Sender, TryRecvError, sync_channel};
use std::time;

use super::PRESSED_KEYS;
Expand Down Expand Up @@ -44,7 +44,10 @@ impl Kanata {
}
try_send_panic(&preprocess_tx, key_event); // Send input_events to the preprocessing loop. Panic if channel somehow gets full or if channel disconnects. Typing input should never trigger a panic based on the channel getting full, assuming regular operation of the program and some other bug isn't the problem. I've tried to crash the program by pressing as many keys on my keyboard at the same time as I could, but was unable to.
#[cfg(feature = "perf_logging")]
debug!(" 🕐{}μs sent msg to tx→rx@start_processing_loop from event loop@KeyboardHook::set_input_cb",(start.elapsed()).as_micros());
debug!(
" 🕐{}μs sent msg to tx→rx@start_processing_loop from event loop@KeyboardHook::set_input_cb",
(start.elapsed()).as_micros()
);
true
});
Ok(())
Expand Down
12 changes: 8 additions & 4 deletions src/kanata/windows/interception.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::{anyhow, Result};
use anyhow::{Result, anyhow};
use kanata_interception as ic;
use parking_lot::Mutex;
use std::sync::mpsc::SyncSender as Sender;
use std::sync::Arc;
use std::sync::mpsc::SyncSender as Sender;

use super::PRESSED_KEYS;
use crate::kanata::*;
Expand Down Expand Up @@ -151,7 +151,9 @@ fn is_device_interceptable(
log::trace!("getting hardware id for input dev: {input_dev}");
let res = intrcptn.get_hardware_id(input_dev, &mut hwid);
let dev_is_interceptable = allowed.contains(&hwid);
log::info!("include check - res {res}; device #{input_dev} is intercepted: {dev_is_interceptable}; hwid {hwid:?} ");
log::info!(
"include check - res {res}; device #{input_dev} is intercepted: {dev_is_interceptable}; hwid {hwid:?} "
);
cache.insert(input_dev, dev_is_interceptable);
dev_is_interceptable
}
Expand All @@ -163,7 +165,9 @@ fn is_device_interceptable(
log::trace!("getting hardware id for input dev: {input_dev}");
let res = intrcptn.get_hardware_id(input_dev, &mut hwid);
let dev_is_interceptable = !excluded.contains(&hwid);
log::info!("exclude check - res {res}; device #{input_dev} is intercepted: {dev_is_interceptable}; hwid {hwid:?} ");
log::info!(
"exclude check - res {res}; device #{input_dev} is intercepted: {dev_is_interceptable}; hwid {hwid:?} "
);
cache.insert(input_dev, dev_is_interceptable);
dev_is_interceptable
}
Expand Down
Loading
Loading