Add option to hide icon from Windows. Fix #95

This commit is contained in:
Federico Terzi 2020-04-15 17:24:40 +02:00
parent 4adedbae43
commit 88f0618b67
4 changed files with 18 additions and 6 deletions

View File

@ -39,6 +39,7 @@
const long refreshKeyboardLayoutInterval = 2000; const long refreshKeyboardLayoutInterval = 2000;
void * manager_instance; void * manager_instance;
int32_t show_icon;
// Keyboard listening // Keyboard listening
@ -298,14 +299,17 @@ LRESULT CALLBACK window_procedure(HWND window, unsigned int msg, WPARAM wp, LPAR
} }
default: default:
if (msg == WM_TASKBARCREATED) { // Explorer crashed, recreate the icon 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); 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; manager_instance = self;
show_icon = _show_icon;
// Load the images // Load the images
g_espanso_bmp = (HBITMAP)LoadImage(NULL, bmp_path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); 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"); StringCchCopy(nid.szTip, ARRAYSIZE(nid.szTip), L"espanso");
// Show the notification. // Show the notification.
Shell_NotifyIcon(NIM_ADD, &nid); if (show_icon) {
Shell_NotifyIcon(NIM_ADD, &nid);
}
} }
}else{ }else{
// Something went wrong, error. // Something went wrong, error.

View File

@ -33,7 +33,7 @@ extern void * manager_instance;
* Initialize the Windows parameters * Initialize the Windows parameters
* return: 1 if OK, -1 otherwise. * 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 LEFT_VARIANT 1
#define RIGHT_VARIANT 2 #define RIGHT_VARIANT 2

View File

@ -30,7 +30,7 @@ pub struct WindowsMenuItem {
#[link(name="winbridge", kind="static")] #[link(name="winbridge", kind="static")]
extern { extern {
pub fn start_daemon_process() -> i32; 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 // SYSTEM
pub fn get_active_window_name(buffer: *mut u16, size: i32) -> i32; pub fn get_active_window_name(buffer: *mut u16, size: i32) -> i32;

View File

@ -87,8 +87,14 @@ impl WindowsContext {
let ico_file_c = U16CString::from_str(ico_icon).unwrap(); let ico_file_c = U16CString::from_str(ico_icon).unwrap();
let bmp_file_c = U16CString::from_str(bmp_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 // 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 { if res != 1 {
panic!("Can't initialize Windows context") panic!("Can't initialize Windows context")
} }