Skip to content

Commit

Permalink
ui: Use AppIndicator with Cinnamon 2.8 (fixes #487)
Browse files Browse the repository at this point in the history
  • Loading branch information
trollixx committed Feb 19, 2016
1 parent fe008a2 commit a96c79b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent) :

setWindowIcon(QIcon::fromTheme(QStringLiteral("zeal"), QIcon(QStringLiteral(":/zeal.ico"))));

#ifdef USE_APPINDICATOR
detectAppIndicatorSupport();
#endif

if (m_settings->showSystrayIcon)
createTrayIcon();

Expand Down Expand Up @@ -678,6 +682,26 @@ QAction *MainWindow::addHistoryAction(QWebHistory *history, const QWebHistoryIte
return backAction;
}

#ifdef USE_APPINDICATOR
void MainWindow::detectAppIndicatorSupport()
{
const QByteArray xdgDesktop = qgetenv("XDG_CURRENT_DESKTOP");

// Unity
if (xdgDesktop == "Unity") {
m_useAppIndicator = true;
return;
}

// Cinnamon 2.8
// Checking specifically for 2.8 because direct AppIndicator support will be dropped soon.
if (xdgDesktop == "X-Cinnamon" && qgetenv("CINNAMON_VERSION").startsWith("2.8")) {
m_useAppIndicator = true;
return;
}
}
#endif

#ifdef USE_APPINDICATOR
void appIndicatorToggleWindow(GtkMenu *menu, gpointer data)
{
Expand All @@ -697,10 +721,7 @@ void MainWindow::createTrayIcon()
#endif

#ifdef USE_APPINDICATOR
const QString desktop = qgetenv("XDG_CURRENT_DESKTOP");
const bool isUnity = (desktop.toLower() == QLatin1String("unity"));

if (isUnity) { // Application Indicators for Unity
if (m_useAppIndicator) {
m_appIndicatorMenu = gtk_menu_new();

m_appIndicatorShowHideMenuItem = gtk_menu_item_new_with_label(qPrintable(tr("Hide")));
Expand Down Expand Up @@ -764,10 +785,7 @@ void MainWindow::removeTrayIcon()
#endif

#ifdef USE_APPINDICATOR
const QString desktop = qgetenv("XDG_CURRENT_DESKTOP");
const bool isUnity = (desktop.toLower() == QLatin1String("unity"));

if (isUnity) {
if (m_useAppIndicator) {
g_clear_object(&m_appIndicator);
g_clear_object(&m_appIndicatorMenu);
g_clear_object(&m_appIndicatorShowHideMenuItem);
Expand Down
5 changes: 5 additions & 0 deletions src/ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ private slots:
QString docsetName(const QUrl &url) const;
QIcon docsetIcon(const QString &docsetName) const;
QAction *addHistoryAction(QWebHistory *history, const QWebHistoryItem &item);

#ifdef USE_APPINDICATOR
void detectAppIndicatorSupport();
#endif
void createTrayIcon();
void removeTrayIcon();

Expand All @@ -159,6 +163,7 @@ private slots:
QSystemTrayIcon *m_trayIcon = nullptr;

#ifdef USE_APPINDICATOR
bool m_useAppIndicator = false;
_AppIndicator *m_appIndicator = nullptr;
_GtkWidget *m_appIndicatorMenu = nullptr;
_GtkWidget *m_appIndicatorQuitMenuItem = nullptr;
Expand Down

0 comments on commit a96c79b

Please sign in to comment.