aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/LuaRuntime.cpp4
-rw-r--r--src/LuaRuntime.hpp4
-rw-r--r--src/WindowActionRouter.cpp17
-rw-r--r--src/WindowActionRouter.hpp4
-rw-r--r--src/events.hpp12
-rw-r--r--src/main.cpp2
-rw-r--r--src/widgets/WebViewStack.cpp9
7 files changed, 27 insertions, 25 deletions
diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp
index d9bc86e..70301b4 100644
--- a/src/LuaRuntime.cpp
+++ b/src/LuaRuntime.cpp
@@ -111,10 +111,10 @@ int LuaRuntime::lua_event_register(lua_State *state) {
const int function_ref = luaL_ref(state, LUA_REGISTRYINDEX);
event.function_ref = function_ref;
// TODO: Delete ref on clear callback
- event.handler = [state, function_ref](BrowserEvent &event) {
+ event.handler = [state, function_ref](BrowserEvent *event) {
preserve_top(state, {
lua_rawgeti(state, LUA_REGISTRYINDEX, function_ref);
- event.lua_push(state);
+ event->lua_push(state);
lua_call(state, 1, 0);
})
};
diff --git a/src/LuaRuntime.hpp b/src/LuaRuntime.hpp
index 2b834aa..e73650c 100644
--- a/src/LuaRuntime.hpp
+++ b/src/LuaRuntime.hpp
@@ -91,8 +91,8 @@ public:
lua_settop(state, top);
}
- static std::vector<std::string> lua_tostringlist(lua_State *state) {
- std::vector<std::string> values;
+ static std::vector<QString> lua_tostringlist(lua_State *state) {
+ std::vector<QString> values;
if (!lua_istable(state, -1))
return values;
diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp
index 1cc39cb..e1d0664 100644
--- a/src/WindowActionRouter.cpp
+++ b/src/WindowActionRouter.cpp
@@ -10,19 +10,20 @@
#include "widgets/BrowserWindow.hpp"
#include "widgets/WebViewStack.hpp"
-void WindowActionRouter::dispatch_event(BrowserEvent &event) {
+void WindowActionRouter::dispatch_event(BrowserEvent *event) {
auto &runtime = LuaRuntime::instance();
- runtime.queue_task([this, &event]() {
- std::unordered_map<std::string, std::vector<EventHandlerRequest>> event_map;
+
+ runtime.queue_task([this, event]() {
+ std::unordered_map<QString, std::vector<EventHandlerRequest>> event_map;
{
const std::lock_guard<std::mutex> lock(events_mutex);
event_map = events;
}
- if (!event_map.contains(event.kind))
+ if (!event_map.contains(event->kind))
return;
- for (auto &event_handler : event_map.at(event.kind)) {
+ for (auto &event_handler : event_map.at(event->kind)) {
// TODO: Pattern filter
event_handler.handler(event);
}
@@ -39,12 +40,6 @@ void WindowActionRouter::register_event(const EventHandlerRequest &event) {
}
void WindowActionRouter::initialize() {
- UrlChangedEvent url_changed_event("https://googa.com", 2, 1);
- WindowActionRouter::instance().dispatch_event(url_changed_event);
-
- UrlChangedEvent url_changed_event_1("https://duckduckgo.com", 5, 1);
- WindowActionRouter::instance().dispatch_event(url_changed_event_1);
-
auto &runtime = LuaRuntime::instance();
connect(&runtime, &LuaRuntime::keymap_added, this,
diff --git a/src/WindowActionRouter.hpp b/src/WindowActionRouter.hpp
index 7e9f5d3..f7cb2b4 100644
--- a/src/WindowActionRouter.hpp
+++ b/src/WindowActionRouter.hpp
@@ -37,7 +37,7 @@ public:
WebViewId fetch_current_tab_id(WindowId win_id = 0);
QList<WebViewData> fetch_webview_data_list(WindowId win_id = 0);
- void dispatch_event(BrowserEvent &event);
+ void dispatch_event(BrowserEvent *event);
void register_event(const EventHandlerRequest &event);
protected:
@@ -56,5 +56,5 @@ private:
// TODO: Split event handling to its own class
std::mutex events_mutex;
- std::unordered_map<std::string, std::vector<EventHandlerRequest>> events;
+ std::unordered_map<QString, std::vector<EventHandlerRequest>> events;
};
diff --git a/src/events.hpp b/src/events.hpp
index 6d10fc7..96b9008 100644
--- a/src/events.hpp
+++ b/src/events.hpp
@@ -14,10 +14,10 @@
class BrowserEvent {
public:
- std::string kind = "-";
+ QString kind = "-";
virtual ~BrowserEvent() = default;
- virtual void lua_push(lua_State *state) { lua_newtable(state); };
+ virtual void lua_push(lua_State *state) const { lua_newtable(state); };
};
class UrlChangedEvent : public BrowserEvent {
@@ -31,7 +31,7 @@ public:
kind = "UrlChanged";
}
- void lua_push(lua_State *state) override {
+ void lua_push(lua_State *state) const override {
lua_newtable(state);
SET_FIELD("tab", integer, webview_id)
SET_FIELD("win", integer, win_id)
@@ -40,8 +40,8 @@ public:
};
struct EventHandlerRequest {
- std::vector<std::string> event_names;
- std::vector<std::string> patterns;
- std::function<void(BrowserEvent &)> handler;
+ std::vector<QString> event_names;
+ std::vector<QString> patterns;
+ std::function<void(BrowserEvent *)> handler;
int function_ref;
};
diff --git a/src/main.cpp b/src/main.cpp
index ac0cedd..03fc0d8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -44,8 +44,6 @@ int main(int argc, char *argv[]) {
auto urls = parser->positionalArguments();
auto lua_expr = parser->value("expr");
- qDebug() << urls;
- qDebug() << lua_expr;
if (!urls.isEmpty() || lua_expr.isEmpty())
instance_manager.write_open_urls_to_socket(urls);
diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp
index 10aa6b8..9b7af78 100644
--- a/src/widgets/WebViewStack.cpp
+++ b/src/widgets/WebViewStack.cpp
@@ -4,8 +4,11 @@
#include <QWebEngineProfile>
#include <cstdint>
#include <cstdlib>
+#include <memory>
#include <vector>
+#include "WindowActionRouter.hpp"
+#include "events.hpp"
#include "widgets/WebViewStack.hpp"
static WebViewId next_webview_id = 1;
@@ -49,6 +52,12 @@ WebView *WebViewStack::create_new_webview(const QUrl &url, bool focus) {
connect(webview->page(), &QWebEnginePage::newWindowRequested, this,
&WebViewStack::on_new_webview_request);
+ connect(webview->page(), &QWebEnginePage::urlChanged, this,
+ [webview](const QUrl &url) {
+ // TODO: Add window id
+ WindowActionRouter::instance().dispatch_event(
+ new UrlChangedEvent(url.toString(), webview->get_id(), 0));
+ });
if (focus)
focus_webview(webview->get_id());