aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-30 19:16:07 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-30 19:16:37 +0530
commit4f945367ebc8e34263acbfca0416e3f75653924e (patch)
treeaff34361a2b2160aea284df9b619193917bcbc88
parente690963fb6c0240171236fc2d669f95ee26b6798 (diff)
downloadnull-browser-4f945367ebc8e34263acbfca0416e3f75653924e.tar.gz
null-browser-4f945367ebc8e34263acbfca0416e3f75653924e.zip
Update window title on tab change + refactoring
Diffstat (limited to '')
-rw-r--r--TODO.org5
-rw-r--r--spec/LuaRuntimeSpec.cpp52
-rw-r--r--src/LuaRuntime.cpp36
-rw-r--r--src/LuaRuntime.hpp6
-rw-r--r--src/WindowActionRouter.cpp71
-rw-r--r--src/WindowActionRouter.hpp14
-rw-r--r--src/WindowMediator.cpp5
-rw-r--r--src/keymap/KeymapEvaluator.hpp4
-rw-r--r--src/widgets/BrowserApp.cpp14
-rw-r--r--src/widgets/BrowserWindow.cpp48
-rw-r--r--src/widgets/BrowserWindow.hpp6
-rw-r--r--src/widgets/WebViewStack.cpp6
-rw-r--r--src/widgets/WebViewStack.hpp3
13 files changed, 144 insertions, 126 deletions
diff --git a/TODO.org b/TODO.org
index f308e22..bee6eb2 100644
--- a/TODO.org
+++ b/TODO.org
@@ -11,12 +11,12 @@
- [X] Assign ID to each tab (reference in lua api)
- [X] Tab select by id
- [X] Multi-window
-- [ ] Handle resource cleanup + signal disconnecting
- [ ] Socket for opening window in current session (lua eval)
-- [ ] Log stdout, errors and results from lua somewhere
- [ ] Events/autocommands
- [ ] History storage
- [ ] History completion
+- [ ] Log stdout, errors and results from lua somewhere
+- [ ] Handle resource cleanup + signal disconnecting
** Next
- [ ] Config loading and runtime path
@@ -33,6 +33,7 @@
- [ ] Permission requests handling
- [ ] Pipe page contents to external program
- [ ] `web.inspect`
+- [ ] Update window title on current webview title change
** Later later
- [ ] Fullscreen
diff --git a/spec/LuaRuntimeSpec.cpp b/spec/LuaRuntimeSpec.cpp
index 4d89f30..b5dd914 100644
--- a/spec/LuaRuntimeSpec.cpp
+++ b/spec/LuaRuntimeSpec.cpp
@@ -9,21 +9,21 @@ class LuaRuntimeSpec : public QObject {
Q_OBJECT
private slots:
- void beforeTestCase() { LuaRuntime::instance()->start_event_loop(); }
+ void beforeTestCase() { LuaRuntime::instance().start_event_loop(); }
void cleanupTestCase() {
- LuaRuntime::instance()->stop_event_loop();
+ LuaRuntime::instance().stop_event_loop();
uv_library_shutdown();
}
void test_evaluate() {
context("when given an expression returning a number");
it("emits evaluation_completed with the result") {
- auto *lua = LuaRuntime::instance();
- QSignalSpy evaluation_completed_spy(lua,
+ auto &lua = LuaRuntime::instance();
+ QSignalSpy evaluation_completed_spy(&lua,
&LuaRuntime::evaluation_completed);
- lua->evaluate("return 20 + 1 * 5");
+ lua.evaluate("return 20 + 1 * 5");
evaluation_completed_spy.wait();
QCOMPARE(evaluation_completed_spy.count(), 1);
@@ -33,11 +33,11 @@ private slots:
context("when given an expression returning a string");
it("emits evaluation_completed with the result") {
- auto *lua = LuaRuntime::instance();
- QSignalSpy evaluation_completed_spy(lua,
+ auto &lua = LuaRuntime::instance();
+ QSignalSpy evaluation_completed_spy(&lua,
&LuaRuntime::evaluation_completed);
- lua->evaluate("local name = 'world'; return 'hello ' .. name");
+ lua.evaluate("local name = 'world'; return 'hello ' .. name");
evaluation_completed_spy.wait();
QCOMPARE(evaluation_completed_spy.count(), 1);
@@ -47,11 +47,11 @@ private slots:
context("when given an expression returning a boolean");
it("emits evaluation_completed with the result") {
- auto *lua = LuaRuntime::instance();
- QSignalSpy evaluation_completed_spy(lua,
+ auto &lua = LuaRuntime::instance();
+ QSignalSpy evaluation_completed_spy(&lua,
&LuaRuntime::evaluation_completed);
- lua->evaluate("local num = 5; return 5 == num");
+ lua.evaluate("local num = 5; return 5 == num");
evaluation_completed_spy.wait();
QCOMPARE(evaluation_completed_spy.count(), 1);
@@ -61,11 +61,11 @@ private slots:
context("when given an expression returning nil");
it("emits evaluation_completed with the result") {
- auto *lua = LuaRuntime::instance();
- QSignalSpy evaluation_completed_spy(lua,
+ auto &lua = LuaRuntime::instance();
+ QSignalSpy evaluation_completed_spy(&lua,
&LuaRuntime::evaluation_completed);
- lua->evaluate("return nil");
+ lua.evaluate("return nil");
QVERIFY(evaluation_completed_spy.wait());
QCOMPARE(evaluation_completed_spy.count(), 1);
@@ -77,10 +77,10 @@ private slots:
void test_queue_task() {
context("when task is queued");
it("evaluates task asynchronously") {
- auto *lua = LuaRuntime::instance();
+ auto &lua = LuaRuntime::instance();
bool was_task_called = false;
- lua->queue_task([&was_task_called]() { was_task_called = true; });
+ lua.queue_task([&was_task_called]() { was_task_called = true; });
QVERIFY(NOT was_task_called);
QVERIFY(
@@ -92,11 +92,11 @@ private slots:
void test_sanity_check_uv_timer() {
context("when a 1 second timer is set");
it("calls callback after 1 second") {
- auto *lua = LuaRuntime::instance();
- QSignalSpy evaluation_completed_spy(lua,
+ auto &lua = LuaRuntime::instance();
+ QSignalSpy evaluation_completed_spy(&lua,
&LuaRuntime::evaluation_completed);
- lua->evaluate(R"(
+ lua.evaluate(R"(
_G.was_timer_called = false;
local timer = uv.new_timer();
timer:start(1000, 0, function()
@@ -105,31 +105,31 @@ private slots:
end)
)");
QVERIFY(evaluation_completed_spy.wait());
- QVERIFY(NOT lua->evaluate_sync("return _G.was_timer_called").toBool());
+ QVERIFY(NOT lua.evaluate_sync("return _G.was_timer_called").toBool());
QVERIFY(QTest::qWaitFor([&lua]() {
- return lua->evaluate_sync("return _G.was_timer_called").toBool();
+ return lua.evaluate_sync("return _G.was_timer_called").toBool();
}));
}
}
void test_sanity_check_uv_spawn() {
it("calls exit callback when process exists") {
- auto *lua = LuaRuntime::instance();
- QSignalSpy evaluation_completed_spy(lua,
+ auto &lua = LuaRuntime::instance();
+ QSignalSpy evaluation_completed_spy(&lua,
&LuaRuntime::evaluation_completed);
- lua->evaluate(R"(
+ lua.evaluate(R"(
_G.spawn_exit_code = -1;
local handle, pid = uv.spawn('ls', {}, function(code)
_G.spawn_exit_code = code;
end)
)");
QVERIFY(evaluation_completed_spy.wait());
- QCOMPARE(lua->evaluate_sync("return _G.spawn_exit_code").toInt(), -1);
+ QCOMPARE(lua.evaluate_sync("return _G.spawn_exit_code").toInt(), -1);
QVERIFY(QTest::qWaitFor([&lua]() {
- return 0 == lua->evaluate_sync("return _G.spawn_exit_code").toInt();
+ return 0 == lua.evaluate_sync("return _G.spawn_exit_code").toInt();
}));
}
}
diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp
index 2e711cb..37349b0 100644
--- a/src/LuaRuntime.cpp
+++ b/src/LuaRuntime.cpp
@@ -135,15 +135,15 @@ QVariant LuaRuntime::get_lua_value(int idx, QVariant default_value) {
int LuaRuntime::lua_open_url(lua_State *state) {
const char *url = lua_tostring(state, 1);
WebViewId tab_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2);
- auto *runtime = LuaRuntime::instance();
- emit runtime->url_opened(url, OpenType::OpenUrl, tab_id);
+ auto &runtime = LuaRuntime::instance();
+ emit runtime.url_opened(url, OpenType::OpenUrl, tab_id);
return 1;
}
int LuaRuntime::lua_tab_create(lua_State *state) {
const char *url = luaL_optstring(state, 1, "");
- auto *runtime = LuaRuntime::instance();
- emit runtime->url_opened(url, OpenType::OpenUrlInTab, 0);
+ auto &runtime = LuaRuntime::instance();
+ emit runtime.url_opened(url, OpenType::OpenUrlInTab, 0);
return 1;
}
@@ -164,22 +164,22 @@ int LuaRuntime::lua_keymap_set(lua_State *state) {
};
// TODO: Cleanup function ref on after keymap clear
- auto *runtime = LuaRuntime::instance();
- emit runtime->keymap_added(mode, keyseq, action);
+ auto &runtime = LuaRuntime::instance();
+ emit runtime.keymap_added(mode, keyseq, action);
return 1;
}
int LuaRuntime::lua_tab_current(lua_State *state) {
- auto *router = WindowActionRouter::instance();
- auto tab_id = router->fetch_current_tab_id();
+ auto &router = WindowActionRouter::instance();
+ auto tab_id = router.fetch_current_tab_id();
lua_pushinteger(state, tab_id);
return 1;
}
int LuaRuntime::lua_tab_list(lua_State *state) {
- auto *router = WindowActionRouter::instance();
- auto tabs = router->fetch_webview_data_list();
+ auto &router = WindowActionRouter::instance();
+ auto tabs = router.fetch_webview_data_list();
lua_newtable(state);
int index = 1; // 1-indexed
@@ -206,35 +206,35 @@ int LuaRuntime::lua_tab_list(lua_State *state) {
}
int LuaRuntime::lua_history_back(lua_State *state) {
- auto *runtime = LuaRuntime::instance();
+ auto &runtime = LuaRuntime::instance();
qsizetype history_index =
lua_isnoneornil(state, 1) ? 1 : lua_tointeger(state, 1);
WebViewId tab_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2);
- emit runtime->history_back_requested(tab_id, history_index);
+ emit runtime.history_back_requested(tab_id, history_index);
return 1;
}
int LuaRuntime::lua_history_forward(lua_State *state) {
- auto *runtime = LuaRuntime::instance();
+ auto &runtime = LuaRuntime::instance();
qsizetype history_index =
lua_isnoneornil(state, 1) ? 1 : lua_tointeger(state, 1);
WebViewId tab_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2);
- emit runtime->history_forward_requested(tab_id, history_index);
+ emit runtime.history_forward_requested(tab_id, history_index);
return 1;
}
int LuaRuntime::lua_tab_close(lua_State *state) {
- auto *runtime = LuaRuntime::instance();
+ auto &runtime = LuaRuntime::instance();
WebViewId tab_id = lua_isnoneornil(state, 1) ? 0 : lua_tointeger(state, 1);
- emit runtime->webview_closed(tab_id);
+ emit runtime.webview_closed(tab_id);
return 1;
}
@@ -242,9 +242,9 @@ int LuaRuntime::lua_tab_select(lua_State *state) {
if (lua_isnoneornil(state, 1))
return 1; // TODO: return nil (for others too)
- auto *runtime = LuaRuntime::instance();
+ auto &runtime = LuaRuntime::instance();
WebViewId tab_id = lua_tointeger(state, 1);
- emit runtime->webview_selected(tab_id);
+ emit runtime.webview_selected(tab_id);
return 1;
}
diff --git a/src/LuaRuntime.hpp b/src/LuaRuntime.hpp
index 4d69760..d2211df 100644
--- a/src/LuaRuntime.hpp
+++ b/src/LuaRuntime.hpp
@@ -20,9 +20,9 @@ class LuaRuntime : public QObject {
const char *web_global_name = "web";
public:
- static LuaRuntime *instance() {
- static LuaRuntime inst;
- return &inst;
+ static LuaRuntime &instance() {
+ static LuaRuntime runtime;
+ return runtime;
}
void evaluate(const QString &code);
diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp
index c04b330..1c5164e 100644
--- a/src/WindowActionRouter.cpp
+++ b/src/WindowActionRouter.cpp
@@ -7,58 +7,42 @@
#include "widgets/WebViewStack.hpp"
void WindowActionRouter::initialize() {
- auto *runtime = LuaRuntime::instance();
+ auto &runtime = LuaRuntime::instance();
- connect(runtime, &LuaRuntime::keymap_added, this,
+ connect(&runtime, &LuaRuntime::keymap_added, this,
&WindowActionRouter::add_keymap);
- connect(runtime, &LuaRuntime::history_back_requested, this,
+ connect(&runtime, &LuaRuntime::history_back_requested, this,
[this](WebViewId webview_id, qsizetype history_index) {
- for (auto &win : window_map) {
- auto *mediator = win.second->mediator();
- if (mediator->has_webview(webview_id)) {
- emit mediator->history_back_requested(webview_id,
- history_index);
- }
- }
+ WITH_WEBVIEW_WINDOW(webview_id, window, {
+ emit window->mediator()->history_back_requested(webview_id,
+ history_index);
+ });
});
- connect(runtime, &LuaRuntime::history_forward_requested, this,
+ connect(&runtime, &LuaRuntime::history_forward_requested, this,
[this](WebViewId webview_id, qsizetype history_index) {
- for (auto &win : window_map) {
- auto *mediator = win.second->mediator();
- if (mediator->has_webview(webview_id)) {
- emit mediator->history_forward_requested(webview_id,
- history_index);
- }
- }
+ WITH_WEBVIEW_WINDOW(webview_id, window, {
+ emit window->mediator()->history_forward_requested(webview_id,
+ history_index);
+ });
});
-
- connect(runtime, &LuaRuntime::url_opened, this,
+ connect(&runtime, &LuaRuntime::url_opened, this,
[this](const QString &url, OpenType open_type, WebViewId webview_id) {
- for (auto &win : window_map) {
- auto *mediator = win.second->mediator();
- if (mediator->has_webview(webview_id)) {
- emit mediator->url_opened(url, open_type, webview_id);
- }
- }
+ WITH_WEBVIEW_WINDOW(webview_id, window, {
+ emit window->mediator()->url_opened(url, open_type, webview_id);
+ });
});
- connect(runtime, &LuaRuntime::webview_closed, this,
+ connect(&runtime, &LuaRuntime::webview_closed, this,
[this](WebViewId webview_id) {
- for (auto &win : window_map) {
- auto *mediator = win.second->mediator();
- if (mediator->has_webview(webview_id)) {
- emit mediator->webview_closed(webview_id);
- }
- }
+ WITH_WEBVIEW_WINDOW(webview_id, window, {
+ emit window->mediator()->webview_closed(webview_id);
+ });
});
- connect(runtime, &LuaRuntime::webview_selected, this,
+ connect(&runtime, &LuaRuntime::webview_selected, this,
[this](WebViewId webview_id) {
- for (auto &win : window_map) {
- auto *mediator = win.second->mediator();
- if (mediator->has_webview(webview_id)) {
- emit mediator->webview_selected(webview_id);
- }
- }
+ WITH_WEBVIEW_WINDOW(webview_id, window, {
+ emit window->mediator()->webview_selected(webview_id);
+ });
});
}
@@ -77,10 +61,9 @@ const WindowMap &WindowActionRouter::windows() { return window_map; }
void WindowActionRouter::add_keymap(const QString &mode_string,
const QString &keyseq,
std::function<void()> action) {
- qDebug() << "ADD KEY" << mode_string << keyseq;
- auto *keymap_evaluator = KeymapEvaluator::instance();
- const KeyMode mode = keymap_evaluator->mode_from_string(mode_string);
- keymap_evaluator->add_keymap(mode, keyseq, std::move(action));
+ auto &keymap_evaluator = KeymapEvaluator::instance();
+ const KeyMode mode = keymap_evaluator.mode_from_string(mode_string);
+ keymap_evaluator.add_keymap(mode, keyseq, std::move(action));
}
WebViewId WindowActionRouter::fetch_current_tab_id(WindowId win_id) {
diff --git a/src/WindowActionRouter.hpp b/src/WindowActionRouter.hpp
index 9a5059b..384c76c 100644
--- a/src/WindowActionRouter.hpp
+++ b/src/WindowActionRouter.hpp
@@ -3,15 +3,25 @@
#include <QWidget>
#include <QtCore>
#include <cstdint>
+#include <functional>
#include "widgets/BrowserWindow.hpp"
+#include "widgets/WebViewStack.hpp"
+
+#define WITH_WEBVIEW_WINDOW(WEBVIEW_ID, IDENT, BLOCK) \
+ for (auto &win_match : window_map) { \
+ auto *IDENT = win_match.second; \
+ if (IDENT->mediator()->has_webview(WEBVIEW_ID)) { \
+ BLOCK; \
+ } \
+ }
class WindowActionRouter : public QWidget {
Q_OBJECT
public:
- static WindowActionRouter *instance() {
- static auto *router = new WindowActionRouter;
+ static WindowActionRouter &instance() {
+ static WindowActionRouter router;
return router;
}
diff --git a/src/WindowMediator.cpp b/src/WindowMediator.cpp
index 1e24173..df81f9f 100644
--- a/src/WindowMediator.cpp
+++ b/src/WindowMediator.cpp
@@ -20,4 +20,7 @@ WindowMediator::WindowMediator(WebViewStack *webview_stack)
&WebViewStack::focus_webview);
}
-WindowMediator::~WindowMediator() { delete webview_stack; }
+WindowMediator::~WindowMediator() {
+ disconnect(this);
+ delete webview_stack;
+}
diff --git a/src/keymap/KeymapEvaluator.hpp b/src/keymap/KeymapEvaluator.hpp
index f3ee791..34f4ae5 100644
--- a/src/keymap/KeymapEvaluator.hpp
+++ b/src/keymap/KeymapEvaluator.hpp
@@ -23,9 +23,9 @@ class KeymapEvaluator : public QObject {
public:
KeymapEvaluator() = default;
- static KeymapEvaluator *instance() {
+ static KeymapEvaluator &instance() {
static KeymapEvaluator keymap_evaluator;
- return &keymap_evaluator;
+ return keymap_evaluator;
}
void add_keymap(KeyMode mode, const QString &key, KeyAction action);
diff --git a/src/widgets/BrowserApp.cpp b/src/widgets/BrowserApp.cpp
index 13d855b..f2d541d 100644
--- a/src/widgets/BrowserApp.cpp
+++ b/src/widgets/BrowserApp.cpp
@@ -7,24 +7,24 @@
#include "widgets/BrowserWindow.hpp"
BrowserApp::BrowserApp() {
- auto *lua = LuaRuntime::instance();
- lua->start_event_loop();
+ auto &lua = LuaRuntime::instance();
+ lua.start_event_loop();
// Router init
- auto *router = WindowActionRouter::instance();
- router->initialize();
+ auto &router = WindowActionRouter::instance();
+ router.initialize();
// Global event filter
qApp->installEventFilter(this);
// NOTE: TMP
- LuaRuntime::instance()->load_file("./config.lua");
+ lua.load_file("./config.lua");
};
BrowserWindow *BrowserApp::create_window() {
auto *win = new BrowserWindow((const Configuration &)configuration);
- WindowActionRouter::instance()->add_window(win);
win->setWindowTitle("null-browser");
+ WindowActionRouter::instance().add_window(win);
win->show();
return win;
}
@@ -33,7 +33,7 @@ bool BrowserApp::eventFilter(QObject *target, QEvent *event) {
if (event->type() != QEvent::KeyPress)
return false;
- for (const auto &match : WindowActionRouter::instance()->windows()) {
+ for (const auto &match : WindowActionRouter::instance().windows()) {
auto *win = match.second;
if (auto *target_widget = dynamic_cast<QWidget *>(target);
diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp
index 886572e..e38f234 100644
--- a/src/widgets/BrowserWindow.cpp
+++ b/src/widgets/BrowserWindow.cpp
@@ -26,35 +26,47 @@ BrowserWindow::BrowserWindow(const Configuration &configuration)
new WebViewStack(&configuration, new QWebEngineProfile("null-browser"));
layout->addWidget(web_view_stack);
- auto *keymap_evaluator = KeymapEvaluator::instance();
+ auto &keymap_evaluator = KeymapEvaluator::instance();
// TODO: remove
- keymap_evaluator->add_keymap(KeyMode::Normal, "i", [keymap_evaluator]() {
- keymap_evaluator->set_current_mode(KeyMode::Insert);
+ keymap_evaluator.add_keymap(KeyMode::Normal, "i", [&keymap_evaluator]() {
+ keymap_evaluator.set_current_mode(KeyMode::Insert);
});
- keymap_evaluator->add_keymap(KeyMode::Insert, "<esc>", [keymap_evaluator]() {
- keymap_evaluator->set_current_mode(KeyMode::Normal);
+ keymap_evaluator.add_keymap(KeyMode::Insert, "<esc>", [&keymap_evaluator]() {
+ keymap_evaluator.set_current_mode(KeyMode::Normal);
});
- keymap_evaluator->add_keymap(KeyMode::Normal, "<c-t>a",
- []() { qDebug() << "Stuff"; });
+ keymap_evaluator.add_keymap(KeyMode::Normal, "<c-t>a",
+ []() { qDebug() << "Stuff"; });
- input_mediator = new WindowMediator(web_view_stack);
+ win_mediator = new WindowMediator(web_view_stack);
- auto *lua = LuaRuntime::instance();
- lua->queue_task([this]() {
- emit input_mediator->url_opened("https://github.com/phenax/null-browser",
- OpenType::OpenUrl, 0);
- emit input_mediator->url_opened("https://ediblemonad.dev",
- OpenType::OpenUrlInBgTab, 0);
- emit input_mediator->url_opened("https://github.com/trending",
- OpenType::OpenUrlInBgTab, 0);
+ connect(web_view_stack, &WebViewStack::current_webview_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);
+ }
+ });
+
+ // TODO: remove
+ auto &lua = LuaRuntime::instance();
+ lua.queue_task([this]() {
+ emit win_mediator->url_opened("https://github.com/phenax/null-browser",
+ OpenType::OpenUrl, 0);
+ emit win_mediator->url_opened("https://ediblemonad.dev",
+ OpenType::OpenUrlInBgTab, 0);
+ emit win_mediator->url_opened("https://github.com/trending",
+ OpenType::OpenUrlInBgTab, 0);
});
}
+void BrowserWindow::closeEvent(QCloseEvent * /*event*/) { emit closed(); }
+
bool BrowserWindow::on_window_key_event(QKeyEvent *event) {
- auto *keymap_evaluator = KeymapEvaluator::instance();
+ auto &keymap_evaluator = KeymapEvaluator::instance();
const bool should_skip =
- keymap_evaluator->evaluate(event->modifiers(), (Qt::Key)event->key());
+ keymap_evaluator.evaluate(event->modifiers(), (Qt::Key)event->key());
return should_skip;
}
diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp
index cab7721..9aeeda3 100644
--- a/src/widgets/BrowserWindow.hpp
+++ b/src/widgets/BrowserWindow.hpp
@@ -14,19 +14,19 @@ class BrowserWindow : public QMainWindow {
public:
BrowserWindow(const Configuration &configuration);
- DEFINE_GETTER(mediator, input_mediator)
+ DEFINE_GETTER(mediator, win_mediator)
DEFINE_GETTER(get_id, win_id)
DEFINE_SETTER(set_id, win_id)
bool on_window_key_event(QKeyEvent *event);
- void closeEvent(QCloseEvent * /*event*/) override { emit closed(); }
+ void closeEvent(QCloseEvent * /*event*/) override;
signals:
void closed();
private:
- WindowMediator *input_mediator;
+ WindowMediator *win_mediator;
const Configuration &configuration;
WindowId win_id = -1;
diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp
index f01b75c..6de170a 100644
--- a/src/widgets/WebViewStack.cpp
+++ b/src/widgets/WebViewStack.cpp
@@ -17,6 +17,9 @@ WebViewStack::WebViewStack(const Configuration *configuration,
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);
}
@@ -50,6 +53,8 @@ WebView *WebViewStack::create_new_webview(const QUrl &url, bool focus) {
if (focus)
focus_webview(webview->get_id());
+ emit current_webview_changed(layout->currentIndex());
+
return webview;
}
@@ -116,6 +121,7 @@ void WebViewStack::close(WebViewId webview_id) {
// TODO: Close window on empty
if (webview_list.isEmpty()) {
+ // window()->close();
create_new_webview(configuration->new_tab_url, true);
}
}
diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp
index 40c2184..0f0d923 100644
--- a/src/widgets/WebViewStack.hpp
+++ b/src/widgets/WebViewStack.hpp
@@ -45,6 +45,9 @@ public:
/// @deprecated TODO: Remove
uint32_t current_webview_index();
+signals:
+ void current_webview_changed(int index);
+
protected:
void set_current_url(const QUrl &url);
WebView *create_new_webview(const QUrl &url, bool focus = false);