diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 120218d70..a6f12dd39 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -54,8 +54,6 @@ enum { AVBlockSize = 4096, // 4Kb for ffmpeg blocksize - SaveWindowPositionTimeout = 1000, // 1 sec - AutoSearchTimeout = 900, // 0.9 secs SearchPerPage = 50, SearchManyPerPage = 100, diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index e758a8d6a..8298c687b 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -19,7 +19,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Window { -constexpr auto kInactivePressTimeout = 200; +constexpr auto kInactivePressTimeout = TimeMs(200); +constexpr auto kSaveWindowPositionTimeout = TimeMs(1000); QImage LoadLogo() { return QImage(qsl(":/gui/art/logo_256.png")); @@ -45,8 +46,8 @@ QIcon CreateIcon() { return result; } -MainWindow::MainWindow() : QWidget() -, _positionUpdatedTimer(this) +MainWindow::MainWindow() +: _positionUpdatedTimer([=] { savePosition(); }) , _body(this) , _icon(CreateIcon()) , _titleText(qsl("Telegram")) { @@ -104,26 +105,13 @@ bool MainWindow::computeIsActive() const { return isActiveWindow() && isVisible() && !(windowState() & Qt::WindowMinimized); } -void MainWindow::onReActivate() { - if (auto w = App::wnd()) { - if (auto f = QApplication::focusWidget()) { - f->clearFocus(); - } - w->windowHandle()->requestActivate(); - w->activate(); - if (auto f = QApplication::focusWidget()) { - f->clearFocus(); - } - w->setInnerFocus(); - } -} - void MainWindow::updateWindowIcon() { setWindowIcon(_icon); } void MainWindow::init() { Expects(!windowHandle()); + createWinId(); initHook(); @@ -132,9 +120,6 @@ void MainWindow::init() { connect(windowHandle(), &QWindow::activeChanged, this, [this] { handleActiveChanged(); }, Qt::QueuedConnection); connect(windowHandle(), &QWindow::windowStateChanged, this, [this](Qt::WindowState state) { handleStateChanged(state); }); - _positionUpdatedTimer->setSingleShot(true); - connect(_positionUpdatedTimer, SIGNAL(timeout()), this, SLOT(savePositionByTimer())); - updatePalette(); if ((_title = Platform::CreateTitleWidget(this))) { @@ -221,7 +206,7 @@ void MainWindow::initSize() { } void MainWindow::positionUpdated() { - _positionUpdatedTimer->start(SaveWindowPositionTimeout); + _positionUpdatedTimer.callOnce(kSaveWindowPositionTimeout); } bool MainWindow::titleVisible() const { @@ -345,6 +330,26 @@ bool MainWindow::minimizeToTray() { return true; } +void MainWindow::reActivateWindow() { +#if defined Q_OS_LINUX32 || defined Q_OS_LINUX64 + const auto reActivate = [=] { + if (const auto w = App::wnd()) { + if (auto f = QApplication::focusWidget()) { + f->clearFocus(); + } + windowHandle()->requestActivate(); + w->activate(); + if (auto f = QApplication::focusWidget()) { + f->clearFocus(); + } + w->setInnerFocus(); + } + }; + crl::on_main(this, reActivate); + App::CallDelayed(200, this, reActivate); +#endif // Q_OS_LINUX32 || Q_OS_LINUX64 +} + void MainWindow::showRightColumn(object_ptr widget) { auto wasWidth = width(); auto wasRightWidth = _rightColumn ? _rightColumn->width() : 0; diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index 01b5898d2..1fec65f06 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -56,12 +56,7 @@ public: return _titleText; } - void reActivateWindow() { -#if defined Q_OS_LINUX32 || defined Q_OS_LINUX64 - onReActivate(); - QTimer::singleShot(200, this, SLOT(onReActivate())); -#endif // Q_OS_LINUX32 || Q_OS_LINUX64 - } + void reActivateWindow(); void showRightColumn(object_ptr widget); int maximalExtendBy() const; @@ -147,12 +142,6 @@ protected: void setPositionInited(); -private slots: - void savePositionByTimer() { - savePosition(); - } - void onReActivate(); - private: void checkAuthSession(); void updatePalette(); @@ -161,7 +150,7 @@ private: bool computeIsActive() const; - object_ptr _positionUpdatedTimer; + base::Timer _positionUpdatedTimer; bool _positionInited = false; std::unique_ptr _controller;