mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
parent
fd6e135700
commit
80fb506f84
3 changed files with 43 additions and 21 deletions
|
@ -18,7 +18,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "styles/style_window.h"
|
#include "styles/style_window.h"
|
||||||
|
|
||||||
#include <QtWidgets/QSystemTrayIcon>
|
#include <qpa/qplatformscreen.h>
|
||||||
|
#include <qpa/qplatformsystemtrayicon.h>
|
||||||
|
#include <qpa/qplatformtheme.h>
|
||||||
|
#include <private/qguiapplication_p.h>
|
||||||
|
#include <private/qhighdpiscaling_p.h>
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
|
|
||||||
|
@ -96,28 +100,45 @@ Tray::Tray() {
|
||||||
|
|
||||||
void Tray::createIcon() {
|
void Tray::createIcon() {
|
||||||
if (!_icon) {
|
if (!_icon) {
|
||||||
_icon = base::make_unique_q<QSystemTrayIcon>(nullptr);
|
if (const auto theme = QGuiApplicationPrivate::platformTheme()) {
|
||||||
|
_icon.reset(theme->createPlatformSystemTrayIcon());
|
||||||
|
}
|
||||||
|
if (!_icon) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_icon->init();
|
||||||
updateIcon();
|
updateIcon();
|
||||||
_icon->setToolTip(AppName.utf16());
|
_icon->updateToolTip(AppName.utf16());
|
||||||
using Reason = QSystemTrayIcon::ActivationReason;
|
|
||||||
|
using Reason = QPlatformSystemTrayIcon::ActivationReason;
|
||||||
base::qt_signal_producer(
|
base::qt_signal_producer(
|
||||||
_icon.get(),
|
_icon.get(),
|
||||||
&QSystemTrayIcon::activated
|
&QPlatformSystemTrayIcon::activated
|
||||||
) | rpl::start_with_next([=](Reason reason) {
|
) | rpl::filter(
|
||||||
if (reason == QSystemTrayIcon::Context && _menu) {
|
rpl::mappers::_1 != Reason::Context
|
||||||
_aboutToShowRequests.fire({});
|
) | rpl::map_to(
|
||||||
InvokeQueued(_menu.get(), [=] {
|
rpl::empty
|
||||||
_menu->popup(QCursor::pos());
|
) | rpl::start_to_stream(_iconClicks, _lifetime);
|
||||||
});
|
|
||||||
} else {
|
base::qt_signal_producer(
|
||||||
_iconClicks.fire({});
|
_icon.get(),
|
||||||
}
|
&QPlatformSystemTrayIcon::contextMenuRequested
|
||||||
|
) | rpl::filter([=] {
|
||||||
|
return _menu != nullptr;
|
||||||
|
}) | rpl::start_with_next([=](
|
||||||
|
QPoint globalNativePosition,
|
||||||
|
const QPlatformScreen *screen) {
|
||||||
|
_aboutToShowRequests.fire({});
|
||||||
|
const auto position = QHighDpi::fromNativePixels(
|
||||||
|
globalNativePosition,
|
||||||
|
screen ? screen->screen() : nullptr);
|
||||||
|
InvokeQueued(_menu.get(), [=] {
|
||||||
|
_menu->popup(position);
|
||||||
|
});
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
} else {
|
} else {
|
||||||
updateIcon();
|
updateIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
_icon->show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::destroyIcon() {
|
void Tray::destroyIcon() {
|
||||||
|
@ -155,7 +176,7 @@ void Tray::updateIcon() {
|
||||||
forTrayIcon.addPixmap(iconSizeWidth >= 20
|
forTrayIcon.addPixmap(iconSizeWidth >= 20
|
||||||
? iconSmallPixmap32
|
? iconSmallPixmap32
|
||||||
: iconSmallPixmap16);
|
: iconSmallPixmap16);
|
||||||
_icon->setIcon(forTrayIcon);
|
_icon->updateIcon(forTrayIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tray::createMenu() {
|
void Tray::createMenu() {
|
||||||
|
@ -199,7 +220,8 @@ void Tray::showTrayMessage() const {
|
||||||
_icon->showMessage(
|
_icon->showMessage(
|
||||||
AppName.utf16(),
|
AppName.utf16(),
|
||||||
tr::lng_tray_icon_text(tr::now),
|
tr::lng_tray_icon_text(tr::now),
|
||||||
QSystemTrayIcon::Information,
|
QIcon(),
|
||||||
|
QPlatformSystemTrayIcon::Information,
|
||||||
kTooltipDelay);
|
kTooltipDelay);
|
||||||
cSetSeenTrayTooltip(true);
|
cSetSeenTrayTooltip(true);
|
||||||
Local::writeSettings();
|
Local::writeSettings();
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace Ui {
|
||||||
class PopupMenu;
|
class PopupMenu;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
class QSystemTrayIcon;
|
class QPlatformSystemTrayIcon;
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public:
|
||||||
bool supportMode);
|
bool supportMode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
base::unique_qptr<QSystemTrayIcon> _icon;
|
base::unique_qptr<QPlatformSystemTrayIcon> _icon;
|
||||||
base::unique_qptr<Ui::PopupMenu> _menu;
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||||
|
|
||||||
rpl::event_stream<> _iconClicks;
|
rpl::event_stream<> _iconClicks;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit e497dc134de3f8e2933ee0acdbba8bd702ce2130
|
Subproject commit 185679354c7d0b7dd8d719daaaf806d177cb20bf
|
Loading…
Add table
Reference in a new issue