Set window inner focus async. Fixes #4560.
This commit is contained in:
		
							parent
							
								
									72f95b984f
								
							
						
					
					
						commit
						d16cbbf279
					
				
					 3 changed files with 28 additions and 36 deletions
				
			
		| 
						 | 
				
			
			@ -54,8 +54,6 @@ enum {
 | 
			
		|||
 | 
			
		||||
	AVBlockSize = 4096, // 4Kb for ffmpeg blocksize
 | 
			
		||||
 | 
			
		||||
	SaveWindowPositionTimeout = 1000, // 1 sec
 | 
			
		||||
 | 
			
		||||
	AutoSearchTimeout = 900, // 0.9 secs
 | 
			
		||||
	SearchPerPage = 50,
 | 
			
		||||
	SearchManyPerPage = 100,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<TWidget> 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<QTimer> _positionUpdatedTimer;
 | 
			
		||||
	base::Timer _positionUpdatedTimer;
 | 
			
		||||
	bool _positionInited = false;
 | 
			
		||||
 | 
			
		||||
	std::unique_ptr<Window::Controller> _controller;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue