diff --git a/src/client/Settings.cpp b/src/client/Settings.cpp index 8a388e8..131c97a 100644 --- a/src/client/Settings.cpp +++ b/src/client/Settings.cpp @@ -34,6 +34,11 @@ bool interpret_commandline(Settings& settings, int argc, char* argv[]) { else if (argument == T("--check")) { settings.check_config = true; } +#if defined(_WIN32) + else if (argument == T("--no-tray")) { + settings.no_tray_icon = true; + } +#endif else { return false; } @@ -57,6 +62,9 @@ void print_help_message() { " -c, --config configuration file.\n" " -u, --update reload configuration file when it changes.\n" " -v, --verbose enable verbose output.\n" +#if defined(_WIN32) + " --no-tray do not show tray icon.\n" +#endif " --check check the config for errors.\n" " -h, --help print this help.\n" "\n" diff --git a/src/client/Settings.h b/src/client/Settings.h index ce08054..54e2ded 100644 --- a/src/client/Settings.h +++ b/src/client/Settings.h @@ -9,6 +9,7 @@ struct Settings { bool auto_update_config; bool verbose; bool check_config; + bool no_tray_icon; }; #if defined(_WIN32) diff --git a/src/client/windows/main.cpp b/src/client/windows/main.cpp index 3289bcf..7ece8d9 100644 --- a/src/client/windows/main.cpp +++ b/src/client/windows/main.cpp @@ -319,6 +319,8 @@ namespace { } // namespace void show_notification(const char* message_) { + if (g_settings.no_tray_icon) + return; auto& icon = g_tray_icon; const auto message = utf8_to_wide(message_); icon.uFlags = NIF_INFO; @@ -366,16 +368,20 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, LPWSTR, int) { if (!connect()) return 1; - auto& icon = g_tray_icon; - icon.cbSize = sizeof(icon); - icon.hWnd = g_window; - icon.uID = static_cast( - reinterpret_cast(g_window)); - icon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; - lstrcpyW(icon.szTip, window_class_name); - icon.uCallbackMessage = WM_APP_TRAY_NOTIFY; - icon.hIcon = LoadIconW(instance, L"IDI_ICON1"); - Shell_NotifyIconW(NIM_ADD, &icon); + if (!g_settings.no_tray_icon) { + auto& icon = g_tray_icon; + icon.cbSize = sizeof(icon); + icon.hWnd = g_window; + icon.uID = static_cast( + reinterpret_cast(g_window)); + icon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; + lstrcpyW(icon.szTip, window_class_name); + icon.uCallbackMessage = WM_APP_TRAY_NOTIFY; + icon.hIcon = LoadIconW(instance, L"IDI_ICON1"); + Shell_NotifyIconW(NIM_ADD, &icon); + + SetTimer(g_window, TIMER_CREATE_TRAY_ICON, recreate_tray_icon_interval_ms, NULL); + } verbose("Loading configuration file '%ws'", g_settings.config_file_path.c_str()); g_config_file.load(g_settings.config_file_path); @@ -390,7 +396,6 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, LPWSTR, int) { if (g_settings.auto_update_config) SetTimer(g_window, TIMER_UPDATE_CONFIG, update_config_interval_ms, NULL); SetTimer(g_window, TIMER_UPDATE_CONTEXT, update_context_inverval_ms, NULL); - SetTimer(g_window, TIMER_CREATE_TRAY_ICON, recreate_tray_icon_interval_ms, NULL); verbose("Entering update loop"); auto message = MSG{ }; @@ -400,7 +405,8 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, LPWSTR, int) { } verbose("Exiting"); - Shell_NotifyIconW(NIM_DELETE, &g_tray_icon); + if (!g_settings.no_tray_icon) + Shell_NotifyIconW(NIM_DELETE, &g_tray_icon); return 0; }