From 3372dfcd3e57df5acee893b43b1ad104b70b1999 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 10 Mar 2019 16:40:44 +0300 Subject: [PATCH] Refactored checking of last input while notifications are displayed. - Removed condition for Windows platform only. - Added smooth hiding of notifications in case video is watched or voice message is recorded. - psUserActionDone() was completely replaced with Core::App().updateNonIdle(). --- Telegram/SourceFiles/core/application.cpp | 4 ++-- Telegram/SourceFiles/mainwindow.cpp | 2 +- .../SourceFiles/platform/linux/specific_linux.cpp | 12 +----------- .../SourceFiles/platform/linux/specific_linux.h | 1 - Telegram/SourceFiles/platform/mac/specific_mac.h | 1 - Telegram/SourceFiles/platform/mac/specific_mac.mm | 12 +----------- Telegram/SourceFiles/platform/win/specific_win.cpp | 13 +------------ Telegram/SourceFiles/platform/win/specific_win.h | 1 - Telegram/SourceFiles/window/main_window.cpp | 2 +- .../window/notifications_manager_default.cpp | 13 ++----------- .../window/notifications_manager_default.h | 2 -- 11 files changed, 9 insertions(+), 54 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 93a6bc40a9..075a1e9201 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -233,7 +233,7 @@ bool Application::eventFilter(QObject *object, QEvent *e) { case QEvent::MouseButtonPress: case QEvent::TouchBegin: case QEvent::Wheel: { - psUserActionDone(); + updateNonIdle(); } break; case QEvent::ShortcutOverride: { @@ -252,7 +252,7 @@ bool Application::eventFilter(QObject *object, QEvent *e) { case QEvent::ApplicationActivate: { if (object == QCoreApplication::instance()) { - psUserActionDone(); + updateNonIdle(); } } break; diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 114864fa94..0f3a2335d4 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -484,7 +484,7 @@ bool MainWindow::eventFilter(QObject *object, QEvent *e) { case QEvent::MouseMove: { if (_main && _main->isIdle()) { - psUserActionDone(); + Core::App().updateNonIdle(); _main->checkIdleFinish(); } } break; diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 2848528665..2342e2a616 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -193,16 +193,6 @@ void psDeleteDir(const QString &dir) { _removeDirectory(dir); } -namespace { - -auto _lastUserAction = 0LL; - -} // namespace - -void psUserActionDone() { - _lastUserAction = crl::now(); -} - bool psIdleSupported() { return false; } @@ -446,7 +436,7 @@ bool OpenSystemSettings(SystemSettingsType type) { } crl::time LastUserInputTime() { - return _lastUserAction; + return 0LL; } namespace ThirdParty { diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.h b/Telegram/SourceFiles/platform/linux/specific_linux.h index 681d0d92ae..646a15384f 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.h +++ b/Telegram/SourceFiles/platform/linux/specific_linux.h @@ -51,7 +51,6 @@ void psWriteDump(); void psDeleteDir(const QString &dir); -void psUserActionDone(); bool psIdleSupported(); QStringList psInitLogs(); diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.h b/Telegram/SourceFiles/platform/mac/specific_mac.h index 136aec8754..6e080886c3 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.h +++ b/Telegram/SourceFiles/platform/mac/specific_mac.h @@ -52,7 +52,6 @@ void psWriteDump(); void psDeleteDir(const QString &dir); -void psUserActionDone(); bool psIdleSupported(); QStringList psInitLogs(); diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.mm b/Telegram/SourceFiles/platform/mac/specific_mac.mm index 8d0ac876c4..4a2f212896 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac.mm @@ -90,16 +90,6 @@ void psDeleteDir(const QString &dir) { objc_deleteDir(dir); } -namespace { - -auto _lastUserAction = 0LL; - -} // namespace - -void psUserActionDone() { - _lastUserAction = crl::now(); -} - bool psIdleSupported() { return objc_idleSupported(); } @@ -267,7 +257,7 @@ bool OpenSystemSettings(SystemSettingsType type) { crl::time LastUserInputTime() { auto idleTime = 0LL; - return objc_idleTime(idleTime) ? (crl::now() - crl::time(idleTime)) : _lastUserAction; + return objc_idleTime(idleTime) ? (crl::now() - crl::time(idleTime)) : 0LL; } } // namespace Platform diff --git a/Telegram/SourceFiles/platform/win/specific_win.cpp b/Telegram/SourceFiles/platform/win/specific_win.cpp index 59b0886790..5526fb09a9 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.cpp +++ b/Telegram/SourceFiles/platform/win/specific_win.cpp @@ -128,17 +128,6 @@ namespace { } } -namespace { - -crl::time _lastUserAction = 0; - -} // namespace - -void psUserActionDone() { - _lastUserAction = crl::now(); - EventFilter::getInstance()->setSessionLoggedOff(false); -} - bool psIdleSupported() { LASTINPUTINFO lii; lii.cbSize = sizeof(LASTINPUTINFO); @@ -347,7 +336,7 @@ QString CurrentExecutablePath(int argc, char *argv[]) { crl::time LastUserInputTime() { LASTINPUTINFO lii; lii.cbSize = sizeof(LASTINPUTINFO); - return GetLastInputInfo(&lii) ? (crl::now() + lii.dwTime - GetTickCount()) : _lastUserAction; + return GetLastInputInfo(&lii) ? (crl::now() + lii.dwTime - GetTickCount()) : 0LL; } namespace { diff --git a/Telegram/SourceFiles/platform/win/specific_win.h b/Telegram/SourceFiles/platform/win/specific_win.h index 89d08e78dd..169b0f5e4f 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.h +++ b/Telegram/SourceFiles/platform/win/specific_win.h @@ -59,7 +59,6 @@ void psWriteDump(); void psDeleteDir(const QString &dir); -void psUserActionDone(); bool psIdleSupported(); QStringList psInitLogs(); diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index a1e4bde643..42a232b640 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -288,7 +288,7 @@ void MainWindow::init() { void MainWindow::handleStateChanged(Qt::WindowState state) { stateChangedHook(state); updateIsActive((state == Qt::WindowMinimized) ? Global::OfflineBlurTimeout() : Global::OnlineFocusTimeout()); - psUserActionDone(); + Core::App().updateNonIdle(); if (state == Qt::WindowMinimized && Global::WorkMode().value() == dbiwmTrayOnly) { minimizeToTray(); } diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 5a7ddfd46f..0e9f659b5e 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -505,9 +505,7 @@ Notification::Notification( int shift, Direction shiftDirection) : Widget(manager, startPosition, shift, shiftDirection) -#ifdef Q_OS_WIN -, _started(GetTickCount()) -#endif // Q_OS_WIN +, _started(crl::now()) , _history(history) , _peer(peer) , _author(author) @@ -588,14 +586,7 @@ void Notification::prepareActionsCache() { bool Notification::checkLastInput(bool hasReplyingNotifications) { if (!_waitingForInput) return true; - auto wasUserInput = true; // TODO -#ifdef Q_OS_WIN - LASTINPUTINFO lii; - lii.cbSize = sizeof(LASTINPUTINFO); - BOOL res = GetLastInputInfo(&lii); - wasUserInput = (!res || lii.dwTime >= _started); -#endif // Q_OS_WIN - if (wasUserInput) { + if (Core::App().lastNonIdleTime() > _started) { _waitingForInput = false; if (!hasReplyingNotifications) { _hideTimer.start(st::notifyWaitLongHide); diff --git a/Telegram/SourceFiles/window/notifications_manager_default.h b/Telegram/SourceFiles/window/notifications_manager_default.h index f13f83b818..a40f7a006d 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.h +++ b/Telegram/SourceFiles/window/notifications_manager_default.h @@ -216,9 +216,7 @@ private: Animation a_actionsOpacity; QPixmap _buttonsCache; -#ifdef Q_OS_WIN crl::time _started; -#endif // Q_OS_WIN History *_history; PeerData *_peer;