Compare commits

...

11 commits
v0.4.2 ... main

Author SHA1 Message Date
Vaxry
980ebd486b
version: bump to 0.4.5
Some checks failed
Build Hyprpicker (Nix) / Build (push) Has been cancelled
2025-05-01 01:54:26 +01:00
Honkazel
5dcb341c13
clang-tidy: fix some errors (#118) 2025-04-22 23:24:11 +02:00
nyx
5bbeaeebd3
LayerSurface: always render in callback (#117)
* LayerSurface: always render in callback
2025-04-21 20:47:47 +02:00
Vaxry
fd77aea026 version: bump to 0.4.4 2025-04-11 13:58:11 +01:00
nyx
23664963a1
layerSurface: fix commit lag (#114) 2025-04-09 17:47:02 +02:00
Vaxry
6692091d56 core: buffer handling fixes
fixes #101
2025-03-31 21:27:04 +01:00
vaxerski
09101f77a4 version: bump to 0.4.3 2025-03-24 11:34:15 +00:00
nyx
e990630562
layerSurface: fix circle not following cursor movement (#113)
* layerSurface: fix circle not following cursor movement

* misc: format code
2025-03-21 09:35:34 +01:00
Honkazel
b85b06577d
core: clang-tidy and comp fixes (#110)
* clang-tidy and comp fixes

* remove stupid comment

* oaooaoaoaoao

* quack

* remove comment
2025-02-21 21:32:08 +01:00
Sepandar
36a24e61be
core: Fix negative HSV values (#111)
* fixed description in CMakeLists.txt and fixed negative hsv

* ran clang-format
2025-02-15 18:50:05 +01:00
Mihai Fufezan
c3777320b3
flake.lock: update 2025-01-23 14:33:21 +02:00
11 changed files with 171 additions and 70 deletions

101
.clang-tidy Normal file
View file

@ -0,0 +1,101 @@
WarningsAsErrors: '*'
HeaderFilterRegex: '.*\.hpp'
FormatStyle: 'file'
Checks: >
-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
-bugprone-forward-declaration-namespace,
-bugprone-forward-declaration-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

View file

@ -5,7 +5,7 @@ string(STRIP ${VER_RAW} VERSION)
project(
hyprpicker
DESCRIPTION "A blazing fast wayland wallpaper utility"
DESCRIPTION "A wlroots-compatible Wayland color picker that does not suck"
VERSION ${VERSION})
set(CMAKE_MESSAGE_LOG_LEVEL "STATUS")
@ -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)

View file

@ -1 +1 @@
0.4.2
0.4.5

View file

@ -10,11 +10,11 @@
]
},
"locked": {
"lastModified": 1733502241,
"narHash": "sha256-KAUNC4Dgq8WQjYov5auBw/usaHixhacvb7cRDd0AG/k=",
"lastModified": 1737632363,
"narHash": "sha256-X9I8POSlHxBVjD0fiX1O2j7U9Zi1+4rIkrsyHP0uHXY=",
"owner": "hyprwm",
"repo": "hyprutils",
"rev": "104117aed6dd68561be38b50f218190aa47f2cd8",
"rev": "006620eb29d54ea9086538891404c78563d1bae1",
"type": "github"
},
"original": {
@ -33,11 +33,11 @@
]
},
"locked": {
"lastModified": 1726874836,
"narHash": "sha256-VKR0sf0PSNCB0wPHVKSAn41mCNVCnegWmgkrneKDhHM=",
"lastModified": 1735493474,
"narHash": "sha256-fktzv4NaqKm94VAkAoVqO/nqQlw+X0/tJJNAeCSfzK4=",
"owner": "hyprwm",
"repo": "hyprwayland-scanner",
"rev": "500c81a9e1a76760371049a8d99e008ea77aa59e",
"rev": "de913476b59ee88685fdc018e77b8f6637a2ae0b",
"type": "github"
},
"original": {
@ -48,11 +48,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1734119587,
"narHash": "sha256-AKU6qqskl0yf2+JdRdD0cfxX4b9x3KKV5RqA6wijmPM=",
"lastModified": 1737469691,
"narHash": "sha256-nmKOgAU48S41dTPIXAq0AHZSehWUn6ZPrUKijHAMmIk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3566ab7246670a43abd2ffa913cc62dad9cdf7d5",
"rev": "9e4d5190a9482a1fb9d18adf0bdb83c6e506eaab",
"type": "github"
},
"original": {

View file

@ -17,4 +17,4 @@ void Clipboard::copy(const char* fmt, ...) {
execlp("wl-copy", "wl-copy", outputStr, NULL);
free(outputStr);
}
}

View file

@ -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;
}

View file

@ -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) {
@ -68,15 +66,17 @@ CLayerSurface::~CLayerSurface() {
static void onCallbackDone(CLayerSurface* surf, uint32_t when) {
surf->frameCallback.reset();
if (surf->dirty || !surf->rendered)
g_pHyprpicker->renderSurface(g_pHyprpicker->m_pLastSurface);
g_pHyprpicker->renderSurface(surf);
}
void CLayerSurface::sendFrame() {
lastBuffer = lastBuffer == 0 ? 1 : 0;
const auto& PBUFFER = buffers[lastBuffer];
frameCallback = makeShared<CCWlCallback>(pSurface->sendFrame());
frameCallback->setDone([this](CCWlCallback* r, uint32_t when) { onCallbackDone(this, when); });
const auto& PBUFFER = lastBuffer == 0 ? buffers[0] : buffers[1];
pSurface->sendDamageBuffer(0, 0, 0xFFFF, 0xFFFF);
pSurface->sendAttach(PBUFFER->buffer.get(), 0, 0);
if (!g_pHyprpicker->m_bNoFractional) {
@ -85,16 +85,12 @@ void CLayerSurface::sendFrame() {
} else
pSurface->sendSetBufferScale(m_pMonitor->scale);
pSurface->sendDamageBuffer(0, 0, 0xFFFF, 0xFFFF);
pSurface->sendCommit();
dirty = false;
}
void CLayerSurface::markDirty() {
frameCallback = makeShared<CCWlCallback>(pSurface->sendFrame());
frameCallback->setDone([this](CCWlCallback* r, uint32_t when) { onCallbackDone(this, when); });
pSurface->sendCommit();
dirty = true;
}

View file

@ -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);
}
}

View file

@ -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;
@ -341,7 +341,7 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) {
const auto PBUFFER = getBufferForLS(pSurface);
if (!PBUFFER || !pSurface->screenBuffer) {
// Debug::log(ERR, PBUFFER ? "renderSurface: pSurface->screenBuffer null" : "renderSurface: PBUFFER null");
Debug::log(ERR, PBUFFER ? "renderSurface: pSurface->screenBuffer null" : "renderSurface: PBUFFER null");
return;
}
@ -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;
@ -583,8 +583,6 @@ void CHyprpicker::initMouse() {
m_vLastCoords = {x, y};
markDirty();
for (auto& ls : m_vLayerSurfaces) {
if (ls->pSurface->resource() == surface) {
m_pLastSurface = ls.get();
@ -593,13 +591,19 @@ void CHyprpicker::initMouse() {
}
m_pCursorShapeDevice->sendSetShape(serial, WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR);
markDirty();
});
m_pPointer->setLeave([this](CCWlPointer* r, uint32_t timeMs, wl_proxy* surf) {
m_pPointer->setLeave([this](CCWlPointer* r, uint32_t timeMs, wl_proxy* surface) {
for (auto& ls : m_vLayerSurfaces) {
if (ls->pSurface->resource() == surf) {
renderSurface(ls.get(), true);
if (ls->pSurface->resource() == surface) {
if (m_pLastSurface == ls.get())
m_pLastSurface = nullptr;
break;
}
}
markDirty();
});
m_pPointer->setMotion([this](CCWlPointer* r, uint32_t timeMs, wl_fixed_t surface_x, wl_fixed_t surface_y) {
auto x = wl_fixed_to_double(surface_x);
@ -631,7 +635,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 +665,7 @@ void CHyprpicker::initMouse() {
return result;
};
auto hexR = toHex(COL.r);
auto hexG = toHex(COL.g);
auto hexB = toHex(COL.b);
@ -721,7 +726,7 @@ void CHyprpicker::initMouse() {
l_or_v = std::round(v * 100);
}
h = std::round(h);
h = std::round(h < 0 ? h + 360 : h);
s = std::round(s * 100);
if (m_bFancyOutput)

View file

@ -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>

View file

@ -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)