mirror of
https://github.com/hyprwm/hyprutils.git
synced 2025-05-13 13:50:44 +01:00
clang-tidy/clang fixes and format
This commit is contained in:
parent
6a8bc9d2a4
commit
0ccb43f5cd
37 changed files with 1191 additions and 1210 deletions
|
@ -19,6 +19,14 @@ set(LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
|
||||||
configure_file(hyprutils.pc.in hyprutils.pc @ONLY)
|
configure_file(hyprutils.pc.in hyprutils.pc @ONLY)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
add_compile_options(
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
||||||
|
-Wpedantic
|
||||||
|
-Wno-unused-parameter
|
||||||
|
-Wno-unused-value
|
||||||
|
-Wno-missing-field-initializers)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
|
||||||
|
|
||||||
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
|
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
|
||||||
message(STATUS "Configuring hyprutils in Debug")
|
message(STATUS "Configuring hyprutils in Debug")
|
||||||
|
|
|
@ -9,9 +9,8 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Animation {
|
namespace Hyprutils::Animation {
|
||||||
|
|
||||||
/* A base class for animated variables. */
|
/* A base class for animated variables. */
|
||||||
class CBaseAnimatedVariable {
|
class CBaseAnimatedVariable {
|
||||||
public:
|
public:
|
||||||
|
@ -222,5 +221,4 @@ namespace Hyprutils {
|
||||||
VarType m_Goal{};
|
VarType m_Goal{};
|
||||||
VarType m_Begun{};
|
VarType m_Begun{};
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Animation {
|
namespace Hyprutils::Animation {
|
||||||
/*
|
/*
|
||||||
Structure for animation properties.
|
Structure for animation properties.
|
||||||
Config properties need to have a static lifetime to allow for config reload.
|
Config properties need to have a static lifetime to allow for config reload.
|
||||||
|
@ -53,5 +53,4 @@ namespace Hyprutils {
|
||||||
void setAnimForChildren(Memory::CSharedPointer<SAnimationPropertyConfig> PANIM);
|
void setAnimForChildren(Memory::CSharedPointer<SAnimationPropertyConfig> PANIM);
|
||||||
std::unordered_map<std::string, Memory::CSharedPointer<SAnimationPropertyConfig>> m_mAnimationConfig;
|
std::unordered_map<std::string, Memory::CSharedPointer<SAnimationPropertyConfig>> m_mAnimationConfig;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Animation {
|
namespace Hyprutils::Animation {
|
||||||
class CBaseAnimatedVariable;
|
class CBaseAnimatedVariable;
|
||||||
|
|
||||||
/* A class for managing bezier curves and variables that are being animated. */
|
/* A class for managing bezier curves and variables that are being animated. */
|
||||||
|
@ -59,5 +59,4 @@ namespace Hyprutils {
|
||||||
Memory::CUniquePointer<SAnimVarListeners> m_listeners;
|
Memory::CUniquePointer<SAnimVarListeners> m_listeners;
|
||||||
Memory::CUniquePointer<SAnimationManagerSignals> m_events;
|
Memory::CUniquePointer<SAnimationManagerSignals> m_events;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
#include "../math/Vector2D.hpp"
|
#include "../math/Vector2D.hpp"
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Animation {
|
namespace Hyprutils::Animation {
|
||||||
constexpr int BAKEDPOINTS = 255;
|
constexpr int BAKEDPOINTS = 255;
|
||||||
constexpr float INVBAKEDPOINTS = 1.f / BAKEDPOINTS;
|
constexpr float INVBAKEDPOINTS = 1.f / BAKEDPOINTS;
|
||||||
|
|
||||||
|
@ -26,5 +26,4 @@ namespace Hyprutils {
|
||||||
|
|
||||||
std::array<Hyprutils::Math::Vector2D, BAKEDPOINTS> m_aPointsBaked;
|
std::array<Hyprutils::Math::Vector2D, BAKEDPOINTS> m_aPointsBaked;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,14 @@ namespace Hyprutils::Math {
|
||||||
* @return Scaled SBoxExtents.
|
* @return Scaled SBoxExtents.
|
||||||
*/
|
*/
|
||||||
SBoxExtents operator*(const double& scale) const {
|
SBoxExtents operator*(const double& scale) const {
|
||||||
return SBoxExtents{topLeft * scale, bottomRight * scale};
|
return SBoxExtents{.topLeft = topLeft * scale, .bottomRight = bottomRight * scale};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Rounds the coordinates of the extents.
|
* @brief Rounds the coordinates of the extents.
|
||||||
* @return Rounded SBoxExtents.
|
* @return Rounded SBoxExtents.
|
||||||
*/
|
*/
|
||||||
SBoxExtents round() {
|
SBoxExtents round() {
|
||||||
return {topLeft.round(), bottomRight.round()};
|
return {.topLeft = topLeft.round(), .bottomRight = bottomRight.round()};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Checks equality between two SBoxExtents objects.
|
* @brief Checks equality between two SBoxExtents objects.
|
||||||
|
@ -58,9 +58,7 @@ namespace Hyprutils::Math {
|
||||||
* @param w_ Width of the box.
|
* @param w_ Width of the box.
|
||||||
* @param h_ Height of the box.
|
* @param h_ Height of the box.
|
||||||
*/
|
*/
|
||||||
CBox(double x_, double y_, double w_, double h_) {
|
CBox(double x_, double y_, double w_, double h_) : x(x_), y(y_) {
|
||||||
x = x_;
|
|
||||||
y = y_;
|
|
||||||
w = w_;
|
w = w_;
|
||||||
h = h_;
|
h = h_;
|
||||||
}
|
}
|
||||||
|
@ -75,9 +73,8 @@ namespace Hyprutils::Math {
|
||||||
* @brief Constructs a CBox with uniform dimensions.
|
* @brief Constructs a CBox with uniform dimensions.
|
||||||
* @param d Dimensions to apply uniformly (x, y, width, height).
|
* @param d Dimensions to apply uniformly (x, y, width, height).
|
||||||
*/
|
*/
|
||||||
CBox(const double d) {
|
// XD. This comment will be deleted before MR, but it'll be saved in the history. Sometimes it's nice to be an idiot.
|
||||||
x = d;
|
CBox(const double d) : x(d), y(d) {
|
||||||
y = d;
|
|
||||||
w = d;
|
w = d;
|
||||||
h = d;
|
h = d;
|
||||||
}
|
}
|
||||||
|
@ -86,9 +83,7 @@ namespace Hyprutils::Math {
|
||||||
* @param pos Position vector representing the top-left corner.
|
* @param pos Position vector representing the top-left corner.
|
||||||
* @param size Size vector representing width and height.
|
* @param size Size vector representing width and height.
|
||||||
*/
|
*/
|
||||||
CBox(const Vector2D& pos, const Vector2D& size) {
|
CBox(const Vector2D& pos, const Vector2D& size) : x(pos.x), y(pos.y) {
|
||||||
x = pos.x;
|
|
||||||
y = pos.y;
|
|
||||||
w = size.x;
|
w = size.x;
|
||||||
h = size.y;
|
h = size.y;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
//NOLINTNEXTLINE
|
||||||
namespace Hyprutils::Math {
|
namespace Hyprutils::Math {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,11 +7,12 @@
|
||||||
|
|
||||||
#include "./Misc.hpp"
|
#include "./Misc.hpp"
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Math {
|
namespace Hyprutils::Math {
|
||||||
class CBox;
|
class CBox;
|
||||||
class Vector2D;
|
class Vector2D;
|
||||||
|
|
||||||
|
//NOLINTNEXTLINE
|
||||||
class Mat3x3 {
|
class Mat3x3 {
|
||||||
public:
|
public:
|
||||||
Mat3x3();
|
Mat3x3();
|
||||||
|
@ -55,5 +56,4 @@ namespace Hyprutils {
|
||||||
private:
|
private:
|
||||||
std::array<float, 9> matrix;
|
std::array<float, 9> matrix;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Math {
|
namespace Hyprutils::Math {
|
||||||
enum eTransform {
|
// Welcome nahui
|
||||||
|
enum eTransform : unsigned char {
|
||||||
HYPRUTILS_TRANSFORM_NORMAL = 0,
|
HYPRUTILS_TRANSFORM_NORMAL = 0,
|
||||||
HYPRUTILS_TRANSFORM_90 = 1,
|
HYPRUTILS_TRANSFORM_90 = 1,
|
||||||
HYPRUTILS_TRANSFORM_180 = 2,
|
HYPRUTILS_TRANSFORM_180 = 2,
|
||||||
|
@ -12,5 +13,4 @@ namespace Hyprutils {
|
||||||
HYPRUTILS_TRANSFORM_FLIPPED_180 = 6,
|
HYPRUTILS_TRANSFORM_FLIPPED_180 = 6,
|
||||||
HYPRUTILS_TRANSFORM_FLIPPED_270 = 7,
|
HYPRUTILS_TRANSFORM_FLIPPED_270 = 7,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -5,8 +5,8 @@
|
||||||
#include "Vector2D.hpp"
|
#include "Vector2D.hpp"
|
||||||
#include "Box.hpp"
|
#include "Box.hpp"
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Math {
|
namespace Hyprutils::Math {
|
||||||
class CRegion {
|
class CRegion {
|
||||||
public:
|
public:
|
||||||
/* Create an empty region */
|
/* Create an empty region */
|
||||||
|
@ -21,16 +21,17 @@ namespace Hyprutils {
|
||||||
CRegion(pixman_box32_t* box);
|
CRegion(pixman_box32_t* box);
|
||||||
|
|
||||||
CRegion(const CRegion&);
|
CRegion(const CRegion&);
|
||||||
CRegion(CRegion&&);
|
CRegion(CRegion&&) noexcept;
|
||||||
|
|
||||||
~CRegion();
|
~CRegion();
|
||||||
|
|
||||||
CRegion& operator=(CRegion&& other) {
|
CRegion& operator=(CRegion&& other) noexcept {
|
||||||
pixman_region32_copy(&m_rRegion, other.pixman());
|
pixman_region32_copy(&m_rRegion, other.pixman());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CRegion& operator=(CRegion& other) {
|
// CRegion&& will shit-talkin you about being non-redeclarable and CRegion const&... pixman moment.
|
||||||
|
CRegion& operator=(CRegion other) {
|
||||||
pixman_region32_copy(&m_rRegion, other.pixman());
|
pixman_region32_copy(&m_rRegion, other.pixman());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -67,5 +68,4 @@ namespace Hyprutils {
|
||||||
private:
|
private:
|
||||||
pixman_region32_t m_rRegion;
|
pixman_region32_t m_rRegion;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Math {
|
namespace Hyprutils::Math {
|
||||||
|
//NOLINTNEXTLINE
|
||||||
class Vector2D {
|
class Vector2D {
|
||||||
public:
|
public:
|
||||||
Vector2D(double, double);
|
Vector2D(double, double);
|
||||||
|
@ -98,7 +99,6 @@ namespace Hyprutils {
|
||||||
|
|
||||||
Vector2D getComponentMax(const Vector2D& other) const;
|
Vector2D getComponentMax(const Vector2D& other) const;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// absolutely ridiculous formatter spec parsing
|
// absolutely ridiculous formatter spec parsing
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Memory {
|
namespace Hyprutils::Memory::Impl_ {
|
||||||
namespace Impl_ {
|
//NOLINTNEXTLINE
|
||||||
class impl_base {
|
class impl_base {
|
||||||
public:
|
public:
|
||||||
virtual ~impl_base() {};
|
virtual ~impl_base() = default;
|
||||||
|
|
||||||
virtual void inc() noexcept = 0;
|
virtual void inc() noexcept = 0;
|
||||||
virtual void dec() noexcept = 0;
|
virtual void dec() noexcept = 0;
|
||||||
|
@ -23,6 +23,7 @@ namespace Hyprutils {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
//NOLINTNEXTLINE
|
||||||
class impl : public impl_base {
|
class impl : public impl_base {
|
||||||
public:
|
public:
|
||||||
impl(T* data, bool lock = true) noexcept : _data(data), _lockable(lock) {
|
impl(T* data, bool lock = true) noexcept : _data(data), _lockable(lock) {
|
||||||
|
@ -38,7 +39,7 @@ namespace Hyprutils {
|
||||||
|
|
||||||
T* _data = nullptr;
|
T* _data = nullptr;
|
||||||
|
|
||||||
friend void swap(impl*& a, impl*& b) {
|
friend void swap(impl*& a, impl*& b) noexcept {
|
||||||
impl* tmp = a;
|
impl* tmp = a;
|
||||||
a = b;
|
a = b;
|
||||||
b = tmp;
|
b = tmp;
|
||||||
|
@ -56,13 +57,13 @@ namespace Hyprutils {
|
||||||
// this way, weak pointers will still be able to
|
// this way, weak pointers will still be able to
|
||||||
// reference and use, but no longer create shared ones.
|
// reference and use, but no longer create shared ones.
|
||||||
_destroying = true;
|
_destroying = true;
|
||||||
__deleter(_data);
|
_deleter(_data);
|
||||||
// now, we can reset the data and call it a day.
|
// now, we can reset the data and call it a day.
|
||||||
_data = nullptr;
|
_data = nullptr;
|
||||||
_destroying = false;
|
_destroying = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::default_delete<T> __deleter{};
|
std::default_delete<T> _deleter{};
|
||||||
|
|
||||||
//
|
//
|
||||||
virtual void inc() noexcept {
|
virtual void inc() noexcept {
|
||||||
|
@ -113,7 +114,4 @@ namespace Hyprutils {
|
||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -13,38 +13,34 @@
|
||||||
or deref an existing one inside the destructor.
|
or deref an existing one inside the destructor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Hyprutils {
|
namespace Hyprutils::Memory {
|
||||||
namespace Memory {
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class CSharedPointer {
|
class CSharedPointer {
|
||||||
public:
|
public:
|
||||||
template <typename X>
|
template <typename X>
|
||||||
using validHierarchy = typename std::enable_if<std::is_assignable<CSharedPointer<T>&, X>::value, CSharedPointer&>::type;
|
using validHierarchy = std::enable_if_t<std::is_assignable_v<CSharedPointer<T>&, X>, CSharedPointer&>;
|
||||||
template <typename X>
|
template <typename X>
|
||||||
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
|
using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
|
||||||
|
|
||||||
/* creates a new shared pointer managing a resource
|
/* creates a new shared pointer managing a resource
|
||||||
avoid calling. Could duplicate ownership. Prefer makeShared */
|
avoid calling. Could duplicate ownership. Prefer makeShared */
|
||||||
explicit CSharedPointer(T* object) noexcept {
|
explicit CSharedPointer(T* object) noexcept : impl_(new Impl_::impl<T>(object)) {
|
||||||
impl_ = new Impl_::impl<T>(object);
|
|
||||||
increment();
|
increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* creates a shared pointer from a reference */
|
/* creates a shared pointer from a reference */
|
||||||
template <typename U, typename = isConstructible<U>>
|
template <typename U, typename = isConstructible<U>>
|
||||||
CSharedPointer(const CSharedPointer<U>& ref) noexcept {
|
CSharedPointer(const CSharedPointer<U>& ref) noexcept : impl_(ref.impl_) {
|
||||||
impl_ = ref.impl_;
|
|
||||||
increment();
|
increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
CSharedPointer(const CSharedPointer& ref) noexcept {
|
CSharedPointer(const CSharedPointer& ref) noexcept : impl_(ref.impl_) {
|
||||||
impl_ = ref.impl_;
|
|
||||||
increment();
|
increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, typename = isConstructible<U>>
|
template <typename U, typename = isConstructible<U>>
|
||||||
CSharedPointer(CSharedPointer<U>&& ref) noexcept {
|
// reason - ref param not moved. But is that correct?
|
||||||
|
CSharedPointer(CSharedPointer<U>& ref) noexcept {
|
||||||
std::swap(impl_, ref.impl_);
|
std::swap(impl_, ref.impl_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +49,7 @@ namespace Hyprutils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allows weakPointer to create from an impl */
|
/* allows weakPointer to create from an impl */
|
||||||
CSharedPointer(Impl_::impl_base* implementation) noexcept {
|
CSharedPointer(Impl_::impl_base* implementation) noexcept : impl_(implementation) {
|
||||||
impl_ = implementation;
|
|
||||||
increment();
|
increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +68,7 @@ namespace Hyprutils {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
|
// Same. And also what should i do with the warning of unconventional assign operators?
|
||||||
validHierarchy<const CSharedPointer<U>&> operator=(const CSharedPointer<U>& rhs) {
|
validHierarchy<const CSharedPointer<U>&> operator=(const CSharedPointer<U>& rhs) {
|
||||||
if (impl_ == rhs.impl_)
|
if (impl_ == rhs.impl_)
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -82,7 +78,7 @@ namespace Hyprutils {
|
||||||
increment();
|
increment();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
//Self assignment warning. What to do?
|
||||||
CSharedPointer& operator=(const CSharedPointer& rhs) {
|
CSharedPointer& operator=(const CSharedPointer& rhs) {
|
||||||
if (impl_ == rhs.impl_)
|
if (impl_ == rhs.impl_)
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -94,12 +90,13 @@ namespace Hyprutils {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
validHierarchy<const CSharedPointer<U>&> operator=(CSharedPointer<U>&& rhs) {
|
// Same
|
||||||
|
validHierarchy<const CSharedPointer<U>&> operator=(CSharedPointer<U>& rhs) {
|
||||||
std::swap(impl_, rhs.impl_);
|
std::swap(impl_, rhs.impl_);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSharedPointer& operator=(CSharedPointer&& rhs) {
|
CSharedPointer& operator=(CSharedPointer&& rhs) noexcept {
|
||||||
std::swap(impl_, rhs.impl_);
|
std::swap(impl_, rhs.impl_);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -185,7 +182,6 @@ namespace Hyprutils {
|
||||||
static CSharedPointer<U> makeShared(Args&&... args) {
|
static CSharedPointer<U> makeShared(Args&&... args) {
|
||||||
return CSharedPointer<U>(new U(std::forward<Args>(args)...));
|
return CSharedPointer<U>(new U(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -9,20 +9,18 @@
|
||||||
to be locked.
|
to be locked.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Hyprutils {
|
namespace Hyprutils::Memory {
|
||||||
namespace Memory {
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class CUniquePointer {
|
class CUniquePointer {
|
||||||
public:
|
public:
|
||||||
template <typename X>
|
template <typename X>
|
||||||
using validHierarchy = typename std::enable_if<std::is_assignable<CUniquePointer<T>&, X>::value, CUniquePointer&>::type;
|
using validHierarchy = std::enable_if_t<std::is_assignable_v<CUniquePointer<T>&, X>, CUniquePointer&>;
|
||||||
template <typename X>
|
template <typename X>
|
||||||
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
|
using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
|
||||||
|
|
||||||
/* creates a new unique pointer managing a resource
|
/* creates a new unique pointer managing a resource
|
||||||
avoid calling. Could duplicate ownership. Prefer makeUnique */
|
avoid calling. Could duplicate ownership. Prefer makeUnique */
|
||||||
explicit CUniquePointer(T* object) noexcept {
|
explicit CUniquePointer(T* object) noexcept : impl_(new Impl_::impl<T>(object, false)) {
|
||||||
impl_ = new Impl_::impl<T>(object, false);
|
|
||||||
increment();
|
increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +30,8 @@ namespace Hyprutils {
|
||||||
CUniquePointer(const CUniquePointer& ref) = delete;
|
CUniquePointer(const CUniquePointer& ref) = delete;
|
||||||
|
|
||||||
template <typename U, typename = isConstructible<U>>
|
template <typename U, typename = isConstructible<U>>
|
||||||
CUniquePointer(CUniquePointer<U>&& ref) noexcept {
|
// Same
|
||||||
|
CUniquePointer(CUniquePointer<U>& ref) noexcept {
|
||||||
std::swap(impl_, ref.impl_);
|
std::swap(impl_, ref.impl_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,12 +58,13 @@ namespace Hyprutils {
|
||||||
CUniquePointer& operator=(const CUniquePointer& rhs) = delete;
|
CUniquePointer& operator=(const CUniquePointer& rhs) = delete;
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
validHierarchy<const CUniquePointer<U>&> operator=(CUniquePointer<U>&& rhs) {
|
// Same with both
|
||||||
|
validHierarchy<const CUniquePointer<U>&> operator=(CUniquePointer<U>& rhs) {
|
||||||
std::swap(impl_, rhs.impl_);
|
std::swap(impl_, rhs.impl_);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CUniquePointer& operator=(CUniquePointer&& rhs) {
|
CUniquePointer& operator=(CUniquePointer&& rhs) noexcept {
|
||||||
std::swap(impl_, rhs.impl_);
|
std::swap(impl_, rhs.impl_);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,6 @@ namespace Hyprutils {
|
||||||
static CUniquePointer<U> makeUnique(Args&&... args) {
|
static CUniquePointer<U> makeUnique(Args&&... args) {
|
||||||
return CUniquePointer<U>(new U(std::forward<Args>(args)...));
|
return CUniquePointer<U>(new U(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -9,15 +9,15 @@
|
||||||
See SharedPtr.hpp for more info on how it's different.
|
See SharedPtr.hpp for more info on how it's different.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Memory {
|
namespace Hyprutils::Memory {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class CWeakPointer {
|
class CWeakPointer {
|
||||||
public:
|
public:
|
||||||
template <typename X>
|
template <typename X>
|
||||||
using validHierarchy = typename std::enable_if<std::is_assignable<CWeakPointer<T>&, X>::value, CWeakPointer&>::type;
|
using validHierarchy = std::enable_if_t<std::is_assignable_v<CWeakPointer<T>&, X>, CWeakPointer&>;
|
||||||
template <typename X>
|
template <typename X>
|
||||||
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
|
using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
|
||||||
|
|
||||||
/* create a weak ptr from a reference */
|
/* create a weak ptr from a reference */
|
||||||
template <typename U, typename = isConstructible<U>>
|
template <typename U, typename = isConstructible<U>>
|
||||||
|
@ -58,7 +58,8 @@ namespace Hyprutils {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, typename = isConstructible<U>>
|
template <typename U, typename = isConstructible<U>>
|
||||||
CWeakPointer(CWeakPointer<U>&& ref) noexcept {
|
// Same
|
||||||
|
CWeakPointer(CWeakPointer<U>& ref) noexcept {
|
||||||
std::swap(impl_, ref.impl_);
|
std::swap(impl_, ref.impl_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +69,7 @@ namespace Hyprutils {
|
||||||
|
|
||||||
/* create a weak ptr from another weak ptr with assignment */
|
/* create a weak ptr from another weak ptr with assignment */
|
||||||
template <typename U>
|
template <typename U>
|
||||||
|
// Same
|
||||||
validHierarchy<const CWeakPointer<U>&> operator=(const CWeakPointer<U>& rhs) {
|
validHierarchy<const CWeakPointer<U>&> operator=(const CWeakPointer<U>& rhs) {
|
||||||
if (impl_ == rhs.impl_)
|
if (impl_ == rhs.impl_)
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -77,7 +79,7 @@ namespace Hyprutils {
|
||||||
incrementWeak();
|
incrementWeak();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
// Same
|
||||||
CWeakPointer<T>& operator=(const CWeakPointer& rhs) {
|
CWeakPointer<T>& operator=(const CWeakPointer& rhs) {
|
||||||
if (impl_ == rhs.impl_)
|
if (impl_ == rhs.impl_)
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -90,6 +92,7 @@ namespace Hyprutils {
|
||||||
|
|
||||||
/* create a weak ptr from a shared ptr with assignment */
|
/* create a weak ptr from a shared ptr with assignment */
|
||||||
template <typename U>
|
template <typename U>
|
||||||
|
// Same...
|
||||||
validHierarchy<const CWeakPointer<U>&> operator=(const CSharedPointer<U>& rhs) {
|
validHierarchy<const CWeakPointer<U>&> operator=(const CSharedPointer<U>& rhs) {
|
||||||
if (reinterpret_cast<uintptr_t>(impl_) == reinterpret_cast<uintptr_t>(rhs.impl_))
|
if (reinterpret_cast<uintptr_t>(impl_) == reinterpret_cast<uintptr_t>(rhs.impl_))
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -208,7 +211,6 @@ namespace Hyprutils {
|
||||||
impl_->incWeak();
|
impl_->incWeak();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
namespace Hyprutils {
|
|
||||||
namespace OS {
|
//NOLINTNEXTLINE
|
||||||
|
namespace Hyprutils::OS {
|
||||||
class CFileDescriptor {
|
class CFileDescriptor {
|
||||||
public:
|
public:
|
||||||
CFileDescriptor() = default;
|
CFileDescriptor() = default;
|
||||||
explicit CFileDescriptor(int const fd);
|
explicit CFileDescriptor(int const fd);
|
||||||
CFileDescriptor(CFileDescriptor&&);
|
CFileDescriptor(CFileDescriptor&&) noexcept;
|
||||||
CFileDescriptor& operator=(CFileDescriptor&&);
|
CFileDescriptor& operator=(CFileDescriptor&&) noexcept;
|
||||||
~CFileDescriptor();
|
~CFileDescriptor();
|
||||||
|
|
||||||
CFileDescriptor(const CFileDescriptor&) = delete;
|
CFileDescriptor(const CFileDescriptor&) = delete;
|
||||||
|
@ -35,5 +36,4 @@ namespace Hyprutils {
|
||||||
private:
|
private:
|
||||||
int m_fd = -1;
|
int m_fd = -1;
|
||||||
};
|
};
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace OS {
|
namespace Hyprutils::OS {
|
||||||
class CProcess {
|
class CProcess {
|
||||||
public:
|
public:
|
||||||
/* Creates a process object, doesn't run yet */
|
/* Creates a process object, doesn't run yet */
|
||||||
|
@ -25,7 +25,7 @@ namespace Hyprutils {
|
||||||
const std::string& stdErr();
|
const std::string& stdErr();
|
||||||
|
|
||||||
// only populated when ran async
|
// only populated when ran async
|
||||||
const pid_t pid();
|
pid_t pid();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string binary, out, err;
|
std::string binary, out, err;
|
||||||
|
@ -33,5 +33,4 @@ namespace Hyprutils {
|
||||||
std::vector<std::pair<std::string, std::string>> env;
|
std::vector<std::pair<std::string, std::string>> env;
|
||||||
pid_t grandchildPid = 0;
|
pid_t grandchildPid = 0;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -4,8 +4,8 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Path {
|
namespace Hyprutils::Path {
|
||||||
/** Check whether a config in the form basePath/hypr/programName.conf exists.
|
/** Check whether a config in the form basePath/hypr/programName.conf exists.
|
||||||
@param basePath the path where the config will be searched
|
@param basePath the path where the config will be searched
|
||||||
@param programName name of the program (and config file) to search for
|
@param programName name of the program (and config file) to search for
|
||||||
|
@ -38,5 +38,4 @@ namespace Hyprutils {
|
||||||
|
|
||||||
using T = std::optional<std::string>;
|
using T = std::optional<std::string>;
|
||||||
std::pair<T, T> findConfig(const std::string programName);
|
std::pair<T, T> findConfig(const std::string programName);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <hyprutils/memory/SharedPtr.hpp>
|
#include <hyprutils/memory/SharedPtr.hpp>
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Signal {
|
namespace Hyprutils::Signal {
|
||||||
class CSignal;
|
class CSignal;
|
||||||
|
|
||||||
class CSignalListener {
|
class CSignalListener {
|
||||||
|
@ -40,5 +40,4 @@ namespace Hyprutils {
|
||||||
void* m_pOwner = nullptr;
|
void* m_pOwner = nullptr;
|
||||||
std::function<void(void*, std::any)> m_fHandler;
|
std::function<void(void*, std::any)> m_fHandler;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
#include <hyprutils/memory/WeakPtr.hpp>
|
#include <hyprutils/memory/WeakPtr.hpp>
|
||||||
#include "./Listener.hpp"
|
#include "./Listener.hpp"
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Signal {
|
namespace Hyprutils::Signal {
|
||||||
class CSignal {
|
class CSignal {
|
||||||
public:
|
public:
|
||||||
void emit(std::any data = {});
|
void emit(std::any data = {});
|
||||||
|
@ -24,5 +24,4 @@ namespace Hyprutils {
|
||||||
std::vector<Hyprutils::Memory::CWeakPointer<CSignalListener>> m_vListeners;
|
std::vector<Hyprutils::Memory::CWeakPointer<CSignalListener>> m_vListeners;
|
||||||
std::vector<std::unique_ptr<CStaticSignalListener>> m_vStaticListeners;
|
std::vector<std::unique_ptr<CStaticSignalListener>> m_vStaticListeners;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,11 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace String {
|
namespace Hyprutils::String {
|
||||||
// trims beginning and end of whitespace characters
|
// trims beginning and end of whitespace characters
|
||||||
std::string trim(const std::string& in);
|
std::string trim(const std::string& in);
|
||||||
bool isNumber(const std::string& str, bool allowfloat = false);
|
bool isNumber(const std::string& str, bool allowfloat = false);
|
||||||
void replaceInString(std::string& string, const std::string& what, const std::string& to);
|
void replaceInString(std::string& string, const std::string& what, const std::string& to);
|
||||||
};
|
|
||||||
};
|
};
|
|
@ -3,8 +3,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace String {
|
namespace Hyprutils::String {
|
||||||
class CVarList {
|
class CVarList {
|
||||||
public:
|
public:
|
||||||
/** Split string into arg list
|
/** Split string into arg list
|
||||||
|
@ -63,5 +63,4 @@ namespace Hyprutils {
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> m_vArgs;
|
std::vector<std::string> m_vArgs;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace Hyprutils {
|
//NOLINTNEXTLINE
|
||||||
namespace Utils {
|
namespace Hyprutils::Utils {
|
||||||
// calls a function when it goes out of scope
|
// calls a function when it goes out of scope
|
||||||
class CScopeGuard {
|
class CScopeGuard {
|
||||||
public:
|
public:
|
||||||
|
@ -13,5 +13,4 @@ namespace Hyprutils {
|
||||||
private:
|
private:
|
||||||
std::function<void()> fn;
|
std::function<void()> fn;
|
||||||
};
|
};
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -99,7 +99,7 @@ bool CAnimationManager::bezierExists(const std::string& bezier) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SP<CBezierCurve> CAnimationManager::getBezier(const std::string& name) {
|
SP<CBezierCurve> CAnimationManager::getBezier(const std::string& name) {
|
||||||
const auto BEZIER = std::find_if(m_mBezierCurves.begin(), m_mBezierCurves.end(), [&](const auto& other) { return other.first == name; });
|
const auto BEZIER = std::ranges::find_if(m_mBezierCurves, [&](const auto& other) { return other.first == name; });
|
||||||
|
|
||||||
return BEZIER == m_mBezierCurves.end() ? m_mBezierCurves["default"] : BEZIER->second;
|
return BEZIER == m_mBezierCurves.end() ? m_mBezierCurves["default"] : BEZIER->second;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,14 +35,14 @@ float CBezierCurve::getXForT(float const& t) const {
|
||||||
float t2 = t * t;
|
float t2 = t * t;
|
||||||
float t3 = t2 * t;
|
float t3 = t2 * t;
|
||||||
|
|
||||||
return 3 * t * (1 - t) * (1 - t) * m_vPoints[1].x + 3 * t2 * (1 - t) * m_vPoints[2].x + t3 * m_vPoints[3].x;
|
return (3 * t * (1 - t) * (1 - t) * m_vPoints[1].x) + (3 * t2 * (1 - t) * m_vPoints[2].x) + (t3 * m_vPoints[3].x);
|
||||||
}
|
}
|
||||||
|
|
||||||
float CBezierCurve::getYForT(float const& t) const {
|
float CBezierCurve::getYForT(float const& t) const {
|
||||||
float t2 = t * t;
|
float t2 = t * t;
|
||||||
float t3 = t2 * t;
|
float t3 = t2 * t;
|
||||||
|
|
||||||
return 3 * t * (1 - t) * (1 - t) * m_vPoints[1].y + 3 * t2 * (1 - t) * m_vPoints[2].y + t3 * m_vPoints[3].y;
|
return (3 * t * (1 - t) * (1 - t) * m_vPoints[1].y) + (3 * t2 * (1 - t) * m_vPoints[2].y) + (t3 * m_vPoints[3].y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Todo: this probably can be done better and faster
|
// Todo: this probably can be done better and faster
|
||||||
|
@ -74,5 +74,5 @@ float CBezierCurve::getYForPoint(float const& x) const {
|
||||||
if (std::isnan(PERCINDELTA) || std::isinf(PERCINDELTA)) // can sometimes happen for VERY small x
|
if (std::isnan(PERCINDELTA) || std::isinf(PERCINDELTA)) // can sometimes happen for VERY small x
|
||||||
return 0.f;
|
return 0.f;
|
||||||
|
|
||||||
return LOWERPOINT->y + (UPPERPOINT->y - LOWERPOINT->y) * PERCINDELTA;
|
return LOWERPOINT->y + ((UPPERPOINT->y - LOWERPOINT->y) * PERCINDELTA);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ CBox& Hyprutils::Math::CBox::translate(const Vector2D& vec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2D Hyprutils::Math::CBox::middle() const {
|
Vector2D Hyprutils::Math::CBox::middle() const {
|
||||||
return Vector2D{x + w * HALF, y + h * HALF};
|
return Vector2D{x + (w * HALF), y + (h * HALF)};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Hyprutils::Math::CBox::containsPoint(const Vector2D& vec) const {
|
bool Hyprutils::Math::CBox::containsPoint(const Vector2D& vec) const {
|
||||||
|
@ -233,5 +233,5 @@ Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
SBoxExtents Hyprutils::Math::CBox::extentsFrom(const CBox& small) {
|
SBoxExtents Hyprutils::Math::CBox::extentsFrom(const CBox& small) {
|
||||||
return {{small.x - x, small.y - y}, {w - small.w - (small.x - x), h - small.h - (small.y - y)}};
|
return {.topLeft = {small.x - x, small.y - y}, .bottomRight = {w - small.w - (small.x - x), h - small.h - (small.y - y)}};
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,7 @@ Mat3x3& Mat3x3::transform(eTransform transform) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat3x3& Mat3x3::rotate(float rot) {
|
Mat3x3& Mat3x3::rotate(float rot) {
|
||||||
|
//no lint or maybe do something?
|
||||||
multiply(std::array<float, 9>{(float)cos(rot), (float)-sin(rot), 0.0f, (float)sin(rot), (float)cos(rot), 0.0f, 0.0f, 0.0f, 1.0f});
|
multiply(std::array<float, 9>{(float)cos(rot), (float)-sin(rot), 0.0f, (float)sin(rot), (float)cos(rot), 0.0f, 0.0f, 0.0f, 1.0f});
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,13 @@ Hyprutils::Math::CRegion::CRegion(pixman_box32_t* box) {
|
||||||
pixman_region32_init_rect(&m_rRegion, box->x1, box->y1, box->x2 - box->x1, box->y2 - box->y1);
|
pixman_region32_init_rect(&m_rRegion, box->x1, box->y1, box->x2 - box->x1, box->y2 - box->y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// What to do with const_cast?
|
||||||
Hyprutils::Math::CRegion::CRegion(const CRegion& other) {
|
Hyprutils::Math::CRegion::CRegion(const CRegion& other) {
|
||||||
pixman_region32_init(&m_rRegion);
|
pixman_region32_init(&m_rRegion);
|
||||||
pixman_region32_copy(&m_rRegion, const_cast<CRegion*>(&other)->pixman());
|
pixman_region32_copy(&m_rRegion, const_cast<CRegion*>(&other)->pixman());
|
||||||
}
|
}
|
||||||
|
|
||||||
Hyprutils::Math::CRegion::CRegion(CRegion&& other) {
|
Hyprutils::Math::CRegion::CRegion(CRegion&& other) noexcept {
|
||||||
pixman_region32_init(&m_rRegion);
|
pixman_region32_init(&m_rRegion);
|
||||||
pixman_region32_copy(&m_rRegion, other.pixman());
|
pixman_region32_copy(&m_rRegion, other.pixman());
|
||||||
}
|
}
|
||||||
|
@ -86,7 +87,7 @@ CRegion& Hyprutils::Math::CRegion::invert(pixman_box32_t* box) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CRegion& Hyprutils::Math::CRegion::invert(const CBox& box) {
|
CRegion& Hyprutils::Math::CRegion::invert(const CBox& box) {
|
||||||
pixman_box32 pixmanBox = {(int32_t)box.x, (int32_t)box.y, (int32_t)box.w + (int32_t)box.x, (int32_t)box.h + (int32_t)box.y};
|
pixman_box32 pixmanBox = {.x1 = (int32_t)box.x, .y1 = (int32_t)box.y, .x2 = (int32_t)box.w + (int32_t)box.x, .y2 = (int32_t)box.h + (int32_t)box.y};
|
||||||
return this->invert(&pixmanBox);
|
return this->invert(&pixmanBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +119,7 @@ CRegion& Hyprutils::Math::CRegion::expand(double units) {
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
for (auto& r : rects) {
|
for (auto& r : rects) {
|
||||||
CBox b{(double)r.x1 - units, (double)r.y1 - units, (double)r.x2 - r.x1 + units * 2, (double)r.y2 - r.y1 + units * 2};
|
CBox b{(double)r.x1 - units, (double)r.y1 - units, (double)r.x2 - r.x1 + (units * 2), (double)r.y2 - r.y1 + (units * 2)};
|
||||||
add(b);
|
add(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,23 +4,18 @@
|
||||||
|
|
||||||
using namespace Hyprutils::Math;
|
using namespace Hyprutils::Math;
|
||||||
|
|
||||||
Hyprutils::Math::Vector2D::Vector2D(double xx, double yy) {
|
Hyprutils::Math::Vector2D::Vector2D(double xx, double yy) : x(xx), y(yy) {
|
||||||
x = xx;
|
;
|
||||||
y = yy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Hyprutils::Math::Vector2D::Vector2D(int xx, int yy) {
|
Hyprutils::Math::Vector2D::Vector2D(int xx, int yy) : x((double)xx), y((double)yy) {
|
||||||
x = (double)xx;
|
;
|
||||||
y = (double)yy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Hyprutils::Math::Vector2D::Vector2D() {
|
Hyprutils::Math::Vector2D::Vector2D() {
|
||||||
x = 0;
|
;
|
||||||
y = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Hyprutils::Math::Vector2D::~Vector2D() {}
|
|
||||||
|
|
||||||
double Hyprutils::Math::Vector2D::normalize() {
|
double Hyprutils::Math::Vector2D::normalize() {
|
||||||
// get max abs
|
// get max abs
|
||||||
const auto max = std::abs(x) > std::abs(y) ? std::abs(x) : std::abs(y);
|
const auto max = std::abs(x) > std::abs(y) ? std::abs(x) : std::abs(y);
|
||||||
|
@ -48,11 +43,11 @@ double Hyprutils::Math::Vector2D::distance(const Vector2D& other) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
double Hyprutils::Math::Vector2D::distanceSq(const Vector2D& other) const {
|
double Hyprutils::Math::Vector2D::distanceSq(const Vector2D& other) const {
|
||||||
return (x - other.x) * (x - other.x) + (y - other.y) * (y - other.y);
|
return ((x - other.x) * (x - other.x)) + ((y - other.y) * (y - other.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
double Hyprutils::Math::Vector2D::size() const {
|
double Hyprutils::Math::Vector2D::size() const {
|
||||||
return std::sqrt(x * x + y * y);
|
return std::sqrt((x * x) + (y * y));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2D Hyprutils::Math::Vector2D::getComponentMax(const Vector2D& other) const {
|
Vector2D Hyprutils::Math::Vector2D::getComponentMax(const Vector2D& other) const {
|
||||||
|
|
|
@ -9,9 +9,9 @@ using namespace Hyprutils::OS;
|
||||||
|
|
||||||
CFileDescriptor::CFileDescriptor(int const fd) : m_fd(fd) {}
|
CFileDescriptor::CFileDescriptor(int const fd) : m_fd(fd) {}
|
||||||
|
|
||||||
CFileDescriptor::CFileDescriptor(CFileDescriptor&& other) : m_fd(std::exchange(other.m_fd, -1)) {}
|
CFileDescriptor::CFileDescriptor(CFileDescriptor&& other) noexcept : m_fd(std::exchange(other.m_fd, -1)) {}
|
||||||
|
|
||||||
CFileDescriptor& CFileDescriptor::operator=(CFileDescriptor&& other) {
|
CFileDescriptor& CFileDescriptor::operator=(CFileDescriptor&& other) noexcept {
|
||||||
if (this == &other) // Shit will go haywire if there is duplicate ownership
|
if (this == &other) // Shit will go haywire if there is duplicate ownership
|
||||||
abort();
|
abort();
|
||||||
|
|
||||||
|
@ -37,10 +37,7 @@ int CFileDescriptor::getFlags() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileDescriptor::setFlags(int flags) {
|
bool CFileDescriptor::setFlags(int flags) {
|
||||||
if (fcntl(m_fd, F_SETFD, flags) == -1)
|
return fcntl(m_fd, F_SETFD, flags) != -1;
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CFileDescriptor::take() {
|
int CFileDescriptor::take() {
|
||||||
|
|
|
@ -6,7 +6,6 @@ using namespace Hyprutils::OS;
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include <sys/fcntl.h>
|
#include <sys/fcntl.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
@ -89,7 +88,7 @@ bool Hyprutils::OS::CProcess::runSync() {
|
||||||
{.fd = outPipe[0], .events = POLLIN, .revents = 0},
|
{.fd = outPipe[0], .events = POLLIN, .revents = 0},
|
||||||
{.fd = errPipe[0], .events = POLLIN, .revents = 0},
|
{.fd = errPipe[0], .events = POLLIN, .revents = 0},
|
||||||
};
|
};
|
||||||
|
// Maybe bool or just leave it as it is?
|
||||||
while (1337) {
|
while (1337) {
|
||||||
int ret = poll(pollfds, 2, 5000);
|
int ret = poll(pollfds, 2, 5000);
|
||||||
|
|
||||||
|
@ -171,7 +170,7 @@ bool Hyprutils::OS::CProcess::runAsync() {
|
||||||
// run in child
|
// run in child
|
||||||
sigset_t set;
|
sigset_t set;
|
||||||
sigemptyset(&set);
|
sigemptyset(&set);
|
||||||
sigprocmask(SIG_SETMASK, &set, NULL);
|
sigprocmask(SIG_SETMASK, &set, nullptr);
|
||||||
|
|
||||||
grandchild = fork();
|
grandchild = fork();
|
||||||
if (grandchild == 0) {
|
if (grandchild == 0) {
|
||||||
|
@ -225,6 +224,6 @@ const std::string& Hyprutils::OS::CProcess::stdErr() {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pid_t Hyprutils::OS::CProcess::pid() {
|
pid_t Hyprutils::OS::CProcess::pid() {
|
||||||
return grandchildPid;
|
return grandchildPid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ using namespace Hyprutils;
|
||||||
|
|
||||||
namespace Hyprutils::Path {
|
namespace Hyprutils::Path {
|
||||||
std::string fullConfigPath(std::string basePath, std::string programName) {
|
std::string fullConfigPath(std::string basePath, std::string programName) {
|
||||||
|
//no lint or...?
|
||||||
return basePath + "/hypr/" + programName + ".conf";
|
return basePath + "/hypr/" + programName + ".conf";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ namespace Hyprutils::Path {
|
||||||
|
|
||||||
static const auto xdgConfigDirs = getXdgConfigDirs();
|
static const auto xdgConfigDirs = getXdgConfigDirs();
|
||||||
if (xdgConfigDirs.has_value()) {
|
if (xdgConfigDirs.has_value()) {
|
||||||
for (auto dir : xdgConfigDirs.value()) {
|
for (auto& dir : xdgConfigDirs.value()) {
|
||||||
if (checkConfigExists(dir, programName))
|
if (checkConfigExists(dir, programName))
|
||||||
return std::make_pair(fullConfigPath(dir, programName), std::nullopt);
|
return std::make_pair(fullConfigPath(dir, programName), std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include <hyprutils/signal/Signal.hpp>
|
#include <hyprutils/signal/Signal.hpp>
|
||||||
#include <hyprutils/memory/WeakPtr.hpp>
|
#include <hyprutils/memory/WeakPtr.hpp>
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
using namespace Hyprutils::Signal;
|
using namespace Hyprutils::Signal;
|
||||||
using namespace Hyprutils::Memory;
|
using namespace Hyprutils::Memory;
|
||||||
|
@ -18,6 +17,7 @@ void Hyprutils::Signal::CSignal::emit(std::any data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CStaticSignalListener*> statics;
|
std::vector<CStaticSignalListener*> statics;
|
||||||
|
statics.reserve(m_vStaticListeners.size());
|
||||||
for (auto& l : m_vStaticListeners) {
|
for (auto& l : m_vStaticListeners) {
|
||||||
statics.emplace_back(l.get());
|
statics.emplace_back(l.get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,13 @@ using namespace Hyprutils::String;
|
||||||
std::string Hyprutils::String::trim(const std::string& in) {
|
std::string Hyprutils::String::trim(const std::string& in) {
|
||||||
if (in.empty())
|
if (in.empty())
|
||||||
return in;
|
return in;
|
||||||
|
//Wsign-compare
|
||||||
int countBefore = 0;
|
size_t countBefore = 0;
|
||||||
while (countBefore < in.length() && std::isspace(in.at(countBefore))) {
|
while (countBefore < in.length() && std::isspace(in.at(countBefore))) {
|
||||||
countBefore++;
|
countBefore++;
|
||||||
}
|
}
|
||||||
|
//Wsign-compare
|
||||||
int countAfter = 0;
|
size_t countAfter = 0;
|
||||||
while (countAfter < in.length() - countBefore && std::isspace(in.at(in.length() - countAfter - 1))) {
|
while (countAfter < in.length() - countBefore && std::isspace(in.at(in.length() - countAfter - 1))) {
|
||||||
countAfter++;
|
countAfter++;
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,7 @@ bool Hyprutils::String::isNumber(const std::string& str, bool allowfloat) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isdigit(str.back()))
|
return isdigit(str.back()) != 0;
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hyprutils::String::replaceInString(std::string& string, const std::string& what, const std::string& to) {
|
void Hyprutils::String::replaceInString(std::string& string, const std::string& what, const std::string& to) {
|
||||||
|
|
|
@ -22,7 +22,8 @@ Hyprutils::String::CVarList::CVarList(const std::string& in, const size_t lastAr
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pos += s.size() + 1;
|
pos += s.size() + 1;
|
||||||
m_vArgs.emplace_back(trim(std::string_view{s}.data()));
|
// Is that correct?
|
||||||
|
m_vArgs.emplace_back(trim(s.data()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <hyprutils/memory/WeakPtr.hpp>
|
#include <hyprutils/memory/WeakPtr.hpp>
|
||||||
#include <hyprutils/memory/UniquePtr.hpp>
|
#include <hyprutils/memory/UniquePtr.hpp>
|
||||||
#include "shared.hpp"
|
#include "shared.hpp"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#define SP CSharedPointer
|
#define SP CSharedPointer
|
||||||
#define WP CWeakPointer
|
#define WP CWeakPointer
|
||||||
|
@ -24,7 +25,7 @@ using PANIMVAR = SP<CAnimatedVariable<VarType>>;
|
||||||
template <typename VarType>
|
template <typename VarType>
|
||||||
using PANIMVARREF = WP<CAnimatedVariable<VarType>>;
|
using PANIMVARREF = WP<CAnimatedVariable<VarType>>;
|
||||||
|
|
||||||
enum eAVTypes {
|
enum eAVTypes : uint8_t {
|
||||||
INT = 1,
|
INT = 1,
|
||||||
TEST,
|
TEST,
|
||||||
};
|
};
|
||||||
|
@ -34,12 +35,13 @@ struct SomeTestType {
|
||||||
bool operator==(const SomeTestType& other) const {
|
bool operator==(const SomeTestType& other) const {
|
||||||
return done == other.done;
|
return done == other.done;
|
||||||
}
|
}
|
||||||
|
// Trivial copy assignment?
|
||||||
SomeTestType& operator=(const SomeTestType& other) {
|
SomeTestType& operator=(const SomeTestType& other) {
|
||||||
done = other.done;
|
done = other.done;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// Do this static?
|
||||||
CAnimationConfigTree animationTree;
|
CAnimationConfigTree animationTree;
|
||||||
|
|
||||||
class CMyAnimationManager : public CAnimationManager {
|
class CMyAnimationManager : public CAnimationManager {
|
||||||
|
@ -106,7 +108,7 @@ class CMyAnimationManager : public CAnimationManager {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// Same
|
||||||
UP<CMyAnimationManager> pAnimationManager;
|
UP<CMyAnimationManager> pAnimationManager;
|
||||||
|
|
||||||
class Subject {
|
class Subject {
|
||||||
|
@ -120,7 +122,7 @@ class Subject {
|
||||||
PANIMVAR<int> m_iB;
|
PANIMVAR<int> m_iB;
|
||||||
PANIMVAR<SomeTestType> m_iC;
|
PANIMVAR<SomeTestType> m_iC;
|
||||||
};
|
};
|
||||||
|
// Same
|
||||||
int config() {
|
int config() {
|
||||||
pAnimationManager = makeUnique<CMyAnimationManager>();
|
pAnimationManager = makeUnique<CMyAnimationManager>();
|
||||||
|
|
||||||
|
@ -299,7 +301,7 @@ int main(int argc, char** argv, char** envp) {
|
||||||
if (v.lock() != vars.back())
|
if (v.lock() != vars.back())
|
||||||
vars.back()->warp();
|
vars.back()->warp();
|
||||||
});
|
});
|
||||||
s.m_iA->setCallbackOnEnd([&s, &vars](auto) {
|
s.m_iA->setCallbackOnEnd([&vars](auto) {
|
||||||
vars.resize(vars.size() + 1);
|
vars.resize(vars.size() + 1);
|
||||||
pAnimationManager->createAnimation(1, vars.back(), "default");
|
pAnimationManager->createAnimation(1, vars.back(), "default");
|
||||||
*vars.back() = 1337;
|
*vars.back() = 1337;
|
||||||
|
@ -313,7 +315,7 @@ int main(int argc, char** argv, char** envp) {
|
||||||
|
|
||||||
EXPECT(s.m_iA->value(), 1000000);
|
EXPECT(s.m_iA->value(), 1000000);
|
||||||
// all vars should be set to 1337
|
// all vars should be set to 1337
|
||||||
EXPECT(std::find_if(vars.begin(), vars.end(), [](const auto& v) { return v->value() != 1337; }) == vars.end(), true);
|
EXPECT(std::ranges::find_if(vars, [](const auto& v) { return v->value() != 1337; }) == vars.end(), true);
|
||||||
|
|
||||||
// test one-time callbacks
|
// test one-time callbacks
|
||||||
s.m_iA->resetAllCallbacks();
|
s.m_iA->resetAllCallbacks();
|
||||||
|
|
Loading…
Reference in a new issue