From c1aa1c5a0f26b29fce1307ba455f9887e7c1c1ec Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 3 Apr 2017 19:56:20 +0300 Subject: [PATCH] Enable Qt tray icon in GNOME and derivatives. As tested in Fedora Qt 5.6.2 tray icon works well in GNOME. Also add more logs about DE and tray icon. Fix #3175 #3188 --- .../linux/linux_desktop_environment.cpp | 30 +++++++++++++++---- .../platform/linux/main_window_linux.cpp | 10 +++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_desktop_environment.cpp b/Telegram/SourceFiles/platform/linux/linux_desktop_environment.cpp index de65d8d1a6..158e6834c4 100644 --- a/Telegram/SourceFiles/platform/linux/linux_desktop_environment.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_desktop_environment.cpp @@ -26,7 +26,9 @@ namespace { QString GetEnv(const char *name) { auto result = getenv(name); - return result ? QString::fromLatin1(result) : QString(); + auto value = result ? QString::fromLatin1(result) : QString(); + LOG(("Getting DE, %1: '%2'").arg(name).arg(value)); + return value; } Type Compute() { @@ -34,7 +36,6 @@ Type Compute() { auto list = xdgCurrentDesktop.split(':', QString::SkipEmptyParts); auto desktopSession = GetEnv("DESKTOP_SESSION").toLower(); auto kdeSession = GetEnv("KDE_SESSION_VERSION"); - if (!list.isEmpty()) { if (list.contains("unity")) { // gnome-fallback sessions set XDG_CURRENT_DESKTOP to Unity @@ -87,16 +88,35 @@ Type Compute() { return Type::Other; } +Type ComputeAndLog() { + auto result = Compute(); + auto name = [result]() -> QString { + switch (result) { + case Type::Other: return "Other"; + case Type::Gnome: return "Gnome"; + case Type::KDE3: return "KDE3"; + case Type::KDE4: return "KDE4"; + case Type::KDE5: return "KDE5"; + case Type::Unity: return "Unity"; + case Type::XFCE: return "XFCE"; + case Type::Pantheon: return "Pantheon"; + } + return QString::number(static_cast(result)); + }; + LOG(("DE: %1").arg(name())); + return result; +} + } // namespace // Thanks Chromium. Type Get() { - static const auto result = Compute(); + static const auto result = ComputeAndLog(); return result; } bool TryQtTrayIcon() { - return !IsPantheon() && !IsGnome(); + return !IsPantheon(); } bool PreferAppIndicatorTrayIcon() { @@ -108,4 +128,4 @@ bool TryUnityCounter() { } } // namespace DesktopEnvironment -} // namespace Platform \ No newline at end of file +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index 65f661fd48..da8915f2d2 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -378,6 +378,8 @@ void MainWindow::LibsLoaded() { noQtTrayIcon = !DesktopEnvironment::TryQtTrayIcon(); tryAppIndicator = !DesktopEnvironment::PreferAppIndicatorTrayIcon(); + LOG(("Tray Icon: Try Qt = %1, Prefer appindicator = %2").arg(Logs::b(!noQtTrayIcon)).arg(Logs::b(tryAppIndicator))); + if (noQtTrayIcon) cSetSupportTray(false); useGtkBase = (Libs::gtk_init_check != nullptr) @@ -438,6 +440,7 @@ void MainWindow::LibsLoaded() { void MainWindow::psCreateTrayIcon() { if (!noQtTrayIcon) { + LOG(("Tray Icon: Using Qt tray icon, available: %1").arg(Logs::b(QSystemTrayIcon::isSystemTrayAvailable()))); cSetSupportTray(QSystemTrayIcon::isSystemTrayAvailable()); return; } @@ -452,7 +455,7 @@ void MainWindow::psCreateTrayIcon() { QByteArray path = QFile::encodeName(iconFile.absoluteFilePath()); _trayIndicator = Libs::app_indicator_new("Telegram Desktop", path.constData(), APP_INDICATOR_CATEGORY_APPLICATION_STATUS); if (_trayIndicator) { - LOG(("Using appindicator tray icon.")); + LOG(("Tray Icon: Using appindicator tray icon.")); } else { DEBUG_LOG(("Failed to app_indicator_new()!")); } @@ -485,7 +488,7 @@ void MainWindow::psCreateTrayIcon() { _trayIcon = Libs::gtk_status_icon_new_from_pixbuf(_trayPixbuf); } if (_trayIcon) { - LOG(("Using GTK status tray icon.")); + LOG(("Tray Icon: Using GTK status tray icon.")); Libs::g_signal_connect_helper(_trayIcon, "popup-menu", GCallback(_trayIconPopup), _trayMenu); Libs::g_signal_connect_helper(_trayIcon, "activate", GCallback(_trayIconActivate), _trayMenu); @@ -505,10 +508,11 @@ void MainWindow::psCreateTrayIcon() { } } if (!useStatusIcon && !useAppIndicator) { + LOG(("Tray Icon: Not able to use any tray icon :(")); if (_trayMenu) { Libs::g_object_ref_sink(_trayMenu); Libs::g_object_unref(_trayMenu); - _trayMenu = 0; + _trayMenu = nullptr; } } cSetSupportTray(useAppIndicator);