mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-03 16:05:57 +00:00
Re-create QSystemTrayIcon on SNI watcher owner change
This commit is contained in:
@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
|
|
||||||
#include "base/invoke_queued.h"
|
#include "base/invoke_queued.h"
|
||||||
#include "base/qt_signal_producer.h"
|
#include "base/qt_signal_producer.h"
|
||||||
|
#include "base/platform/linux/base_linux_dbus_utilities.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/sandbox.h"
|
#include "core/sandbox.h"
|
||||||
#include "platform/platform_specific.h"
|
#include "platform/platform_specific.h"
|
||||||
@@ -21,9 +22,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
#include <QtWidgets/QMenu>
|
#include <QtWidgets/QMenu>
|
||||||
#include <QtWidgets/QSystemTrayIcon>
|
#include <QtWidgets/QSystemTrayIcon>
|
||||||
|
|
||||||
|
#include <gio/gio.hpp>
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using namespace gi::repository;
|
||||||
|
|
||||||
[[nodiscard]] QString PanelIconName(int counter, bool muted) {
|
[[nodiscard]] QString PanelIconName(int counter, bool muted) {
|
||||||
return (counter > 0)
|
return (counter > 0)
|
||||||
? (muted
|
? (muted
|
||||||
@@ -282,11 +287,29 @@ rpl::producer<> TrayEventFilter::contextMenuFilters() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tray::Tray() {
|
Tray::Tray() {
|
||||||
LOG(("System tray available: %1").arg(Logs::b(TrayIconSupported())));
|
auto connection = Gio::bus_get_sync(Gio::BusType::SESSION_, nullptr);
|
||||||
|
if (connection) {
|
||||||
|
_sniWatcher = std::make_unique<base::Platform::DBus::ServiceWatcher>(
|
||||||
|
connection.gobj_(),
|
||||||
|
"org.kde.StatusNotifierWatcher",
|
||||||
|
[=](
|
||||||
|
const std::string &service,
|
||||||
|
const std::string &oldOwner,
|
||||||
|
const std::string &newOwner) {
|
||||||
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
|
if (hasIcon()) {
|
||||||
|
destroyIcon();
|
||||||
|
createIcon();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::createIcon() {
|
void Tray::createIcon() {
|
||||||
if (!_icon) {
|
if (!_icon) {
|
||||||
|
LOG(("System tray available: %1").arg(Logs::b(TrayIconSupported())));
|
||||||
|
|
||||||
if (!_iconGraphic) {
|
if (!_iconGraphic) {
|
||||||
_iconGraphic = std::make_unique<IconGraphic>();
|
_iconGraphic = std::make_unique<IconGraphic>();
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
|
|
||||||
#include "base/unique_qptr.h"
|
#include "base/unique_qptr.h"
|
||||||
|
|
||||||
|
namespace base::Platform::DBus {
|
||||||
|
class ServiceWatcher;
|
||||||
|
} // namespace base::Platform::DBus
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class PopupMenu;
|
class PopupMenu;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
@@ -51,6 +55,7 @@ public:
|
|||||||
[[nodiscard]] rpl::lifetime &lifetime();
|
[[nodiscard]] rpl::lifetime &lifetime();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::unique_ptr<base::Platform::DBus::ServiceWatcher> _sniWatcher;
|
||||||
std::unique_ptr<IconGraphic> _iconGraphic;
|
std::unique_ptr<IconGraphic> _iconGraphic;
|
||||||
|
|
||||||
base::unique_qptr<QSystemTrayIcon> _icon;
|
base::unique_qptr<QSystemTrayIcon> _icon;
|
||||||
|
Reference in New Issue
Block a user