diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-07-27 16:17:21 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-07-27 19:46:01 +0530 |
| commit | c95ee83c24b79e64a91a6d3a55addcb6e7ebd11b (patch) | |
| tree | 1289227e74d6ec955ec039c2a35d8660b0e0533f | |
| parent | 72a47c4eecb31a4976bfd4c47a36cd0ab9811a55 (diff) | |
| download | null-browser-c95ee83c24b79e64a91a6d3a55addcb6e7ebd11b.tar.gz null-browser-c95ee83c24b79e64a91a6d3a55addcb6e7ebd11b.zip | |
Add viewselected/closed/created events
| -rw-r--r-- | lua/null-browser/extras/statusline.lua | 2 | ||||
| -rw-r--r-- | lua/null-browser/extras/tabline.lua | 2 | ||||
| -rw-r--r-- | src/events/ViewClosedEvent.hpp | 24 | ||||
| -rw-r--r-- | src/events/ViewCreatedEvent.hpp | 24 | ||||
| -rw-r--r-- | src/events/ViewSelectedEvent.hpp | 24 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 13 |
6 files changed, 87 insertions, 2 deletions
diff --git a/lua/null-browser/extras/statusline.lua b/lua/null-browser/extras/statusline.lua index 6dd70ba..f70ff37 100644 --- a/lua/null-browser/extras/statusline.lua +++ b/lua/null-browser/extras/statusline.lua @@ -38,7 +38,7 @@ function statusline.show_status_in_window(win_id, decoration) show_statusline() end end) - web.event.add_listener({ 'ModeChanged', 'UrlChanged' }, { + web.event.add_listener({ 'ModeChanged', 'UrlChanged', 'ViewSelected', 'ViewClosed', 'ViewCreated' }, { callback = function(_) show_statusline() end, }) end diff --git a/lua/null-browser/extras/tabline.lua b/lua/null-browser/extras/tabline.lua index 4548207..b9156f5 100644 --- a/lua/null-browser/extras/tabline.lua +++ b/lua/null-browser/extras/tabline.lua @@ -23,7 +23,7 @@ function tabline.init(opts) end function tabline.show_tabs_in_window(win_id, decoration) - web.event.add_listener('UrlChanged', { + web.event.add_listener({ 'UrlChanged', 'ViewSelected', 'ViewCreated', 'ViewClosed' }, { callback = function() if not decoration.is_enabled({ win = win_id }) then return end diff --git a/src/events/ViewClosedEvent.hpp b/src/events/ViewClosedEvent.hpp new file mode 100644 index 0000000..905159e --- /dev/null +++ b/src/events/ViewClosedEvent.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <QtCore> +#include <lua.hpp> + +#include "WebViewData.hpp" +#include "events/Event.hpp" +#include "widgets/BrowserWindow.hpp" + +class ViewClosedEvent : public Event { +public: + const WebViewId view_id; + const WindowId win_id; + + ViewClosedEvent(WebViewId view_id, WindowId win_id) : view_id(view_id), win_id(win_id) { + kind = "ViewClosed"; + } + + void lua_push(lua_State *state) const override { + Event::lua_push(state); + SET_FIELD("view", integer, view_id) + SET_FIELD("win", integer, win_id) + } +}; diff --git a/src/events/ViewCreatedEvent.hpp b/src/events/ViewCreatedEvent.hpp new file mode 100644 index 0000000..10126c9 --- /dev/null +++ b/src/events/ViewCreatedEvent.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <QtCore> +#include <lua.hpp> + +#include "WebViewData.hpp" +#include "events/Event.hpp" +#include "widgets/BrowserWindow.hpp" + +class ViewCreatedEvent : public Event { +public: + const WebViewId view_id; + const WindowId win_id; + + ViewCreatedEvent(WebViewId view_id, WindowId win_id) : view_id(view_id), win_id(win_id) { + kind = "ViewCreated"; + } + + void lua_push(lua_State *state) const override { + Event::lua_push(state); + SET_FIELD("view", integer, view_id) + SET_FIELD("win", integer, win_id) + } +}; diff --git a/src/events/ViewSelectedEvent.hpp b/src/events/ViewSelectedEvent.hpp new file mode 100644 index 0000000..fe8dd40 --- /dev/null +++ b/src/events/ViewSelectedEvent.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <QtCore> +#include <lua.hpp> + +#include "WebViewData.hpp" +#include "events/Event.hpp" +#include "widgets/BrowserWindow.hpp" + +class ViewSelectedEvent : public Event { +public: + const WebViewId view_id; + const WindowId win_id; + + ViewSelectedEvent(WebViewId view_id, WindowId win_id) : view_id(view_id), win_id(win_id) { + kind = "ViewSelected"; + } + + void lua_push(lua_State *state) const override { + Event::lua_push(state); + SET_FIELD("view", integer, view_id) + SET_FIELD("win", integer, win_id) + } +}; diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index 9ec8570..0ed2399 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -12,6 +12,9 @@ #include "WindowActionRouter.hpp" #include "events/PermissionRequestedEvent.hpp" #include "events/UrlChangedEvent.hpp" +#include "events/ViewClosedEvent.hpp" +#include "events/ViewCreatedEvent.hpp" +#include "events/ViewSelectedEvent.hpp" #include "widgets/WebViewStack.hpp" @@ -74,6 +77,10 @@ WebView *WebViewStack::create_new_webview(const QUrl &url, bool focus) { emit current_webview_title_changed(layout->currentIndex()); + // TODO: Add window id + auto *event = new ViewCreatedEvent(webview->get_id(), 0); + WindowActionRouter::instance().dispatch_event(event); + return webview; } @@ -152,6 +159,9 @@ void WebViewStack::close(WebViewId webview_id) { create_new_webview(configuration->new_view_url(), true); } } + + auto *event = new ViewClosedEvent(webview_id, 0); + WindowActionRouter::instance().dispatch_event(event); } void WebViewStack::webview_history_back(WebViewId webview_id, qsizetype history_index) { @@ -209,6 +219,9 @@ void WebViewStack::focus_webview(WebViewId webview_id) { auto webview_index = get_webview_index(webview_id); if (webview_index >= 0) layout->setCurrentIndex((int)webview_index); + + auto *event = new ViewSelectedEvent(webview_id, 0); + WindowActionRouter::instance().dispatch_event(event); } void WebViewStack::open_devtools(WebViewId webview_id) { |
