From f69e573c4dd9e45dbaa7f8124e5ba6f4b0103866 Mon Sep 17 00:00:00 2001 From: trigg Date: Tue, 18 Jun 2024 02:00:00 +0100 Subject: [PATCH] - Optionally include appindicator - Alternative codepath for appindicator where possible --- CMakeLists.txt | 10 ++++++++++ src/abaddon.cpp | 32 ++++++++++++++++++++++++-------- src/abaddon.hpp | 18 +++++++++++++++--- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 526c8c10..dd0e91b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,16 @@ if (Fontconfig_FOUND) target_link_libraries(abaddon Fontconfig::Fontconfig) endif () +pkg_check_modules(APPINDICATOR QUIET appindicator3-0.1) +if (APPINDICATOR_FOUND) + message("AppIndicator was found") + target_compile_definitions(abaddon PRIVATE WITH_APPINDICATOR) + target_include_directories(abaddon PUBLIC ${APPINDICATOR_INCLUDE_DIRS}) + target_link_libraries(abaddon ${APPINDICATOR_LIBRARIES}) +else () + message("AppIndicator not found. Falling back to GTK StatusIcon") +endif () + find_package(spdlog REQUIRED) target_link_libraries(abaddon spdlog::spdlog) diff --git a/src/abaddon.cpp b/src/abaddon.cpp index 7f4281d6..d81d6f84 100644 --- a/src/abaddon.cpp +++ b/src/abaddon.cpp @@ -25,6 +25,10 @@ #include "remoteauth/remoteauthdialog.hpp" #include "util.hpp" +#ifdef WITH_APPINDICATOR +#include +#endif + #if defined(__APPLE__) #include @@ -323,19 +327,29 @@ int Abaddon::StartGTK() { ActionReloadCSS(); AttachCSSMonitor(); - if (m_settings.GetSettings().HideToTray) { - m_tray = Gtk::StatusIcon::create("discord"); - m_tray->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_tray_click)); - m_tray->signal_popup_menu().connect(sigc::mem_fun(*this, &Abaddon::on_tray_popup_menu)); - } m_tray_menu = Gtk::make_managed(); + m_tray_show = Gtk::make_managed("Show", false); m_tray_exit = Gtk::make_managed("Quit", false); - m_tray_exit->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_tray_menu_click)); + m_tray_show->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_tray_show)); + m_tray_exit->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_tray_exit)); + m_tray_menu->append(*m_tray_show); m_tray_menu->append(*m_tray_exit); m_tray_menu->show_all(); + if (m_settings.GetSettings().HideToTray) { + #ifdef WITH_APPINDICATOR + m_tray = app_indicator_new("abaddon", "discord", APP_INDICATOR_CATEGORY_APPLICATION_STATUS); + app_indicator_set_status(m_tray, APP_INDICATOR_STATUS_ACTIVE); + app_indicator_set_menu(m_tray, GTK_MENU(m_tray_menu->gobj())); + #else + m_tray = Gtk::StatusIcon::create("discord"); + m_tray->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_tray_show)); + m_tray->signal_popup_menu().connect(sigc::mem_fun(*this, &Abaddon::on_tray_popup_menu)); + #endif + } + m_main_window->signal_hide().connect(sigc::mem_fun(*this, &Abaddon::on_window_hide)); m_gtk_app->signal_shutdown().connect(sigc::mem_fun(*this, &Abaddon::OnShutdown), false); @@ -1135,17 +1149,19 @@ AudioManager &Abaddon::GetAudio() { } #endif -void Abaddon::on_tray_click() { +void Abaddon::on_tray_show() { m_main_window->set_visible(!m_main_window->is_visible()); } -void Abaddon::on_tray_menu_click() { +void Abaddon::on_tray_exit() { m_gtk_app->quit(); } +#ifndef WITH_APPINDICATOR void Abaddon::on_tray_popup_menu(int button, int activate_time) { m_tray->popup_menu_at_position(*m_tray_menu, button, activate_time); } +#endif void Abaddon::on_window_hide() { if (!m_settings.GetSettings().HideToTray) { diff --git a/src/abaddon.hpp b/src/abaddon.hpp index 6093523f..91f12d66 100644 --- a/src/abaddon.hpp +++ b/src/abaddon.hpp @@ -14,6 +14,10 @@ #include "notifications/notifications.hpp" #include "audio/manager.hpp" +#ifdef WITH_APPINDICATOR +#include +#endif + #define APP_TITLE "Abaddon" class AudioManager; @@ -149,6 +153,7 @@ class Abaddon { Gtk::Menu *m_user_menu_roles_submenu; Gtk::Menu *m_tray_menu; Gtk::MenuItem *m_tray_exit; + Gtk::MenuItem *m_tray_show; void on_user_menu_insert_mention(); void on_user_menu_ban(); @@ -156,10 +161,13 @@ class Abaddon { void on_user_menu_copy_id(); void on_user_menu_open_dm(); void on_user_menu_remove_recipient(); - void on_tray_click(); - void on_tray_popup_menu(int button, int activate_time); - void on_tray_menu_click(); + void on_tray_show(); + void on_tray_exit(); void on_window_hide(); +#ifndef WITH_APPINDICATOR + void on_tray_popup_menu(int button, int activate_time); +#endif + private: SettingsManager m_settings; @@ -182,7 +190,11 @@ class Abaddon { mutable std::mutex m_mutex; Glib::RefPtr m_gtk_app; Glib::RefPtr m_css_provider; +#ifdef WITH_APPINDICATOR + AppIndicator* m_tray; +#else Glib::RefPtr m_tray; +#endif std::unique_ptr m_main_window; // wah wah cant create a gtkstylecontext fuck you Notifications m_notifications;