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

Show layer icon near mouse pointer (win-tray) #1031

Merged
merged 81 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
d0f06fd
move log to mod
eugenesvk May 8, 2024
ac89d5a
gui: update imports
eugenesvk May 12, 2024
7a0b49b
dep: add timer
eugenesvk May 12, 2024
824e705
gui: add imports
eugenesvk May 12, 2024
86b8dcc
gui: show tooltip on layer icon switches
eugenesvk May 12, 2024
3e0d008
rename to icon_act_p to clearly indicate it's not an icon
eugenesvk May 12, 2024
5572e56
doc: update
eugenesvk May 12, 2024
b29c744
gui: dupe main icon as an image
eugenesvk May 11, 2024
a4a50fc
gui: update size
eugenesvk May 12, 2024
96d3dda
gui: add new tooltip info window
eugenesvk May 12, 2024
6fee36c
fix a typo
eugenesvk May 12, 2024
9bd8437
gui: refactor set_menu_item_cfg_icon
eugenesvk May 12, 2024
03f3550
gui: refactor: use a single hashmap for all icon types
eugenesvk May 12, 2024
22d2b6c
gui: position tooltip near mouse pointer
eugenesvk May 12, 2024
20c493c
win-tray: manually fix dpi for tooltip window size
eugenesvk May 12, 2024
5f9b047
win-tray: add IS_TT conditional flag for tooltip activation
eugenesvk May 12, 2024
b488f63
gui: don't show tooltip when no layer icons exist
eugenesvk May 12, 2024
2e006db
gui: fix comment
eugenesvk May 12, 2024
862226c
gui: add IS_TT_BLANK config
eugenesvk May 12, 2024
8391471
gui: make dpi static
eugenesvk May 12, 2024
74ff71d
gui: add support for parsing config tooltip values
eugenesvk May 12, 2024
c1d5d70
gui: replace tooltip constants with values from user config
eugenesvk May 12, 2024
22d679f
gui: hide tooltip on empty icons when tooltip_show_blank is off
eugenesvk May 12, 2024
ec6536c
gui: refactor build_win_tt to Impl to have access to app data
eugenesvk May 12, 2024
7ca9417
gui: refactor update_app_data into as separate function
eugenesvk May 12, 2024
b5f78b7
gui: fix a typo
eugenesvk May 12, 2024
5a57763
gui: update all of app data on config reload
eugenesvk May 12, 2024
66e11ee
gui: move timer offset to a var TTTIMER_L
eugenesvk May 12, 2024
37968c1
gui: update log
eugenesvk May 12, 2024
a10f9e3
gui: add update_tooltip_data to track tooltip size changes on config …
eugenesvk May 12, 2024
8eb52a3
gui: add release builds
eugenesvk May 12, 2024
596f2fa
gui: disable tooltips by default
eugenesvk May 12, 2024
f3da43a
doc: update tooltip layer icon config
eugenesvk May 12, 2024
fb52cec
doc: update example config to have tooltip icons
eugenesvk May 12, 2024
623ef5b
doc: fix position
eugenesvk May 12, 2024
d2e6fba
cargo fmt
eugenesvk May 12, 2024
7c0a6bf
gui: fix duration change check
eugenesvk May 12, 2024
79cd2b3
dep: add win API deps
eugenesvk May 12, 2024
c709d78
gui: add win_ver macro
eugenesvk May 12, 2024
9262608
gui: fix tooltip positioning to avoid taskbar/screen borders
eugenesvk May 12, 2024
6f885e9
cargo fmt and clippy
eugenesvk May 12, 2024
8ba6957
dep: update gui deps
eugenesvk May 13, 2024
1da4cd7
gui: remove dpi macro
eugenesvk May 13, 2024
e23d0ea
dep: add a function to get mouse pointer size adjusted by dpi
eugenesvk May 13, 2024
7f098f0
gui: replace hardcoded mouse pointer size with actual
eugenesvk May 13, 2024
0660621
cargo fmt
eugenesvk May 13, 2024
f88795c
gui: fix icon tooltip hidden behind new windows
eugenesvk May 13, 2024
17e238f
gui: make 0 tooltip timer to never hide
eugenesvk May 15, 2024
e597eb9
doc: update
eugenesvk May 14, 2024
eb4648a
gui: add tooltip_no_base option to ignore tooltip for the base layer
eugenesvk May 15, 2024
243eecb
doc: update tooltip_no_base
eugenesvk May 14, 2024
d3930e6
gui: add tooltip_no_base to the parser
eugenesvk May 15, 2024
df975bb
gui: add a separate notice for config reloads
eugenesvk May 15, 2024
61937bb
gui: update reload layer function to accept cfg reload notices
eugenesvk May 15, 2024
4113ca4
cargo fmt
eugenesvk May 15, 2024
7322126
test: add tooltip config
eugenesvk May 15, 2024
935268d
feat(gui): let layer icon tooltip follow the mouse
eugenesvk May 16, 2024
0fa1e5b
dep: add gui leak plugging requirements
eugenesvk May 16, 2024
63cf6c5
dep: add nwg licenes
eugenesvk May 16, 2024
c01329b
prevent GDI DC resource leak in NWG on getting dpi
eugenesvk May 16, 2024
52ae933
gui: update debug message
eugenesvk May 16, 2024
e1ae5b5
gui: remove unneeded return
eugenesvk May 16, 2024
25b2292
gui: don't update if mouse doesn't move
eugenesvk May 16, 2024
5b60b35
dep: update lock
eugenesvk May 16, 2024
11019ca
cargo fmt
eugenesvk May 16, 2024
26903b9
gui: decrease tooltip polling rate
eugenesvk May 16, 2024
82ec82b
gui: add reload notification options to config
eugenesvk May 17, 2024
097a918
gui: add support for showing notifications on config reloads
eugenesvk May 17, 2024
5a46b2c
cargo fmt
eugenesvk May 17, 2024
3fe4015
doc: update new options
eugenesvk May 17, 2024
fc4c8b4
test: add new config options
eugenesvk May 17, 2024
329303e
refactor(gui): move unsafe to an inner function block
eugenesvk May 19, 2024
8c914cf
refactor(gui): move GUI options to a separate struct
eugenesvk May 19, 2024
0234f49
refactor(gui): use a separate GUI options struct
eugenesvk May 19, 2024
e85073b
add unsafe clippy exemption
eugenesvk May 19, 2024
91c030b
Add safety comment
eugenesvk May 20, 2024
088f489
Remove debug comment
eugenesvk May 20, 2024
a721142
clippy: add unsafe blocks
eugenesvk May 20, 2024
45cb2f7
remove unneded mutex
eugenesvk May 20, 2024
908bc6b
decrease log verbosity
eugenesvk May 20, 2024
3f9ffdb
cargo fmt
eugenesvk May 20, 2024
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
9 changes: 8 additions & 1 deletion Cargo.lock

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

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,19 @@ windows-sys = { version = "0.52.0", features = [
"Win32_System_Threading",
"Win32_UI_Controls",
"Win32_UI_Shell",
"Win32_UI_HiDpi",
"Win32_UI_WindowsAndMessaging",
"Win32_System_SystemInformation",
"Wdk",
"Wdk_System",
"Wdk_System_SystemServices",
], optional=true }
win_dbg_logger = { path = "win_dbg_logger", optional = true }
native-windows-gui = { version = "1.0.13", default_features = false}
native-windows-derive = { version = "1.0.5", default_features = false, optional = true }
regex = { version = "1.10.4", optional = true }
kanata-interception = { version = "0.2.0", optional = true }
muldiv = { version = "1.0.1", optional = true }

[target.'cfg(target_os = "windows")'.build-dependencies]
embed-resource = { version = "2.4.2", optional = true }
Expand All @@ -120,7 +126,7 @@ simulated_output = ["indoc"]
simulated_input = ["indoc"]
passthru_ahk = ["simulated_input","simulated_output"]
wasm = [ "instant/wasm-bindgen" ]
gui = ["win_manifest","native-windows-derive","win_dbg_logger","win_dbg_logger/simple_shared","kanata-parser/gui","native-windows-gui/tray-notification","native-windows-gui/message-window","native-windows-gui/menu","native-windows-gui/cursor","native-windows-gui/high-dpi","native-windows-gui/embed-resource","native-windows-gui/image-decoder","native-windows-gui/notice","dep:windows-sys","win_sendinput_send_scancodes","win_llhook_read_scancodes"]
gui = ["win_manifest","native-windows-derive","win_dbg_logger","win_dbg_logger/simple_shared","kanata-parser/gui","native-windows-gui/tray-notification","native-windows-gui/message-window","native-windows-gui/menu","native-windows-gui/cursor","native-windows-gui/high-dpi","native-windows-gui/embed-resource","native-windows-gui/image-decoder","native-windows-gui/notice","native-windows-gui/animation-timer","muldiv","dep:windows-sys","win_sendinput_send_scancodes","win_llhook_read_scancodes"]

[profile.release]
opt-level = "z"
Expand Down
4 changes: 4 additions & 0 deletions cfg_samples/tray-icon/tray-icon.kbd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
log-layer-changes yes ;;|no| overhead
tray-icon "./_custom-icons/s.png" ;; should activate for layers without icons like '5no-icn'
icon-match-layer-name yes ;;|yes| match layer name to icon files even without an explicit (icon name.ico) config
tooltip-layer-changes yes ;;|false|
tooltip-show-blank yes ;;|no|
tooltip-duration 500 ;;|500|
tooltip-size 24,24 ;;|24 24|
)
(defalias l1 (layer-while-held 1emoji))
(defalias l2 (layer-while-held 2icon-quote))
Expand Down
42 changes: 42 additions & 0 deletions docs/config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2501,6 +2501,48 @@ Show a custom tray icon that matches the name of the active layer if it doesn't
Otherwise <<tray-icon>> will be used. Defaults to true. File search rules are the same as in <<tray-icon>>.
See https://github.com/jtroo/kanata/blob/main/cfg_samples/tray-icon/tray-icon.kbd[example config] for more details.

[[windows-only-tooltip-layer-changes]]
=== Windows only: tooltip-layer-changes
<<table-of-contents,Back to ToC>>

Show a custom layer icon near the mouse pointer position. Defaults to false. Requires <<windows-only-win-tray>> gui-enabled build.

[[windows-only-tooltip-show-blank]]
=== Windows only: tooltip-show-blank
<<table-of-contents,Back to ToC>>

Show a blank square when instead of an icon if a layer isn't configured to have one. Defaults to false. Requires <<windows-only-win-tray>> gui-enabled build.

[[windows-only-tooltip-no-base]]
=== Windows only: tooltip-no-base
<<table-of-contents,Back to ToC>>

Don't show a tooltip layer icon for the base layer (1st deflayer). Defaults to true. Requires <<windows-only-win-tray>> gui-enabled build.

[[windows-only-tooltip-duration]]
=== Windows only: tooltip-duration
<<table-of-contents,Back to ToC>>

Set duration (in ms) for showing a custom layer icon near the mouse pointer position. 0 to never hide. Defaults to 500. Requires <<windows-only-win-tray>> gui-enabled build.

[[windows-only-tooltip-size]]
=== Windows only: tooltip-size
<<table-of-contents,Back to ToC>>

Set the size (comma-separated Width,Height without spaces) for a custom layer icon near the mouse pointer position. Defaults to 24,24. Requires <<windows-only-win-tray>> gui-enabled build.

[[windows-only-notify-cfg-reload]]
=== Windows only: notify-cfg-reload
<<table-of-contents,Back to ToC>>

Show system notification message on config reload. Defaults to true. Requires <<windows-only-win-tray>> gui-enabled build.

[[windows-only-notify-cfg-reload-silent]]
=== Windows only: notify-cfg-reload-silent
<<table-of-contents,Back to ToC>>

Disable sound for the system notification message on config reload. Defaults to false. Requires <<windows-only-win-tray>> gui-enabled build.

[[using-multiple-defcfg-options]]
=== Using multiple defcfg options
<<table-of-contents,Back to ToC>>
Expand Down
2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ build_release_windows output_dir:
cargo build --release --features win_manifest,cmd; cp target/release/kanata.exe "{{output_dir}}\kanata_cmd_allowed.exe"
cargo build --release --features win_manifest,cmd,interception_driver; cp target/release/kanata.exe "{{output_dir}}\kanata_wintercept_cmd_allowed.exe"
cargo build --release --features passthru_ahk --package=simulated_passthru; cp target/release/kanata_passthru.dll "{{output_dir}}\kanata_passthru.dll"
cargo build --release --features win_manifest,gui ; cp target/release/kanata.exe "{{output_dir}}\kanata_gui.exe"
cargo build --release --features win_manifest,gui,cmd; cp target/release/kanata.exe "{{output_dir}}\kanata_gui_cmd_allowed.exe"
cp cfg_samples/kanata.kbd "{{output_dir}}"

# Generate the sha256sums for all files in the output directory
Expand Down
138 changes: 130 additions & 8 deletions parser/src/cfg/defcfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,53 @@ use crate::custom_action::*;
#[allow(unused)]
use crate::{anyhow_expr, anyhow_span, bail, bail_expr, bail_span};

#[cfg(all(any(target_os = "windows", target_os = "unknown"), feature = "gui"))]
#[derive(Debug, Clone)]
pub struct CfgOptionsGui {
/// File name / path to the tray icon file.
pub tray_icon: Option<String>,
#[cfg(all(target_os = "windows", feature = "gui"))]
/// Whether to match layer names to icon files without an explicit 'icon' field
pub icon_match_layer_name: bool,
/// Show tooltip on layer changes showing layer icons
#[cfg(all(target_os = "windows", feature = "gui"))]
pub tooltip_layer_changes: bool,
/// Show tooltip on layer changes for the default/base layer
#[cfg(all(target_os = "windows", feature = "gui"))]
pub tooltip_no_base: bool,
/// Show tooltip on layer changes even for layers without an icon
#[cfg(all(target_os = "windows", feature = "gui"))]
pub tooltip_show_blank: bool,
/// Show tooltip on layer changes for this duration (ms)
#[cfg(all(target_os = "windows", feature = "gui"))]
pub tooltip_duration: u16,
/// Show system notification message on config reload
#[cfg(all(target_os = "windows", feature = "gui"))]
pub notify_cfg_reload: bool,
/// Disable sound for the system notification message on config reload
#[cfg(all(target_os = "windows", feature = "gui"))]
pub notify_cfg_reload_silent: bool,
/// Set tooltip size (width, height)
#[cfg(all(target_os = "windows", feature = "gui"))]
pub tooltip_size: (u16, u16),
}
#[cfg(all(any(target_os = "windows", target_os = "unknown"), feature = "gui"))]
impl Default for CfgOptionsGui {
fn default() -> Self {
Self {
tray_icon: None,
icon_match_layer_name: true,
tooltip_layer_changes: false,
tooltip_show_blank: false,
tooltip_no_base: true,
tooltip_duration: 500,
notify_cfg_reload: true,
notify_cfg_reload_silent: false,
tooltip_size: (24, 24),
}
}
}

#[derive(Debug)]
pub struct CfgOptions {
pub process_unmapped_keys: bool,
Expand Down Expand Up @@ -56,9 +103,7 @@ pub struct CfgOptions {
#[cfg(any(target_os = "macos", target_os = "unknown"))]
pub macos_dev_names_include: Option<Vec<String>>,
#[cfg(all(any(target_os = "windows", target_os = "unknown"), feature = "gui"))]
pub tray_icon: Option<String>,
#[cfg(all(any(target_os = "windows", target_os = "unknown"), feature = "gui"))]
pub icon_match_layer_name: bool,
pub gui_opts: CfgOptionsGui,
}

impl Default for CfgOptions {
Expand Down Expand Up @@ -114,9 +159,7 @@ impl Default for CfgOptions {
#[cfg(any(target_os = "macos", target_os = "unknown"))]
macos_dev_names_include: None,
#[cfg(all(any(target_os = "windows",target_os = "unknown"), feature = "gui"))]
tray_icon: None,
#[cfg(all(any(target_os = "windows",target_os = "unknown"), feature = "gui"))]
icon_match_layer_name: true,
gui_opts: Default::default(),
}
}
}
Expand Down Expand Up @@ -417,7 +460,7 @@ pub fn parse_defcfg(expr: &[SExpr]) -> Result<CfgOptions> {
if icon_path.is_empty() {
log::warn!("tray-icon is empty");
}
cfg.tray_icon = Some(icon_path.to_string());
cfg.gui_opts.tray_icon = Some(icon_path.to_string());
}
}
"icon-match-layer-name" => {
Expand All @@ -426,7 +469,86 @@ pub fn parse_defcfg(expr: &[SExpr]) -> Result<CfgOptions> {
feature = "gui"
))]
{
cfg.icon_match_layer_name = parse_defcfg_val_bool(val, label)?
cfg.gui_opts.icon_match_layer_name = parse_defcfg_val_bool(val, label)?
}
}
"tooltip-layer-changes" => {
#[cfg(all(
any(target_os = "windows", target_os = "unknown"),
feature = "gui"
))]
{
cfg.gui_opts.tooltip_layer_changes = parse_defcfg_val_bool(val, label)?
}
}
"tooltip-show-blank" => {
#[cfg(all(
any(target_os = "windows", target_os = "unknown"),
feature = "gui"
))]
{
cfg.gui_opts.tooltip_show_blank = parse_defcfg_val_bool(val, label)?
}
}
"tooltip-no-base" => {
#[cfg(all(
any(target_os = "windows", target_os = "unknown"),
feature = "gui"
))]
{
cfg.gui_opts.tooltip_no_base = parse_defcfg_val_bool(val, label)?
}
}
"tooltip-duration" => {
#[cfg(all(
any(target_os = "windows", target_os = "unknown"),
feature = "gui"
))]
{
cfg.gui_opts.tooltip_duration = parse_cfg_val_u16(val, label, false)?
}
}
"notify-cfg-reload" => {
#[cfg(all(
any(target_os = "windows", target_os = "unknown"),
feature = "gui"
))]
{
cfg.gui_opts.notify_cfg_reload = parse_defcfg_val_bool(val, label)?
}
}
"notify-cfg-reload-silent" => {
#[cfg(all(
any(target_os = "windows", target_os = "unknown"),
feature = "gui"
))]
{
cfg.gui_opts.notify_cfg_reload_silent =
parse_defcfg_val_bool(val, label)?
}
}
"tooltip-size" => {
#[cfg(all(
any(target_os = "windows", target_os = "unknown"),
feature = "gui"
))]
{
let v = sexpr_to_str_or_err(val, label)?;
let tooltip_size = v.split(',').collect::<Vec<_>>();
const ERRMSG: &str = "Invalid value for tooltip-size.\nExpected two numbers 0-65535 separated by a comma, e.g. 24,24";
if tooltip_size.len() != 2 {
bail_expr!(val, "{}", ERRMSG)
}
cfg.gui_opts.tooltip_size = (
match str::parse::<u16>(tooltip_size[0]) {
Ok(w) => w,
Err(_) => bail_expr!(val, "{}", ERRMSG),
},
match str::parse::<u16>(tooltip_size[1]) {
Ok(h) => h,
Err(_) => bail_expr!(val, "{}", ERRMSG),
},
);
}
}

Expand Down
19 changes: 19 additions & 0 deletions parser/src/cfg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,13 @@ fn parse_all_defcfg() {
linux-x11-repeat-delay-rate 400,50
tray-icon symbols.ico
icon-match-layer-name no
tooltip-layer-changes yes
tooltip-show-blank yes
tooltip-no-base yes
tooltip-duration 300
tooltip-size 24,24
notify-cfg-reload yes
notify-cfg-reload-silent no
windows-altgr add-lctl-release
windows-interception-mouse-hwid "70, 0, 60, 0"
windows-interception-mouse-hwids ("0, 0, 0" "1, 1, 1")
Expand Down Expand Up @@ -1890,3 +1897,15 @@ fn layer_name_allows_var() {
.map_err(|e| eprintln!("{:?}", miette::Error::from(e)))
.expect("parse succeeds");
}

#[test]
fn disallow_whitespace_in_tooltip_size() {
let source = "
(defcfg
tooltip-size 24 24 ;; should be 24,24
)
(defsrc 1)
(deflayer test 1)
";
parse_cfg(source).map(|_| ()).expect_err("fails");
}
1 change: 1 addition & 0 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ use parking_lot::Mutex;
use std::sync::{Arc, OnceLock};
pub static CFG: OnceLock<Arc<Mutex<Kanata>>> = OnceLock::new();
pub static GUI_TX: OnceLock<native_windows_gui::NoticeSender> = OnceLock::new();
pub static GUI_CFG_TX: OnceLock<native_windows_gui::NoticeSender> = OnceLock::new();
Loading
Loading