mirror of
https://github.com/hyprwm/hyprpicker.git
synced 2025-05-12 13:20:43 +01:00
core: clang-tidy and comp fixes (#110)
* clang-tidy and comp fixes * remove stupid comment * oaooaoaoaoao * quack * remove comment
This commit is contained in:
parent
36a24e61be
commit
b85b06577d
9 changed files with 144 additions and 45 deletions
101
.clang-tidy
Normal file
101
.clang-tidy
Normal file
|
@ -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
|
|
@ -42,15 +42,15 @@ execute_process(
|
|||
|
||||
include_directories(.)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
|
||||
add_compile_options(-DWLR_USE_UNSTABLE)
|
||||
add_compile_options(
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wuseless-cast
|
||||
-Wno-unused-parameter
|
||||
-Wno-unused-value
|
||||
-Wno-missing-field-initializers
|
||||
-Wno-narrowing
|
||||
-Wno-pointer-arith)
|
||||
-Wno-missing-field-initializers)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
|
|
@ -17,4 +17,4 @@ void Clipboard::copy(const char* fmt, ...) {
|
|||
execlp("wl-copy", "wl-copy", outputStr, NULL);
|
||||
|
||||
free(outputStr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <print>
|
||||
|
||||
#include "../includes.hpp"
|
||||
|
||||
|
@ -38,7 +39,7 @@ void Debug::log(LogLevel level, const char* fmt, ...) {
|
|||
outputStr = (char*)malloc(logLen + 1);
|
||||
|
||||
if (!outputStr) {
|
||||
printf("CRITICAL: Cannot alloc size %d for log! (Out of memory?)", logLen + 1);
|
||||
std::print("CRITICAL: Cannot alloc size {} for log! (Out of memory?)", logLen + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
#include "../hyprpicker.hpp"
|
||||
|
||||
CLayerSurface::CLayerSurface(SMonitor* pMonitor) {
|
||||
m_pMonitor = pMonitor;
|
||||
|
||||
CLayerSurface::CLayerSurface(SMonitor* pMonitor) : m_pMonitor(pMonitor) {
|
||||
pSurface = makeShared<CCWlSurface>(g_pHyprpicker->m_pCompositor->sendCreateSurface());
|
||||
|
||||
if (!pSurface) {
|
||||
|
|
|
@ -11,7 +11,7 @@ SPoolBuffer::SPoolBuffer(const Vector2D& pixelSize_, uint32_t format_, uint32_t
|
|||
g_pHyprpicker->finish(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);
|
||||
|
||||
size = SIZE;
|
||||
data = DATA;
|
||||
|
@ -39,4 +39,4 @@ SPoolBuffer::~SPoolBuffer() {
|
|||
|
||||
if (paddedData)
|
||||
free(paddedData);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "hyprpicker.hpp"
|
||||
#include <signal.h>
|
||||
#include <csignal>
|
||||
|
||||
void sigHandler(int sig) {
|
||||
g_pHyprpicker->m_vLayerSurfaces.clear();
|
||||
|
@ -248,7 +248,7 @@ void CHyprpicker::convertBuffer(SP<SPoolBuffer> pBuffer) {
|
|||
unsigned char green;
|
||||
unsigned char red;
|
||||
unsigned char alpha;
|
||||
}* px = (struct pixel*)(data + y * (int)pBuffer->pixelSize.x * 4 + x * 4);
|
||||
}* px = (struct pixel*)(data + (y * (int)pBuffer->pixelSize.x * 4) + (x * 4));
|
||||
|
||||
std::swap(px->red, px->blue);
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ void CHyprpicker::convertBuffer(SP<SPoolBuffer> pBuffer) {
|
|||
|
||||
for (int y = 0; y < pBuffer->pixelSize.y; ++y) {
|
||||
for (int x = 0; x < pBuffer->pixelSize.x; ++x) {
|
||||
uint32_t* px = (uint32_t*)(data + y * (int)pBuffer->pixelSize.x * 4 + x * 4);
|
||||
uint32_t* px = (uint32_t*)(data + (y * (int)pBuffer->pixelSize.x * 4) + (x * 4));
|
||||
|
||||
// conv to 8 bit
|
||||
uint8_t R = (uint8_t)std::round((255.0 * (((*px) & 0b00000000000000000000001111111111) >> 0) / 1023.0));
|
||||
|
@ -297,15 +297,15 @@ void* CHyprpicker::convert24To32Buffer(SP<SPoolBuffer> pBuffer) {
|
|||
unsigned char blue;
|
||||
unsigned char green;
|
||||
unsigned char red;
|
||||
}* srcPx = (struct pixel3*)(oldBuffer + y * pBuffer->stride + x * 3);
|
||||
}* srcPx = (struct pixel3*)(oldBuffer + (y * pBuffer->stride) + (x * 3));
|
||||
struct pixel4 {
|
||||
// little-endian ARGB
|
||||
unsigned char blue;
|
||||
unsigned char green;
|
||||
unsigned char red;
|
||||
unsigned char alpha;
|
||||
}* dstPx = (struct pixel4*)(newBuffer + y * newBufferStride + x * 4);
|
||||
*dstPx = {srcPx->red, srcPx->green, srcPx->blue, 0xFF};
|
||||
}* dstPx = (struct pixel4*)(newBuffer + (y * newBufferStride) + (x * 4));
|
||||
*dstPx = {.blue = srcPx->red, .green = srcPx->green, .red = srcPx->blue, .alpha = 0xFF};
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
@ -317,15 +317,15 @@ void* CHyprpicker::convert24To32Buffer(SP<SPoolBuffer> pBuffer) {
|
|||
unsigned char red;
|
||||
unsigned char green;
|
||||
unsigned char blue;
|
||||
}* srcPx = (struct pixel3*)(oldBuffer + y * pBuffer->stride + x * 3);
|
||||
}* srcPx = (struct pixel3*)(oldBuffer + (y * pBuffer->stride) + (x * 3));
|
||||
struct pixel4 {
|
||||
// big-endian ARGB
|
||||
unsigned char alpha;
|
||||
unsigned char red;
|
||||
unsigned char green;
|
||||
unsigned char blue;
|
||||
}* dstPx = (struct pixel4*)(newBuffer + y * newBufferStride + x * 4);
|
||||
*dstPx = {0xFF, srcPx->red, srcPx->green, srcPx->blue};
|
||||
}* dstPx = (struct pixel4*)(newBuffer + (y * newBufferStride) + (x * 4));
|
||||
*dstPx = {.alpha = 0xFF, .red = srcPx->red, .green = srcPx->green, .blue = srcPx->blue};
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
@ -418,7 +418,7 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) {
|
|||
cairo_matrix_init_identity(&matrix);
|
||||
cairo_matrix_translate(&matrix, CLICKPOSBUF.x + 0.5f, CLICKPOSBUF.y + 0.5f);
|
||||
cairo_matrix_scale(&matrix, 0.1f, 0.1f);
|
||||
cairo_matrix_translate(&matrix, -CLICKPOSBUF.x / SCALEBUFS.x - 0.5f, -CLICKPOSBUF.y / SCALEBUFS.y - 0.5f);
|
||||
cairo_matrix_translate(&matrix, (-CLICKPOSBUF.x / SCALEBUFS.x) - 0.5f, (-CLICKPOSBUF.y / SCALEBUFS.y) - 0.5f);
|
||||
cairo_pattern_set_matrix(PATTERN, &matrix);
|
||||
cairo_set_source(PCAIRO, PATTERN);
|
||||
cairo_arc(PCAIRO, CLICKPOS.x, CLICKPOS.y, 100 / SCALEBUFS.x, 0, 2 * M_PI);
|
||||
|
@ -518,7 +518,7 @@ CColor CHyprpicker::getColorFromPixel(CLayerSurface* pLS, Vector2D pix) {
|
|||
pix = pix.floor();
|
||||
|
||||
if (pix.x >= pLS->screenBuffer->pixelSize.x || pix.y >= pLS->screenBuffer->pixelSize.y || pix.x < 0 || pix.y < 0)
|
||||
return CColor{0, 0, 0, 0};
|
||||
return CColor{.r = 0, .g = 0, .b = 0, .a = 0};
|
||||
|
||||
void* dataSrc = pLS->screenBuffer->paddedData ? pLS->screenBuffer->paddedData : pLS->screenBuffer->data;
|
||||
struct pixel {
|
||||
|
@ -526,9 +526,9 @@ CColor CHyprpicker::getColorFromPixel(CLayerSurface* pLS, Vector2D pix) {
|
|||
unsigned char green;
|
||||
unsigned char red;
|
||||
unsigned char alpha;
|
||||
}* px = (struct pixel*)((char*)dataSrc + (int)pix.y * (int)pLS->screenBuffer->pixelSize.x * 4 + (int)pix.x * 4);
|
||||
}* px = (struct pixel*)((char*)dataSrc + ((ptrdiff_t)pix.y * (int)pLS->screenBuffer->pixelSize.x * 4) + ((ptrdiff_t)pix.x * 4));
|
||||
|
||||
return CColor{(uint8_t)px->red, (uint8_t)px->green, (uint8_t)px->blue, (uint8_t)px->alpha};
|
||||
return CColor{.r = px->red, .g = px->green, .b = px->blue, .a = px->alpha};
|
||||
}
|
||||
|
||||
void CHyprpicker::initKeyboard() {
|
||||
|
@ -541,7 +541,7 @@ void CHyprpicker::initKeyboard() {
|
|||
return;
|
||||
}
|
||||
|
||||
const char* buf = (const char*)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
const char* buf = (const char*)mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (buf == MAP_FAILED) {
|
||||
Debug::log(ERR, "Failed to mmap xkb keymap: %d", errno);
|
||||
return;
|
||||
|
@ -631,7 +631,7 @@ void CHyprpicker::initMouse() {
|
|||
case OUTPUT_CMYK: {
|
||||
// http://www.codeproject.com/KB/applications/xcmyk.aspx
|
||||
|
||||
float r = 1 - COL.r / 255.0f, g = 1 - COL.g / 255.0f, b = 1 - COL.b / 255.0f;
|
||||
float r = 1 - (COL.r / 255.0f), g = 1 - (COL.g / 255.0f), b = 1 - (COL.b / 255.0f);
|
||||
float k = fmin3(r, g, b), K = (k == 1) ? 1 : 1 - k;
|
||||
float c = (r - k) / K, m = (g - k) / K, y = (b - k) / K;
|
||||
|
||||
|
@ -661,6 +661,7 @@ void CHyprpicker::initMouse() {
|
|||
|
||||
return result;
|
||||
};
|
||||
|
||||
auto hexR = toHex(COL.r);
|
||||
auto hexG = toHex(COL.g);
|
||||
auto hexB = toHex(COL.b);
|
||||
|
|
|
@ -4,12 +4,11 @@
|
|||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <cmath>
|
||||
#include <math.h>
|
||||
|
||||
#include "protocols/cursor-shape-v1.hpp"
|
||||
#include "protocols/fractional-scale-v1.hpp"
|
||||
|
@ -18,14 +17,13 @@
|
|||
#include "protocols/viewporter.hpp"
|
||||
#include "protocols/wayland.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <cassert>
|
||||
#include <cairo.h>
|
||||
#include <cairo/cairo.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-client.h>
|
||||
|
|
28
src/main.cpp
28
src/main.cpp
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "hyprpicker.hpp"
|
||||
|
||||
static void help(void) {
|
||||
static void help() {
|
||||
std::cout << "Hyprpicker usage: hyprpicker [arg [...]].\n\nArguments:\n"
|
||||
<< " -a | --autocopy | Automatically copies the output to the clipboard (requires wl-clipboard)\n"
|
||||
<< " -f | --format=fmt | Specifies the output format (cmyk, hex, rgb, hsl, hsv)\n"
|
||||
|
@ -25,19 +25,19 @@ int main(int argc, char** argv, char** envp) {
|
|||
|
||||
while (true) {
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {{"autocopy", no_argument, NULL, 'a'},
|
||||
{"format", required_argument, NULL, 'f'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"no-fancy", no_argument, NULL, 'n'},
|
||||
{"render-inactive", no_argument, NULL, 'r'},
|
||||
{"no-zoom", no_argument, NULL, 'z'},
|
||||
{"no-fractional", no_argument, NULL, 't'},
|
||||
{"quiet", no_argument, NULL, 'q'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{"disable-hex-preview", no_argument, NULL, 'd'},
|
||||
{"lowercase-hex", no_argument, NULL, 'l'},
|
||||
{"version", no_argument, NULL, 'V'},
|
||||
{NULL, 0, NULL, 0}};
|
||||
static struct option long_options[] = {{"autocopy", no_argument, nullptr, 'a'},
|
||||
{"format", required_argument, nullptr, 'f'},
|
||||
{"help", no_argument, nullptr, 'h'},
|
||||
{"no-fancy", no_argument, nullptr, 'n'},
|
||||
{"render-inactive", no_argument, nullptr, 'r'},
|
||||
{"no-zoom", no_argument, nullptr, 'z'},
|
||||
{"no-fractional", no_argument, nullptr, 't'},
|
||||
{"quiet", no_argument, nullptr, 'q'},
|
||||
{"verbose", no_argument, nullptr, 'v'},
|
||||
{"disable-hex-preview", no_argument, nullptr, 'd'},
|
||||
{"lowercase-hex", no_argument, nullptr, 'l'},
|
||||
{"version", no_argument, nullptr, 'V'},
|
||||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
int c = getopt_long(argc, argv, ":f:hnarzqvtdlV", long_options, &option_index);
|
||||
if (c == -1)
|
||||
|
|
Loading…
Reference in a new issue