aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/events/KeyPressedEvent.hpp25
-rw-r--r--src/widgets/BrowserApp.cpp2
-rw-r--r--src/widgets/BrowserWindow.cpp12
-rw-r--r--src/widgets/BrowserWindow.hpp2
4 files changed, 38 insertions, 3 deletions
diff --git a/src/events/KeyPressedEvent.hpp b/src/events/KeyPressedEvent.hpp
new file mode 100644
index 0000000..8c7ded1
--- /dev/null
+++ b/src/events/KeyPressedEvent.hpp
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <QtCore>
+#include <lua.hpp>
+#include <qevent.h>
+
+#include "events/Event.hpp"
+
+class KeyPressedEvent : public Event {
+public:
+ const QString key;
+
+ KeyPressedEvent(QString key) : key(std::move(key)) { kind = "KeyPressed"; }
+
+ static KeyPressedEvent *from_qkeyevent(QKeyEvent *qevent) {
+ // TODO: Using with modifiers
+ auto *event = new KeyPressedEvent(qevent->text());
+ return event;
+ }
+
+ void lua_push(lua_State *state) const override {
+ Event::lua_push(state);
+ SET_FIELD("key", string, key.toStdString().c_str())
+ }
+};
diff --git a/src/widgets/BrowserApp.cpp b/src/widgets/BrowserApp.cpp
index d6f274b..c3c2313 100644
--- a/src/widgets/BrowserApp.cpp
+++ b/src/widgets/BrowserApp.cpp
@@ -84,7 +84,7 @@ bool BrowserApp::eventFilter(QObject *target, QEvent *event) {
if (auto *target_widget = dynamic_cast<QWidget *>(target); win->isAncestorOf(target_widget)) {
auto *key_event = static_cast<QKeyEvent *>(event);
- const bool should_skip = win->on_window_key_event(key_event);
+ const bool should_skip = win->on_window_key_event(target, key_event);
return should_skip;
}
}
diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp
index 1971b9c..7852a66 100644
--- a/src/widgets/BrowserWindow.cpp
+++ b/src/widgets/BrowserWindow.cpp
@@ -4,9 +4,13 @@
#include <QStackedLayout>
#include <QVBoxLayout>
#include <QtCore>
+#include <qcoreevent.h>
#include "Configuration.hpp"
+#include "WindowActionRouter.hpp"
+#include "events/KeyPressedEvent.hpp"
#include "keymap/KeymapEvaluator.hpp"
+#include "widgets/BrowserApp.hpp"
#include "widgets/Decorations.hpp"
#include "widgets/WebViewStack.hpp"
@@ -52,10 +56,16 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, QWebEngineProfi
&BrowserWindow::close_window_requested);
}
-bool BrowserWindow::on_window_key_event(QKeyEvent *event) {
+bool BrowserWindow::on_window_key_event(QObject *target, QKeyEvent *event) {
auto &keymap_evaluator = KeymapEvaluator::instance();
const bool should_skip = keymap_evaluator.evaluate(event->modifiers(), (Qt::Key)event->key());
+ // TODO: Fix this logic to find the right "target" for event
+ if (event->type() == QEvent::KeyPress && dynamic_cast<WebView *>(target->parent())) {
+ auto *lua_event = KeyPressedEvent::from_qkeyevent(event);
+ WindowActionRouter::instance().dispatch_event(lua_event);
+ }
+
return should_skip;
}
diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp
index 2ea7b88..bc6cea1 100644
--- a/src/widgets/BrowserWindow.hpp
+++ b/src/widgets/BrowserWindow.hpp
@@ -41,7 +41,7 @@ public:
void run_javascript(const QString &js_code, WebViewId webview_id);
void expose_rpc_function(const QString &name, const RpcFunc &action, WebViewId webview_id);
- bool on_window_key_event(QKeyEvent *event);
+ bool on_window_key_event(QObject *target, QKeyEvent *event);
void closeEvent(QCloseEvent * /*event*/) override { emit closed(); };