Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: add clang-tidy #135

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
101 changes: 101 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
WarningsAsErrors: '*'
HeaderFilterRegex: '.*\.hpp'
FormatStyle: file
Checks: >
-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
-bugprone-forward-declararion-namespace,
-bugprone-forward-declararion-namespace,
-bugprone-macro-parentheses,
-bugprone-narrowing-conversions,
-bugprone-branch-clone,
-bugprone-assignment-in-if-condition,
concurrency-*,
-concurrency-mt-unsafe,
cppcoreguidelines-*,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-avoid-goto,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-special-member-functions,
-cppcoreguidelines-explicit-virtual-functions,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-narrowing-conversions,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-type-member-init,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-macro-to-enum,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-pro-type-reinterpret-cast,
google-global-names-in-headers,
-google-readability-casting,
google-runtime-operator,
misc-*,
-misc-unused-parameters,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-misc-include-cleaner,
-misc-use-anonymous-namespace,
-misc-const-correctness,
modernize-*,
-modernize-return-braced-init-list,
-modernize-use-trailing-return-type,
-modernize-use-using,
-modernize-use-override,
-modernize-avoid-c-arrays,
-modernize-macro-to-enum,
-modernize-loop-convert,
-modernize-use-nodiscard,
-modernize-pass-by-value,
-modernize-use-auto,
performance-*,
-performance-avoid-endl,
-performance-unnecessary-value-param,
portability-std-allocator-const,
readability-*,
-readability-function-cognitive-complexity,
-readability-function-size,
-readability-identifier-length,
-readability-magic-numbers,
-readability-uppercase-literal-suffix,
-readability-braces-around-statements,
-readability-redundant-access-specifiers,
-readability-else-after-return,
-readability-container-data-pointer,
-readability-implicit-bool-conversion,
-readability-avoid-nested-conditional-operator,
-readability-redundant-member-init,
-readability-redundant-string-init,
-readability-avoid-const-params-in-decls,
-readability-named-parameter,
-readability-convert-member-functions-to-static,
-readability-qualified-auto,
-readability-make-member-function-const,
-readability-isolate-declaration,
-readability-inconsistent-declaration-parameter-name,
-clang-diagnostic-error,

CheckOptions:
performance-for-range-copy.WarnOnAllAutoCopies: true
performance-inefficient-string-concatenation.StrictMode: true
readability-braces-around-statements.ShortStatementLines: 0
readability-identifier-naming.ClassCase: CamelCase
readability-identifier-naming.ClassIgnoredRegexp: I.*
readability-identifier-naming.ClassPrefix: C # We can't use regex here?!?!?!?
readability-identifier-naming.EnumCase: CamelCase
readability-identifier-naming.EnumPrefix: e
readability-identifier-naming.EnumConstantCase: UPPER_CASE
readability-identifier-naming.FunctionCase: camelBack
readability-identifier-naming.NamespaceCase: CamelCase
readability-identifier-naming.NamespacePrefix: N
readability-identifier-naming.StructPrefix: S
readability-identifier-naming.StructCase: CamelCase
14 changes: 7 additions & 7 deletions src/allocator/GBM.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <aquamarine/allocator/GBM.hpp>
#include <aquamarine/backend/Backend.hpp>
#include <aquamarine/backend/DRM.hpp>
Expand All @@ -24,23 +25,23 @@ static SDRMFormat guessFormatFrom(std::vector<SDRMFormat> formats, bool cursor,
*/
if (!scanout) {
if (auto it =
std::find_if(formats.begin(), formats.end(), [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB2101010 || f.drmFormat == DRM_FORMAT_ABGR2101010; });
std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB2101010 || f.drmFormat == DRM_FORMAT_ABGR2101010; });
it != formats.end())
return *it;
}

if (auto it = std::find_if(formats.begin(), formats.end(), [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB2101010 || f.drmFormat == DRM_FORMAT_XBGR2101010; });
if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB2101010 || f.drmFormat == DRM_FORMAT_XBGR2101010; });
it != formats.end())
return *it;
}

if (!scanout || cursor /* don't set opaque for cursor plane */) {
if (auto it = std::find_if(formats.begin(), formats.end(), [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB8888 || f.drmFormat == DRM_FORMAT_ABGR8888; });
if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB8888 || f.drmFormat == DRM_FORMAT_ABGR8888; });
it != formats.end())
return *it;
}

if (auto it = std::find_if(formats.begin(), formats.end(), [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB8888 || f.drmFormat == DRM_FORMAT_XBGR8888; });
if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB8888 || f.drmFormat == DRM_FORMAT_XBGR8888; });
it != formats.end())
return *it;

Expand Down Expand Up @@ -119,7 +120,7 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti
TRACE(allocator->backend->log(AQ_LOG_TRACE, std::format("GBM: Renderable has {} formats, clipping", RENDERABLE.size())));
if (params.scanout && !CURSOR && !MULTIGPU) {
// regular scanout plane, check if the format is renderable
auto rformat = std::find_if(RENDERABLE.begin(), RENDERABLE.end(), [f](const auto& e) { return e.drmFormat == f.drmFormat; });
auto rformat = std::ranges::find_if(RENDERABLE, [f](const auto& e) { return e.drmFormat == f.drmFormat; });

if (rformat == RENDERABLE.end()) {
TRACE(allocator->backend->log(AQ_LOG_TRACE, std::format("GBM: Dropping format {} as it's not renderable", fourccToName(f.drmFormat))));
Expand Down Expand Up @@ -322,8 +323,7 @@ SP<CGBMAllocator> Aquamarine::CGBMAllocator::create(int drmfd_, Hyprutils::Memor
return allocator;
}

Aquamarine::CGBMAllocator::CGBMAllocator(int fd_, Hyprutils::Memory::CWeakPointer<CBackend> backend_) : fd(fd_), backend(backend_) {
gbmDevice = gbm_create_device(fd_);
Aquamarine::CGBMAllocator::CGBMAllocator(int fd_, Hyprutils::Memory::CWeakPointer<CBackend> backend_) : fd(fd_), backend(backend_), gbmDevice(gbm_create_device(fd_)) {
if (!gbmDevice) {
backend->log(AQ_LOG_ERROR, std::format("Couldn't open a GBM device at fd {}", fd_));
return;
Expand Down
3 changes: 2 additions & 1 deletion src/allocator/Swapchain.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <aquamarine/allocator/Swapchain.hpp>
#include <aquamarine/backend/Backend.hpp>
#include "FormatUtils.hpp"
Expand Down Expand Up @@ -114,7 +115,7 @@ bool Aquamarine::CSwapchain::resize(size_t newSize) {
}

bool Aquamarine::CSwapchain::contains(SP<IBuffer> buffer) {
return std::find(buffers.begin(), buffers.end(), buffer) != buffers.end();
return std::ranges::find(buffers, buffer) != buffers.end();
}

const SSwapchainOptions& Aquamarine::CSwapchain::currentOptions() {
Expand Down
13 changes: 6 additions & 7 deletions src/backend/Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <aquamarine/allocator/GBM.hpp>
#include <ranges>
#include <sys/timerfd.h>
#include <time.h>
#include <string.h>
#include <ctime>
#include <cstring>
#include <xf86drm.h>
#include <fcntl.h>
#include <unistd.h>
Expand Down Expand Up @@ -44,13 +44,12 @@ Aquamarine::CBackend::CBackend() {
;
}

Aquamarine::SBackendImplementationOptions::SBackendImplementationOptions() {
backendType = AQ_BACKEND_WAYLAND;
backendRequestMode = AQ_BACKEND_REQUEST_IF_AVAILABLE;
Aquamarine::SBackendImplementationOptions::SBackendImplementationOptions() : backendType(AQ_BACKEND_WAYLAND), backendRequestMode(AQ_BACKEND_REQUEST_IF_AVAILABLE) {
;
}

Aquamarine::SBackendOptions::SBackendOptions() {
logFunction = nullptr;
Aquamarine::SBackendOptions::SBackendOptions() : logFunction(nullptr) {
;
}

Hyprutils::Memory::CSharedPointer<CBackend> Aquamarine::CBackend::create(const std::vector<SBackendImplementationOptions>& backends, const SBackendOptions& options) {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/Headless.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <aquamarine/backend/Headless.hpp>
#include <fcntl.h>
#include <time.h>
#include <ctime>
#include <sys/timerfd.h>
#include <string.h>
#include <cstring>
#include "Shared.hpp"

using namespace Aquamarine;
Expand Down
1 change: 0 additions & 1 deletion src/backend/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ void Aquamarine::CSession::dispatchUdevEvents() {
}

udev_device_unref(device);
return;
}

void Aquamarine::CSession::dispatchLibinputEvents() {
Expand Down
7 changes: 4 additions & 3 deletions src/backend/Wayland.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <algorithm>
#include <aquamarine/backend/Wayland.hpp>
#include <wayland.hpp>
#include <xdg-shell.hpp>
#include "Shared.hpp"
#include "FormatUtils.hpp"
#include <string.h>
#include <cstring>
#include <xf86drm.h>
#include <gbm.h>
#include <fcntl.h>
Expand Down Expand Up @@ -403,7 +404,7 @@ bool Aquamarine::CWaylandBackend::initDmabuf() {
backend->log(AQ_LOG_DEBUG, std::format("zwp_linux_dmabuf_v1: Got format {} with modifier {}", fourccToName(fmt.drmFormat), modName ? modName : "UNKNOWN"));
free(modName);

auto it = std::find_if(dmabufFormats.begin(), dmabufFormats.end(), [&fmt](const auto& e) { return e.drmFormat == fmt.drmFormat; });
auto it = std::ranges::find_if(dmabufFormats, [&fmt](const auto& e) { return e.drmFormat == fmt.drmFormat; });
if (it == dmabufFormats.end()) {
dmabufFormats.emplace_back(SDRMFormat{.drmFormat = fmt.drmFormat, .modifiers = {fmt.modifier}});
continue;
Expand Down Expand Up @@ -739,7 +740,7 @@ bool Aquamarine::CWaylandOutput::setCursor(Hyprutils::Memory::CSharedPointer<IBu
}

void Aquamarine::CWaylandOutput::moveCursor(const Hyprutils::Math::Vector2D& coord, bool skipSchedule) {
return;
;
}

void Aquamarine::CWaylandOutput::onEnter(SP<CCWlPointer> pointer, uint32_t serial) {
Expand Down
23 changes: 12 additions & 11 deletions src/backend/drm/DRM.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "aquamarine/output/Output.hpp"
#include <algorithm>
#include <aquamarine/backend/DRM.hpp>
#include <aquamarine/backend/drm/Legacy.hpp>
#include <aquamarine/backend/drm/Atomic.hpp>
Expand Down Expand Up @@ -306,7 +307,7 @@ std::vector<SP<CDRMBackend>> Aquamarine::CDRMBackend::attempt(SP<CBackend> backe
}

Aquamarine::CDRMBackend::~CDRMBackend() {
for (auto conn : connectors) {
for (auto& conn : connectors) {
conn->disconnect();
conn.reset();
}
Expand Down Expand Up @@ -582,14 +583,14 @@ void Aquamarine::CDRMBackend::buildGlFormats(const std::vector<SGLFormat>& fmts)
if (fmt.external && fmt.modifier != DRM_FORMAT_MOD_INVALID)
continue;

if (auto it = std::find_if(result.begin(), result.end(), [fmt](const auto& e) { return fmt.drmFormat == e.drmFormat; }); it != result.end()) {
if (auto it = std::ranges::find_if(result, [fmt](const auto& e) { return fmt.drmFormat == e.drmFormat; }); it != result.end()) {
it->modifiers.emplace_back(fmt.modifier);
continue;
}

result.emplace_back(SDRMFormat{
fmt.drmFormat,
{fmt.modifier},
.drmFormat = fmt.drmFormat,
.modifiers = {fmt.modifier},
});
}

Expand Down Expand Up @@ -774,7 +775,7 @@ void Aquamarine::CDRMBackend::scanConnectors() {
continue;
}

auto it = std::find_if(connectors.begin(), connectors.end(), [connectorID](const auto& e) { return e->id == connectorID; });
auto it = std::ranges::find_if(connectors, [connectorID](const auto& e) { return e->id == connectorID; });
if (it == connectors.end()) {
backend->log(AQ_LOG_DEBUG, std::format("drm: Initializing connector id {}", connectorID));
conn = connectors.emplace_back(SP<SDRMConnector>(new SDRMConnector()));
Expand Down Expand Up @@ -1077,7 +1078,7 @@ bool Aquamarine::SDRMPlane::init(drmModePlane* plane) {

drmModeFormatModifierIterator iter = {0};
while (drmModeFormatModifierBlobIterNext(blob, &iter)) {
auto it = std::find_if(formats.begin(), formats.end(), [iter](const auto& e) { return e.drmFormat == iter.fmt; });
auto it = std::ranges::find_if(formats, [iter](const auto& e) { return e.drmFormat == iter.fmt; });

TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("drm: | Modifier {} with format {}", iter.mod, fourccToName(iter.fmt))));

Expand Down Expand Up @@ -1250,10 +1251,10 @@ IOutput::SParsedEDID Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> d
const auto chromaticity = di_edid_get_chromaticity_coords(edid);
if (chromaticity) {
parsed.chromaticityCoords = IOutput::SChromaticityCoords{
IOutput::xy{chromaticity->red_x, chromaticity->red_y},
IOutput::xy{chromaticity->green_x, chromaticity->green_y},
IOutput::xy{chromaticity->blue_x, chromaticity->blue_y},
IOutput::xy{chromaticity->white_x, chromaticity->white_y},
.red = IOutput::xy{.x = chromaticity->red_x, .y = chromaticity->red_y},
.green = IOutput::xy{.x = chromaticity->green_x, .y = chromaticity->green_y},
.blue = IOutput::xy{.x = chromaticity->blue_x, .y = chromaticity->blue_y},
.white = IOutput::xy{.x = chromaticity->white_x, .y = chromaticity->white_y},
};
TRACE(backend->backend->log(AQ_LOG_TRACE,
std::format("EDID: chromaticity coords {},{} {},{} {},{} {},{}", parsed.chromaticityCoords->red.x, parsed.chromaticityCoords->red.y,
Expand Down Expand Up @@ -1362,7 +1363,7 @@ void Aquamarine::SDRMConnector::connect(drmModeConnector* connector) {

output->modes.emplace_back(aqMode);

if (currentModeInfo && std::memcmp(&drmMode, currentModeInfo, sizeof(drmModeModeInfo))) {
if (currentModeInfo && std::memcmp(&drmMode, currentModeInfo, sizeof(drmModeModeInfo)) != 0) {
output->state->setMode(aqMode);

//uint64_t modeID = 0;
Expand Down
Loading