Focus the message input when the chat window is activated

This commit is contained in:
evgeny committed 2026-11-01 05:49:06 +01:00
1 parent 4e3c1182db
commit d8db018166
5 files changed
+86

No files matched your search

+20
View File
@@ -1361,6 +1361,26 @@ void MainWindow::showIncomingMessageNotification(const QString& target, quint64
m_messageNotification->showMessage(target, m_db->getDisplayName(author), channel, m_trayIcon->geometry(), screen());
}
void MainWindow::changeEvent(QEvent* event) {
QMainWindow::changeEvent(event);
if (event->type() != QEvent::ActivationChange || !isActiveWindow()) return;
QTimer::singleShot(0, this, [this] {
auto* input = m_messageList ? m_messageList->focusProxy() : nullptr;
const bool ready = input && input->isVisible() && input->isEnabled();
if (QApplication::activeWindow() != this || !isVisible() || isMinimized() ||
QApplication::activeModalWidget() || QApplication::activePopupWidget() || !ready) {
GUI_DEBUG("window activation: input focus skipped active=%d visible=%d minimized=%d modal=%d popup=%d input_ready=%d",
QApplication::activeWindow() == this, isVisible(), isMinimized(), bool(QApplication::activeModalWidget()),
bool(QApplication::activePopupWidget()), ready);
return;
}
m_messageList->setFocus(Qt::ActiveWindowFocusReason);
auto* focused = QApplication::focusWidget();
GUI_DEBUG("window activation: message input focused target=%s focus_widget=%s", qPrintable(m_currentChannelId),
focused ? focused->metaObject()->className() : "none");
});
}
void MainWindow::closeEvent(QCloseEvent *event) {
DEBUG_DEBUG(DEBUG_CATEGORY_GENERAL, "MainWindow: closeEvent — hiding to tray");
saveWindowGeometry();