2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Set window inner focus async. Fixes #4560.

This commit is contained in:
John Preston
2018-06-05 21:14:38 +03:00
parent 72f95b984f
commit d16cbbf279
3 changed files with 28 additions and 36 deletions

View File

@@ -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<TWidget> widget) {
auto wasWidth = width();
auto wasRightWidth = _rightColumn ? _rightColumn->width() : 0;