diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-18 20:52:36 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-18 20:52:36 +0530 |
| commit | 056b0b16947ac19a0c425aa9d2ff8f589378d3bc (patch) | |
| tree | d062dc2de09711c1f7e980fc8475c19a97ff7d99 /src/widgets/MainWindow.cpp | |
| parent | dd6590a0fda614fa2fb0ca9e4ad11b086393372e (diff) | |
| download | null-browser-056b0b16947ac19a0c425aa9d2ff8f589378d3bc.tar.gz null-browser-056b0b16947ac19a0c425aa9d2ff8f589378d3bc.zip | |
Add keymap evaluation with strict event filter
Diffstat (limited to '')
| -rw-r--r-- | src/widgets/MainWindow.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/widgets/MainWindow.cpp b/src/widgets/MainWindow.cpp index d2b1578..7d045bc 100644 --- a/src/widgets/MainWindow.cpp +++ b/src/widgets/MainWindow.cpp @@ -1,8 +1,9 @@ #include <QKeyEvent> #include <QStackedLayout> #include <QVBoxLayout> -#include <QWebEngineView> +#include <QtCore/qcoreevent.h> #include <QtCore/qnamespace.h> +#include <QtWidgets/qapplication.h> #include "InputMediator.hpp" #include "widgets/InputLine.hpp" @@ -13,6 +14,8 @@ MainWindow::MainWindow() { setStyleSheet("background-color: #000; color: #fff;"); setCentralWidget(new QWidget()); // TODO: manage widget memory + qApp->installEventFilter(this); + // Root stacked layout auto layout = new QStackedLayout(); layout->setContentsMargins(0, 0, 0, 0); @@ -31,6 +34,9 @@ MainWindow::MainWindow() { inputMediator = new InputMediator(inputLine, webViewStack, LuaRuntime::instance()); + + keymapEvaluator.addKeymap("default", "<c-t>a", "Stuff"); + keymapEvaluator.addKeymap("default", "<c-t>b", "Other stuff"); } void MainWindow::keyPressEvent(QKeyEvent *event) { @@ -57,3 +63,19 @@ void MainWindow::keyPressEvent(QKeyEvent *event) { inputMediator->closeCurrentWebView(); } } + +bool MainWindow::eventFilter(QObject *object, QEvent *event) { + if (event->type() != QEvent::KeyPress && event->type() != QEvent::KeyRelease) + return false; + + if (auto keyEvent = dynamic_cast<QKeyEvent *>(event)) { + if (keyEvent->type() == QEvent::KeyPress) + keymapEvaluator.evaluate(keyEvent->modifiers(), (Qt::Key)keyEvent->key()); + + // qDebug() << "EV SELF: " << (object == this) << " | " << event->type(); + // qDebug() << "Key: " << keyEvent->modifiers() << keyEvent->key(); + return true; + } + + return false; +} |
