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
This commit is contained in:
John Preston 2017-04-03 19:56:20 +03:00
parent 78d245c02c
commit c1aa1c5a0f
2 changed files with 32 additions and 8 deletions

View File

@ -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<int>(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
} // namespace Platform

View File

@ -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);