Update icons when icon theme on Linux changes

This commit is contained in:
Ilya Fedin 2023-05-27 12:35:17 +04:00 committed by John Preston
parent 6aef6d7f4e
commit 2ce9e610fa
4 changed files with 17 additions and 9 deletions

View file

@ -100,6 +100,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtCore/QMimeDatabase> #include <QtCore/QMimeDatabase>
#include <QtGui/QGuiApplication> #include <QtGui/QGuiApplication>
#include <QtGui/QScreen> #include <QtGui/QScreen>
#include <QtGui/QWindow>
namespace Core { namespace Core {
namespace { namespace {
@ -676,6 +677,13 @@ bool Application::eventFilter(QObject *object, QEvent *e) {
} }
} }
} break; } break;
case QEvent::ThemeChange: {
if (Platform::IsLinux() && object == QGuiApplication::allWindows().first()) {
Core::App().refreshApplicationIcon();
Core::App().tray().updateIconCounters();
}
} break;
} }
return QObject::eventFilter(object, e); return QObject::eventFilter(object, e);

View file

@ -400,6 +400,8 @@ OverlayWidget::OverlayWidget()
e->ignore(); e->ignore();
close(); close();
return base::EventFilterResult::Cancel; return base::EventFilterResult::Cancel;
} else if (type == QEvent::ThemeChange && Platform::IsLinux()) {
_window->setWindowIcon(Window::CreateIcon(_session));
} }
return base::EventFilterResult::Continue; return base::EventFilterResult::Continue;
}); });

View file

@ -179,6 +179,12 @@ MainWindow::MainWindow(not_null<Window::Controller*> controller)
} }
void MainWindow::initHook() { void MainWindow::initHook() {
events() | rpl::start_with_next([=](not_null<QEvent*> e) {
if (e->type() == QEvent::ThemeChange) {
updateWindowIcon();
}
}, lifetime());
base::install_event_filter(windowHandle(), [=](not_null<QEvent*> e) { base::install_event_filter(windowHandle(), [=](not_null<QEvent*> e) {
if (e->type() == QEvent::Expose) { if (e->type() == QEvent::Expose) {
auto ee = static_cast<QExposeEvent*>(e.get()); auto ee = static_cast<QExposeEvent*>(e.get());
@ -221,12 +227,7 @@ void MainWindow::updateWindowIcon() {
const auto session = sessionController() const auto session = sessionController()
? &sessionController()->session() ? &sessionController()->session()
: nullptr; : nullptr;
const auto supportIcon = session && session->supportMode(); setWindowIcon(Window::CreateIcon(session));
if (supportIcon != _usingSupportIcon || _icon.isNull()) {
_icon = Window::CreateIcon(session);
_usingSupportIcon = supportIcon;
}
setWindowIcon(_icon);
} }
void MainWindow::updateUnityCounter() { void MainWindow::updateUnityCounter() {

View file

@ -60,9 +60,6 @@ private:
QAction *psMonospace = nullptr; QAction *psMonospace = nullptr;
QAction *psClearFormat = nullptr; QAction *psClearFormat = nullptr;
QIcon _icon;
bool _usingSupportIcon = false;
}; };
[[nodiscard]] inline int32 ScreenNameChecksum(const QString &name) { [[nodiscard]] inline int32 ScreenNameChecksum(const QString &name) {