diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 97a2040e2..2a3b7d286 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "src/misc/smileypack.h" #include "src/widget/emoticonswidget.h" @@ -240,6 +241,23 @@ void GenericChatForm::show(Ui::MainWindow &ui) QWidget::show(); } +void GenericChatForm::showEvent(QShowEvent *) +{ + msgEdit->setFocus(); +} + +bool GenericChatForm::event(QEvent* e) +{ + // If the user accidentally starts typing outside of the msgEdit, focus it automatically + if (e->type() == QEvent::KeyRelease && !msgEdit->hasFocus()) + { + QKeyEvent* ke = static_cast(e); + if (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier) + msgEdit->setFocus(); + } + return QWidget::event(e); +} + void GenericChatForm::onChatContextMenuRequested(QPoint pos) { QWidget* sender = (QWidget*)QObject::sender(); diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 34f914c90..87a07109f 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -87,6 +87,8 @@ protected: QString resolveToxId(const ToxId &id); void insertChatMessage(ChatMessage::Ptr msg); void hideEvent(QHideEvent* event); + void showEvent(QShowEvent *); + bool event(QEvent *); void resizeEvent(QResizeEvent* event); void adjustFileMenuPosition();