mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
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:
parent
78d245c02c
commit
c1aa1c5a0f
2 changed files with 32 additions and 8 deletions
|
@ -26,7 +26,9 @@ namespace {
|
||||||
|
|
||||||
QString GetEnv(const char *name) {
|
QString GetEnv(const char *name) {
|
||||||
auto result = getenv(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() {
|
Type Compute() {
|
||||||
|
@ -34,7 +36,6 @@ Type Compute() {
|
||||||
auto list = xdgCurrentDesktop.split(':', QString::SkipEmptyParts);
|
auto list = xdgCurrentDesktop.split(':', QString::SkipEmptyParts);
|
||||||
auto desktopSession = GetEnv("DESKTOP_SESSION").toLower();
|
auto desktopSession = GetEnv("DESKTOP_SESSION").toLower();
|
||||||
auto kdeSession = GetEnv("KDE_SESSION_VERSION");
|
auto kdeSession = GetEnv("KDE_SESSION_VERSION");
|
||||||
|
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
if (list.contains("unity")) {
|
if (list.contains("unity")) {
|
||||||
// gnome-fallback sessions set XDG_CURRENT_DESKTOP to Unity
|
// gnome-fallback sessions set XDG_CURRENT_DESKTOP to Unity
|
||||||
|
@ -87,16 +88,35 @@ Type Compute() {
|
||||||
return Type::Other;
|
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
|
} // namespace
|
||||||
|
|
||||||
// Thanks Chromium.
|
// Thanks Chromium.
|
||||||
Type Get() {
|
Type Get() {
|
||||||
static const auto result = Compute();
|
static const auto result = ComputeAndLog();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TryQtTrayIcon() {
|
bool TryQtTrayIcon() {
|
||||||
return !IsPantheon() && !IsGnome();
|
return !IsPantheon();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PreferAppIndicatorTrayIcon() {
|
bool PreferAppIndicatorTrayIcon() {
|
||||||
|
@ -108,4 +128,4 @@ bool TryUnityCounter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace DesktopEnvironment
|
} // namespace DesktopEnvironment
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -378,6 +378,8 @@ void MainWindow::LibsLoaded() {
|
||||||
noQtTrayIcon = !DesktopEnvironment::TryQtTrayIcon();
|
noQtTrayIcon = !DesktopEnvironment::TryQtTrayIcon();
|
||||||
tryAppIndicator = !DesktopEnvironment::PreferAppIndicatorTrayIcon();
|
tryAppIndicator = !DesktopEnvironment::PreferAppIndicatorTrayIcon();
|
||||||
|
|
||||||
|
LOG(("Tray Icon: Try Qt = %1, Prefer appindicator = %2").arg(Logs::b(!noQtTrayIcon)).arg(Logs::b(tryAppIndicator)));
|
||||||
|
|
||||||
if (noQtTrayIcon) cSetSupportTray(false);
|
if (noQtTrayIcon) cSetSupportTray(false);
|
||||||
|
|
||||||
useGtkBase = (Libs::gtk_init_check != nullptr)
|
useGtkBase = (Libs::gtk_init_check != nullptr)
|
||||||
|
@ -438,6 +440,7 @@ void MainWindow::LibsLoaded() {
|
||||||
|
|
||||||
void MainWindow::psCreateTrayIcon() {
|
void MainWindow::psCreateTrayIcon() {
|
||||||
if (!noQtTrayIcon) {
|
if (!noQtTrayIcon) {
|
||||||
|
LOG(("Tray Icon: Using Qt tray icon, available: %1").arg(Logs::b(QSystemTrayIcon::isSystemTrayAvailable())));
|
||||||
cSetSupportTray(QSystemTrayIcon::isSystemTrayAvailable());
|
cSetSupportTray(QSystemTrayIcon::isSystemTrayAvailable());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -452,7 +455,7 @@ void MainWindow::psCreateTrayIcon() {
|
||||||
QByteArray path = QFile::encodeName(iconFile.absoluteFilePath());
|
QByteArray path = QFile::encodeName(iconFile.absoluteFilePath());
|
||||||
_trayIndicator = Libs::app_indicator_new("Telegram Desktop", path.constData(), APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
|
_trayIndicator = Libs::app_indicator_new("Telegram Desktop", path.constData(), APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
|
||||||
if (_trayIndicator) {
|
if (_trayIndicator) {
|
||||||
LOG(("Using appindicator tray icon."));
|
LOG(("Tray Icon: Using appindicator tray icon."));
|
||||||
} else {
|
} else {
|
||||||
DEBUG_LOG(("Failed to app_indicator_new()!"));
|
DEBUG_LOG(("Failed to app_indicator_new()!"));
|
||||||
}
|
}
|
||||||
|
@ -485,7 +488,7 @@ void MainWindow::psCreateTrayIcon() {
|
||||||
_trayIcon = Libs::gtk_status_icon_new_from_pixbuf(_trayPixbuf);
|
_trayIcon = Libs::gtk_status_icon_new_from_pixbuf(_trayPixbuf);
|
||||||
}
|
}
|
||||||
if (_trayIcon) {
|
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, "popup-menu", GCallback(_trayIconPopup), _trayMenu);
|
||||||
Libs::g_signal_connect_helper(_trayIcon, "activate", GCallback(_trayIconActivate), _trayMenu);
|
Libs::g_signal_connect_helper(_trayIcon, "activate", GCallback(_trayIconActivate), _trayMenu);
|
||||||
|
@ -505,10 +508,11 @@ void MainWindow::psCreateTrayIcon() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!useStatusIcon && !useAppIndicator) {
|
if (!useStatusIcon && !useAppIndicator) {
|
||||||
|
LOG(("Tray Icon: Not able to use any tray icon :("));
|
||||||
if (_trayMenu) {
|
if (_trayMenu) {
|
||||||
Libs::g_object_ref_sink(_trayMenu);
|
Libs::g_object_ref_sink(_trayMenu);
|
||||||
Libs::g_object_unref(_trayMenu);
|
Libs::g_object_unref(_trayMenu);
|
||||||
_trayMenu = 0;
|
_trayMenu = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cSetSupportTray(useAppIndicator);
|
cSetSupportTray(useAppIndicator);
|
||||||
|
|
Loading…
Add table
Reference in a new issue