1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include <QKeyEvent>
#include <QStackedLayout>
#include <QVBoxLayout>
#include <QtCore>
#include "Configuration.hpp"
#include "LuaRuntime.hpp"
#include "WindowMediator.hpp"
#include "keymap/KeymapEvaluator.hpp"
#include "widgets/BrowserWindow.hpp"
#include "widgets/WebViewStack.hpp"
BrowserWindow::BrowserWindow(const Configuration &configuration)
: configuration(configuration) {
setCentralWidget(new QWidget());
// Root stacked layout
auto *layout = new QStackedLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setStackingMode(QStackedLayout::StackAll);
centralWidget()->setLayout(layout);
// Web engine
auto *web_view_stack =
new WebViewStack(&configuration, new QWebEngineProfile("null-browser"));
layout->addWidget(web_view_stack);
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::Insert, "<esc>", [keymap_evaluator]() {
keymap_evaluator->set_current_mode(KeyMode::Normal);
});
keymap_evaluator->add_keymap(KeyMode::Normal, "<c-t>a",
[]() { qDebug() << "Stuff"; });
input_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);
});
}
bool BrowserWindow::on_window_key_event(QKeyEvent *event) {
auto *keymap_evaluator = KeymapEvaluator::instance();
const bool should_skip =
keymap_evaluator->evaluate(event->modifiers(), (Qt::Key)event->key());
return should_skip;
}
|