diff options
Diffstat (limited to '')
| -rw-r--r-- | src/Configuration.hpp | 4 | ||||
| -rw-r--r-- | src/LuaRuntime.cpp | 64 | ||||
| -rw-r--r-- | src/LuaRuntime.hpp | 20 | ||||
| -rw-r--r-- | src/WindowActionRouter.cpp | 2 | ||||
| -rw-r--r-- | src/WindowActionRouter.hpp | 2 | ||||
| -rw-r--r-- | src/events.hpp | 10 | ||||
| -rw-r--r-- | src/widgets/BrowserWindow.cpp | 4 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 14 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.hpp | 4 |
9 files changed, 62 insertions, 62 deletions
diff --git a/src/Configuration.hpp b/src/Configuration.hpp index 837e3e6..c1744e6 100644 --- a/src/Configuration.hpp +++ b/src/Configuration.hpp @@ -8,7 +8,7 @@ class Configuration : public QObject { public: using QObject::QObject; - QUrl new_tab_url = QUrl("https://lite.duckduckgo.com"); + QUrl new_view_url = QUrl("https://lite.duckduckgo.com"); - bool close_window_when_no_tabs = true; + bool close_window_when_no_views = true; }; diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp index d54bb37..036f47f 100644 --- a/src/LuaRuntime.cpp +++ b/src/LuaRuntime.cpp @@ -154,18 +154,18 @@ void LuaRuntime::init_web_lib() { luaL_newlib(state, webkeymap); lua_setfield(state, -2, "keymap"); - // Tab actions (web.tabs) - luaL_Reg webtabs[] = { - {"close", &LuaRuntime::lua_tab_close}, - {"new", &LuaRuntime::lua_tab_create}, - {"current", &LuaRuntime::lua_tab_current}, - {"list", &LuaRuntime::lua_tab_list}, - {"select", &LuaRuntime::lua_tab_select}, + // View actions (web.view) + luaL_Reg webviews[] = { + {"close", &LuaRuntime::lua_view_close}, + {"new", &LuaRuntime::lua_view_create}, + {"current", &LuaRuntime::lua_view_current}, + {"list", &LuaRuntime::lua_view_list}, + {"select", &LuaRuntime::lua_view_select}, {"set_url", &LuaRuntime::lua_open_url}, {nullptr, nullptr}, }; - luaL_newlib(state, webtabs); - lua_setfield(state, -2, "tabs"); + luaL_newlib(state, webviews); + lua_setfield(state, -2, "view"); // History navigation luaL_Reg webhistory[] = { @@ -197,16 +197,16 @@ 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); + WebViewId view_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2); auto &runtime = LuaRuntime::instance(); - emit runtime.url_opened(url, OpenType::OpenUrl, tab_id); + emit runtime.url_opened(url, OpenType::OpenUrl, view_id); return 1; } -int LuaRuntime::lua_tab_create(lua_State *state) { +int LuaRuntime::lua_view_create(lua_State *state) { const char *url = luaL_optstring(state, 1, ""); auto &runtime = LuaRuntime::instance(); - emit runtime.url_opened(url, OpenType::OpenUrlInTab, 0); + emit runtime.url_opened(url, OpenType::OpenUrlInView, 0); return 1; } @@ -233,32 +233,32 @@ int LuaRuntime::lua_keymap_set(lua_State *state) { return 1; } -int LuaRuntime::lua_tab_current(lua_State *state) { +int LuaRuntime::lua_view_current(lua_State *state) { auto &router = WindowActionRouter::instance(); - auto tab_id = router.fetch_current_tab_id(); - lua_pushinteger(state, tab_id); + auto view_id = router.fetch_current_view_id(); + lua_pushinteger(state, view_id); return 1; } -int LuaRuntime::lua_tab_list(lua_State *state) { +int LuaRuntime::lua_view_list(lua_State *state) { auto &router = WindowActionRouter::instance(); - auto tabs = router.fetch_webview_data_list(); + auto views = router.fetch_webview_data_list(); lua_newtable(state); int index = 1; // 1-indexed - for (auto &tab : tabs) { + for (auto &view : views) { lua_newtable(state); lua_pushstring(state, "id"); - lua_pushinteger(state, tab.id); + lua_pushinteger(state, view.id); lua_settable(state, -3); lua_pushstring(state, "url"); - lua_pushstring(state, tab.url.toStdString().c_str()); + lua_pushstring(state, view.url.toStdString().c_str()); lua_settable(state, -3); lua_pushstring(state, "title"); - lua_pushstring(state, tab.title.toStdString().c_str()); + lua_pushstring(state, view.title.toStdString().c_str()); lua_settable(state, -3); lua_rawseti(state, -2, index); @@ -273,9 +273,9 @@ int LuaRuntime::lua_history_back(lua_State *state) { qsizetype history_index = lua_isnoneornil(state, 1) ? 1 : lua_tointeger(state, 1); - WebViewId tab_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2); + WebViewId view_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2); - emit runtime.history_back_requested(tab_id, history_index); + emit runtime.history_back_requested(view_id, history_index); return 1; } @@ -284,28 +284,28 @@ int LuaRuntime::lua_history_forward(lua_State *state) { qsizetype history_index = lua_isnoneornil(state, 1) ? 1 : lua_tointeger(state, 1); - WebViewId tab_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2); + WebViewId view_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2); - emit runtime.history_forward_requested(tab_id, history_index); + emit runtime.history_forward_requested(view_id, history_index); return 1; } -int LuaRuntime::lua_tab_close(lua_State *state) { +int LuaRuntime::lua_view_close(lua_State *state) { auto &runtime = LuaRuntime::instance(); - WebViewId tab_id = lua_isnoneornil(state, 1) ? 0 : lua_tointeger(state, 1); + WebViewId view_id = lua_isnoneornil(state, 1) ? 0 : lua_tointeger(state, 1); - emit runtime.webview_closed(tab_id); + emit runtime.webview_closed(view_id); return 1; } -int LuaRuntime::lua_tab_select(lua_State *state) { +int LuaRuntime::lua_view_select(lua_State *state) { if (lua_isnoneornil(state, 1)) return 1; // TODO: return nil (for others too) auto &runtime = LuaRuntime::instance(); - WebViewId tab_id = lua_tointeger(state, 1); - emit runtime.webview_selected(tab_id); + WebViewId view_id = lua_tointeger(state, 1); + emit runtime.webview_selected(view_id); return 1; } diff --git a/src/LuaRuntime.hpp b/src/LuaRuntime.hpp index e73650c..64bb1f1 100644 --- a/src/LuaRuntime.hpp +++ b/src/LuaRuntime.hpp @@ -14,11 +14,11 @@ #define PROJECT_LUA_PATH "" #endif -#define preserve_top(STATE, BODY) \ - { \ - const int __top = lua_gettop(STATE); \ - BODY; \ - lua_settop(STATE, __top); \ +#define preserve_top(STATE, BODY) \ + { \ + const int __top = lua_gettop(STATE); \ + BODY; \ + lua_settop(STATE, __top); \ }; class LuaRuntime : public QObject { @@ -66,11 +66,11 @@ protected: static int lua_event_register(lua_State *state); static int lua_keymap_set(lua_State *state); static int lua_open_url(lua_State *state); - static int lua_tab_close(lua_State *state); - static int lua_tab_create(lua_State *state); - static int lua_tab_current(lua_State *state); - static int lua_tab_list(lua_State *state); - static int lua_tab_select(lua_State *state); + static int lua_view_close(lua_State *state); + static int lua_view_create(lua_State *state); + static int lua_view_current(lua_State *state); + static int lua_view_list(lua_State *state); + static int lua_view_select(lua_State *state); private: lua_State *state; diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp index d1cd816..51e24e9 100644 --- a/src/WindowActionRouter.cpp +++ b/src/WindowActionRouter.cpp @@ -74,7 +74,7 @@ void WindowActionRouter::add_keymap(const QString &mode_string, const QString &k keymap_evaluator.add_keymap(mode, keyseq, std::move(action)); } -WebViewId WindowActionRouter::fetch_current_tab_id(WindowId win_id) { +WebViewId WindowActionRouter::fetch_current_view_id(WindowId win_id) { const std::lock_guard<std::mutex> lock(window_map_mutex); for (auto &pair : window_map) { auto *win = pair.second; diff --git a/src/WindowActionRouter.hpp b/src/WindowActionRouter.hpp index 3c82b28..cfb25da 100644 --- a/src/WindowActionRouter.hpp +++ b/src/WindowActionRouter.hpp @@ -32,7 +32,7 @@ public: void add_window(BrowserWindow *window); const WindowMap &windows(); - WebViewId fetch_current_tab_id(WindowId win_id = 0); + WebViewId fetch_current_view_id(WindowId win_id = 0); QList<WebViewData> fetch_webview_data_list(WindowId win_id = 0); DELEGATE((&event_queue), dispatch_event, dispatch_event); diff --git a/src/events.hpp b/src/events.hpp index 96b9008..ffa4f8b 100644 --- a/src/events.hpp +++ b/src/events.hpp @@ -7,9 +7,9 @@ #include "widgets/BrowserWindow.hpp" #include "widgets/WebViewStack.hpp" -#define SET_FIELD(NAME, TYPE, VALUE) \ - lua_pushstring(state, NAME); \ - lua_push##TYPE(state, VALUE); \ +#define SET_FIELD(NAME, TYPE, VALUE) \ + lua_pushstring(state, NAME); \ + lua_push##TYPE(state, VALUE); \ lua_settable(state, -3); class BrowserEvent { @@ -33,8 +33,8 @@ public: void lua_push(lua_State *state) const override { lua_newtable(state); - SET_FIELD("tab", integer, webview_id) - SET_FIELD("win", integer, win_id) + SET_FIELD("view_id", integer, webview_id) + SET_FIELD("win_id", integer, win_id) SET_FIELD("url", string, url.toStdString().c_str()) } }; diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp index f1b786b..cc3c6a8 100644 --- a/src/widgets/BrowserWindow.cpp +++ b/src/widgets/BrowserWindow.cpp @@ -27,10 +27,10 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, const QStringLi // Open webviews for given urls if (urls.isEmpty()) { - webview_stack->open_url(configuration.new_tab_url.toString()); + webview_stack->open_url(configuration.new_view_url.toString()); } else { for (const auto &url : urls) { - webview_stack->open_url(url, OpenType::OpenUrlInTab); + webview_stack->open_url(url, OpenType::OpenUrlInView); } } diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index 8c432f1..d43c9b5 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -28,10 +28,10 @@ void WebViewStack::open_url(const QUrl &url, OpenType open_type, WebViewId webvi case OpenType::OpenUrl: set_webview_url(url, webview_id); break; - case OpenType::OpenUrlInTab: + case OpenType::OpenUrlInView: create_new_webview(url, true); break; - case OpenType::OpenUrlInBgTab: + case OpenType::OpenUrlInBgView: create_new_webview(url, false); break; case OpenType::OpenUrlInWindow: @@ -81,10 +81,10 @@ QList<WebViewData> WebViewStack::get_webview_list() { void WebViewStack::on_new_webview_request(const QWebEngineNewWindowRequest &request) { switch (request.destination()) { case QWebEngineNewWindowRequest::InNewTab: - open_url(request.requestedUrl(), OpenType::OpenUrlInTab); + open_url(request.requestedUrl(), OpenType::OpenUrlInView); break; case QWebEngineNewWindowRequest::InNewBackgroundTab: - open_url(request.requestedUrl(), OpenType::OpenUrlInBgTab); + open_url(request.requestedUrl(), OpenType::OpenUrlInBgView); break; case QWebEngineNewWindowRequest::InNewWindow: case QWebEngineNewWindowRequest::InNewDialog: @@ -126,10 +126,10 @@ void WebViewStack::close(WebViewId webview_id) { webview->deleteLater(); if (webview_list.isEmpty()) { - if (configuration->close_window_when_no_tabs) { + if (configuration->close_window_when_no_views) { emit close_window_requested(); } else { - create_new_webview(configuration->new_tab_url, true); + create_new_webview(configuration->new_view_url, true); } } } @@ -204,7 +204,7 @@ QUrl WebViewStack::current_url() { auto *webview = current_webview(); if (webview == nullptr) { qDebug() << "No current webview"; - return configuration->new_tab_url; + return configuration->new_view_url; } return webview->url(); diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp index 7cc2143..b36c389 100644 --- a/src/widgets/WebViewStack.hpp +++ b/src/widgets/WebViewStack.hpp @@ -12,8 +12,8 @@ using WebViewId = qsizetype; enum OpenType : uint8_t { OpenUrl, - OpenUrlInTab, - OpenUrlInBgTab, + OpenUrlInView, + OpenUrlInBgView, OpenUrlInWindow, }; |
