Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally use AppIndicator for system tray #315

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
32 changes: 24 additions & 8 deletions src/abaddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "remoteauth/remoteauthdialog.hpp"
#include "util.hpp"

#ifdef WITH_APPINDICATOR
#include <libappindicator/app-indicator.h>
#endif

#if defined(__APPLE__)
#include <CoreFoundation/CoreFoundation.h>

Expand Down Expand Up @@ -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<Gtk::Menu>();
m_tray_show = Gtk::make_managed<Gtk::MenuItem>("Show", false);
m_tray_exit = Gtk::make_managed<Gtk::MenuItem>("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);

Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 15 additions & 3 deletions src/abaddon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "notifications/notifications.hpp"
#include "audio/manager.hpp"

#ifdef WITH_APPINDICATOR
#include <libappindicator/app-indicator.h>
#endif

#define APP_TITLE "Abaddon"

class AudioManager;
Expand Down Expand Up @@ -149,17 +153,21 @@ 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();
void on_user_menu_kick();
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;
Expand All @@ -182,7 +190,11 @@ class Abaddon {
mutable std::mutex m_mutex;
Glib::RefPtr<Gtk::Application> m_gtk_app;
Glib::RefPtr<Gtk::CssProvider> m_css_provider;
#ifdef WITH_APPINDICATOR
AppIndicator* m_tray;
#else
Glib::RefPtr<Gtk::StatusIcon> m_tray;
#endif
std::unique_ptr<MainWindow> m_main_window; // wah wah cant create a gtkstylecontext fuck you

Notifications m_notifications;
Expand Down
Loading