diff --git a/CMakeLists.txt b/CMakeLists.txt index 50dbbc2..6173835 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.4) +cmake_minimum_required(VERSION 3.12) project(hyprpicker DESCRIPTION "A blazing fast wayland wallpaper utility" ) @@ -72,7 +72,7 @@ add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value -Wno-m find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) -pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols xkbcommon cairo pango pangocairo libjpeg) +pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols xkbcommon cairo pango pangocairo libjpeg hyprutils>=0.2.0) file(GLOB_RECURSE SRCFILES "src/*.cpp") diff --git a/README.md b/README.md index dedaade..34f3145 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,15 @@ Launch it. Click. That's it. ## Manual -Install build dependencies (Debian): - -```sh -apt install --no-install-recommends -y cmake g++ make pkg-config libpango1.0-dev libjpeg-dev libwayland-dev wayland-protocols libxkbcommon-dev -``` +Install dependencies: + - cmake + - pkg-config + - pango + - cairo + - wayland + - wayland-protocols + - hyprutils + - xkbcommon Building is done via CMake: diff --git a/src/debug/Log.cpp b/src/debug/Log.cpp index b8dcd3c..264dd79 100644 --- a/src/debug/Log.cpp +++ b/src/debug/Log.cpp @@ -9,28 +9,17 @@ void Debug::log(LogLevel level, const char* fmt, ...) { std::string levelstr = ""; switch (level) { - case LOG: - levelstr = "[LOG] "; - break; - case WARN: - levelstr = "[WARN] "; - break; - case ERR: - levelstr = "[ERR] "; - break; - case CRIT: - levelstr = "[CRITICAL] "; - break; - case INFO: - levelstr = "[INFO] "; - break; - default: - break; + case LOG: levelstr = "[LOG] "; break; + case WARN: levelstr = "[WARN] "; break; + case ERR: levelstr = "[ERR] "; break; + case CRIT: levelstr = "[CRITICAL] "; break; + case INFO: levelstr = "[INFO] "; break; + default: break; } - char buf[LOGMESSAGESIZE] = ""; - char* outputStr; - int logLen; + char buf[LOGMESSAGESIZE] = ""; + char* outputStr; + int logLen; va_list args; va_start(args, fmt); diff --git a/src/debug/Log.hpp b/src/debug/Log.hpp index 8948086..bdf9380 100644 --- a/src/debug/Log.hpp +++ b/src/debug/Log.hpp @@ -5,7 +5,7 @@ enum LogLevel { NONE = -1, - LOG = 0, + LOG = 0, WARN, ERR, CRIT, diff --git a/src/defines.hpp b/src/defines.hpp index 6d627ec..599c418 100644 --- a/src/defines.hpp +++ b/src/defines.hpp @@ -1,7 +1,6 @@ #pragma once #include "debug/Log.hpp" -#include "helpers/Vector2D.hpp" #include "includes.hpp" #include "helpers/Monitor.hpp" #include "helpers/Color.hpp" @@ -22,3 +21,6 @@ #endif #include + +#include +using namespace Hyprutils::Math; diff --git a/src/events/Events.cpp b/src/events/Events.cpp index c261b20..4745f87 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -39,7 +39,7 @@ void Events::description(void* data, wl_output* wl_output, const char* descripti 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->m_pMonitor->size = Vector2D((int)width, (int)height); PLAYERSURFACE->ACKSerial = serial; PLAYERSURFACE->wantsACK = true; @@ -82,9 +82,7 @@ void Events::handleCapabilities(void* data, wl_seat* wl_seat, uint32_t capabilit if (capabilities & WL_SEAT_CAPABILITY_POINTER) { const auto POINTER = wl_seat_get_pointer(wl_seat); wl_pointer_add_listener(POINTER, &pointerListener, wl_seat); - g_pHyprpicker->m_pCursorShapeDevice = (g_pHyprpicker->m_pCursorShape) ? - wp_cursor_shape_manager_v1_get_pointer(g_pHyprpicker->m_pCursorShape, POINTER) : - nullptr; + g_pHyprpicker->m_pCursorShapeDevice = (g_pHyprpicker->m_pCursorShape) ? wp_cursor_shape_manager_v1_get_pointer(g_pHyprpicker->m_pCursorShape, POINTER) : nullptr; } else { Debug::log(CRIT, "Hyprpicker cannot work without a pointer!"); g_pHyprpicker->finish(1); @@ -397,8 +395,6 @@ void Events::handleSCReady(void* lsdata, struct zwlr_screencopy_frame_v1* frame, if (TR == 0) return; - const auto TRFLIP = PLS->m_pMonitor->transform >= 4; - cairo_matrix_rotate(mtx, -M_PI_2 * (double)TR); if (TR == 1) diff --git a/src/events/Events.hpp b/src/events/Events.hpp index ddc40e1..8249111 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -3,73 +3,76 @@ #include "../defines.hpp" namespace Events { - void 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 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 mode(void *data, wl_output *output, uint32_t flags, int32_t width, int32_t height, int32_t refresh); + void mode(void* data, wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refresh); - void done(void *data, wl_output *wl_output); + void done(void* data, wl_output* wl_output); - void scale(void *data, wl_output *wl_output, int32_t scale); + void scale(void* data, wl_output* wl_output, int32_t scale); - void name(void *data, wl_output *wl_output, const char *name); + void name(void* data, wl_output* wl_output, const char* name); - void description(void *data, wl_output *wl_output, const char *description); + void description(void* data, wl_output* wl_output, const char* description); - void ls_configure(void *data, zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t width, uint32_t height); + void ls_configure(void* data, zwlr_layer_surface_v1* surface, uint32_t serial, uint32_t width, uint32_t height); - void handleGlobal(void *data, wl_registry *registry, uint32_t name, const char *interface, uint32_t version); + void handleGlobal(void* data, wl_registry* registry, uint32_t name, const char* interface, uint32_t version); - void handleGlobalRemove(void *data, wl_registry *registry, uint32_t name); + void handleGlobalRemove(void* data, wl_registry* registry, uint32_t name); - void handleCapabilities(void *data, wl_seat *wl_seat, uint32_t capabilities); + void handleCapabilities(void* data, wl_seat* wl_seat, uint32_t capabilities); - void handlePointerMotion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y); + void handlePointerMotion(void* data, struct wl_pointer* wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y); - void handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state); + void handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state); - void handlePointerAxis(void *data, wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value); + void handlePointerAxis(void* data, wl_pointer* wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value); - void 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 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 handlePointerLeave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface); + void handlePointerLeave(void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface); void handleKeyboardKeymap(void* data, wl_keyboard* wl_keyboard, uint format, int fd, uint size); - void handleKeyboardKey(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state); - + void handleKeyboardKey(void* data, struct wl_keyboard* keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state); + void handleKeyboardEnter(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface, wl_array* keys); void handleKeyboardLeave(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface); void handleKeyboardModifiers(void* data, wl_keyboard* wl_keyboard, uint serial, uint mods_depressed, uint mods_latched, uint mods_locked, uint group); - void handleFrameDone(void *data, struct wl_callback *callback, uint32_t time); + void handleFrameDone(void* data, struct wl_callback* callback, uint32_t time); - void handleBufferRelease(void *data, struct wl_buffer *wl_buffer); + void handleBufferRelease(void* data, struct wl_buffer* wl_buffer); - void handleSCBuffer(void *data, struct zwlr_screencopy_frame_v1 *frame, uint32_t format, uint32_t width, uint32_t height, uint32_t stride); + void handleSCBuffer(void* data, struct zwlr_screencopy_frame_v1* frame, uint32_t format, uint32_t width, uint32_t height, uint32_t stride); - void handleSCFlags(void *data, struct zwlr_screencopy_frame_v1 *frame, uint32_t flags); + void handleSCFlags(void* data, struct zwlr_screencopy_frame_v1* frame, uint32_t flags); - void handleSCReady(void *data, struct zwlr_screencopy_frame_v1 *frame, uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec); + void handleSCReady(void* data, struct zwlr_screencopy_frame_v1* frame, uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec); - void handleSCFailed(void *data, struct zwlr_screencopy_frame_v1 *frame); + void handleSCFailed(void* data, struct zwlr_screencopy_frame_v1* frame); - inline const wl_output_listener outputListener = {.geometry = geometry, .mode = mode, .done = done, .scale = scale, .name = name, .description = description}; + inline const wl_output_listener outputListener = {.geometry = geometry, .mode = mode, .done = done, .scale = scale, .name = name, .description = description}; - inline const zwlr_layer_surface_v1_listener layersurfaceListener = { .configure = ls_configure }; + inline const zwlr_layer_surface_v1_listener layersurfaceListener = {.configure = ls_configure}; - inline const wl_registry_listener registryListener = { .global = handleGlobal, .global_remove = handleGlobalRemove }; - - inline const wl_seat_listener seatListener = { .capabilities = handleCapabilities }; + inline const wl_registry_listener registryListener = {.global = handleGlobal, .global_remove = handleGlobalRemove}; - inline const wl_pointer_listener pointerListener = { .enter = handlePointerEnter, .leave = handlePointerLeave, .motion = handlePointerMotion, .button = handlePointerButton, .axis = handlePointerAxis }; + inline const wl_seat_listener seatListener = {.capabilities = handleCapabilities}; - inline const wl_keyboard_listener keyboardListener = { .keymap = handleKeyboardKeymap, .enter = handleKeyboardEnter,.leave = handleKeyboardLeave, .key = handleKeyboardKey, .modifiers = handleKeyboardModifiers }; + inline const wl_pointer_listener pointerListener = { + .enter = handlePointerEnter, .leave = handlePointerLeave, .motion = handlePointerMotion, .button = handlePointerButton, .axis = handlePointerAxis}; - inline const wl_callback_listener frameListener = { .done = handleFrameDone }; + inline const wl_keyboard_listener keyboardListener = { + .keymap = handleKeyboardKeymap, .enter = handleKeyboardEnter, .leave = handleKeyboardLeave, .key = handleKeyboardKey, .modifiers = handleKeyboardModifiers}; - inline const wl_buffer_listener bufferListener = { .release = handleBufferRelease }; + inline const wl_callback_listener frameListener = {.done = handleFrameDone}; - inline const zwlr_screencopy_frame_v1_listener screencopyListener = { .buffer = handleSCBuffer, .flags = handleSCFlags, .ready = handleSCReady, .failed = handleSCFailed }; + inline const wl_buffer_listener bufferListener = {.release = handleBufferRelease}; + + inline const zwlr_screencopy_frame_v1_listener screencopyListener = {.buffer = handleSCBuffer, .flags = handleSCFlags, .ready = handleSCReady, .failed = handleSCFailed}; }; diff --git a/src/helpers/Color.hpp b/src/helpers/Color.hpp index 274e000..30a2913 100644 --- a/src/helpers/Color.hpp +++ b/src/helpers/Color.hpp @@ -3,6 +3,6 @@ #include "../defines.hpp" class CColor { -public: + public: uint8_t r = 0, g = 0, b = 0, a = 0; }; \ No newline at end of file diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index 9587b5b..cbd9232 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -1,6 +1,8 @@ #pragma once #include "../defines.hpp" +#include +using namespace Hyprutils::Math; struct SMonitor { std::string name = ""; diff --git a/src/helpers/PoolBuffer.hpp b/src/helpers/PoolBuffer.hpp index 8b286d0..7a397ea 100644 --- a/src/helpers/PoolBuffer.hpp +++ b/src/helpers/PoolBuffer.hpp @@ -3,21 +3,21 @@ #include "../defines.hpp" struct SPoolBuffer { - wl_buffer* buffer = nullptr; + wl_buffer* buffer = nullptr; cairo_surface_t* surface = nullptr; - cairo_t* cairo = nullptr; - void* data = nullptr; + cairo_t* cairo = nullptr; + void* data = nullptr; // malloc'ed buffer for 24bit formats - void* paddedData = nullptr; + void* paddedData = nullptr; - size_t size = 0; - uint32_t stride = 0; - Vector2D pixelSize; + size_t size = 0; + uint32_t stride = 0; + Vector2D pixelSize; - uint32_t format; + uint32_t format; std::string name; - bool busy = false; + bool busy = false; }; \ No newline at end of file diff --git a/src/helpers/Vector2D.cpp b/src/helpers/Vector2D.cpp deleted file mode 100644 index acaace1..0000000 --- a/src/helpers/Vector2D.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "Vector2D.hpp" - -Vector2D::Vector2D(double xx, double yy) { - x = xx; - y = yy; -} - -Vector2D::Vector2D() { x = 0; y = 0; } -Vector2D::~Vector2D() {} - -double Vector2D::normalize() { - // get max abs - const auto max = abs(x) > abs(y) ? abs(x) : abs(y); - - x /= max; - y /= max; - - return max; -} - -Vector2D Vector2D::floor() { - return Vector2D((int)x, (int)y); -} \ No newline at end of file diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp deleted file mode 100644 index 7288a08..0000000 --- a/src/helpers/Vector2D.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -class Vector2D { - public: - Vector2D(double, double); - Vector2D(); - ~Vector2D(); - - double x = 0; - double y = 0; - - // returns the scale - double normalize(); - - Vector2D operator+(const Vector2D a) const { - return Vector2D(this->x + a.x, this->y + a.y); - } - Vector2D operator-(const Vector2D a) const { - return Vector2D(this->x - a.x, this->y - a.y); - } - Vector2D operator*(const float a) const { - return Vector2D(this->x * a, this->y * a); - } - Vector2D operator/(const float a) const { - return Vector2D(this->x / a, this->y / a); - } - - bool operator==(const Vector2D& a) const { - return a.x == x && a.y == y; - } - - bool operator!=(const Vector2D& a) const { - return a.x != x || a.y != y; - } - - Vector2D floor(); -}; \ No newline at end of file