aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-04-05 19:07:03 +0530
committerAkshay Nair <phenax5@gmail.com>2025-04-05 19:07:03 +0530
commit26504893e75fb33e9d3f01abdebf1d61f362f1b1 (patch)
tree2610afb45431ddb53e43161214cb1feaa4f0dd99 /src
parentf682527b2f81376ca462d14bcbaae9e0ce77561d (diff)
downloadnull-browser-26504893e75fb33e9d3f01abdebf1d61f362f1b1.tar.gz
null-browser-26504893e75fb33e9d3f01abdebf1d61f362f1b1.zip
Set url for windows synchronously + handle title change in webview
Diffstat (limited to 'src')
-rw-r--r--src/widgets/BrowserWindow.cpp27
-rw-r--r--src/widgets/BrowserWindow.hpp1
-rw-r--r--src/widgets/WebViewStack.cpp11
-rw-r--r--src/widgets/WebViewStack.hpp2
4 files changed, 23 insertions, 18 deletions
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: