clang-format, no-zoom and render-inactive

This commit is contained in:
vaxerski 2023-03-31 17:41:40 +01:00
parent 234c2da51a
commit cc6b3234b2
5 changed files with 259 additions and 203 deletions

65
.clang-format Normal file
View file

@ -0,0 +1,65 @@
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: true
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
ColumnLimit: 180
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
IncludeBlocks: Preserve
IndentCaseLabels: true
IndentWidth: 4
PointerAlignment: Left
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: Never
AllowShortEnumsOnASingleLine: false
BraceWrapping:
AfterEnum: false
AlignConsecutiveDeclarations: AcrossEmptyLines
NamespaceIndentation: All

View file

@ -1,39 +1,41 @@
#include "Events.hpp"
#include "../hyprpicker.hpp"
void Events::geometry(void *data, wl_output *output, int32_t x, int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, const char *make, const char *model, int32_t transform) {
void Events::geometry(void* data, wl_output* output, int32_t x, int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, const char* make, const char* model,
int32_t transform) {
// ignored
}
void Events::mode(void *data, wl_output *output, uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
void Events::mode(void* data, wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
// ignored
}
void Events::done(void *data, wl_output *wl_output) {
void Events::done(void* data, wl_output* wl_output) {
const auto PMONITOR = (SMonitor*)data;
PMONITOR->ready = true;
}
void Events::scale(void *data, wl_output *wl_output, int32_t scale) {
void Events::scale(void* data, wl_output* wl_output, int32_t scale) {
const auto PMONITOR = (SMonitor*)data;
PMONITOR->scale = scale;
}
void Events::name(void *data, wl_output *wl_output, const char *name) {
void Events::name(void* data, wl_output* wl_output, const char* name) {
const auto PMONITOR = (SMonitor*)data;
if (name)
PMONITOR->name = name;
}
void Events::description(void *data, wl_output *wl_output, const char *description) {
void Events::description(void* data, wl_output* wl_output, const char* description) {
// i do not care
}
void Events::ls_configure(void *data, zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t width, uint32_t height) {
const auto PLAYERSURFACE = (CLayerSurface *)data;
void Events::ls_configure(void* data, zwlr_layer_surface_v1* surface, uint32_t serial, uint32_t width, uint32_t height) {
const auto PLAYERSURFACE = (CLayerSurface*)data;
PLAYERSURFACE->m_pMonitor->size = Vector2D(width, height);
PLAYERSURFACE->ACKSerial = serial;
@ -43,23 +45,23 @@ void Events::ls_configure(void *data, zwlr_layer_surface_v1 *surface, uint32_t s
g_pHyprpicker->recheckACK();
}
void Events::handleGlobal(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) {
void Events::handleGlobal(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) {
if (strcmp(interface, wl_compositor_interface.name) == 0) {
g_pHyprpicker->m_pCompositor = (wl_compositor *)wl_registry_bind(registry, name, &wl_compositor_interface, 4);
g_pHyprpicker->m_pCompositor = (wl_compositor*)wl_registry_bind(registry, name, &wl_compositor_interface, 4);
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
g_pHyprpicker->m_pWLSHM = (wl_shm *)wl_registry_bind(registry, name, &wl_shm_interface, 1);
g_pHyprpicker->m_pWLSHM = (wl_shm*)wl_registry_bind(registry, name, &wl_shm_interface, 1);
} else if (strcmp(interface, wl_output_interface.name) == 0) {
g_pHyprpicker->m_mtTickMutex.lock();
const auto PMONITOR = g_pHyprpicker->m_vMonitors.emplace_back(std::make_unique<SMonitor>()).get();
PMONITOR->wayland_name = name;
PMONITOR->name = "";
PMONITOR->output = (wl_output *)wl_registry_bind(registry, name, &wl_output_interface, 4);
PMONITOR->output = (wl_output*)wl_registry_bind(registry, name, &wl_output_interface, 4);
wl_output_add_listener(PMONITOR->output, &Events::outputListener, PMONITOR);
g_pHyprpicker->m_mtTickMutex.unlock();
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
g_pHyprpicker->m_pLayerShell = (zwlr_layer_shell_v1 *)wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 1);
g_pHyprpicker->m_pLayerShell = (zwlr_layer_shell_v1*)wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 1);
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
g_pHyprpicker->createSeat((wl_seat*)wl_registry_bind(registry, name, &wl_seat_interface, 1));
} else if (strcmp(interface, zwlr_screencopy_manager_v1_interface.name) == 0) {
@ -67,11 +69,11 @@ void Events::handleGlobal(void *data, struct wl_registry *registry, uint32_t nam
}
}
void Events::handleGlobalRemove(void *data, struct wl_registry *registry, uint32_t name) {
void Events::handleGlobalRemove(void* data, struct wl_registry* registry, uint32_t name) {
// todo
}
void Events::handleCapabilities(void *data, wl_seat *wl_seat, uint32_t capabilities) {
void Events::handleCapabilities(void* data, wl_seat* wl_seat, uint32_t capabilities) {
if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
wl_pointer_add_listener(wl_seat_get_pointer(wl_seat), &pointerListener, wl_seat);
} else {
@ -84,7 +86,7 @@ void Events::handleCapabilities(void *data, wl_seat *wl_seat, uint32_t capabilit
}
}
void Events::handlePointerEnter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
void Events::handlePointerEnter(void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
g_pHyprpicker->markDirty();
for (auto& ls : g_pHyprpicker->m_vLayerSurfaces) {
@ -99,7 +101,7 @@ void Events::handlePointerEnter(void *data, struct wl_pointer *wl_pointer, uint3
}
}
void Events::handlePointerLeave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface) {
void Events::handlePointerLeave(void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface) {
for (auto& ls : g_pHyprpicker->m_vLayerSurfaces) {
if (ls->pSurface == surface) {
g_pHyprpicker->renderSurface(ls.get(), true);
@ -107,12 +109,11 @@ void Events::handlePointerLeave(void *data, struct wl_pointer *wl_pointer, uint3
}
}
void Events::handlePointerAxis(void *data, wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value) {
void Events::handlePointerAxis(void* data, wl_pointer* wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value) {
// ignored
}
void Events::handlePointerMotion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
void Events::handlePointerMotion(void* data, struct wl_pointer* wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
auto x = wl_fixed_to_double(surface_x);
auto y = wl_fixed_to_double(surface_y);
@ -121,37 +122,26 @@ void Events::handlePointerMotion(void *data, struct wl_pointer *wl_pointer, uint
g_pHyprpicker->markDirty();
}
void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state) {
auto fmax3 = [](float a, float b, float c) -> float {
return (a > b && a > c) ? a : (b > c) ? b : c;
};
auto fmin3 = [](float a, float b, float c) -> float {
return (a < b && a < c) ? a : (b < c) ? b : c;
};
void Events::handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state) {
auto fmax3 = [](float a, float b, float c) -> float { return (a > b && a > c) ? a : (b > c) ? b : c; };
auto fmin3 = [](float a, float b, float c) -> float { return (a < b && a < c) ? a : (b < c) ? b : c; };
// get the px and print it
const auto SCALE = Vector2D{
g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.x / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.x / g_pHyprpicker->m_pLastSurface->m_pMonitor->scale),
g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.y / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.y / g_pHyprpicker->m_pLastSurface->m_pMonitor->scale)
};
g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.y / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.y / g_pHyprpicker->m_pLastSurface->m_pMonitor->scale)};
const auto CLICKPOS = Vector2D{g_pHyprpicker->m_vLastCoords.floor().x * SCALE.x, g_pHyprpicker->m_vLastCoords.floor().y * SCALE.y};
const auto COL = g_pHyprpicker->getColorFromPixel(g_pHyprpicker->m_pLastSurface, CLICKPOS);
switch (g_pHyprpicker->m_bSelectedOutputMode) {
case OUTPUT_CMYK:
{
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 k = fmin3(r, g, b),
K = 1 - k;
float c = (r - k) / K,
m = (g - k) / K,
y = (b - k) / K;
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 = 1 - k;
float c = (r - k) / K, m = (g - k) / K, y = (b - k) / K;
c = std::round(c * 100);
m = std::round(m * 100);
@ -168,8 +158,7 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
g_pHyprpicker->finish();
break;
}
case OUTPUT_HEX:
{
case OUTPUT_HEX: {
auto toHex = [](int i) -> std::string {
const char* DS = "0123456789ABCDEF";
@ -191,8 +180,7 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
g_pHyprpicker->finish();
break;
}
case OUTPUT_RGB:
{
case OUTPUT_RGB: {
if (g_pHyprpicker->m_bFancyOutput)
Debug::log(NONE, "\033[38;2;%i;%i;%im%i %i %i\033[0m", COL.r, COL.g, COL.b, COL.r, COL.g, COL.b);
else
@ -204,8 +192,7 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
break;
}
case OUTPUT_HSL:
case OUTPUT_HSV:
{
case OUTPUT_HSV: {
// https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB
auto floatEq = [](float a, float b) -> bool {
@ -213,11 +200,8 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
};
float h, s, l, v;
float r = COL.r / 255.0f,
g = COL.g / 255.0f,
b = COL.b / 255.0f;
float max = fmax3(r, g, b),
min = fmin3(r, g, b);
float r = COL.r / 255.0f, g = COL.g / 255.0f, b = COL.b / 255.0f;
float max = fmax3(r, g, b), min = fmin3(r, g, b);
float c = max - min;
v = max;
@ -259,29 +243,20 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
g_pHyprpicker->finish();
}
void Events::handleKeyboardKeymap(void* data, wl_keyboard* wl_keyboard, uint format, int fd, uint size) {
void Events::handleKeyboardKeymap(void* data, wl_keyboard* wl_keyboard, uint format, int fd, uint size) {}
}
void Events::handleKeyboardKey(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
void Events::handleKeyboardKey(void* data, struct wl_keyboard* keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
if (key == 1) // escape
g_pHyprpicker->finish();
}
void Events::handleKeyboardEnter(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface, wl_array* keys) {
void Events::handleKeyboardEnter(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface, wl_array* keys) {}
}
void Events::handleKeyboardLeave(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface) {}
void Events::handleKeyboardLeave(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface) {
void Events::handleKeyboardModifiers(void* data, wl_keyboard* wl_keyboard, uint serial, uint mods_depressed, uint mods_latched, uint mods_locked, uint group) {}
}
void Events::handleKeyboardModifiers(void* data, wl_keyboard* wl_keyboard, uint serial, uint mods_depressed, uint mods_latched, uint mods_locked, uint group) {
}
void Events::handleFrameDone(void *data, struct wl_callback *callback, uint32_t time) {
void Events::handleFrameDone(void* data, struct wl_callback* callback, uint32_t time) {
CLayerSurface* pLS = (CLayerSurface*)data;
if (pLS->frame_callback)
@ -293,12 +268,12 @@ void Events::handleFrameDone(void *data, struct wl_callback *callback, uint32_t
g_pHyprpicker->renderSurface(g_pHyprpicker->m_pLastSurface);
}
void Events::handleBufferRelease(void *data, struct wl_buffer *wl_buffer) {
void Events::handleBufferRelease(void* data, struct wl_buffer* wl_buffer) {
auto buf = (SPoolBuffer*)data;
buf->busy = false;
}
void Events::handleSCBuffer(void *data, struct zwlr_screencopy_frame_v1 *frame, uint32_t format, uint32_t width, uint32_t height, uint32_t stride) {
void Events::handleSCBuffer(void* data, struct zwlr_screencopy_frame_v1* frame, uint32_t format, uint32_t width, uint32_t height, uint32_t stride) {
const auto PLS = (CLayerSurface*)data;
g_pHyprpicker->createBuffer(&PLS->screenBuffer, width, height, format, stride);
@ -306,8 +281,8 @@ void Events::handleSCBuffer(void *data, struct zwlr_screencopy_frame_v1 *frame,
zwlr_screencopy_frame_v1_copy(frame, PLS->screenBuffer.buffer);
}
void Events::handleSCFlags(void *data, struct zwlr_screencopy_frame_v1 *frame, uint32_t flags) {
const auto PLS = (CLayerSurface *)data;
void Events::handleSCFlags(void* data, struct zwlr_screencopy_frame_v1* frame, uint32_t flags) {
const auto PLS = (CLayerSurface*)data;
PLS->scflags = flags;
@ -316,11 +291,11 @@ void Events::handleSCFlags(void *data, struct zwlr_screencopy_frame_v1 *frame, u
g_pHyprpicker->renderSurface(PLS);
}
void Events::handleSCReady(void *data, struct zwlr_screencopy_frame_v1 *frame, uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec) {
void Events::handleSCReady(void* data, struct zwlr_screencopy_frame_v1* frame, uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec) {
// ignore
}
void Events::handleSCFailed(void *data, struct zwlr_screencopy_frame_v1 *frame) {
void Events::handleSCFailed(void* data, struct zwlr_screencopy_frame_v1* frame) {
Debug::log(CRIT, "Failed to get a Screencopy!");
g_pHyprpicker->finish(1);
}

View file

@ -65,8 +65,10 @@ void CHyprpicker::recheckACK() {
zwlr_layer_surface_v1_ack_configure(ls->pLayerSurface, ls->ACKSerial);
if (!ls->buffers[0].buffer) {
createBuffer(&ls->buffers[0], ls->m_pMonitor->size.x * ls->m_pMonitor->scale, ls->m_pMonitor->size.y * ls->m_pMonitor->scale, WL_SHM_FORMAT_ARGB8888, ls->m_pMonitor->size.x * ls->m_pMonitor->scale * 4);
createBuffer(&ls->buffers[1], ls->m_pMonitor->size.x * ls->m_pMonitor->scale, ls->m_pMonitor->size.y * ls->m_pMonitor->scale, WL_SHM_FORMAT_ARGB8888, ls->m_pMonitor->size.x * ls->m_pMonitor->scale * 4);
createBuffer(&ls->buffers[0], ls->m_pMonitor->size.x * ls->m_pMonitor->scale, ls->m_pMonitor->size.y * ls->m_pMonitor->scale, WL_SHM_FORMAT_ARGB8888,
ls->m_pMonitor->size.x * ls->m_pMonitor->scale * 4);
createBuffer(&ls->buffers[1], ls->m_pMonitor->size.x * ls->m_pMonitor->scale, ls->m_pMonitor->size.y * ls->m_pMonitor->scale, WL_SHM_FORMAT_ARGB8888,
ls->m_pMonitor->size.x * ls->m_pMonitor->scale * 4);
int XCURSOR_SIZE = 24;
if (getenv("XCURSOR_SIZE")) {
@ -208,8 +210,7 @@ void CHyprpicker::createSeat(wl_seat* pSeat) {
void CHyprpicker::convertBuffer(SPoolBuffer* pBuffer) {
switch (pBuffer->format) {
case WL_SHM_FORMAT_ARGB8888:
case WL_SHM_FORMAT_XRGB8888:
break;
case WL_SHM_FORMAT_XRGB8888: break;
case WL_SHM_FORMAT_ABGR8888:
case WL_SHM_FORMAT_XBGR8888: {
uint8_t* data = (uint8_t*)pBuffer->data;
@ -261,8 +262,7 @@ void* convert24To32Buffer(SPoolBuffer* pBuffer) {
*dstPx = {srcPx->red, srcPx->green, srcPx->blue, 0xFF};
}
}
}
break;
} break;
case WL_SHM_FORMAT_RGB888: {
for (int y = 0; y < pBuffer->pixelSize.y; ++y) {
for (int x = 0; x < pBuffer->pixelSize.x; ++x) {
@ -282,8 +282,7 @@ void* convert24To32Buffer(SPoolBuffer* pBuffer) {
*dstPx = {0xFF, srcPx->red, srcPx->green, srcPx->blue};
}
}
}
break;
} break;
default: {
Debug::log(CRIT, "Unsupported format for 24bit buffer %i", pBuffer->format);
}
@ -303,20 +302,20 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) {
void* data = pSurface->screenBuffer.data;
if (bytesPerPixel == 4) {
convertBuffer(&pSurface->screenBuffer);
}
else if (bytesPerPixel == 3) {
} else if (bytesPerPixel == 3) {
Debug::log(WARN, "24 bit formats are unsupported, hyprpicker may or may not work as intended!");
data = convert24To32Buffer(&pSurface->screenBuffer);
pSurface->screenBuffer.paddedData = data;
}
else {
} else {
Debug::log(CRIT, "Unsupported stride/bytes per pixel %i", bytesPerPixel);
g_pHyprpicker->finish(1);
}
pSurface->screenBuffer.surface = cairo_image_surface_create_for_data((unsigned char*)data, CAIRO_FORMAT_ARGB32, pSurface->screenBuffer.pixelSize.x, pSurface->screenBuffer.pixelSize.y, pSurface->screenBuffer.pixelSize.x * 4);
pSurface->screenBuffer.surface = cairo_image_surface_create_for_data((unsigned char*)data, CAIRO_FORMAT_ARGB32, pSurface->screenBuffer.pixelSize.x,
pSurface->screenBuffer.pixelSize.y, pSurface->screenBuffer.pixelSize.x * 4);
}
PBUFFER->surface = cairo_image_surface_create_for_data((unsigned char*)PBUFFER->data, CAIRO_FORMAT_ARGB32, pSurface->m_pMonitor->size.x * pSurface->m_pMonitor->scale, pSurface->m_pMonitor->size.y * pSurface->m_pMonitor->scale, PBUFFER->pixelSize.x * 4);
PBUFFER->surface = cairo_image_surface_create_for_data((unsigned char*)PBUFFER->data, CAIRO_FORMAT_ARGB32, pSurface->m_pMonitor->size.x * pSurface->m_pMonitor->scale,
pSurface->m_pMonitor->size.y * pSurface->m_pMonitor->scale, PBUFFER->pixelSize.x * 4);
PBUFFER->cairo = cairo_create(PBUFFER->surface);
const auto PCAIRO = PBUFFER->cairo;
@ -358,6 +357,7 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) {
//
cairo_restore(PCAIRO);
if (!g_pHyprpicker->m_bNoZoom) {
cairo_save(PCAIRO);
const auto PIXCOLOR = getColorFromPixel(pSurface, CLICKPOS);
@ -394,11 +394,26 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) {
cairo_restore(PCAIRO);
cairo_pattern_destroy(PATTERN);
} else {
}
} else if (!g_pHyprpicker->m_bRenderInactive) {
cairo_set_operator(PCAIRO, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba(PCAIRO, 0, 0, 0, 0);
cairo_rectangle(PCAIRO, 0, 0, pSurface->m_pMonitor->size.x * pSurface->m_pMonitor->scale, pSurface->m_pMonitor->size.y * pSurface->m_pMonitor->scale);
cairo_fill(PCAIRO);
} else {
const auto SCALEBUFS = Vector2D{pSurface->screenBuffer.pixelSize.x / PBUFFER->pixelSize.x, pSurface->screenBuffer.pixelSize.y / PBUFFER->pixelSize.y};
const auto PATTERNPRE = cairo_pattern_create_for_surface(pSurface->screenBuffer.surface);
cairo_pattern_set_filter(PATTERNPRE, CAIRO_FILTER_BILINEAR);
cairo_matrix_t matrixPre;
cairo_matrix_init_identity(&matrixPre);
cairo_matrix_scale(&matrixPre, SCALEBUFS.x, SCALEBUFS.y);
cairo_pattern_set_matrix(PATTERNPRE, &matrixPre);
cairo_set_source(PCAIRO, PATTERNPRE);
cairo_paint(PCAIRO);
cairo_surface_flush(PBUFFER->surface);
cairo_pattern_destroy(PATTERNPRE);
}
sendFrame(pSurface);

View file

@ -4,7 +4,8 @@
#include "helpers/LayerSurface.hpp"
#include "helpers/PoolBuffer.hpp"
enum eOutputMode {
enum eOutputMode
{
OUTPUT_CMYK = 0,
OUTPUT_HEX,
OUTPUT_RGB,
@ -13,7 +14,7 @@ enum eOutputMode {
};
class CHyprpicker {
public:
public:
void init();
std::mutex m_mtTickMutex;
@ -30,6 +31,8 @@ public:
bool m_bFancyOutput = true;
bool m_bAutoCopy = false;
bool m_bRenderInactive = false;
bool m_bNoZoom = false;
bool m_bRunning = true;
@ -48,7 +51,6 @@ public:
void destroyBuffer(SPoolBuffer*);
int createPoolFile(size_t, std::string&);
bool setCloexec(const int&);
void recheckACK();
void sendFrame(CLayerSurface*);
@ -62,8 +64,8 @@ public:
void finish(int code = 0);
CColor getColorFromPixel(CLayerSurface*, Vector2D);
private:
private:
};
inline std::unique_ptr<CHyprpicker> g_pHyprpicker;

View file

@ -1,13 +1,17 @@
#include <strings.h>
#include <iostream>
#include "hyprpicker.hpp"
static void help(void) {
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" <<
" -n | --no-fancy | Disables the \"fancy\" (aka. colored) outputting\n" <<
" -h | --help | Show this help message\n";
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"
<< " -n | --no-fancy | Disables the \"fancy\" (aka. colored) outputting\n"
<< " -h | --help | Show this help message\n"
<< " -r | --render-inactive | Render (freeze) inactive displays\n"
<< " -z | --no-zoom | Disable the zoom lens\n";
}
int main(int argc, char** argv, char** envp) {
@ -15,15 +19,15 @@ int main(int argc, char** argv, char** envp) {
while (true) {
int option_index = 0;
static struct option long_options[] = {
{"autocopy", no_argument, NULL, 'a'},
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'},
{NULL, 0, NULL, 0 }
};
{"render-inactive", no_argument, NULL, 'r'},
{"no-zoom", no_argument, NULL, 'z'},
{NULL, 0, NULL, 0}};
int c = getopt_long(argc, argv, ":f:hna", long_options, &option_index);
int c = getopt_long(argc, argv, ":f:hnarz", long_options, &option_index);
if (c == -1)
break;
@ -44,18 +48,13 @@ int main(int argc, char** argv, char** envp) {
exit(1);
}
break;
case 'h':
help();
exit(0);
case 'n':
g_pHyprpicker->m_bFancyOutput = false;
break;
case 'a':
g_pHyprpicker->m_bAutoCopy = true;
break;
default:
help();
exit(1);
case 'h': help(); exit(0);
case 'n': g_pHyprpicker->m_bFancyOutput = false; break;
case 'a': g_pHyprpicker->m_bAutoCopy = true; break;
case 'r': g_pHyprpicker->m_bRenderInactive = true; break;
case 'z': g_pHyprpicker->m_bNoZoom = true; break;
default: help(); exit(1);
}
}