aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--TODO.org32
-rw-r--r--src/WindowActionRouter.cpp3
-rw-r--r--src/widgets/BrowserApp.cpp3
-rw-r--r--src/widgets/BrowserWindow.cpp7
-rw-r--r--src/widgets/BrowserWindow.hpp2
-rw-r--r--src/widgets/Decorations.cpp43
-rw-r--r--src/widgets/Decorations.hpp19
-rw-r--r--src/widgets/EdgeDecoration.cpp67
-rw-r--r--src/widgets/EdgeDecoration.hpp30
-rw-r--r--src/widgets/WebViewStack.cpp5
-rw-r--r--src/widgets/WebViewStack.hpp2
12 files changed, 201 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index eff7dca..23f8f82 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-.PHONY: clean build build-release build-source test run check
+.PHONY: clean build build-release dev-setup build-dev install build-source test run check fmt
all: build-dev
@@ -39,8 +39,10 @@ debug:
DEBUG=1 make build-dev
gdb ./build/null-browser
-check:
+fmt:
clang-format -i ./src/**/*.{hpp,cpp}
+
+check: fmt
clang-tidy --config-file=.clang-tidy ./src/**/*.{hpp,cpp}
# appimage:
diff --git a/TODO.org b/TODO.org
index 0a6b89f..ce4cb95 100644
--- a/TODO.org
+++ b/TODO.org
@@ -13,6 +13,7 @@
- [ ] INVESTIGATE: Check why urlchanged doesnt fire for first url open sometimes
- [ ] INVESTIGATE: Segfault on close sometimes
- [ ] API's don't validate types. (type conversion segfaults)
+- [ ] web.view apis in `-e` flag from "clients" (non-servers calls) don't work
** Next
- [ ] Tests for window
@@ -95,15 +96,26 @@ web.search.get_search_text()
web.search.current()
web.search.total()
-web.decorations.configure('left', {
- url = 'https://something.com',
- size = 100,
-})
-local sidebar_decoration = web.decorations.left()
-web.decorations.delete(sidebar_decoration)
-web.decorations.hide(sidebar_decoration)
+web.decorations.top.configure({ visible = true, size = 30 })
+web.decorations.top.configure({ visible = false }) -- hide/show
+local view_id = web.decorations.top.view()
+web.view.set_html('<div>Hello world</div>', { view = view })
+web.decorations.top.destroy() -- Maybe to destroy unwanted webviews
-web.decorations.configure('top', { size = 28 })
-local tabline_decoration = web.decorations.top()
-web.view.set_html('<div>Hello world</div>', { view_id = tabline_decoration.view_id })
+-- Show tabs in top decoration
+web.view.expose_js('openTab', function(tabId)
+ web.view.select({ view = tabId })
+end, { view = web.decorations.top.view() })
+web.event.add_listener({ 'TabOpen', 'TabClose' }, {
+ callback = function()
+ local tabs_html = ''
+ local views = web.view.list()
+ for index, view in ipairs(web.view.list()) do
+ local text = index..': '..view.title..' ('..view.url..')'
+ local tab = '<span onclick="__nullbrowser__.openTab('..view.id..')">' .. text .. '</span>')
+ tabs_html = tabs_html .. tab
+ end
+ web.view.set_html(tabs_html, { view = web.decorations.top.view() })
+ end,
+})
#+end_src
diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp
index 3e8d99e..1c68a35 100644
--- a/src/WindowActionRouter.cpp
+++ b/src/WindowActionRouter.cpp
@@ -3,11 +3,12 @@
#include <unordered_map>
#include "LuaRuntime.hpp"
-#include "WindowActionRouter.hpp"
#include "keymap/KeymapEvaluator.hpp"
#include "widgets/BrowserWindow.hpp"
#include "widgets/WebViewStack.hpp"
+#include "WindowActionRouter.hpp"
+
QVariant WindowActionRouter::fetch_config_value(const QString &key) {
return configuration->get_config(key);
}
diff --git a/src/widgets/BrowserApp.cpp b/src/widgets/BrowserApp.cpp
index 9326d45..49054b8 100644
--- a/src/widgets/BrowserApp.cpp
+++ b/src/widgets/BrowserApp.cpp
@@ -6,9 +6,10 @@
#include "LuaRuntime.hpp"
#include "WindowActionRouter.hpp"
#include "events/NotificationReceivedEvent.hpp"
-#include "widgets/BrowserApp.hpp"
#include "widgets/BrowserWindow.hpp"
+#include "widgets/BrowserApp.hpp"
+
BrowserApp::BrowserApp(Configuration &configuration) : configuration(configuration) {
auto &lua = LuaRuntime::instance();
lua.start_event_loop();
diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp
index c565cb9..fe2285b 100644
--- a/src/widgets/BrowserWindow.cpp
+++ b/src/widgets/BrowserWindow.cpp
@@ -7,9 +7,11 @@
#include "Configuration.hpp"
#include "keymap/KeymapEvaluator.hpp"
-#include "widgets/BrowserWindow.hpp"
+#include "widgets/Decorations.hpp"
#include "widgets/WebViewStack.hpp"
+#include "widgets/BrowserWindow.hpp"
+
BrowserWindow::BrowserWindow(const Configuration &configuration, QWebEngineProfile *profile,
const QStringList &urls)
: QMainWindow(nullptr), configuration(configuration) {
@@ -23,7 +25,8 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, QWebEngineProfi
// Stack of web views
webview_stack = new WebViewStack(&configuration, profile, this);
- layout->addWidget(webview_stack);
+ decorations = new Decorations(webview_stack, profile, this);
+ layout->addWidget(decorations);
// Open webviews for given urls
if (urls.isEmpty()) {
diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp
index 6c49006..7dc6ee4 100644
--- a/src/widgets/BrowserWindow.hpp
+++ b/src/widgets/BrowserWindow.hpp
@@ -4,6 +4,7 @@
#include "Configuration.hpp"
#include "utils.hpp"
+#include "widgets/Decorations.hpp"
#include "widgets/WebViewStack.hpp"
using WindowId = qsizetype;
@@ -47,6 +48,7 @@ signals:
private:
const Configuration &configuration;
WebViewStack *webview_stack;
+ Decorations *decorations;
WindowId win_id = -1;
};
diff --git a/src/widgets/Decorations.cpp b/src/widgets/Decorations.cpp
new file mode 100644
index 0000000..659f972
--- /dev/null
+++ b/src/widgets/Decorations.cpp
@@ -0,0 +1,43 @@
+#include <QWidget>
+#include <QtCore>
+#include <qboxlayout.h>
+#include <qlabel.h>
+#include <qwidget.h>
+
+#include "Decorations.hpp"
+
+Decorations::Decorations(QWidget *content_widget, QWebEngineProfile *profile, QWidget *parent)
+ : QWidget(parent) {
+ decoration_top = new EdgeDecoration(false, profile, this);
+ decoration_bottom = new EdgeDecoration(false, profile, this);
+ decoration_left = new EdgeDecoration(true, profile, this);
+ decoration_right = new EdgeDecoration(true, profile, this);
+
+ QString content = R"HTML(
+ <div>
+ Hello world testing testing
+ <button>Btn 1</button><button>Btn 2</button>
+ </div>
+ )HTML";
+ decoration_bottom->set_html(content);
+ decoration_bottom->set_enabled(true);
+
+ auto *vbox = new QVBoxLayout();
+ vbox->setContentsMargins(0, 0, 0, 0);
+ vbox->setSpacing(0);
+ setLayout(vbox);
+
+ auto *container = new QWidget(this);
+ auto *hbox = new QHBoxLayout();
+ hbox->setContentsMargins(0, 0, 0, 0);
+ hbox->setSpacing(0);
+ container->setLayout(hbox);
+
+ vbox->addWidget(decoration_top);
+ vbox->addWidget(container);
+ vbox->addWidget(decoration_bottom);
+
+ hbox->addWidget(decoration_left);
+ hbox->addWidget(content_widget);
+ hbox->addWidget(decoration_right);
+}
diff --git a/src/widgets/Decorations.hpp b/src/widgets/Decorations.hpp
new file mode 100644
index 0000000..e35e83c
--- /dev/null
+++ b/src/widgets/Decorations.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "widgets/EdgeDecoration.hpp"
+#include <QWidget>
+#include <QtCore>
+#include <qwebengineprofile.h>
+
+class Decorations : public QWidget {
+ Q_OBJECT
+
+public:
+ Decorations(QWidget *content_widget, QWebEngineProfile *profile, QWidget *parent = nullptr);
+
+private:
+ EdgeDecoration *decoration_top;
+ EdgeDecoration *decoration_bottom;
+ EdgeDecoration *decoration_left;
+ EdgeDecoration *decoration_right;
+};
diff --git a/src/widgets/EdgeDecoration.cpp b/src/widgets/EdgeDecoration.cpp
new file mode 100644
index 0000000..58db639
--- /dev/null
+++ b/src/widgets/EdgeDecoration.cpp
@@ -0,0 +1,67 @@
+#include <QWidget>
+#include <QtCore>
+#include <qboxlayout.h>
+#include <qlabel.h>
+#include <qwebengineview.h>
+
+#include "widgets/WebView.hpp"
+#include "widgets/WebViewStack.hpp"
+
+#include "widgets/EdgeDecoration.hpp"
+
+QString default_html_layout = R"HTML(
+ {{body}}
+ <style>
+ :where(html, body) {
+ margin: 0;
+ padding: 0;
+ background: black;
+ color: white;
+ overflow: hidden;
+ }
+ </style>
+)HTML";
+
+EdgeDecoration::EdgeDecoration(bool vertical, QWebEngineProfile *profile, QWidget *parent)
+ : QWidget(parent), vertical(vertical), profile(profile) {
+ auto *vbox = new QVBoxLayout();
+ vbox->setContentsMargins(0, 0, 0, 0);
+ vbox->setSpacing(0);
+ setLayout(vbox);
+}
+
+void EdgeDecoration::set_html(const QString &content) {
+ html_content = content;
+ setup_webview();
+}
+
+void EdgeDecoration::set_size(u_int16_t size_value) {
+ size = size_value;
+ setup_webview();
+}
+
+void EdgeDecoration::set_enabled(bool enabled_value) {
+ enabled = enabled_value;
+ setup_webview();
+}
+
+void EdgeDecoration::setup_webview() {
+ if (enabled) {
+ if (webview == nullptr) {
+ webview = new WebView(WebViewStack::next_webview_id++, profile, this);
+ layout()->addWidget(webview);
+ }
+
+ webview->setHtml(default_html_layout.replace("{{body}}", html_content));
+ if (vertical)
+ setFixedWidth(size);
+ else
+ setFixedHeight(size);
+ } else {
+ if (webview != nullptr) {
+ layout()->removeWidget(webview);
+ webview->deleteLater();
+ webview = nullptr;
+ }
+ }
+}
diff --git a/src/widgets/EdgeDecoration.hpp b/src/widgets/EdgeDecoration.hpp
new file mode 100644
index 0000000..c83227a
--- /dev/null
+++ b/src/widgets/EdgeDecoration.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <QWidget>
+#include <QtCore>
+#include <cstdint>
+#include <qwebengineprofile.h>
+#include <qwebengineview.h>
+
+#include "widgets/WebView.hpp"
+
+class EdgeDecoration : public QWidget {
+ Q_OBJECT
+
+public:
+ EdgeDecoration(bool vertical, QWebEngineProfile *profile, QWidget *parent = nullptr);
+
+ void set_size(uint16_t size_value);
+ void set_html(const QString &content);
+ void set_enabled(bool enabled_value);
+
+private:
+ bool vertical;
+ WebView *webview = nullptr;
+ QWebEngineProfile *profile;
+ bool enabled;
+ QString html_content;
+ uint16_t size = 24;
+
+ void setup_webview();
+};
diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp
index 6bbd5b5..45d9c88 100644
--- a/src/widgets/WebViewStack.cpp
+++ b/src/widgets/WebViewStack.cpp
@@ -12,9 +12,10 @@
#include "WindowActionRouter.hpp"
#include "events/PermissionRequestedEvent.hpp"
#include "events/UrlChangedEvent.hpp"
+
#include "widgets/WebViewStack.hpp"
-static WebViewId next_webview_id = 1;
+WebViewId WebViewStack::next_webview_id = 1;
WebViewStack::WebViewStack(const Configuration *configuration, QWebEngineProfile *profile,
QWidget *parent)
@@ -46,7 +47,7 @@ void WebViewStack::open_url(const QUrl &url, OpenType open_type, WebViewId webvi
}
WebView *WebViewStack::create_new_webview(const QUrl &url, bool focus) {
- auto *webview = new WebView(next_webview_id++, profile);
+ auto *webview = new WebView(WebViewStack::next_webview_id++, profile);
webview->setUrl(url);
layout->addWidget(webview);
webview_list.append(webview);
diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp
index cee0593..a5c4d4c 100644
--- a/src/widgets/WebViewStack.hpp
+++ b/src/widgets/WebViewStack.hpp
@@ -28,6 +28,8 @@ class WebViewStack : public QWidget {
Q_OBJECT
public:
+ static WebViewId next_webview_id;
+
WebViewStack(const Configuration *configuration,
QWebEngineProfile *profile = new QWebEngineProfile, QWidget *parent = nullptr);