mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-25 04:38:23 +00:00
Implement three items tray menu on Linux
This commit is contained in:
parent
bb119ca967
commit
1a3253ae8b
@ -137,17 +137,6 @@ Application::Application(not_null<Launcher*> launcher)
|
||||
UpdateChecker().setMtproto(session);
|
||||
}
|
||||
}, _lifetime);
|
||||
|
||||
_domain->activeValue(
|
||||
) | rpl::filter(rpl::mappers::_1 != nullptr
|
||||
) | rpl::take(1) | rpl::start_with_next([=] {
|
||||
if (_window) {
|
||||
// Global::DesktopNotify is used in updateTrayMenu.
|
||||
// This should be called when user settings are read.
|
||||
// Right now after they are read the startMtp() is called.
|
||||
_window->widget()->updateTrayMenu();
|
||||
}
|
||||
}, _lifetime);
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
|
@ -138,18 +138,17 @@ void MainWindow::createTrayIconMenu() {
|
||||
trayIconMenu->deleteOnHide(false);
|
||||
#else // Q_OS_WIN
|
||||
trayIconMenu = new QMenu(this);
|
||||
|
||||
connect(trayIconMenu, &QMenu::aboutToShow, [=] {
|
||||
updateIsActive();
|
||||
updateTrayMenu();
|
||||
});
|
||||
#endif // else for Q_OS_WIN
|
||||
|
||||
auto notificationActionText = Core::App().settings().desktopNotify()
|
||||
? tr::lng_disable_notifications_from_tray(tr::now)
|
||||
: tr::lng_enable_notifications_from_tray(tr::now);
|
||||
|
||||
if (Platform::IsLinux() && !Platform::IsWayland()) {
|
||||
trayIconMenu->addAction(tr::lng_open_from_tray(tr::now), [=] {
|
||||
showFromTray();
|
||||
});
|
||||
}
|
||||
const auto showLifetime = std::make_shared<rpl::lifetime>();
|
||||
trayIconMenu->addAction(tr::lng_minimize_to_tray(tr::now), [=] {
|
||||
if (_activeForTrayIconAction) {
|
||||
minimizeToTray();
|
||||
@ -205,7 +204,6 @@ void MainWindow::finishFirstShow() {
|
||||
applyInitialWorkMode();
|
||||
createGlobalMenu();
|
||||
firstShadowsUpdate();
|
||||
updateTrayMenu();
|
||||
|
||||
windowDeactivateEvents(
|
||||
) | rpl::start_with_next([=] {
|
||||
@ -644,24 +642,19 @@ bool MainWindow::eventFilter(QObject *object, QEvent *e) {
|
||||
return Platform::MainWindow::eventFilter(object, e);
|
||||
}
|
||||
|
||||
void MainWindow::updateTrayMenu(bool force) {
|
||||
if (!trayIconMenu || (Platform::IsWindows() && !force)) return;
|
||||
void MainWindow::updateTrayMenu() {
|
||||
if (!trayIconMenu) return;
|
||||
|
||||
auto actions = trayIconMenu->actions();
|
||||
if (Platform::IsLinux() && !Platform::IsWayland()) {
|
||||
const auto minimizeAction = actions.at(1);
|
||||
minimizeAction->setEnabled(isVisible());
|
||||
} else {
|
||||
const auto active = isActiveForTrayMenu();
|
||||
if (_activeForTrayIconAction != active) {
|
||||
_activeForTrayIconAction = active;
|
||||
const auto toggleAction = actions.at(0);
|
||||
toggleAction->setText(_activeForTrayIconAction
|
||||
? tr::lng_minimize_to_tray(tr::now)
|
||||
: tr::lng_open_from_tray(tr::now));
|
||||
}
|
||||
const auto active = isActiveForTrayMenu();
|
||||
if (_activeForTrayIconAction != active) {
|
||||
_activeForTrayIconAction = active;
|
||||
const auto toggleAction = actions.at(0);
|
||||
toggleAction->setText(_activeForTrayIconAction
|
||||
? tr::lng_minimize_to_tray(tr::now)
|
||||
: tr::lng_open_from_tray(tr::now));
|
||||
}
|
||||
auto notificationAction = actions.at(Platform::IsLinux() && !Platform::IsWayland() ? 2 : 1);
|
||||
auto notificationAction = actions.at(1);
|
||||
auto notificationActionText = Core::App().settings().desktopNotify()
|
||||
? tr::lng_disable_notifications_from_tray(tr::now)
|
||||
: tr::lng_enable_notifications_from_tray(tr::now);
|
||||
@ -691,7 +684,7 @@ void MainWindow::handleTrayIconActication(
|
||||
return;
|
||||
}
|
||||
if (reason == QSystemTrayIcon::Context) {
|
||||
updateTrayMenu(true);
|
||||
updateTrayMenu();
|
||||
base::call_delayed(1, this, [=] {
|
||||
psShowTrayMenu();
|
||||
});
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
}
|
||||
|
||||
void showMainMenu();
|
||||
void updateTrayMenu(bool force = false) override;
|
||||
void updateTrayMenu() override;
|
||||
void fixOrder() override;
|
||||
|
||||
void showSpecialLayer(
|
||||
|
@ -628,11 +628,6 @@ void MainWindow::psShowTrayMenu() {
|
||||
}
|
||||
|
||||
void MainWindow::psTrayMenuUpdated() {
|
||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
if (_sniTrayIcon && trayIconMenu) {
|
||||
_sniTrayIcon->setContextMenu(trayIconMenu);
|
||||
}
|
||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
}
|
||||
|
||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
@ -692,7 +687,6 @@ void MainWindow::attachToSNITrayIcon() {
|
||||
handleTrayIconActication(QSystemTrayIcon::MiddleClick);
|
||||
});
|
||||
});
|
||||
updateTrayMenu();
|
||||
}
|
||||
|
||||
void MainWindow::sniSignalEmitted(
|
||||
@ -804,6 +798,7 @@ void MainWindow::psSetupTrayIcon() {
|
||||
this);
|
||||
|
||||
_sniTrayIcon->setTitle(AppName.utf16());
|
||||
_sniTrayIcon->setContextMenu(trayIconMenu);
|
||||
setSNITrayIcon(counter, muted);
|
||||
|
||||
attachToSNITrayIcon();
|
||||
|
@ -525,6 +525,18 @@ void MainWindow::stateChangedHook(Qt::WindowState state) {
|
||||
|
||||
void MainWindow::handleActiveChangedHook() {
|
||||
InvokeQueued(this, [this] { _private->updateNativeTitle(); });
|
||||
|
||||
// On macOS just remove trayIcon menu if the window is not active.
|
||||
// So we will activate the window on click instead of showing the menu.
|
||||
if (isActiveForTrayMenu()) {
|
||||
if (trayIcon
|
||||
&& trayIconMenu
|
||||
&& trayIcon->contextMenu() != trayIconMenu) {
|
||||
trayIcon->setContextMenu(trayIconMenu);
|
||||
}
|
||||
} else if (trayIcon) {
|
||||
trayIcon->setContextMenu(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::initHook() {
|
||||
@ -555,16 +567,6 @@ void MainWindow::psShowTrayMenu() {
|
||||
}
|
||||
|
||||
void MainWindow::psTrayMenuUpdated() {
|
||||
// On macOS just remove trayIcon menu if the window is not active.
|
||||
// So we will activate the window on click instead of showing the menu.
|
||||
if (isActive()) {
|
||||
if (trayIcon && trayIconMenu
|
||||
&& trayIcon->contextMenu() != trayIconMenu) {
|
||||
trayIcon->setContextMenu(trayIconMenu);
|
||||
}
|
||||
} else if (trayIcon) {
|
||||
trayIcon->setContextMenu(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::psSetupTrayIcon() {
|
||||
@ -573,6 +575,11 @@ void MainWindow::psSetupTrayIcon() {
|
||||
trayIcon->setIcon(generateIconForTray(
|
||||
Core::App().unreadBadge(),
|
||||
Core::App().unreadBadgeMuted()));
|
||||
if (isActiveForTrayMenu()) {
|
||||
trayIcon->setContextMenu(trayIconMenu);
|
||||
} else {
|
||||
trayIcon->setContextMenu(nullptr);
|
||||
}
|
||||
attachToTrayIcon(trayIcon);
|
||||
} else {
|
||||
updateIconCounters();
|
||||
|
@ -280,7 +280,6 @@ void MainWindow::handleActiveChanged() {
|
||||
Core::App().checkMediaViewActivation();
|
||||
}
|
||||
base::call_delayed(1, this, [this] {
|
||||
updateTrayMenu();
|
||||
handleActiveChangedHook();
|
||||
});
|
||||
}
|
||||
@ -300,7 +299,6 @@ void MainWindow::handleVisibleChanged(bool visible) {
|
||||
|
||||
void MainWindow::showFromTray() {
|
||||
base::call_delayed(1, this, [this] {
|
||||
updateTrayMenu();
|
||||
updateGlobalMenu();
|
||||
});
|
||||
activate();
|
||||
@ -556,7 +554,6 @@ void MainWindow::attachToTrayIcon(not_null<QSystemTrayIcon*> icon) {
|
||||
handleTrayIconActication(reason);
|
||||
});
|
||||
});
|
||||
App::wnd()->updateTrayMenu();
|
||||
}
|
||||
|
||||
void MainWindow::paintEvent(QPaintEvent *e) {
|
||||
@ -694,7 +691,6 @@ bool MainWindow::minimizeToTray() {
|
||||
|
||||
closeWithoutDestroy();
|
||||
controller().updateIsActiveBlur();
|
||||
updateTrayMenu();
|
||||
updateGlobalMenu();
|
||||
showTrayTooltip();
|
||||
return true;
|
||||
|
@ -90,7 +90,7 @@ public:
|
||||
// Returns how much could the window get extended.
|
||||
int tryToExtendWidthBy(int addToWidth);
|
||||
|
||||
virtual void updateTrayMenu(bool force = false) {
|
||||
virtual void updateTrayMenu() {
|
||||
}
|
||||
virtual void fixOrder() {
|
||||
}
|
||||
|
@ -54,7 +54,6 @@ System::System()
|
||||
, _waitForAllGroupedTimer([=] { showGrouped(); }) {
|
||||
subscribe(settingsChanged(), [=](ChangeType type) {
|
||||
if (type == ChangeType::DesktopEnabled) {
|
||||
App::wnd()->updateTrayMenu();
|
||||
clearAll();
|
||||
} else if (type == ChangeType::ViewParams) {
|
||||
updateAll();
|
||||
|
Loading…
Reference in New Issue
Block a user