Skip to content

Commit

Permalink
mainwindow.cpp: only pass event to view if not in focus
Browse files Browse the repository at this point in the history
Since both MainWindow and the view have the StrongFocus policy, if the
view has the focus then the view is already receiving the keyPressEvent
and the keyReleaseEvent from the Qt Engine, in that case the MainWindow
shouldn't send the keyPressEvent or the keyReleaseEvent to the view,
since MainWindow does that, then the view gets a double report of that
event. However if the view does not have focus, and if the MainWindow
does, it should send the event to the view, including in the case where
hotkeys are disabled in the MainWindow.

In addition to that view == view->page()->view() so we don't need to set
StrongFocus policy for both of those views since they are in fact the
same.
  • Loading branch information
HED-jzignego committed Jan 24, 2022
1 parent 5c7500b commit 9295bc9
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ void MainWindow::init(AnyOption *opts)
// Window show, start events loop
show();

view->page()->view()->setFocusPolicy(Qt::StrongFocus);
view->setFocusPolicy(Qt::StrongFocus);

if (qwkSettings->getBool("view/hide_mouse_cursor")) {
Expand Down Expand Up @@ -449,19 +448,27 @@ void MainWindow::centerFixedSizeWindow()

void MainWindow::keyPressEvent(QKeyEvent *event)
{
qDebug(">> MainWindow received keyPressEvent...");

if (qwkSettings->getUInt("browser/disable_hotkeys")) {
QMainWindow::keyPressEvent(event);
if (! view->hasFocus()) {
view->event(event);
}
return;
}

switch (event->key()) {
case Qt::Key_Up:
view->scrollUp();
view->event(event);
if (! view->hasFocus()) {
view->event(event);
}
break;
case Qt::Key_Down:
view->scrollDown();
view->event(event);
if (! view->hasFocus()) {
view->event(event);
}
break;
case Qt::Key_PageUp:
view->scrollPageUp();
Expand Down Expand Up @@ -490,12 +497,18 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
clearCacheOnExit();
QApplication::exit(0);
}
else if (! view->hasFocus()) {
view->event(event);
}
break;
case Qt::Key_R:
if (int(event->modifiers()) == Qt::CTRL) {
clearCache();
view->reload();
}
else if (! view->hasFocus()) {
view->event(event);
}
break;
case Qt::Key_F5:
view->reload();
Expand All @@ -520,14 +533,20 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
}
break;
default:
view->event(event);
if (! view->hasFocus()) {
view->event(event);
}
break;
}
}

void MainWindow::keyReleaseEvent(QKeyEvent *event)
{
view->event(event);
qDebug(">> MainWindow received keyReleaseEvent...");

if (! view->hasFocus()) {
view->event(event);
}
}

void MainWindow::handleQwkNetworkError(QNetworkReply::NetworkError error, QString message)
Expand Down

0 comments on commit 9295bc9

Please sign in to comment.