core: migrate to hyprutils for utils

This commit is contained in:
Vaxry 2024-07-17 17:08:10 +02:00
parent 8791f717ef
commit cffd2ca3f8
12 changed files with 74 additions and 140 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.4) cmake_minimum_required(VERSION 3.12)
project(hyprpicker project(hyprpicker
DESCRIPTION "A blazing fast wayland wallpaper utility" 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(Threads REQUIRED)
find_package(PkgConfig 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") file(GLOB_RECURSE SRCFILES "src/*.cpp")

View File

@ -30,11 +30,15 @@ Launch it. Click. That's it.
## Manual ## Manual
Install build dependencies (Debian): Install dependencies:
- cmake
```sh - pkg-config
apt install --no-install-recommends -y cmake g++ make pkg-config libpango1.0-dev libjpeg-dev libwayland-dev wayland-protocols libxkbcommon-dev - pango
``` - cairo
- wayland
- wayland-protocols
- hyprutils
- xkbcommon
Building is done via CMake: Building is done via CMake:

View File

@ -9,23 +9,12 @@ void Debug::log(LogLevel level, const char* fmt, ...) {
std::string levelstr = ""; std::string levelstr = "";
switch (level) { switch (level) {
case LOG: case LOG: levelstr = "[LOG] "; break;
levelstr = "[LOG] "; case WARN: levelstr = "[WARN] "; break;
break; case ERR: levelstr = "[ERR] "; break;
case WARN: case CRIT: levelstr = "[CRITICAL] "; break;
levelstr = "[WARN] "; case INFO: levelstr = "[INFO] "; break;
break; default: break;
case ERR:
levelstr = "[ERR] ";
break;
case CRIT:
levelstr = "[CRITICAL] ";
break;
case INFO:
levelstr = "[INFO] ";
break;
default:
break;
} }
char buf[LOGMESSAGESIZE] = ""; char buf[LOGMESSAGESIZE] = "";

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "helpers/Vector2D.hpp"
#include "includes.hpp" #include "includes.hpp"
#include "helpers/Monitor.hpp" #include "helpers/Monitor.hpp"
#include "helpers/Color.hpp" #include "helpers/Color.hpp"
@ -22,3 +21,6 @@
#endif #endif
#include <sys/types.h> #include <sys/types.h>
#include <hyprutils/math/Vector2D.hpp>
using namespace Hyprutils::Math;

View File

@ -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) { 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((int)width, (int)height);
PLAYERSURFACE->ACKSerial = serial; PLAYERSURFACE->ACKSerial = serial;
PLAYERSURFACE->wantsACK = true; 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) { if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
const auto POINTER = wl_seat_get_pointer(wl_seat); const auto POINTER = wl_seat_get_pointer(wl_seat);
wl_pointer_add_listener(POINTER, &pointerListener, wl_seat); wl_pointer_add_listener(POINTER, &pointerListener, wl_seat);
g_pHyprpicker->m_pCursorShapeDevice = (g_pHyprpicker->m_pCursorShape) ? g_pHyprpicker->m_pCursorShapeDevice = (g_pHyprpicker->m_pCursorShape) ? wp_cursor_shape_manager_v1_get_pointer(g_pHyprpicker->m_pCursorShape, POINTER) : nullptr;
wp_cursor_shape_manager_v1_get_pointer(g_pHyprpicker->m_pCursorShape, POINTER) :
nullptr;
} else { } else {
Debug::log(CRIT, "Hyprpicker cannot work without a pointer!"); Debug::log(CRIT, "Hyprpicker cannot work without a pointer!");
g_pHyprpicker->finish(1); g_pHyprpicker->finish(1);
@ -397,8 +395,6 @@ void Events::handleSCReady(void* lsdata, struct zwlr_screencopy_frame_v1* frame,
if (TR == 0) if (TR == 0)
return; return;
const auto TRFLIP = PLS->m_pMonitor->transform >= 4;
cairo_matrix_rotate(mtx, -M_PI_2 * (double)TR); cairo_matrix_rotate(mtx, -M_PI_2 * (double)TR);
if (TR == 1) if (TR == 1)

View File

@ -3,39 +3,40 @@
#include "../defines.hpp" #include "../defines.hpp"
namespace Events { 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 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 handleKeyboardEnter(void* data, wl_keyboard* wl_keyboard, uint serial, wl_surface* surface, wl_array* keys);
@ -43,33 +44,35 @@ namespace Events {
void handleKeyboardModifiers(void* data, wl_keyboard* wl_keyboard, uint serial, uint mods_depressed, uint mods_latched, uint mods_locked, uint group); 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_registry_listener registryListener = {.global = handleGlobal, .global_remove = handleGlobalRemove};
inline const wl_seat_listener seatListener = { .capabilities = handleCapabilities }; inline const wl_seat_listener seatListener = {.capabilities = handleCapabilities};
inline const wl_pointer_listener pointerListener = { .enter = handlePointerEnter, .leave = handlePointerLeave, .motion = handlePointerMotion, .button = handlePointerButton, .axis = handlePointerAxis }; inline const wl_pointer_listener pointerListener = {
.enter = handlePointerEnter, .leave = handlePointerLeave, .motion = handlePointerMotion, .button = handlePointerButton, .axis = handlePointerAxis};
inline const wl_keyboard_listener keyboardListener = { .keymap = handleKeyboardKeymap, .enter = handleKeyboardEnter,.leave = handleKeyboardLeave, .key = handleKeyboardKey, .modifiers = handleKeyboardModifiers }; inline const wl_keyboard_listener keyboardListener = {
.keymap = handleKeyboardKeymap, .enter = handleKeyboardEnter, .leave = handleKeyboardLeave, .key = handleKeyboardKey, .modifiers = handleKeyboardModifiers};
inline const wl_callback_listener frameListener = { .done = handleFrameDone }; inline const wl_callback_listener frameListener = {.done = handleFrameDone};
inline const wl_buffer_listener bufferListener = { .release = handleBufferRelease }; inline const wl_buffer_listener bufferListener = {.release = handleBufferRelease};
inline const zwlr_screencopy_frame_v1_listener screencopyListener = { .buffer = handleSCBuffer, .flags = handleSCFlags, .ready = handleSCReady, .failed = handleSCFailed }; inline const zwlr_screencopy_frame_v1_listener screencopyListener = {.buffer = handleSCBuffer, .flags = handleSCFlags, .ready = handleSCReady, .failed = handleSCFailed};
}; };

View File

@ -3,6 +3,6 @@
#include "../defines.hpp" #include "../defines.hpp"
class CColor { class CColor {
public: public:
uint8_t r = 0, g = 0, b = 0, a = 0; uint8_t r = 0, g = 0, b = 0, a = 0;
}; };

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#include "../defines.hpp" #include "../defines.hpp"
#include <hyprutils/math/Vector2D.hpp>
using namespace Hyprutils::Math;
struct SMonitor { struct SMonitor {
std::string name = ""; std::string name = "";

View File

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

View File

@ -1,39 +0,0 @@
#pragma once
#include <math.h>
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();
};