diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-04-05 16:36:18 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-04-05 16:36:18 +0530 |
| commit | b6526785478ea8ba70ddd119f1e3e53a892d4a22 (patch) | |
| tree | ab8d25169ead042255c5057f0969e775c61ab8dc /src | |
| parent | 09cdcd15b31469c839831cad534fec9896999b60 (diff) | |
| download | null-browser-b6526785478ea8ba70ddd119f1e3e53a892d4a22.tar.gz null-browser-b6526785478ea8ba70ddd119f1e3e53a892d4a22.zip | |
Update clang formatting
Diffstat (limited to '')
| -rw-r--r-- | src/keymap/KeySeqParser.cpp | 4 | ||||
| -rw-r--r-- | src/keymap/KeySeqParser.hpp | 9 | ||||
| -rw-r--r-- | src/keymap/KeymapEvaluator.cpp | 16 | ||||
| -rw-r--r-- | src/widgets/BrowserApp.cpp | 7 | ||||
| -rw-r--r-- | src/widgets/BrowserWindow.cpp | 27 | ||||
| -rw-r--r-- | src/widgets/BrowserWindow.hpp | 3 | ||||
| -rw-r--r-- | src/widgets/WebView.cpp | 3 | ||||
| -rw-r--r-- | src/widgets/WebView.hpp | 3 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 44 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.hpp | 8 |
10 files changed, 47 insertions, 77 deletions
diff --git a/src/keymap/KeySeqParser.cpp b/src/keymap/KeySeqParser.cpp index f81ba2a..aef3b58 100644 --- a/src/keymap/KeySeqParser.cpp +++ b/src/keymap/KeySeqParser.cpp @@ -5,8 +5,8 @@ #include "keymap/KeySeqParser.hpp" -bool operator==(const KeyChord chord1, const KeyChord chord2) { - return chord1.mod == chord2.mod && chord1.key == chord2.key; +bool KeyChord::operator==(const KeyChord &chord2) const { + return this->mod == chord2.mod && this->key == chord2.key; } QList<KeyChord> KeySeqParser::parse(QString key_sequence) { diff --git a/src/keymap/KeySeqParser.hpp b/src/keymap/KeySeqParser.hpp index eb878ab..31680a9 100644 --- a/src/keymap/KeySeqParser.hpp +++ b/src/keymap/KeySeqParser.hpp @@ -6,8 +6,9 @@ struct KeyChord { Qt::KeyboardModifiers mod; Qt::Key key; + + bool operator==(const KeyChord &chord2) const; }; -bool operator==(KeyChord chord1, KeyChord chord2); using KeySequence = QList<KeyChord>; @@ -19,14 +20,12 @@ enum KeyMatchType : uint8_t { class KeySeqParser { public: - static KeyMatchType key_sequence_match(const KeySequence &target, - const KeySequence ¤t) { + static KeyMatchType key_sequence_match(const KeySequence &target, const KeySequence ¤t) { for (int i = 0; i < target.length(); i++) { if (current.length() <= i) return KeyMatchType::Pending; - if (target[i].key != current[i].key || - !target[i].mod.testFlags(current[i].mod)) + if (target[i].key != current[i].key || !target[i].mod.testFlags(current[i].mod)) return KeyMatchType::NoMatch; } diff --git a/src/keymap/KeymapEvaluator.cpp b/src/keymap/KeymapEvaluator.cpp index 396e494..e42ec3c 100644 --- a/src/keymap/KeymapEvaluator.cpp +++ b/src/keymap/KeymapEvaluator.cpp @@ -7,21 +7,18 @@ // TODO: Clear mapping after some time -void KeymapEvaluator::add_keymap(KeyMode mode, const QString &key, - KeyAction action) { +void KeymapEvaluator::add_keymap(KeyMode mode, const QString &key, KeyAction action) { if (!modal_keys.contains(mode)) modal_keys.insert(mode, {}); qDebug() << " " << mode << key; auto key_seq = key_seq_parser.parse(key); - modal_keys[mode].append( - KeyMap{.key_sequence = key_seq, .action = std::move(action)}); + modal_keys[mode].append(KeyMap{.key_sequence = key_seq, .action = std::move(action)}); } bool KeymapEvaluator::evaluate(Qt::KeyboardModifiers modifiers, Qt::Key key) { - if (key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Meta || - key == Qt::Key_Alt) + if (key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Meta || key == Qt::Key_Alt) return true; const auto *keymaps = current_mode_keys(); @@ -30,8 +27,7 @@ bool KeymapEvaluator::evaluate(Qt::KeyboardModifiers modifiers, Qt::Key key) { active_key_sequence.append(KeyChord{.mod = modifiers, .key = key}); for (const auto &keymap : *keymaps) { - auto match_type = KeySeqParser::key_sequence_match(keymap.key_sequence, - active_key_sequence); + auto match_type = KeySeqParser::key_sequence_match(keymap.key_sequence, active_key_sequence); if (match_type == KeyMatchType::Match) { qDebug() << "CALLED" << key; @@ -53,9 +49,7 @@ bool KeymapEvaluator::evaluate(Qt::KeyboardModifiers modifiers, Qt::Key key) { return true; } -bool KeymapEvaluator::is_insertable_mode() { - return current_mode == KeyMode::Insert; -} +bool KeymapEvaluator::is_insertable_mode() { return current_mode == KeyMode::Insert; } const QList<KeyMap> *KeymapEvaluator::current_mode_keys() { if (!modal_keys.contains(current_mode)) diff --git a/src/widgets/BrowserApp.cpp b/src/widgets/BrowserApp.cpp index 4977a2a..26124d6 100644 --- a/src/widgets/BrowserApp.cpp +++ b/src/widgets/BrowserApp.cpp @@ -20,8 +20,8 @@ BrowserApp::BrowserApp() { // NOTE: TMP lua.load_file("./config.lua"); - connect(&window_action_router, &WindowActionRouter::new_window_requested, - this, [this](const QUrl &url) { create_window({url.toString()}); }); + connect(&window_action_router, &WindowActionRouter::new_window_requested, this, + [this](const QUrl &url) { create_window({url.toString()}); }); }; BrowserWindow *BrowserApp::create_window(const QStringList &urls) { @@ -40,8 +40,7 @@ bool BrowserApp::eventFilter(QObject *target, QEvent *event) { for (const auto &match : WindowActionRouter::instance().windows()) { auto *win = match.second; - if (auto *target_widget = dynamic_cast<QWidget *>(target); - win->isAncestorOf(target_widget)) { + if (auto *target_widget = dynamic_cast<QWidget *>(target); win->isAncestorOf(target_widget)) { auto *key_event = static_cast<QKeyEvent *>(event); const bool should_skip = win->on_window_key_event(key_event); return should_skip; diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp index 38392a0..ff05b0e 100644 --- a/src/widgets/BrowserWindow.cpp +++ b/src/widgets/BrowserWindow.cpp @@ -10,8 +10,7 @@ #include "widgets/BrowserWindow.hpp" #include "widgets/WebViewStack.hpp" -BrowserWindow::BrowserWindow(const Configuration &configuration, - const QStringList &urls) +BrowserWindow::BrowserWindow(const Configuration &configuration, const QStringList &urls) : configuration(configuration) { setCentralWidget(new QWidget()); @@ -23,8 +22,7 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, centralWidget()->setLayout(layout); // Web engine - auto *web_view_stack = - new WebViewStack(&configuration, new QWebEngineProfile("null-browser")); + auto *web_view_stack = new WebViewStack(&configuration, new QWebEngineProfile("null-browser")); layout->addWidget(web_view_stack); auto &keymap_evaluator = KeymapEvaluator::instance(); @@ -36,19 +34,17 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, 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"; }); win_mediator = new WindowMediator(web_view_stack); - 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); - } - }); + 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); + } + }); auto &lua = LuaRuntime::instance(); lua.queue_task([this, urls]() { @@ -62,8 +58,7 @@ void BrowserWindow::closeEvent(QCloseEvent * /*event*/) { emit closed(); } 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()); + const bool should_skip = 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 c83b4b7..e657970 100644 --- a/src/widgets/BrowserWindow.hpp +++ b/src/widgets/BrowserWindow.hpp @@ -12,8 +12,7 @@ class BrowserWindow : public QMainWindow { Q_OBJECT public: - BrowserWindow(const Configuration &configuration, - const QStringList &urls = {}); + BrowserWindow(const Configuration &configuration, const QStringList &urls = {}); DEFINE_GETTER(mediator, win_mediator) DEFINE_GETTER(get_id, win_id) diff --git a/src/widgets/WebView.cpp b/src/widgets/WebView.cpp index 2ba5c4c..300f8ae 100644 --- a/src/widgets/WebView.cpp +++ b/src/widgets/WebView.cpp @@ -3,6 +3,5 @@ #include "widgets/WebView.hpp" -WebView::WebView(uint32_t webview_id, QWebEngineProfile *profile, - QWidget *parent_node) +WebView::WebView(uint32_t webview_id, QWebEngineProfile *profile, QWidget *parent_node) : QWebEngineView(profile, parent_node), id(webview_id) {} diff --git a/src/widgets/WebView.hpp b/src/widgets/WebView.hpp index 0f2aae6..3f73316 100644 --- a/src/widgets/WebView.hpp +++ b/src/widgets/WebView.hpp @@ -10,8 +10,7 @@ class WebView : public QWebEngineView { Q_OBJECT public: - WebView(uint32_t webview_id, QWebEngineProfile *profile, - QWidget *parent_node = nullptr); + WebView(uint32_t webview_id, QWebEngineProfile *profile, QWidget *parent_node = nullptr); DEFINE_GETTER(get_id, id) private: diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index 9b7af78..5134101 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -4,7 +4,6 @@ #include <QWebEngineProfile> #include <cstdint> #include <cstdlib> -#include <memory> #include <vector> #include "WindowActionRouter.hpp" @@ -13,21 +12,19 @@ static WebViewId next_webview_id = 1; -WebViewStack::WebViewStack(const Configuration *configuration, - QWebEngineProfile *profile, QWidget *parent) +WebViewStack::WebViewStack(const Configuration *configuration, QWebEngineProfile *profile, + QWidget *parent) : QWidget(parent), configuration(configuration), profile(profile) { layout = new QStackedLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setStackingMode(QStackedLayout::StackOne); - connect(layout, &QStackedLayout::currentChanged, this, - &WebViewStack::current_webview_changed); + connect(layout, &QStackedLayout::currentChanged, this, &WebViewStack::current_webview_changed); create_new_webview(configuration->new_tab_url, true); } -void WebViewStack::open_url(const QUrl &url, OpenType open_type, - WebViewId webview_id) { +void WebViewStack::open_url(const QUrl &url, OpenType open_type, WebViewId webview_id) { switch (open_type) { case OpenType::OpenUrl: set_webview_url(url, webview_id); @@ -52,12 +49,11 @@ WebView *WebViewStack::create_new_webview(const QUrl &url, bool focus) { connect(webview->page(), &QWebEnginePage::newWindowRequested, this, &WebViewStack::on_new_webview_request); - connect(webview->page(), &QWebEnginePage::urlChanged, this, - [webview](const QUrl &url) { - // TODO: Add window id - WindowActionRouter::instance().dispatch_event( - new UrlChangedEvent(url.toString(), webview->get_id(), 0)); - }); + connect(webview->page(), &QWebEnginePage::urlChanged, this, [webview](const QUrl &url) { + // TODO: Add window id + WindowActionRouter::instance().dispatch_event( + new UrlChangedEvent(url.toString(), webview->get_id(), 0)); + }); if (focus) focus_webview(webview->get_id()); @@ -70,14 +66,12 @@ WebView *WebViewStack::create_new_webview(const QUrl &url, bool focus) { QList<WebViewData> WebViewStack::get_webview_list() { QList<WebViewData> urls; for (auto &view : webview_list) - urls.append(WebViewData{.id = view->get_id(), - .url = view->url().toString(), - .title = view->title()}); + urls.append( + WebViewData{.id = view->get_id(), .url = view->url().toString(), .title = view->title()}); return urls; } -void WebViewStack::on_new_webview_request( - const QWebEngineNewWindowRequest &request) { +void WebViewStack::on_new_webview_request(const QWebEngineNewWindowRequest &request) { qDebug() << request.destination(); switch (request.destination()) { case QWebEngineNewWindowRequest::InNewTab: @@ -135,8 +129,7 @@ void WebViewStack::close(WebViewId webview_id) { } } -void WebViewStack::webview_history_back(WebViewId webview_id, - qsizetype history_index) { +void WebViewStack::webview_history_back(WebViewId webview_id, qsizetype history_index) { auto *webview = get_webview(webview_id); if (webview == nullptr) { qDebug() << "Invalid webview id" << webview_id; @@ -150,8 +143,7 @@ void WebViewStack::webview_history_back(WebViewId webview_id, history->back(); } -void WebViewStack::webview_history_forward(WebViewId webview_id, - qsizetype history_index) { +void WebViewStack::webview_history_forward(WebViewId webview_id, qsizetype history_index) { auto *webview = get_webview(webview_id); if (webview == nullptr) { qDebug() << "Invalid webview id" << webview_id; @@ -184,9 +176,7 @@ WebView *WebViewStack::current_webview() { return webview_list.at(current_webview_index()); } -uint32_t WebViewStack::current_webview_index() { - return layout->currentIndex(); -} +uint32_t WebViewStack::current_webview_index() { return layout->currentIndex(); } uint32_t WebViewStack::count() { return webview_list.length(); } @@ -203,9 +193,7 @@ WebView *WebViewStack::get_webview(WebViewId webview_id) { return webview_list.at(webview_index); } -bool WebViewStack::has_webview(WebViewId webview_id) { - return get_webview(webview_id) != nullptr; -} +bool WebViewStack::has_webview(WebViewId webview_id) { return get_webview(webview_id) != nullptr; } QUrl WebViewStack::current_url() { auto *webview = current_webview(); diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp index 67d443f..5d09aaf 100644 --- a/src/widgets/WebViewStack.hpp +++ b/src/widgets/WebViewStack.hpp @@ -14,7 +14,7 @@ enum OpenType : uint8_t { OpenUrl, OpenUrlInTab, OpenUrlInBgTab, - OpenUrlInWindow + OpenUrlInWindow, }; struct WebViewData { @@ -28,8 +28,7 @@ class WebViewStack : public QWidget { public: WebViewStack(const Configuration *configuration, - QWebEngineProfile *profile = new QWebEngineProfile, - QWidget *parent = nullptr); + QWebEngineProfile *profile = new QWebEngineProfile, QWidget *parent = nullptr); QList<WebViewData> get_webview_list(); WebView *current_webview(); @@ -56,8 +55,7 @@ protected: WebView *get_webview(WebViewId webview_id); public slots: - void open_url(const QUrl &url, OpenType open_type = OpenType::OpenUrl, - WebViewId webview_id = 0); + void open_url(const QUrl &url, OpenType open_type = OpenType::OpenUrl, WebViewId webview_id = 0); void webview_history_back(WebViewId webview_id, qsizetype history_index); void webview_history_forward(WebViewId webview_id, qsizetype history_index); void close(WebViewId webview_id); |
