diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..7c7590a --- /dev/null +++ b/.clang-format @@ -0,0 +1,114 @@ +--- +Language: Cpp +Standard: Auto +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignArrayOfStructures: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: Consecutive +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: None +AlignEscapedNewlines: Right +AlignOperands: DontAlign +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BreakAfterJavaFieldAnnotations: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeConceptDeclarations: true +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +BreakConstructorInitializersBeforeComma: false +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 0 +CompactNamespaces: true +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 8 +ContinuationIndentWidth: 4 +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +FixNamespaceComments: false +IncludeBlocks: Preserve +IncludeIsMainRegex: (Test)?$ +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: true +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: All +PPIndentWidth: -1 +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseCRLF: false +UseTab: Never +... diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..cddc8f8 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,6 @@ +--- +Checks: '-*,clang-diagnostic-*,bugprone-*,cert-*,misc-*,modernize-*,performance-*,readability-*,hicpp-exception-baseclass,hicpp-avoid-goto,-clang-diagnostic-address-of-packed-member,-cert-dcl16-c,-cert-dcl21-cpp,-cert-err58-cpp,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-modernize-avoid-c-arrays,-modernize-concat-nested-namespaces,-modernize-raw-string-literal,-modernize-use-default-member-init,-modernize-use-nodiscard,-modernize-use-override,-modernize-use-trailing-return-type,-readability-else-after-return,-readability-identifier-naming,-readability-implicit-bool-cast,-readability-implicit-bool-conversion,-readability-magic-numbers,-readability-named-parameter,-readability-qualified-auto,-readability-redundant-access-specifiers,-readability-redundant-member-init,-readability-uppercase-literal-suffix' +WarningsAsErrors: '*' +HeaderFilterRegex: '' +FormatStyle: none +... diff --git a/.gitignore b/.gitignore index c5ae067..deae30f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ _deps build/ result /.vscode/ +/.idea *.o *-protocol.c @@ -22,4 +23,4 @@ hyprctl/hyprctl gmon.out *.out -*.tar.gz \ No newline at end of file +*.tar.gz diff --git a/src/Hyprpaper.cpp b/src/Hyprpaper.cpp index 95c07f4..2511072 100644 --- a/src/Hyprpaper.cpp +++ b/src/Hyprpaper.cpp @@ -1,6 +1,6 @@ #include "Hyprpaper.hpp" -CHyprpaper::CHyprpaper() { } +CHyprpaper::CHyprpaper() = default; void CHyprpaper::init() { @@ -9,12 +9,11 @@ void CHyprpaper::init() { g_pConfigManager = std::make_unique(); g_pIPCSocket = std::make_unique(); - m_sDisplay = (wl_display *)wl_display_connect(NULL); + m_sDisplay = (wl_display *)wl_display_connect(nullptr); if (!m_sDisplay) { Debug::log(CRIT, "No wayland compositor running!"); exit(1); - return; } preloadAllWallpapersFromConfig(); @@ -35,7 +34,7 @@ void CHyprpaper::init() { m_bShouldExit = true; }).detach(); - while (1) { // we also tick every 1ms for socket and other shit's updates + while (true) { // we also tick every 1ms for socket and other shit's updates tick(false); std::this_thread::sleep_for(std::chrono::milliseconds(1)); @@ -352,7 +351,7 @@ void CHyprpaper::createBuffer(SPoolBuffer* pBuffer, int32_t w, int32_t h, uint32 exit(1); } - const auto DATA = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, FD, 0); + const auto DATA = mmap(nullptr, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, FD, 0); const auto POOL = wl_shm_create_pool(g_pHyprpaper->m_sSHM, FD, SIZE); pBuffer->buffer = wl_shm_pool_create_buffer(POOL, 0, w, h, STRIDE, format); wl_shm_pool_destroy(POOL); @@ -470,4 +469,4 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) { } } } -} \ No newline at end of file +} diff --git a/src/Hyprpaper.hpp b/src/Hyprpaper.hpp index c7bed0a..d3c4624 100644 --- a/src/Hyprpaper.hpp +++ b/src/Hyprpaper.hpp @@ -60,4 +60,4 @@ private: bool m_bShouldExit = false; }; -inline std::unique_ptr g_pHyprpaper; \ No newline at end of file +inline std::unique_ptr g_pHyprpaper; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index c09cba9..d87f8eb 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -5,7 +5,7 @@ CConfigManager::CConfigManager() { // init the entire thing std::string configPath; - if (g_pHyprpaper->m_szExplicitConfigPath == "") { + if (g_pHyprpaper->m_szExplicitConfigPath.empty()) { const char *const ENVHOME = getenv("HOME"); configPath = ENVHOME + (std::string) "/.config/hypr/hyprpaper.conf"; } @@ -19,7 +19,6 @@ CConfigManager::CConfigManager() { if (!ifs.good()) { Debug::log(CRIT, "Hyprpaper was not provided a config!"); exit(1); - return; //jic } std::string line = ""; @@ -36,7 +35,7 @@ CConfigManager::CConfigManager() { parseError += "Config error at line " + std::to_string(linenum) + ": Line parsing error."; } - if (parseError != "" && parseError.find("Config error at line") != 0) { + if (!parseError.empty() && parseError.find("Config error at line") != 0) { parseError = "Config error at line " + std::to_string(linenum) + ": " + parseError; } @@ -46,7 +45,7 @@ CConfigManager::CConfigManager() { ifs.close(); } - if (parseError != "") { + if (!parseError.empty()) { Debug::log(CRIT, "Exiting because of config parse errors!\n%s", parseError.c_str()); exit(1); return; diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 684a42a..426bb2a 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -11,7 +11,7 @@ public: std::deque m_dRequestedPreloads; private: - std::string parseError = ""; + std::string parseError; void parseLine(std::string&); std::string removeBeginEndSpacesTabs(std::string in); @@ -24,4 +24,4 @@ private: friend class CIPCSocket; }; -inline std::unique_ptr g_pConfigManager; \ No newline at end of file +inline std::unique_ptr g_pConfigManager; diff --git a/src/debug/Log.hpp b/src/debug/Log.hpp index 8948086..0fd16cf 100644 --- a/src/debug/Log.hpp +++ b/src/debug/Log.hpp @@ -14,4 +14,4 @@ enum LogLevel { namespace Debug { void log(LogLevel level, const char* fmt, ...); -}; \ No newline at end of file +} diff --git a/src/events/Events.hpp b/src/events/Events.hpp index 58f5e09..c03e00d 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -26,4 +26,4 @@ namespace Events { inline const zwlr_layer_surface_v1_listener layersurfaceListener = { .configure = ls_configure }; inline const struct wl_registry_listener registryListener = { .global = handleGlobal, .global_remove = handleGlobalRemove }; -}; \ No newline at end of file +} diff --git a/src/helpers/Jpeg.cpp b/src/helpers/Jpeg.cpp index c1423ae..5719e89 100644 --- a/src/helpers/Jpeg.cpp +++ b/src/helpers/Jpeg.cpp @@ -22,7 +22,7 @@ cairo_surface_t* JPEG::createSurfaceFromJPEG(const std::string& path) { void* imageRawData; - struct stat fileInfo; + struct stat fileInfo = {}; const auto FD = open(path.c_str(), O_RDONLY); @@ -36,8 +36,8 @@ cairo_surface_t* JPEG::createSurfaceFromJPEG(const std::string& path) { // now the JPEG is in the memory - jpeg_decompress_struct decompressStruct; - jpeg_error_mgr errorManager; + jpeg_decompress_struct decompressStruct = {}; + jpeg_error_mgr errorManager = {}; decompressStruct.err = jpeg_std_error(&errorManager); jpeg_create_decompress(&decompressStruct); @@ -72,4 +72,4 @@ cairo_surface_t* JPEG::createSurfaceFromJPEG(const std::string& path) { jpeg_destroy_decompress(&decompressStruct); return cairoSurface; -} \ No newline at end of file +} diff --git a/src/helpers/Vector2D.cpp b/src/helpers/Vector2D.cpp index acaace1..7071a8e 100644 --- a/src/helpers/Vector2D.cpp +++ b/src/helpers/Vector2D.cpp @@ -6,7 +6,7 @@ Vector2D::Vector2D(double xx, double yy) { } Vector2D::Vector2D() { x = 0; y = 0; } -Vector2D::~Vector2D() {} +Vector2D::~Vector2D() = default; double Vector2D::normalize() { // get max abs @@ -18,6 +18,6 @@ double Vector2D::normalize() { return max; } -Vector2D Vector2D::floor() { - return Vector2D((int)x, (int)y); -} \ No newline at end of file +Vector2D Vector2D::floor() const { + return {static_cast(x), static_cast(y)}; +} diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp index 7288a08..b347aa1 100644 --- a/src/helpers/Vector2D.hpp +++ b/src/helpers/Vector2D.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include class Vector2D { public: @@ -35,5 +35,5 @@ class Vector2D { return a.x != x || a.y != y; } - Vector2D floor(); -}; \ No newline at end of file + Vector2D floor() const; +}; diff --git a/src/includes.hpp b/src/includes.hpp index 9d6fb60..f515ee4 100644 --- a/src/includes.hpp +++ b/src/includes.hpp @@ -4,12 +4,12 @@ #include #include #include -#include +#include #include #include #include -#include +#include #define class _class #define namespace _namespace @@ -27,13 +27,13 @@ extern "C" { #include #include -#include +#include #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/src/ipc/Socket.cpp b/src/ipc/Socket.cpp index 367c342..57e3c3a 100644 --- a/src/ipc/Socket.cpp +++ b/src/ipc/Socket.cpp @@ -2,15 +2,15 @@ #include "../Hyprpaper.hpp" #include -#include -#include -#include +#include +#include +#include #include #include #include #include #include -#include +#include void CIPCSocket::initialize() { std::thread([&]() { @@ -40,7 +40,7 @@ void CIPCSocket::initialize() { // 10 max queued. listen(SOCKET, 10); - sockaddr_in clientAddress; + sockaddr_in clientAddress = {}; socklen_t clientSize = sizeof(clientAddress); char readBuffer[1024] = {0}; @@ -104,7 +104,7 @@ bool CIPCSocket::mainThreadParseRequest() { g_pConfigManager->parseKeyword(copy.substr(0, copy.find_first_of(' ')), copy.substr(copy.find_first_of(' ') + 1)); - if (g_pConfigManager->parseError != "") { + if (!g_pConfigManager->parseError.empty()) { m_szReply = g_pConfigManager->parseError; m_bReplyReady = true; m_bRequestReady = false; @@ -123,4 +123,4 @@ bool CIPCSocket::mainThreadParseRequest() { m_bRequestReady = false; return true; -} \ No newline at end of file +} diff --git a/src/render/LayerSurface.cpp b/src/render/LayerSurface.cpp index b24a0a5..40e6da7 100644 --- a/src/render/LayerSurface.cpp +++ b/src/render/LayerSurface.cpp @@ -10,7 +10,6 @@ CLayerSurface::CLayerSurface(SMonitor* pMonitor) { if (!pSurface) { Debug::log(CRIT, "The compositor did not allow hyprpaper a surface!"); exit(1); - return; } const auto PINPUTREGION = wl_compositor_create_region(g_pHyprpaper->m_sCompositor); @@ -18,7 +17,6 @@ CLayerSurface::CLayerSurface(SMonitor* pMonitor) { if (!PINPUTREGION) { Debug::log(CRIT, "The compositor did not allow hyprpaper a region!"); exit(1); - return; } wl_surface_set_input_region(pSurface, PINPUTREGION); @@ -28,7 +26,6 @@ CLayerSurface::CLayerSurface(SMonitor* pMonitor) { if (!pLayerSurface) { Debug::log(CRIT, "The compositor did not allow hyprpaper a layersurface!"); exit(1); - return; } zwlr_layer_surface_v1_set_size(pLayerSurface, 0, 0); @@ -47,4 +44,4 @@ CLayerSurface::~CLayerSurface() { zwlr_layer_surface_v1_destroy(pLayerSurface); wl_display_flush(g_pHyprpaper->m_sDisplay); -} \ No newline at end of file +} diff --git a/src/render/LayerSurface.hpp b/src/render/LayerSurface.hpp index 09aa406..0a75983 100644 --- a/src/render/LayerSurface.hpp +++ b/src/render/LayerSurface.hpp @@ -6,13 +6,11 @@ struct SMonitor; class CLayerSurface { public: - CLayerSurface(SMonitor*); + explicit CLayerSurface(SMonitor*); ~CLayerSurface(); SMonitor* m_pMonitor = nullptr; zwlr_layer_surface_v1* pLayerSurface = nullptr; wl_surface* pSurface = nullptr; - - bool m_bCurrent = false; -}; \ No newline at end of file +}; diff --git a/src/render/WallpaperTarget.cpp b/src/render/WallpaperTarget.cpp index 73678e8..9751e1f 100644 --- a/src/render/WallpaperTarget.cpp +++ b/src/render/WallpaperTarget.cpp @@ -18,7 +18,6 @@ void CWallpaperTarget::create(const std::string& path) { } else { Debug::log(CRIT, "unrecognized image %s", path.c_str()); exit(1); - return; } if (cairo_surface_status(CAIROSURFACE) != CAIRO_STATUS_SUCCESS) { @@ -33,4 +32,4 @@ void CWallpaperTarget::create(const std::string& path) { Debug::log(LOG, "Preloaded target %s in %.2fms -> Pixel size: [%i, %i]", path.c_str(), MS, (int)m_vSize.x, (int)m_vSize.y); m_pCairoSurface = CAIROSURFACE; -} \ No newline at end of file +} diff --git a/src/render/WallpaperTarget.hpp b/src/render/WallpaperTarget.hpp index b80d6cd..15ebccf 100644 --- a/src/render/WallpaperTarget.hpp +++ b/src/render/WallpaperTarget.hpp @@ -9,7 +9,6 @@ public: ~CWallpaperTarget(); void create(const std::string& path); - void render(); std::string m_szPath; @@ -18,4 +17,4 @@ public: bool m_bHasAlpha = true; cairo_surface_t* m_pCairoSurface; -}; \ No newline at end of file +};