diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-22 17:17:15 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-22 18:26:37 +0530 |
| commit | 0d728071e3287a71ce7928640e63c19f4d0ab00f (patch) | |
| tree | d6e9fc90331e690dbc439e7ab8b9983df2d796a6 | |
| parent | f09f1aa704f06472ec134b40e2f69bf3279c3f06 (diff) | |
| download | null-browser-0d728071e3287a71ce7928640e63c19f4d0ab00f.tar.gz null-browser-0d728071e3287a71ce7928640e63c19f4d0ab00f.zip | |
Build fixes + formatting
| -rw-r--r-- | .clang-tidy | 43 | ||||
| -rw-r--r-- | CMakeLists.txt | 12 | ||||
| -rw-r--r-- | Makefile | 12 | ||||
| -rw-r--r-- | TODO.org | 5 | ||||
| -rw-r--r-- | flake.lock | 19 | ||||
| -rw-r--r-- | flake.nix | 31 | ||||
| -rw-r--r-- | spec/KeySeqParserSpec.cpp | 4 | ||||
| -rw-r--r-- | src/AsyncEventLoop.cpp | 6 | ||||
| -rw-r--r-- | src/AsyncEventLoop.hpp | 1 | ||||
| -rw-r--r-- | src/LuaRuntime.cpp | 16 | ||||
| -rw-r--r-- | src/LuaRuntime.hpp | 2 | ||||
| -rw-r--r-- | src/keymap/KeySeqParser.hpp | 4 | ||||
| -rw-r--r-- | src/keymap/KeymapEvaluator.cpp | 4 | ||||
| -rw-r--r-- | src/widgets/MainWindow.cpp | 2 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 20 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.hpp | 8 |
16 files changed, 115 insertions, 74 deletions
diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..d948960 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,43 @@ +--- +Checks: > + bugprone-* + clang-analyzer-* + cppcoreguidelines-* + modernize-* + performance-* + readability-* + misc-* + -modernize-use-trailing-return-type + -cppcoreguidelines-pro-bounds-pointer-arithmetic + -cppcoreguidelines-avoid-magic-numbers + +WarningsAsErrors: > + bugprone-* + clang-analyzer-* + cppcoreguidelines-* + modernize-* + performance-* + +HeaderFilterRegex: '' +HeaderFileExtensions: + - h + - hpp +ImplementationFileExtensions: + - c + - cpp + +CheckOptions: + modernize-use-nullptr.CheckSmartPointers: true + modernize-use-nullptr.IgnoreMacros: false + # Use 'auto' when it improves readability + modernize-use-auto.MinTypeNameLength: 5 + readability-container-size-empty.IgnoreQtContainers: true + # Performance optimizations + performance-noexcept-move-constructor.StrictMode: true + performance-trivially-destructible.StrictMode: true + modernize-use-override.IgnoreDestructors: false + modernize-use-override.IgnoreVirtualWithFinal: true + # Clang Analyzer settings + clang-analyzer-optin.cplusplus.VirtualCall: true + clang-analyzer-optin.cplusplus.UninitializedObject: true +... diff --git a/CMakeLists.txt b/CMakeLists.txt index 7854e82..ef6123f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,11 +5,21 @@ project(${PROJECT} VERSION 0.0.0 LANGUAGES CXX) +set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(AUTOMOC ON) find_package(PkgConfig REQUIRED) +set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-p=${CMAKE_BINARY_DIR}") + +if(DEFINED ENV{RELEASE}) + set(CMAKE_BUILD_TYPE Release) + set(CMAKE_CXX_FLAGS "-O3 ${CMAKE_CXX_FLAGS}") +elseif(DEFINED ENV{DEBUG}) + set(CMAKE_BUILD_TYPE Debug) + set(CMAKE_CXX_FLAGS_DEBUG "-g ${CMAKE_CXX_FLAGS}") +endif() # Source file(GLOB_RECURSE SOURCE_FILES src/*.cpp) @@ -18,3 +18,15 @@ clean: run: build ./build/null-browser + +debug: + DEBUG=1 make build + gdb ./build/null-browser + +build-release: + RELEASE=1 make build + +check: + clang-format -i ./src/**/*.{hpp,cpp} + clang-tidy ./src/**/*.{hpp,cpp} + @@ -1,6 +1,8 @@ ** Current - [X] Process spawning lua (+ stdio) - [X] Keybindings (lua api) +- [X] Modal keys +- [X] event loop for async work - [ ] example: trigger dmenu for simple selection - [ ] Config loading and runtime path - [ ] Tab history navigation @@ -8,12 +10,11 @@ - [ ] Get tab list api - [ ] Assign ID to each tab (reference in lua api) - [ ] Tab select by id -- [X] event loop for async work - [ ] Fix segfault on quit - [ ] Multi-window ** Next -- [ ] Modal keys +- [ ] Conflict in keymap (keymap already exists) - [ ] History persistance - [ ] History completion - [ ] Open url parsing (add protocol if missing, remove quotes, etc) @@ -18,24 +18,6 @@ "type": "github" } }, - "lua-luv-source": { - "flake": false, - "locked": { - "lastModified": 1738768796, - "narHash": "sha256-E75DkNBmyLTq9vw3o6CxiTBATMLJmBvTGPTt+bvbloA=", - "ref": "refs/heads/master", - "rev": "ec4185f98209d5e5cf96885ab126d4c2a26dfaa9", - "revCount": 1390, - "submodules": true, - "type": "git", - "url": "https://github.com/luvit/luv" - }, - "original": { - "submodules": true, - "type": "git", - "url": "https://github.com/luvit/luv" - } - }, "nixpkgs": { "locked": { "lastModified": 1741037377, @@ -55,7 +37,6 @@ "root": { "inputs": { "flake-utils": "flake-utils", - "lua-luv-source": "lua-luv-source", "nixpkgs": "nixpkgs" } }, @@ -2,14 +2,9 @@ inputs = { flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - - lua-luv-source = { - url = "git+https://github.com/luvit/luv?submodules=1"; - flake = false; - }; }; - outputs = { self, nixpkgs, flake-utils, lua-luv-source, ... }: + outputs = { self, nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; @@ -19,32 +14,32 @@ luajit libuv luajitPackages.libluv - # luajitPackages.luv # libcef # nss ]; in { - packages.default = pkgs.stdenv.mkDerivation { - pname = "null-browser"; - version = "0.0.0"; - src = ./.; - - buildInputs = with pkgs; [ - qt6.qtbase - ] ++ dependencies; - nativeBuildInputs = with pkgs; [ cmake qt6.wrapQtAppsHook pkg-config ]; - }; - devShells.default = pkgs.mkShell rec { buildInputs = with pkgs; [ cmake gnumake clang-tools pkg-config + gdb # vcpkg ] ++ dependencies; LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}"; }; + + packages.default = pkgs.stdenv.mkDerivation { + pname = "null-browser"; + version = "0.0.0"; + src = ./.; + + buildInputs = with pkgs; [ + qt6.qtbase + ] ++ dependencies; + nativeBuildInputs = with pkgs; [ cmake qt6.wrapQtAppsHook pkg-config ]; + }; }); } diff --git a/spec/KeySeqParserSpec.cpp b/spec/KeySeqParserSpec.cpp index a29c97e..306f5ab 100644 --- a/spec/KeySeqParserSpec.cpp +++ b/spec/KeySeqParserSpec.cpp @@ -29,10 +29,6 @@ private slots: QList<KeyChord> keys = parser.parse("ab<c><s><sPace><tab><esC>z"); - for (auto &k : keys) { - qDebug() << k.key << k.mod; - } - QList<KeyChord> expectedKeys = { {.mod = Qt::NoModifier, .key = Qt::Key_A}, {.mod = Qt::NoModifier, .key = Qt::Key_B}, diff --git a/src/AsyncEventLoop.cpp b/src/AsyncEventLoop.cpp index 360a45e..31be89c 100644 --- a/src/AsyncEventLoop.cpp +++ b/src/AsyncEventLoop.cpp @@ -1,7 +1,9 @@ #include <QtCore> #include <functional> #include <mutex> +#include <queue> #include <thread> +#include <utility> #include <uv.h> #include "AsyncEventLoop.hpp" @@ -63,7 +65,7 @@ AsyncEventLoop::~AsyncEventLoop() { uv_stop(loop); // Close all handles - AsyncEventLoop::closeHandle((uv_handle_t *)&asyncHandle); + AsyncEventLoop::closeHandle(reinterpret_cast<uv_handle_t *>(&asyncHandle)); uv_walk(loop, AsyncEventLoop::closeHandle, nullptr); while (uv_run(loop, UV_RUN_ONCE) != 0) ; @@ -87,7 +89,7 @@ void AsyncEventLoop::asyncHandleCallback(uv_async_t *handle) { runtime->processTasks(); } -void AsyncEventLoop::closeHandle(uv_handle_t *handle, void *arg) { +void AsyncEventLoop::closeHandle(uv_handle_t *handle, void *) { if (!uv_is_closing(handle)) { uv_close(handle, [](uv_handle_t *h) { h->data = nullptr; }); } diff --git a/src/AsyncEventLoop.hpp b/src/AsyncEventLoop.hpp index ebe2cad..29c2958 100644 --- a/src/AsyncEventLoop.hpp +++ b/src/AsyncEventLoop.hpp @@ -5,6 +5,7 @@ #include <mutex> #include <queue> #include <thread> +#include <utility> #include <uv.h> #include "utils.hpp" diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp index f83ee48..cdf95b0 100644 --- a/src/LuaRuntime.cpp +++ b/src/LuaRuntime.cpp @@ -18,7 +18,7 @@ LuaRuntime::LuaRuntime() { luaL_Reg weblib[] = { {"open", &LuaRuntime::lua_onUrlOpen}, {"tabopen", &LuaRuntime::lua_onUrlTabOpen}, - {NULL, NULL}, + {nullptr, nullptr}, }; luaL_newlib(state, weblib); lua_setglobal(state, web_global_name); @@ -60,13 +60,13 @@ void LuaRuntime::stopEventLoop() { void LuaRuntime::evaluate(QString code) { eventLoop->queueTask([this, code]() { if (luaL_dostring(state, code.toStdString().c_str()) != LUA_OK) { - auto value = lua_tostring(state, -1); + const char *value = lua_tostring(state, -1); lua_pop(state, 1); qDebug() << "Lua Error: " << value; emit evaluationFailed(value); } else { - auto value = getValue(-1); + QVariant value = getValue(-1); lua_pop(state, 1); qDebug() << "result: " << value; @@ -76,7 +76,7 @@ void LuaRuntime::evaluate(QString code) { } QVariant LuaRuntime::evaluateSync(QString code) { - auto result = luaL_dostring(state, code.toStdString().c_str()); + luaL_dostring(state, code.toStdString().c_str()); return getValue(-1); // TODO: error handling } @@ -113,25 +113,21 @@ int LuaRuntime::lua_onUrlTabOpen(lua_State *state) { int LuaRuntime::lua_addKeymap(lua_State *state) { const char *mode = lua_tostring(state, 1); const char *keyseq = lua_tostring(state, 2); - qDebug() << "Adduing" << mode << keyseq; - - qDebug() << "---" << lua_isfunction(state, 3); lua_pushvalue(state, 3); int functionRef = luaL_ref(state, LUA_REGISTRYINDEX); auto action = [state, functionRef]() { - qDebug() << "Hello"; + qDebug() << "key action"; lua_rawgeti(state, LUA_REGISTRYINDEX, functionRef); if (lua_pcall(state, 0, 0, 0) != LUA_OK) { const char *error = lua_tostring(state, -1); qDebug() << "Error calling Lua function:" << error; lua_pop(state, 1); - } else { - qDebug() << "Done"; } lua_pop(state, 1); }; + // TODO: Cleanup function ref on after keymap clear auto runtime = LuaRuntime::instance(); emit runtime->keymapAddRequested(mode, keyseq, action); diff --git a/src/LuaRuntime.hpp b/src/LuaRuntime.hpp index 6c45ca5..9f672e9 100644 --- a/src/LuaRuntime.hpp +++ b/src/LuaRuntime.hpp @@ -19,7 +19,7 @@ public: void evaluate(QString code); QVariant evaluateSync(QString code); - void loadFile(QString code); + void loadFile(QString path); void stopEventLoop(); void startEventLoop(); diff --git a/src/keymap/KeySeqParser.hpp b/src/keymap/KeySeqParser.hpp index fac2546..2dad0c7 100644 --- a/src/keymap/KeySeqParser.hpp +++ b/src/keymap/KeySeqParser.hpp @@ -20,8 +20,8 @@ enum KeyMatchType { class KeySeqParser { public: - static const KeyMatchType keySequenceMatch(const KeySequence target, - const KeySequence current) { + static KeyMatchType keySequenceMatch(const KeySequence target, + const KeySequence current) { for (int i = 0; i < target.length(); i++) { if (current.length() <= i) return KeyMatchType::Pending; diff --git a/src/keymap/KeymapEvaluator.cpp b/src/keymap/KeymapEvaluator.cpp index b20aeda..692317b 100644 --- a/src/keymap/KeymapEvaluator.cpp +++ b/src/keymap/KeymapEvaluator.cpp @@ -14,7 +14,7 @@ void KeymapEvaluator::addKeymap(KeyMode mode, QString key, KeyAction action) { qDebug() << " " << mode << key; auto keySeq = keySeqParser.parse(key); - modalKeys[mode].append((KeyMap){.keySequence = keySeq, .action = action}); + modalKeys[mode].append(KeyMap{.keySequence = keySeq, .action = action}); } bool KeymapEvaluator::evaluate(Qt::KeyboardModifiers modifiers, Qt::Key key) { @@ -25,7 +25,7 @@ bool KeymapEvaluator::evaluate(Qt::KeyboardModifiers modifiers, Qt::Key key) { auto keymaps = currentModeKeys(); auto foundPendingMatches = false; - activeKeySequence.append((KeyChord){.mod = modifiers, .key = key}); + activeKeySequence.append(KeyChord{.mod = modifiers, .key = key}); for (auto &keymap : *keymaps) { auto matchType = diff --git a/src/widgets/MainWindow.cpp b/src/widgets/MainWindow.cpp index ca572e7..ce03bce 100644 --- a/src/widgets/MainWindow.cpp +++ b/src/widgets/MainWindow.cpp @@ -73,7 +73,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event) { } } -bool MainWindow::eventFilter(QObject *object, QEvent *event) { +bool MainWindow::eventFilter(QObject *, QEvent *event) { if (event->type() != QEvent::KeyPress) return false; diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index f915d9e..fa5d3ab 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -1,11 +1,13 @@ #include <QStackedLayout> #include <QWebEngineNewWindowRequest> +#include <algorithm> +#include <vector> #include "widgets/WebViewStack.hpp" WebViewStack::WebViewStack(const Configuration *configuration, QWebEngineProfile *profile, QWidget *parent) - : QWidget(parent), profile(profile), configuration(configuration) { + : QWidget(parent), configuration(configuration), profile(profile) { layout = new QStackedLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setStackingMode(QStackedLayout::StackOne); @@ -48,11 +50,12 @@ WebView *WebViewStack::createNewWebView(QUrl url, bool focus) { QList<Tab> WebViewStack::getTabList() { QList<Tab> urls; for (auto &view : webViewList) - urls.append((Tab){.url = view->url().toString(), .title = view->title()}); + urls.append(Tab{.url = view->url().toString(), .title = view->title()}); return urls; } -void WebViewStack::onNewWebViewRequest(QWebEngineNewWindowRequest &request) { +void WebViewStack::onNewWebViewRequest( + const QWebEngineNewWindowRequest &request) { switch (request.destination()) { case QWebEngineNewWindowRequest::InNewTab: createNewWebView(request.requestedUrl(), true); @@ -83,15 +86,15 @@ void WebViewStack::next() { void WebViewStack::previous() { if (webViewList.isEmpty()) return; - auto index = currentWebViewIndex() - 1; - auto total = webViewList.length(); + int index = ((int)currentWebViewIndex()) - 1; + qsizetype total = webViewList.length(); index = index < 0 ? total + index : index; focusWebView(index); } void WebViewStack::closeCurrent() { close(currentWebViewIndex()); } -void WebViewStack::close(long index) { +void WebViewStack::close(int32_t index) { if (index < 0 || index >= webViewList.length()) return; @@ -119,11 +122,12 @@ u_int32_t WebViewStack::currentWebViewIndex() { return layout->currentIndex(); } u_int32_t WebViewStack::count() { return webViewList.length(); } -void WebViewStack::focusWebView(long index) { +void WebViewStack::focusWebView(int32_t index) { if (webViewList.isEmpty()) return; - index = std::max((long)0, std::min(index, (long)webViewList.length() - 1)); + index = std::max((long long)0, + std::min((long long)index, webViewList.length() - 1)); layout->setCurrentIndex(index); } diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp index e5b7ecc..473f699 100644 --- a/src/widgets/WebViewStack.hpp +++ b/src/widgets/WebViewStack.hpp @@ -2,7 +2,7 @@ #include <QStackedLayout> #include <QWebEngineProfile> -#include <sys/types.h> +#include <vector> #include "Configuration.hpp" #include "widgets/WebView.hpp" @@ -33,11 +33,11 @@ public: u_int32_t count(); QUrl currentUrl(); - void focusWebView(long index); + void focusWebView(int32_t index); void next(); void previous(); - void close(long index); + void close(int32_t index); void closeCurrent(); private: @@ -45,7 +45,7 @@ private: WebView *createNewWebView(QUrl url, bool focus = false); private slots: - void onNewWebViewRequest(QWebEngineNewWindowRequest &request); + void onNewWebViewRequest(const QWebEngineNewWindowRequest &request); private: const Configuration *configuration; |
