mirror of
https://github.com/hyprwm/hyprpicker.git
synced 2024-12-22 06:09:48 +01:00
clang-format, no-zoom and render-inactive
This commit is contained in:
parent
234c2da51a
commit
cc6b3234b2
5 changed files with 259 additions and 203 deletions
65
.clang-format
Normal file
65
.clang-format
Normal 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
|
|
@ -1,65 +1,67 @@
|
||||||
#include "Events.hpp"
|
#include "Events.hpp"
|
||||||
|
|
||||||
#include "../hyprpicker.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
|
// 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
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::done(void *data, wl_output *wl_output) {
|
void Events::done(void* data, wl_output* wl_output) {
|
||||||
const auto PMONITOR = (SMonitor*)data;
|
const auto PMONITOR = (SMonitor*)data;
|
||||||
|
|
||||||
PMONITOR->ready = true;
|
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;
|
const auto PMONITOR = (SMonitor*)data;
|
||||||
|
|
||||||
PMONITOR->scale = scale;
|
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;
|
const auto PMONITOR = (SMonitor*)data;
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
PMONITOR->name = 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
|
// i do not care
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::ls_configure(void *data, zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t width, uint32_t height) {
|
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;
|
const auto PLAYERSURFACE = (CLayerSurface*)data;
|
||||||
|
|
||||||
PLAYERSURFACE->m_pMonitor->size = Vector2D(width, height);
|
PLAYERSURFACE->m_pMonitor->size = Vector2D(width, height);
|
||||||
PLAYERSURFACE->ACKSerial = serial;
|
PLAYERSURFACE->ACKSerial = serial;
|
||||||
PLAYERSURFACE->wantsACK = true;
|
PLAYERSURFACE->wantsACK = true;
|
||||||
PLAYERSURFACE->working = true;
|
PLAYERSURFACE->working = true;
|
||||||
|
|
||||||
g_pHyprpicker->recheckACK();
|
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) {
|
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) {
|
} 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) {
|
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
||||||
g_pHyprpicker->m_mtTickMutex.lock();
|
g_pHyprpicker->m_mtTickMutex.lock();
|
||||||
|
|
||||||
const auto PMONITOR = g_pHyprpicker->m_vMonitors.emplace_back(std::make_unique<SMonitor>()).get();
|
const auto PMONITOR = g_pHyprpicker->m_vMonitors.emplace_back(std::make_unique<SMonitor>()).get();
|
||||||
PMONITOR->wayland_name = name;
|
PMONITOR->wayland_name = name;
|
||||||
PMONITOR->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);
|
wl_output_add_listener(PMONITOR->output, &Events::outputListener, PMONITOR);
|
||||||
|
|
||||||
g_pHyprpicker->m_mtTickMutex.unlock();
|
g_pHyprpicker->m_mtTickMutex.unlock();
|
||||||
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
} 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) {
|
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
|
||||||
g_pHyprpicker->createSeat((wl_seat*)wl_registry_bind(registry, name, &wl_seat_interface, 1));
|
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) {
|
} 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
|
// 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) {
|
if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
|
||||||
wl_pointer_add_listener(wl_seat_get_pointer(wl_seat), &pointerListener, wl_seat);
|
wl_pointer_add_listener(wl_seat_get_pointer(wl_seat), &pointerListener, wl_seat);
|
||||||
} else {
|
} 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();
|
g_pHyprpicker->markDirty();
|
||||||
|
|
||||||
for (auto& ls : g_pHyprpicker->m_vLayerSurfaces) {
|
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) {
|
for (auto& ls : g_pHyprpicker->m_vLayerSurfaces) {
|
||||||
if (ls->pSurface == surface) {
|
if (ls->pSurface == surface) {
|
||||||
g_pHyprpicker->renderSurface(ls.get(), true);
|
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
|
// 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 x = wl_fixed_to_double(surface_x);
|
||||||
auto y = wl_fixed_to_double(surface_y);
|
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();
|
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) {
|
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 {
|
auto fmax3 = [](float a, float b, float c) -> float { return (a > b && a > c) ? a : (b > c) ? b : c; };
|
||||||
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; };
|
||||||
};
|
|
||||||
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
|
// get the px and print it
|
||||||
const auto SCALE = Vector2D{
|
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.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 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);
|
const auto COL = g_pHyprpicker->getColorFromPixel(g_pHyprpicker->m_pLastSurface, CLICKPOS);
|
||||||
|
|
||||||
switch (g_pHyprpicker->m_bSelectedOutputMode) {
|
switch (g_pHyprpicker->m_bSelectedOutputMode) {
|
||||||
case OUTPUT_CMYK:
|
case OUTPUT_CMYK: {
|
||||||
{
|
|
||||||
// http://www.codeproject.com/KB/applications/xcmyk.aspx
|
// http://www.codeproject.com/KB/applications/xcmyk.aspx
|
||||||
|
|
||||||
float r = 1 - COL.r / 255.0f,
|
float r = 1 - COL.r / 255.0f, g = 1 - COL.g / 255.0f, b = 1 - COL.b / 255.0f;
|
||||||
g = 1 - COL.g / 255.0f,
|
float k = fmin3(r, g, b), K = 1 - k;
|
||||||
b = 1 - COL.b / 255.0f;
|
float c = (r - k) / K, m = (g - k) / K, y = (b - k) / K;
|
||||||
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);
|
c = std::round(c * 100);
|
||||||
m = std::round(m * 100);
|
m = std::round(m * 100);
|
||||||
|
@ -168,8 +158,7 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
|
||||||
g_pHyprpicker->finish();
|
g_pHyprpicker->finish();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OUTPUT_HEX:
|
case OUTPUT_HEX: {
|
||||||
{
|
|
||||||
auto toHex = [](int i) -> std::string {
|
auto toHex = [](int i) -> std::string {
|
||||||
const char* DS = "0123456789ABCDEF";
|
const char* DS = "0123456789ABCDEF";
|
||||||
|
|
||||||
|
@ -191,8 +180,7 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
|
||||||
g_pHyprpicker->finish();
|
g_pHyprpicker->finish();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OUTPUT_RGB:
|
case OUTPUT_RGB: {
|
||||||
{
|
|
||||||
if (g_pHyprpicker->m_bFancyOutput)
|
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);
|
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
|
else
|
||||||
|
@ -204,20 +192,16 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OUTPUT_HSL:
|
case OUTPUT_HSL:
|
||||||
case OUTPUT_HSV:
|
case OUTPUT_HSV: {
|
||||||
{
|
|
||||||
// https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB
|
// https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB
|
||||||
|
|
||||||
auto floatEq = [](float a, float b) -> bool {
|
auto floatEq = [](float a, float b) -> bool {
|
||||||
return std::nextafter(a, std::numeric_limits<double>::lowest()) <= b && std::nextafter(a, std::numeric_limits<double>::max()) >= b;
|
return std::nextafter(a, std::numeric_limits<double>::lowest()) <= b && std::nextafter(a, std::numeric_limits<double>::max()) >= b;
|
||||||
};
|
};
|
||||||
|
|
||||||
float h, s, l, v;
|
float h, s, l, v;
|
||||||
float r = COL.r / 255.0f,
|
float r = COL.r / 255.0f, g = COL.g / 255.0f, b = COL.b / 255.0f;
|
||||||
g = COL.g / 255.0f,
|
float max = fmax3(r, g, b), min = fmin3(r, g, b);
|
||||||
b = COL.b / 255.0f;
|
|
||||||
float max = fmax3(r, g, b),
|
|
||||||
min = fmin3(r, g, b);
|
|
||||||
float c = max - min;
|
float c = max - min;
|
||||||
|
|
||||||
v = max;
|
v = max;
|
||||||
|
@ -232,12 +216,12 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
|
||||||
|
|
||||||
float l_or_v;
|
float l_or_v;
|
||||||
if (g_pHyprpicker->m_bSelectedOutputMode == OUTPUT_HSL) {
|
if (g_pHyprpicker->m_bSelectedOutputMode == OUTPUT_HSL) {
|
||||||
l = (max + min) / 2;
|
l = (max + min) / 2;
|
||||||
s = (floatEq(l, 0.0f) || floatEq(l, 1.0f)) ? 0 : (v - l) / std::min(l, 1 - l);
|
s = (floatEq(l, 0.0f) || floatEq(l, 1.0f)) ? 0 : (v - l) / std::min(l, 1 - l);
|
||||||
l_or_v = std::round(l * 100);
|
l_or_v = std::round(l * 100);
|
||||||
} else {
|
} else {
|
||||||
v = max;
|
v = max;
|
||||||
s = floatEq(v, 0.0f) ? 0 : c / v;
|
s = floatEq(v, 0.0f) ? 0 : c / v;
|
||||||
l_or_v = std::round(v * 100);
|
l_or_v = std::round(v * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,29 +243,20 @@ void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint
|
||||||
g_pHyprpicker->finish();
|
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
|
if (key == 1) // escape
|
||||||
g_pHyprpicker->finish();
|
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::handleFrameDone(void* data, struct wl_callback* callback, uint32_t time) {
|
||||||
|
|
||||||
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) {
|
|
||||||
CLayerSurface* pLS = (CLayerSurface*)data;
|
CLayerSurface* pLS = (CLayerSurface*)data;
|
||||||
|
|
||||||
if (pLS->frame_callback)
|
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);
|
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;
|
auto buf = (SPoolBuffer*)data;
|
||||||
buf->busy = false;
|
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;
|
const auto PLS = (CLayerSurface*)data;
|
||||||
|
|
||||||
g_pHyprpicker->createBuffer(&PLS->screenBuffer, width, height, format, stride);
|
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);
|
zwlr_screencopy_frame_v1_copy(frame, PLS->screenBuffer.buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handleSCFlags(void *data, struct zwlr_screencopy_frame_v1 *frame, uint32_t flags) {
|
void Events::handleSCFlags(void* data, struct zwlr_screencopy_frame_v1* frame, uint32_t flags) {
|
||||||
const auto PLS = (CLayerSurface *)data;
|
const auto PLS = (CLayerSurface*)data;
|
||||||
|
|
||||||
PLS->scflags = flags;
|
PLS->scflags = flags;
|
||||||
|
|
||||||
|
@ -316,11 +291,11 @@ void Events::handleSCFlags(void *data, struct zwlr_screencopy_frame_v1 *frame, u
|
||||||
g_pHyprpicker->renderSurface(PLS);
|
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
|
// 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!");
|
Debug::log(CRIT, "Failed to get a Screencopy!");
|
||||||
g_pHyprpicker->finish(1);
|
g_pHyprpicker->finish(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,10 @@ void CHyprpicker::recheckACK() {
|
||||||
zwlr_layer_surface_v1_ack_configure(ls->pLayerSurface, ls->ACKSerial);
|
zwlr_layer_surface_v1_ack_configure(ls->pLayerSurface, ls->ACKSerial);
|
||||||
|
|
||||||
if (!ls->buffers[0].buffer) {
|
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[0], ls->m_pMonitor->size.x * ls->m_pMonitor->scale, ls->m_pMonitor->size.y * ls->m_pMonitor->scale, WL_SHM_FORMAT_ARGB8888,
|
||||||
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);
|
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;
|
int XCURSOR_SIZE = 24;
|
||||||
if (getenv("XCURSOR_SIZE")) {
|
if (getenv("XCURSOR_SIZE")) {
|
||||||
|
@ -158,8 +160,8 @@ int CHyprpicker::createPoolFile(size_t size, std::string& name) {
|
||||||
void CHyprpicker::createBuffer(SPoolBuffer* pBuffer, int32_t w, int32_t h, uint32_t format, uint32_t stride) {
|
void CHyprpicker::createBuffer(SPoolBuffer* pBuffer, int32_t w, int32_t h, uint32_t format, uint32_t stride) {
|
||||||
const size_t SIZE = stride * h;
|
const size_t SIZE = stride * h;
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
const auto FD = createPoolFile(SIZE, name);
|
const auto FD = createPoolFile(SIZE, name);
|
||||||
|
|
||||||
if (FD == -1) {
|
if (FD == -1) {
|
||||||
Debug::log(CRIT, "Unable to create pool file!");
|
Debug::log(CRIT, "Unable to create pool file!");
|
||||||
|
@ -176,12 +178,12 @@ void CHyprpicker::createBuffer(SPoolBuffer* pBuffer, int32_t w, int32_t h, uint3
|
||||||
|
|
||||||
close(FD);
|
close(FD);
|
||||||
|
|
||||||
pBuffer->format = format;
|
pBuffer->format = format;
|
||||||
pBuffer->size = SIZE;
|
pBuffer->size = SIZE;
|
||||||
pBuffer->data = DATA;
|
pBuffer->data = DATA;
|
||||||
pBuffer->pixelSize = Vector2D(w, h);
|
pBuffer->pixelSize = Vector2D(w, h);
|
||||||
pBuffer->name = name;
|
pBuffer->name = name;
|
||||||
pBuffer->stride = stride;
|
pBuffer->stride = stride;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprpicker::destroyBuffer(SPoolBuffer* pBuffer) {
|
void CHyprpicker::destroyBuffer(SPoolBuffer* pBuffer) {
|
||||||
|
@ -190,8 +192,8 @@ void CHyprpicker::destroyBuffer(SPoolBuffer* pBuffer) {
|
||||||
cairo_surface_destroy(pBuffer->surface);
|
cairo_surface_destroy(pBuffer->surface);
|
||||||
munmap(pBuffer->data, pBuffer->size);
|
munmap(pBuffer->data, pBuffer->size);
|
||||||
|
|
||||||
pBuffer->buffer = nullptr;
|
pBuffer->buffer = nullptr;
|
||||||
pBuffer->cairo = nullptr;
|
pBuffer->cairo = nullptr;
|
||||||
pBuffer->surface = nullptr;
|
pBuffer->surface = nullptr;
|
||||||
|
|
||||||
unlink(pBuffer->name.c_str());
|
unlink(pBuffer->name.c_str());
|
||||||
|
@ -208,8 +210,7 @@ void CHyprpicker::createSeat(wl_seat* pSeat) {
|
||||||
void CHyprpicker::convertBuffer(SPoolBuffer* pBuffer) {
|
void CHyprpicker::convertBuffer(SPoolBuffer* pBuffer) {
|
||||||
switch (pBuffer->format) {
|
switch (pBuffer->format) {
|
||||||
case WL_SHM_FORMAT_ARGB8888:
|
case WL_SHM_FORMAT_ARGB8888:
|
||||||
case WL_SHM_FORMAT_XRGB8888:
|
case WL_SHM_FORMAT_XRGB8888: break;
|
||||||
break;
|
|
||||||
case WL_SHM_FORMAT_ABGR8888:
|
case WL_SHM_FORMAT_ABGR8888:
|
||||||
case WL_SHM_FORMAT_XBGR8888: {
|
case WL_SHM_FORMAT_XBGR8888: {
|
||||||
uint8_t* data = (uint8_t*)pBuffer->data;
|
uint8_t* data = (uint8_t*)pBuffer->data;
|
||||||
|
@ -237,9 +238,9 @@ void CHyprpicker::convertBuffer(SPoolBuffer* pBuffer) {
|
||||||
|
|
||||||
// Mallocs a new buffer, which needs to be free'd!
|
// Mallocs a new buffer, which needs to be free'd!
|
||||||
void* convert24To32Buffer(SPoolBuffer* pBuffer) {
|
void* convert24To32Buffer(SPoolBuffer* pBuffer) {
|
||||||
uint8_t* newBuffer = (uint8_t*)malloc((size_t)pBuffer->pixelSize.x * pBuffer->pixelSize.y * 4);
|
uint8_t* newBuffer = (uint8_t*)malloc((size_t)pBuffer->pixelSize.x * pBuffer->pixelSize.y * 4);
|
||||||
int newBufferStride = pBuffer->pixelSize.x * 4;
|
int newBufferStride = pBuffer->pixelSize.x * 4;
|
||||||
uint8_t* oldBuffer = (uint8_t*)pBuffer->data;
|
uint8_t* oldBuffer = (uint8_t*)pBuffer->data;
|
||||||
|
|
||||||
switch (pBuffer->format) {
|
switch (pBuffer->format) {
|
||||||
case WL_SHM_FORMAT_BGR888: {
|
case WL_SHM_FORMAT_BGR888: {
|
||||||
|
@ -258,11 +259,10 @@ void* convert24To32Buffer(SPoolBuffer* pBuffer) {
|
||||||
unsigned char red;
|
unsigned char red;
|
||||||
unsigned char alpha;
|
unsigned char alpha;
|
||||||
}* dstPx = (struct pixel4*)(newBuffer + y * newBufferStride + x * 4);
|
}* dstPx = (struct pixel4*)(newBuffer + y * newBufferStride + x * 4);
|
||||||
*dstPx = {srcPx->red, srcPx->green, srcPx->blue, 0xFF};
|
*dstPx = {srcPx->red, srcPx->green, srcPx->blue, 0xFF};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
case WL_SHM_FORMAT_RGB888: {
|
case WL_SHM_FORMAT_RGB888: {
|
||||||
for (int y = 0; y < pBuffer->pixelSize.y; ++y) {
|
for (int y = 0; y < pBuffer->pixelSize.y; ++y) {
|
||||||
for (int x = 0; x < pBuffer->pixelSize.x; ++x) {
|
for (int x = 0; x < pBuffer->pixelSize.x; ++x) {
|
||||||
|
@ -279,15 +279,14 @@ void* convert24To32Buffer(SPoolBuffer* pBuffer) {
|
||||||
unsigned char green;
|
unsigned char green;
|
||||||
unsigned char blue;
|
unsigned char blue;
|
||||||
}* dstPx = (struct pixel4*)(newBuffer + y * newBufferStride + x * 4);
|
}* dstPx = (struct pixel4*)(newBuffer + y * newBufferStride + x * 4);
|
||||||
*dstPx = {0xFF, srcPx->red, srcPx->green, srcPx->blue};
|
*dstPx = {0xFF, srcPx->red, srcPx->green, srcPx->blue};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
default: {
|
default: {
|
||||||
Debug::log(CRIT, "Unsupported format for 24bit buffer %i", pBuffer->format);
|
Debug::log(CRIT, "Unsupported format for 24bit buffer %i", pBuffer->format);
|
||||||
}
|
}
|
||||||
g_pHyprpicker->finish(1);
|
g_pHyprpicker->finish(1);
|
||||||
}
|
}
|
||||||
return newBuffer;
|
return newBuffer;
|
||||||
}
|
}
|
||||||
|
@ -299,25 +298,25 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!pSurface->screenBuffer.surface) {
|
if (!pSurface->screenBuffer.surface) {
|
||||||
int bytesPerPixel = pSurface->screenBuffer.stride / (int)pSurface->screenBuffer.pixelSize.x;
|
int bytesPerPixel = pSurface->screenBuffer.stride / (int)pSurface->screenBuffer.pixelSize.x;
|
||||||
void* data = pSurface->screenBuffer.data;
|
void* data = pSurface->screenBuffer.data;
|
||||||
if (bytesPerPixel == 4) {
|
if (bytesPerPixel == 4) {
|
||||||
convertBuffer(&pSurface->screenBuffer);
|
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!");
|
Debug::log(WARN, "24 bit formats are unsupported, hyprpicker may or may not work as intended!");
|
||||||
data = convert24To32Buffer(&pSurface->screenBuffer);
|
data = convert24To32Buffer(&pSurface->screenBuffer);
|
||||||
pSurface->screenBuffer.paddedData = data;
|
pSurface->screenBuffer.paddedData = data;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Debug::log(CRIT, "Unsupported stride/bytes per pixel %i", bytesPerPixel);
|
Debug::log(CRIT, "Unsupported stride/bytes per pixel %i", bytesPerPixel);
|
||||||
g_pHyprpicker->finish(1);
|
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,
|
||||||
PBUFFER->cairo = cairo_create(PBUFFER->surface);
|
pSurface->m_pMonitor->size.y * pSurface->m_pMonitor->scale, PBUFFER->pixelSize.x * 4);
|
||||||
|
PBUFFER->cairo = cairo_create(PBUFFER->surface);
|
||||||
|
|
||||||
const auto PCAIRO = PBUFFER->cairo;
|
const auto PCAIRO = PBUFFER->cairo;
|
||||||
|
|
||||||
|
@ -328,7 +327,7 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) {
|
||||||
cairo_fill(PCAIRO);
|
cairo_fill(PCAIRO);
|
||||||
|
|
||||||
if (pSurface == g_pHyprpicker->m_pLastSurface && !forceInactive) {
|
if (pSurface == g_pHyprpicker->m_pLastSurface && !forceInactive) {
|
||||||
const auto SCALEBUFS = Vector2D{pSurface->screenBuffer.pixelSize.x / PBUFFER->pixelSize.x, pSurface->screenBuffer.pixelSize.y / PBUFFER->pixelSize.y};
|
const auto SCALEBUFS = Vector2D{pSurface->screenBuffer.pixelSize.x / PBUFFER->pixelSize.x, pSurface->screenBuffer.pixelSize.y / PBUFFER->pixelSize.y};
|
||||||
const auto SCALECURSOR = Vector2D{
|
const auto SCALECURSOR = 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.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)};
|
||||||
|
@ -358,54 +357,70 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) {
|
||||||
//
|
//
|
||||||
|
|
||||||
cairo_restore(PCAIRO);
|
cairo_restore(PCAIRO);
|
||||||
cairo_save(PCAIRO);
|
if (!g_pHyprpicker->m_bNoZoom) {
|
||||||
|
cairo_save(PCAIRO);
|
||||||
|
|
||||||
const auto PIXCOLOR = getColorFromPixel(pSurface, CLICKPOS);
|
const auto PIXCOLOR = getColorFromPixel(pSurface, CLICKPOS);
|
||||||
cairo_set_source_rgba(PCAIRO, PIXCOLOR.r / 255.f, PIXCOLOR.g / 255.f, PIXCOLOR.b / 255.f, PIXCOLOR.a / 255.f);
|
cairo_set_source_rgba(PCAIRO, PIXCOLOR.r / 255.f, PIXCOLOR.g / 255.f, PIXCOLOR.b / 255.f, PIXCOLOR.a / 255.f);
|
||||||
|
|
||||||
cairo_scale(PCAIRO, 1, 1);
|
cairo_scale(PCAIRO, 1, 1);
|
||||||
|
|
||||||
cairo_arc(PCAIRO, m_vLastCoords.x * pSurface->m_pMonitor->scale, m_vLastCoords.y * pSurface->m_pMonitor->scale, 105 / SCALEBUFS.x, 0, 2 * M_PI);
|
cairo_arc(PCAIRO, m_vLastCoords.x * pSurface->m_pMonitor->scale, m_vLastCoords.y * pSurface->m_pMonitor->scale, 105 / SCALEBUFS.x, 0, 2 * M_PI);
|
||||||
cairo_clip(PCAIRO);
|
cairo_clip(PCAIRO);
|
||||||
|
|
||||||
cairo_fill(PCAIRO);
|
cairo_fill(PCAIRO);
|
||||||
cairo_paint(PCAIRO);
|
cairo_paint(PCAIRO);
|
||||||
|
|
||||||
cairo_surface_flush(PBUFFER->surface);
|
cairo_surface_flush(PBUFFER->surface);
|
||||||
|
|
||||||
cairo_restore(PCAIRO);
|
cairo_restore(PCAIRO);
|
||||||
cairo_save(PCAIRO);
|
cairo_save(PCAIRO);
|
||||||
|
|
||||||
const auto PATTERN = cairo_pattern_create_for_surface(pSurface->screenBuffer.surface);
|
const auto PATTERN = cairo_pattern_create_for_surface(pSurface->screenBuffer.surface);
|
||||||
cairo_pattern_set_filter(PATTERN, CAIRO_FILTER_NEAREST);
|
cairo_pattern_set_filter(PATTERN, CAIRO_FILTER_NEAREST);
|
||||||
cairo_matrix_t matrix;
|
cairo_matrix_t matrix;
|
||||||
cairo_matrix_init_identity(&matrix);
|
cairo_matrix_init_identity(&matrix);
|
||||||
cairo_matrix_translate(&matrix, CLICKPOS.x + 0.5f, CLICKPOS.y + 0.5f);
|
cairo_matrix_translate(&matrix, CLICKPOS.x + 0.5f, CLICKPOS.y + 0.5f);
|
||||||
cairo_matrix_scale(&matrix, 0.1f, 0.1f);
|
cairo_matrix_scale(&matrix, 0.1f, 0.1f);
|
||||||
cairo_matrix_translate(&matrix, -CLICKPOS.x / SCALEBUFS.x - 0.5f, -CLICKPOS.y / SCALEBUFS.y - 0.5f);
|
cairo_matrix_translate(&matrix, -CLICKPOS.x / SCALEBUFS.x - 0.5f, -CLICKPOS.y / SCALEBUFS.y - 0.5f);
|
||||||
cairo_pattern_set_matrix(PATTERN, &matrix);
|
cairo_pattern_set_matrix(PATTERN, &matrix);
|
||||||
cairo_set_source(PCAIRO, PATTERN);
|
cairo_set_source(PCAIRO, PATTERN);
|
||||||
cairo_arc(PCAIRO, m_vLastCoords.x * pSurface->m_pMonitor->scale, m_vLastCoords.y * pSurface->m_pMonitor->scale, 100 / SCALEBUFS.x, 0, 2 * M_PI);
|
cairo_arc(PCAIRO, m_vLastCoords.x * pSurface->m_pMonitor->scale, m_vLastCoords.y * pSurface->m_pMonitor->scale, 100 / SCALEBUFS.x, 0, 2 * M_PI);
|
||||||
cairo_clip(PCAIRO);
|
cairo_clip(PCAIRO);
|
||||||
cairo_paint(PCAIRO);
|
cairo_paint(PCAIRO);
|
||||||
|
|
||||||
cairo_surface_flush(PBUFFER->surface);
|
cairo_surface_flush(PBUFFER->surface);
|
||||||
|
|
||||||
cairo_restore(PCAIRO);
|
cairo_restore(PCAIRO);
|
||||||
|
|
||||||
cairo_pattern_destroy(PATTERN);
|
cairo_pattern_destroy(PATTERN);
|
||||||
} else {
|
}
|
||||||
|
} else if (!g_pHyprpicker->m_bRenderInactive) {
|
||||||
cairo_set_operator(PCAIRO, CAIRO_OPERATOR_SOURCE);
|
cairo_set_operator(PCAIRO, CAIRO_OPERATOR_SOURCE);
|
||||||
cairo_set_source_rgba(PCAIRO, 0, 0, 0, 0);
|
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_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);
|
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);
|
sendFrame(pSurface);
|
||||||
cairo_destroy(PCAIRO);
|
cairo_destroy(PCAIRO);
|
||||||
cairo_surface_destroy(PBUFFER->surface);
|
cairo_surface_destroy(PBUFFER->surface);
|
||||||
|
|
||||||
PBUFFER->cairo = nullptr;
|
PBUFFER->cairo = nullptr;
|
||||||
PBUFFER->surface = nullptr;
|
PBUFFER->surface = nullptr;
|
||||||
|
|
||||||
pSurface->rendered = true;
|
pSurface->rendered = true;
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#include "helpers/LayerSurface.hpp"
|
#include "helpers/LayerSurface.hpp"
|
||||||
#include "helpers/PoolBuffer.hpp"
|
#include "helpers/PoolBuffer.hpp"
|
||||||
|
|
||||||
enum eOutputMode {
|
enum eOutputMode
|
||||||
|
{
|
||||||
OUTPUT_CMYK = 0,
|
OUTPUT_CMYK = 0,
|
||||||
OUTPUT_HEX,
|
OUTPUT_HEX,
|
||||||
OUTPUT_RGB,
|
OUTPUT_RGB,
|
||||||
|
@ -13,57 +14,58 @@ enum eOutputMode {
|
||||||
};
|
};
|
||||||
|
|
||||||
class CHyprpicker {
|
class CHyprpicker {
|
||||||
public:
|
public:
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
std::mutex m_mtTickMutex;
|
std::mutex m_mtTickMutex;
|
||||||
|
|
||||||
wl_compositor* m_pCompositor;
|
wl_compositor* m_pCompositor;
|
||||||
wl_display* m_pWLDisplay;
|
wl_display* m_pWLDisplay;
|
||||||
wl_registry* m_pWLRegistry;
|
wl_registry* m_pWLRegistry;
|
||||||
wl_shm* m_pWLSHM;
|
wl_shm* m_pWLSHM;
|
||||||
zwlr_layer_shell_v1* m_pLayerShell;
|
zwlr_layer_shell_v1* m_pLayerShell;
|
||||||
zwlr_screencopy_manager_v1* m_pSCMgr;
|
zwlr_screencopy_manager_v1* m_pSCMgr;
|
||||||
|
|
||||||
eOutputMode m_bSelectedOutputMode = OUTPUT_HEX;
|
eOutputMode m_bSelectedOutputMode = OUTPUT_HEX;
|
||||||
|
|
||||||
bool m_bFancyOutput = true;
|
bool m_bFancyOutput = true;
|
||||||
|
|
||||||
bool m_bAutoCopy = false;
|
bool m_bAutoCopy = false;
|
||||||
|
bool m_bRenderInactive = false;
|
||||||
|
bool m_bNoZoom = false;
|
||||||
|
|
||||||
bool m_bRunning = true;
|
bool m_bRunning = true;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<SMonitor>> m_vMonitors;
|
std::vector<std::unique_ptr<SMonitor>> m_vMonitors;
|
||||||
std::vector<std::unique_ptr<CLayerSurface>> m_vLayerSurfaces;
|
std::vector<std::unique_ptr<CLayerSurface>> m_vLayerSurfaces;
|
||||||
|
|
||||||
void createSeat(wl_seat*);
|
void createSeat(wl_seat*);
|
||||||
|
|
||||||
CLayerSurface* m_pLastSurface;
|
CLayerSurface* m_pLastSurface;
|
||||||
|
|
||||||
Vector2D m_vLastCoords;
|
Vector2D m_vLastCoords;
|
||||||
|
|
||||||
void renderSurface(CLayerSurface*, bool forceInactive = false);
|
void renderSurface(CLayerSurface*, bool forceInactive = false);
|
||||||
|
|
||||||
void createBuffer(SPoolBuffer*, int32_t, int32_t, uint32_t, uint32_t);
|
void createBuffer(SPoolBuffer*, int32_t, int32_t, uint32_t, uint32_t);
|
||||||
void destroyBuffer(SPoolBuffer*);
|
void destroyBuffer(SPoolBuffer*);
|
||||||
int createPoolFile(size_t, std::string&);
|
int createPoolFile(size_t, std::string&);
|
||||||
bool setCloexec(const int&);
|
bool setCloexec(const int&);
|
||||||
|
void recheckACK();
|
||||||
|
|
||||||
void recheckACK();
|
void sendFrame(CLayerSurface*);
|
||||||
|
|
||||||
void sendFrame(CLayerSurface*);
|
SPoolBuffer* getBufferForLS(CLayerSurface*);
|
||||||
|
|
||||||
SPoolBuffer* getBufferForLS(CLayerSurface*);
|
void convertBuffer(SPoolBuffer*);
|
||||||
|
|
||||||
void convertBuffer(SPoolBuffer*);
|
void markDirty();
|
||||||
|
|
||||||
void markDirty();
|
void finish(int code = 0);
|
||||||
|
|
||||||
void finish(int code = 0);
|
CColor getColorFromPixel(CLayerSurface*, Vector2D);
|
||||||
|
|
||||||
CColor getColorFromPixel(CLayerSurface*, Vector2D);
|
private:
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::unique_ptr<CHyprpicker> g_pHyprpicker;
|
inline std::unique_ptr<CHyprpicker> g_pHyprpicker;
|
53
src/main.cpp
53
src/main.cpp
|
@ -1,29 +1,33 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "hyprpicker.hpp"
|
#include "hyprpicker.hpp"
|
||||||
|
|
||||||
static void help(void) {
|
static void help(void) {
|
||||||
std::cout << "Hyprpicker usage: hyprpicker [arg [...]].\n\nArguments:\n" <<
|
std::cout << "Hyprpicker usage: hyprpicker [arg [...]].\n\nArguments:\n"
|
||||||
" -a | --autocopy | Automatically copies the output to the clipboard (requires wl-clipboard)\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" <<
|
<< " -f | --format=fmt | Specifies the output format (cmyk, hex, rgb, hsl, hsv)\n"
|
||||||
" -n | --no-fancy | Disables the \"fancy\" (aka. colored) outputting\n" <<
|
<< " -n | --no-fancy | Disables the \"fancy\" (aka. colored) outputting\n"
|
||||||
" -h | --help | Show this help message\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) {
|
int main(int argc, char** argv, char** envp) {
|
||||||
g_pHyprpicker = std::make_unique<CHyprpicker>();
|
g_pHyprpicker = std::make_unique<CHyprpicker>();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {{"autocopy", no_argument, NULL, 'a'},
|
||||||
{"autocopy", no_argument, NULL, 'a'},
|
{"format", required_argument, NULL, 'f'},
|
||||||
{"format", required_argument, NULL, 'f'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"no-fancy", no_argument, NULL, 'n'},
|
||||||
{"no-fancy", no_argument, NULL, 'n'},
|
{"render-inactive", no_argument, NULL, 'r'},
|
||||||
{NULL, 0, NULL, 0 }
|
{"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)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -44,19 +48,14 @@ int main(int argc, char** argv, char** envp) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h': help(); exit(0);
|
||||||
help();
|
case 'n': g_pHyprpicker->m_bFancyOutput = false; break;
|
||||||
exit(0);
|
case 'a': g_pHyprpicker->m_bAutoCopy = true; break;
|
||||||
case 'n':
|
case 'r': g_pHyprpicker->m_bRenderInactive = true; break;
|
||||||
g_pHyprpicker->m_bFancyOutput = false;
|
case 'z': g_pHyprpicker->m_bNoZoom = true; break;
|
||||||
break;
|
|
||||||
case 'a':
|
default: help(); exit(1);
|
||||||
g_pHyprpicker->m_bAutoCopy = true;
|
}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
help();
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isatty(fileno(stdout)) || getenv("NO_COLOR"))
|
if (!isatty(fileno(stdout)) || getenv("NO_COLOR"))
|
||||||
|
|
Loading…
Reference in a new issue