From 88f0618b6777219dea18a36df2810f4e06256f80 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Wed, 15 Apr 2020 17:24:40 +0200 Subject: [PATCH] Add option to hide icon from Windows. Fix #95 --- native/libwinbridge/bridge.cpp | 12 +++++++++--- native/libwinbridge/bridge.h | 2 +- src/bridge/windows.rs | 2 +- src/context/windows.rs | 8 +++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/native/libwinbridge/bridge.cpp b/native/libwinbridge/bridge.cpp index dfb6d42..7011d4b 100644 --- a/native/libwinbridge/bridge.cpp +++ b/native/libwinbridge/bridge.cpp @@ -39,6 +39,7 @@ const long refreshKeyboardLayoutInterval = 2000; void * manager_instance; +int32_t show_icon; // Keyboard listening @@ -298,14 +299,17 @@ LRESULT CALLBACK window_procedure(HWND window, unsigned int msg, WPARAM wp, LPAR } default: if (msg == WM_TASKBARCREATED) { // Explorer crashed, recreate the icon - Shell_NotifyIcon(NIM_ADD, &nid); + if (show_icon) { + Shell_NotifyIcon(NIM_ADD, &nid); + } } return DefWindowProc(window, msg, wp, lp); } } -int32_t initialize(void * self, wchar_t * ico_path, wchar_t * bmp_path) { +int32_t initialize(void * self, wchar_t * ico_path, wchar_t * bmp_path, int32_t _show_icon) { manager_instance = self; + show_icon = _show_icon; // Load the images g_espanso_bmp = (HBITMAP)LoadImage(NULL, bmp_path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); @@ -440,7 +444,9 @@ int32_t initialize(void * self, wchar_t * ico_path, wchar_t * bmp_path) { StringCchCopy(nid.szTip, ARRAYSIZE(nid.szTip), L"espanso"); // Show the notification. - Shell_NotifyIcon(NIM_ADD, &nid); + if (show_icon) { + Shell_NotifyIcon(NIM_ADD, &nid); + } } }else{ // Something went wrong, error. diff --git a/native/libwinbridge/bridge.h b/native/libwinbridge/bridge.h index 304f10b..bd07a78 100644 --- a/native/libwinbridge/bridge.h +++ b/native/libwinbridge/bridge.h @@ -33,7 +33,7 @@ extern void * manager_instance; * Initialize the Windows parameters * return: 1 if OK, -1 otherwise. */ -extern "C" int32_t initialize(void * self, wchar_t * ico_path, wchar_t * bmp_path); +extern "C" int32_t initialize(void * self, wchar_t * ico_path, wchar_t * bmp_path, int32_t show_icon); #define LEFT_VARIANT 1 #define RIGHT_VARIANT 2 diff --git a/src/bridge/windows.rs b/src/bridge/windows.rs index f337638..0513fd4 100644 --- a/src/bridge/windows.rs +++ b/src/bridge/windows.rs @@ -30,7 +30,7 @@ pub struct WindowsMenuItem { #[link(name="winbridge", kind="static")] extern { pub fn start_daemon_process() -> i32; - pub fn initialize(s: *const c_void, ico_path: *const u16, bmp_path: *const u16) -> i32; + pub fn initialize(s: *const c_void, ico_path: *const u16, bmp_path: *const u16, show_icon: i32) -> i32; // SYSTEM pub fn get_active_window_name(buffer: *mut u16, size: i32) -> i32; diff --git a/src/context/windows.rs b/src/context/windows.rs index 0640d65..77c9be4 100644 --- a/src/context/windows.rs +++ b/src/context/windows.rs @@ -87,8 +87,14 @@ impl WindowsContext { let ico_file_c = U16CString::from_str(ico_icon).unwrap(); let bmp_file_c = U16CString::from_str(bmp_icon).unwrap(); + let show_icon = if config.show_icon { + 1 + }else{ + 0 + }; + // Initialize the windows - let res = initialize(context_ptr, ico_file_c.as_ptr(), bmp_file_c.as_ptr()); + let res = initialize(context_ptr, ico_file_c.as_ptr(), bmp_file_c.as_ptr(), show_icon); if res != 1 { panic!("Can't initialize Windows context") }