Skip to content

Commit

Permalink
Allow to disabled notifications using --no-tray
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed Mar 9, 2023
1 parent 8d23ca6 commit 0531e9c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 32 deletions.
Empty file modified keymapper.conf
100755 → 100644
Empty file.
6 changes: 1 addition & 5 deletions src/client/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ 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;
}
Expand All @@ -54,9 +52,7 @@ void print_help_message() {
" -c, --config <path> 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
" --no-tray do not show tray icon/notifications.\n"
" --check check the config for errors.\n"
" -h, --help print this help.\n"
"\n"
Expand Down
14 changes: 8 additions & 6 deletions src/client/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,22 @@ namespace {
}
return std::filesystem::absolute(filename, error);
}
} // namespace

void show_notification(const char* message) {
auto ss = std::stringstream();
ss << "notify-send -a keymapper keymapper \"" << message << "\"";
std::system(ss.str().c_str());
}
void show_notification(const char* message) {
auto ss = std::stringstream();
ss << "notify-send -a keymapper keymapper \"" << message << "\"";
std::system(ss.str().c_str());
}
} // namespace

int main(int argc, char* argv[]) {
if (!interpret_commandline(g_settings, argc, argv)) {
print_help_message();
return 1;
}
g_verbose_output = g_settings.verbose;
if (!g_settings.no_tray_icon)
g_show_notification = &show_notification;

g_settings.config_file_path =
resolve_config_file_path(std::move(g_settings.config_file_path));
Expand Down
20 changes: 10 additions & 10 deletions src/client/windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,24 +338,24 @@ namespace {
}
return std::filesystem::absolute(filename, error);
}

void show_notification(const char* message_) {
auto& icon = g_tray_icon;
const auto message = utf8_to_wide(message_);
icon.uFlags = NIF_INFO;
lstrcpyW(icon.szInfo, message.c_str());
Shell_NotifyIconW(NIM_MODIFY, &icon);
}
} // 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;
lstrcpyW(icon.szInfo, message.c_str());
Shell_NotifyIconW(NIM_MODIFY, &icon);
}

int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, LPWSTR, int) {
if (!interpret_commandline(g_settings, __argc, __wargv)) {
print_help_message();
return 1;
}
g_verbose_output = g_settings.verbose;
if (!g_settings.no_tray_icon)
g_show_notification = &show_notification;

g_settings.config_file_path =
resolve_config_file_path(g_settings.config_file_path);
Expand Down
5 changes: 3 additions & 2 deletions src/common/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>

bool g_verbose_output = false;
void(*g_show_notification)(const char* message);

const auto about_header_str = std::string(
#if __has_include("_version.h")
Expand Down Expand Up @@ -54,8 +55,8 @@ namespace {
std::fputc('\n', stdout);
std::fflush(stdout);

if (notify)
show_notification(buffer.data());
if (notify && g_show_notification)
g_show_notification(buffer.data());
}
} // namespace

Expand Down
1 change: 1 addition & 0 deletions src/common/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern const char* about_footer;

extern bool g_verbose_output;
extern bool g_output_color;
extern void(*g_show_notification)(const char* message);

void message(const char* format, ...);
void error(const char* format, ...);
Expand Down
4 changes: 0 additions & 4 deletions src/server/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,6 @@ namespace {
}
} // namespace

void show_notification(const char* message) {
// don't show notifications
}

int main(int argc, char* argv[]) {
auto settings = Settings{ };

Expand Down
11 changes: 6 additions & 5 deletions src/server/windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,19 +486,20 @@ namespace {
}
return DefWindowProcW(window, message, wparam, lparam);
}
} // namespace

void show_notification(const char* message) {
MessageBoxA(nullptr, message, "Keymapper",
MB_ICONWARNING | MB_TOPMOST);
}
void show_notification(const char* message) {
MessageBoxA(nullptr, message, "Keymapper",
MB_ICONWARNING | MB_TOPMOST);
}
} // namespace

int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, LPWSTR, int) {
auto settings = Settings{ };
if (!interpret_commandline(settings, __argc, __wargv)) {
print_help_message();
return 1;
}
g_show_notification = &show_notification;

const auto single_instance = LimitSingleInstance(
"Global\\{E28F6E4E-A892-47ED-A6C2-DAC6AB8CCBFC}");
Expand Down

0 comments on commit 0531e9c

Please sign in to comment.