diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-04-05 19:07:03 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-04-05 19:07:03 +0530 |
| commit | 26504893e75fb33e9d3f01abdebf1d61f362f1b1 (patch) | |
| tree | 2610afb45431ddb53e43161214cb1feaa4f0dd99 | |
| parent | f682527b2f81376ca462d14bcbaae9e0ce77561d (diff) | |
| download | null-browser-26504893e75fb33e9d3f01abdebf1d61f362f1b1.tar.gz null-browser-26504893e75fb33e9d3f01abdebf1d61f362f1b1.zip | |
Set url for windows synchronously + handle title change in webview
Diffstat (limited to '')
| -rw-r--r-- | TODO.org | 28 | ||||
| -rw-r--r-- | src/widgets/BrowserWindow.cpp | 27 | ||||
| -rw-r--r-- | src/widgets/BrowserWindow.hpp | 1 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 11 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.hpp | 2 |
5 files changed, 41 insertions, 28 deletions
@@ -18,28 +18,36 @@ - [X] Url changed event - [X] History storage - [X] History completion +- [ ] Close window if last tab closed +- [ ] Switch to __internals +- [ ] Tests for api - [ ] Log stdout, errors and results from lua somewhere - [ ] Downloading ** Next +- [ ] Search text in page +- [ ] Dev tools +- [ ] Fullscreen +- [ ] Zoom in/out +- [ ] Permission requests handling/persisting +- [ ] window.opener controls +- [ ] Notifications - [ ] Conflict in keymap (keymap already exists) +- [ ] Allow pattern filtering for event listeners +- [ ] Allow tab_id, win_id filtering for event listeners +- [ ] Handle resource cleanup + signal disconnecting - [ ] Open url sanitize/humanize (add protocol if missing, remove quotes, etc) +- [ ] static linking for qt +- [ ] static linking for libluv - [ ] Bookmarking -- [ ] Get static linking for qt and libluv working -- [ ] Handle resource cleanup + signal disconnecting ** Later - [ ] Support multiple modes for keymap.set: `web.keymap.set({'n','i'}, ...)` -- [ ] Search text in page -- [ ] Notifications -- [ ] Dev tools -- [ ] Permission requests handling -- [ ] Pipe page contents to external program -- [ ] `web.inspect` -- [ ] Update window title on current webview title change +- [ ] Read page contents via lua +- [ ] `web.to_string`: like vim.inspect +- [X] Update window title on current webview title change ** Later later -- [ ] Fullscreen - [ ] Custom file picker - [ ] remote debugging with cdp (spider-repl) diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp index ff05b0e..2867379 100644 --- a/src/widgets/BrowserWindow.cpp +++ b/src/widgets/BrowserWindow.cpp @@ -4,7 +4,6 @@ #include <QtCore> #include "Configuration.hpp" -#include "LuaRuntime.hpp" #include "WindowMediator.hpp" #include "keymap/KeymapEvaluator.hpp" #include "widgets/BrowserWindow.hpp" @@ -22,9 +21,19 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, const QStringLi centralWidget()->setLayout(layout); // Web engine - auto *web_view_stack = new WebViewStack(&configuration, new QWebEngineProfile("null-browser")); - layout->addWidget(web_view_stack); + auto *webview_stack = new WebViewStack(&configuration, new QWebEngineProfile("null-browser")); + layout->addWidget(webview_stack); + // Open webviews for given urls + if (urls.isEmpty()) { + webview_stack->open_url(configuration.new_tab_url.toString(), OpenType::OpenUrlInTab); + } else { + for (const auto &url : urls) { + webview_stack->open_url(url, OpenType::OpenUrlInTab); + } + } + + // Default keymaps auto &keymap_evaluator = KeymapEvaluator::instance(); // TODO: remove @@ -36,22 +45,16 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, const QStringLi }); keymap_evaluator.add_keymap(KeyMode::Normal, "<c-t>a", []() { qDebug() << "Stuff"; }); - win_mediator = new WindowMediator(web_view_stack); + win_mediator = new WindowMediator(webview_stack); - connect(web_view_stack, &WebViewStack::current_webview_changed, this, [this](int index) { + // Update window title when webview changes + connect(webview_stack, &WebViewStack::current_webview_title_changed, this, [this](int index) { auto webviews = win_mediator->get_webview_list(); if (index >= 0 && index < webviews.count()) { const auto &webview = webviews.at(index); setWindowTitle(webview.title); } }); - - auto &lua = LuaRuntime::instance(); - lua.queue_task([this, urls]() { - for (const auto &url : urls) { - emit win_mediator->url_opened(url, OpenType::OpenUrlInTab, 0); - } - }); } void BrowserWindow::closeEvent(QCloseEvent * /*event*/) { emit closed(); } diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp index e657970..638d8de 100644 --- a/src/widgets/BrowserWindow.hpp +++ b/src/widgets/BrowserWindow.hpp @@ -24,7 +24,6 @@ public: signals: void closed(); - // void new_window_requested(const QUrl &url); private: WindowMediator *win_mediator; diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index 5134101..f5e9765 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -19,9 +19,8 @@ WebViewStack::WebViewStack(const Configuration *configuration, QWebEngineProfile layout->setContentsMargins(0, 0, 0, 0); layout->setStackingMode(QStackedLayout::StackOne); - connect(layout, &QStackedLayout::currentChanged, this, &WebViewStack::current_webview_changed); - - create_new_webview(configuration->new_tab_url, true); + connect(layout, &QStackedLayout::currentChanged, this, + &WebViewStack::current_webview_title_changed); } void WebViewStack::open_url(const QUrl &url, OpenType open_type, WebViewId webview_id) { @@ -54,11 +53,15 @@ WebView *WebViewStack::create_new_webview(const QUrl &url, bool focus) { WindowActionRouter::instance().dispatch_event( new UrlChangedEvent(url.toString(), webview->get_id(), 0)); }); + connect(webview->page(), &QWebEnginePage::titleChanged, this, + [this](const QString & /* title */) { + emit current_webview_title_changed(layout->currentIndex()); + }); if (focus) focus_webview(webview->get_id()); - emit current_webview_changed(layout->currentIndex()); + emit current_webview_title_changed(layout->currentIndex()); return webview; } diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp index 5d09aaf..23b9382 100644 --- a/src/widgets/WebViewStack.hpp +++ b/src/widgets/WebViewStack.hpp @@ -45,7 +45,7 @@ public: uint32_t current_webview_index(); signals: - void current_webview_changed(int index); + void current_webview_title_changed(int index); void new_window_requested(const QUrl &url); protected: |
