mirror of
https://github.com/hyprwm/hyprutils.git
synced 2025-05-14 22:20:42 +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)
|
||||
|
||||
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)
|
||||
message(STATUS "Configuring hyprutils in Debug")
|
||||
|
|
|
@ -9,9 +9,8 @@
|
|||
#include <functional>
|
||||
#include <chrono>
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Animation {
|
||||
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Animation {
|
||||
/* A base class for animated variables. */
|
||||
class CBaseAnimatedVariable {
|
||||
public:
|
||||
|
@ -222,5 +221,4 @@ namespace Hyprutils {
|
|||
VarType m_Goal{};
|
||||
VarType m_Begun{};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Animation {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Animation {
|
||||
/*
|
||||
Structure for animation properties.
|
||||
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);
|
||||
std::unordered_map<std::string, Memory::CSharedPointer<SAnimationPropertyConfig>> m_mAnimationConfig;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Animation {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Animation {
|
||||
class CBaseAnimatedVariable;
|
||||
|
||||
/* 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<SAnimationManagerSignals> m_events;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
#include "../math/Vector2D.hpp"
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Animation {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Animation {
|
||||
constexpr int BAKEDPOINTS = 255;
|
||||
constexpr float INVBAKEDPOINTS = 1.f / BAKEDPOINTS;
|
||||
|
||||
|
@ -26,5 +26,4 @@ namespace Hyprutils {
|
|||
|
||||
std::array<Hyprutils::Math::Vector2D, BAKEDPOINTS> m_aPointsBaked;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@ namespace Hyprutils::Math {
|
|||
* @return Scaled SBoxExtents.
|
||||
*/
|
||||
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.
|
||||
* @return Rounded SBoxExtents.
|
||||
*/
|
||||
SBoxExtents round() {
|
||||
return {topLeft.round(), bottomRight.round()};
|
||||
return {.topLeft = topLeft.round(), .bottomRight = bottomRight.round()};
|
||||
}
|
||||
/**
|
||||
* @brief Checks equality between two SBoxExtents objects.
|
||||
|
@ -58,9 +58,7 @@ namespace Hyprutils::Math {
|
|||
* @param w_ Width of the box.
|
||||
* @param h_ Height of the box.
|
||||
*/
|
||||
CBox(double x_, double y_, double w_, double h_) {
|
||||
x = x_;
|
||||
y = y_;
|
||||
CBox(double x_, double y_, double w_, double h_) : x(x_), y(y_) {
|
||||
w = w_;
|
||||
h = h_;
|
||||
}
|
||||
|
@ -75,9 +73,8 @@ namespace Hyprutils::Math {
|
|||
* @brief Constructs a CBox with uniform dimensions.
|
||||
* @param d Dimensions to apply uniformly (x, y, width, height).
|
||||
*/
|
||||
CBox(const double d) {
|
||||
x = d;
|
||||
y = 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.
|
||||
CBox(const double d) : x(d), y(d) {
|
||||
w = d;
|
||||
h = d;
|
||||
}
|
||||
|
@ -86,9 +83,7 @@ namespace Hyprutils::Math {
|
|||
* @param pos Position vector representing the top-left corner.
|
||||
* @param size Size vector representing width and height.
|
||||
*/
|
||||
CBox(const Vector2D& pos, const Vector2D& size) {
|
||||
x = pos.x;
|
||||
y = pos.y;
|
||||
CBox(const Vector2D& pos, const Vector2D& size) : x(pos.x), y(pos.y) {
|
||||
w = size.x;
|
||||
h = size.y;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Math {
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
|
||||
#include "./Misc.hpp"
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Math {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Math {
|
||||
class CBox;
|
||||
class Vector2D;
|
||||
|
||||
//NOLINTNEXTLINE
|
||||
class Mat3x3 {
|
||||
public:
|
||||
Mat3x3();
|
||||
|
@ -55,5 +56,4 @@ namespace Hyprutils {
|
|||
private:
|
||||
std::array<float, 9> matrix;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Math {
|
||||
enum eTransform {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Math {
|
||||
// Welcome nahui
|
||||
enum eTransform : unsigned char {
|
||||
HYPRUTILS_TRANSFORM_NORMAL = 0,
|
||||
HYPRUTILS_TRANSFORM_90 = 1,
|
||||
HYPRUTILS_TRANSFORM_180 = 2,
|
||||
|
@ -12,5 +13,4 @@ namespace Hyprutils {
|
|||
HYPRUTILS_TRANSFORM_FLIPPED_180 = 6,
|
||||
HYPRUTILS_TRANSFORM_FLIPPED_270 = 7,
|
||||
};
|
||||
}
|
||||
}
|
|
@ -5,8 +5,8 @@
|
|||
#include "Vector2D.hpp"
|
||||
#include "Box.hpp"
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Math {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Math {
|
||||
class CRegion {
|
||||
public:
|
||||
/* Create an empty region */
|
||||
|
@ -21,16 +21,17 @@ namespace Hyprutils {
|
|||
CRegion(pixman_box32_t* box);
|
||||
|
||||
CRegion(const CRegion&);
|
||||
CRegion(CRegion&&);
|
||||
CRegion(CRegion&&) noexcept;
|
||||
|
||||
~CRegion();
|
||||
|
||||
CRegion& operator=(CRegion&& other) {
|
||||
CRegion& operator=(CRegion&& other) noexcept {
|
||||
pixman_region32_copy(&m_rRegion, other.pixman());
|
||||
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());
|
||||
return *this;
|
||||
}
|
||||
|
@ -67,5 +68,4 @@ namespace Hyprutils {
|
|||
private:
|
||||
pixman_region32_t m_rRegion;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
#include <format>
|
||||
#include <string>
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Math {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Math {
|
||||
//NOLINTNEXTLINE
|
||||
class Vector2D {
|
||||
public:
|
||||
Vector2D(double, double);
|
||||
|
@ -98,7 +99,6 @@ namespace Hyprutils {
|
|||
|
||||
Vector2D getComponentMax(const Vector2D& other) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// absolutely ridiculous formatter spec parsing
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Memory {
|
||||
namespace Impl_ {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Memory::Impl_ {
|
||||
//NOLINTNEXTLINE
|
||||
class impl_base {
|
||||
public:
|
||||
virtual ~impl_base() {};
|
||||
virtual ~impl_base() = default;
|
||||
|
||||
virtual void inc() noexcept = 0;
|
||||
virtual void dec() noexcept = 0;
|
||||
|
@ -23,6 +23,7 @@ namespace Hyprutils {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
//NOLINTNEXTLINE
|
||||
class impl : public impl_base {
|
||||
public:
|
||||
impl(T* data, bool lock = true) noexcept : _data(data), _lockable(lock) {
|
||||
|
@ -38,7 +39,7 @@ namespace Hyprutils {
|
|||
|
||||
T* _data = nullptr;
|
||||
|
||||
friend void swap(impl*& a, impl*& b) {
|
||||
friend void swap(impl*& a, impl*& b) noexcept {
|
||||
impl* tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
|
@ -56,13 +57,13 @@ namespace Hyprutils {
|
|||
// this way, weak pointers will still be able to
|
||||
// reference and use, but no longer create shared ones.
|
||||
_destroying = true;
|
||||
__deleter(_data);
|
||||
_deleter(_data);
|
||||
// now, we can reset the data and call it a day.
|
||||
_data = nullptr;
|
||||
_destroying = false;
|
||||
}
|
||||
|
||||
std::default_delete<T> __deleter{};
|
||||
std::default_delete<T> _deleter{};
|
||||
|
||||
//
|
||||
virtual void inc() noexcept {
|
||||
|
@ -113,7 +114,4 @@ namespace Hyprutils {
|
|||
destroy();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -13,38 +13,34 @@
|
|||
or deref an existing one inside the destructor.
|
||||
*/
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Memory {
|
||||
|
||||
namespace Hyprutils::Memory {
|
||||
template <typename T>
|
||||
class CSharedPointer {
|
||||
public:
|
||||
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>
|
||||
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
|
||||
avoid calling. Could duplicate ownership. Prefer makeShared */
|
||||
explicit CSharedPointer(T* object) noexcept {
|
||||
impl_ = new Impl_::impl<T>(object);
|
||||
explicit CSharedPointer(T* object) noexcept : impl_(new Impl_::impl<T>(object)) {
|
||||
increment();
|
||||
}
|
||||
|
||||
/* creates a shared pointer from a reference */
|
||||
template <typename U, typename = isConstructible<U>>
|
||||
CSharedPointer(const CSharedPointer<U>& ref) noexcept {
|
||||
impl_ = ref.impl_;
|
||||
CSharedPointer(const CSharedPointer<U>& ref) noexcept : impl_(ref.impl_) {
|
||||
increment();
|
||||
}
|
||||
|
||||
CSharedPointer(const CSharedPointer& ref) noexcept {
|
||||
impl_ = ref.impl_;
|
||||
CSharedPointer(const CSharedPointer& ref) noexcept : impl_(ref.impl_) {
|
||||
increment();
|
||||
}
|
||||
|
||||
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_);
|
||||
}
|
||||
|
||||
|
@ -53,8 +49,7 @@ namespace Hyprutils {
|
|||
}
|
||||
|
||||
/* allows weakPointer to create from an impl */
|
||||
CSharedPointer(Impl_::impl_base* implementation) noexcept {
|
||||
impl_ = implementation;
|
||||
CSharedPointer(Impl_::impl_base* implementation) noexcept : impl_(implementation) {
|
||||
increment();
|
||||
}
|
||||
|
||||
|
@ -73,6 +68,7 @@ namespace Hyprutils {
|
|||
}
|
||||
|
||||
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) {
|
||||
if (impl_ == rhs.impl_)
|
||||
return *this;
|
||||
|
@ -82,7 +78,7 @@ namespace Hyprutils {
|
|||
increment();
|
||||
return *this;
|
||||
}
|
||||
|
||||
//Self assignment warning. What to do?
|
||||
CSharedPointer& operator=(const CSharedPointer& rhs) {
|
||||
if (impl_ == rhs.impl_)
|
||||
return *this;
|
||||
|
@ -94,12 +90,13 @@ namespace Hyprutils {
|
|||
}
|
||||
|
||||
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_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
CSharedPointer& operator=(CSharedPointer&& rhs) {
|
||||
CSharedPointer& operator=(CSharedPointer&& rhs) noexcept {
|
||||
std::swap(impl_, rhs.impl_);
|
||||
return *this;
|
||||
}
|
||||
|
@ -185,7 +182,6 @@ namespace Hyprutils {
|
|||
static CSharedPointer<U> makeShared(Args&&... args) {
|
||||
return CSharedPointer<U>(new U(std::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -9,20 +9,18 @@
|
|||
to be locked.
|
||||
*/
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Memory {
|
||||
namespace Hyprutils::Memory {
|
||||
template <typename T>
|
||||
class CUniquePointer {
|
||||
public:
|
||||
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>
|
||||
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
|
||||
avoid calling. Could duplicate ownership. Prefer makeUnique */
|
||||
explicit CUniquePointer(T* object) noexcept {
|
||||
impl_ = new Impl_::impl<T>(object, false);
|
||||
explicit CUniquePointer(T* object) noexcept : impl_(new Impl_::impl<T>(object, false)) {
|
||||
increment();
|
||||
}
|
||||
|
||||
|
@ -32,7 +30,8 @@ namespace Hyprutils {
|
|||
CUniquePointer(const CUniquePointer& ref) = delete;
|
||||
|
||||
template <typename U, typename = isConstructible<U>>
|
||||
CUniquePointer(CUniquePointer<U>&& ref) noexcept {
|
||||
// Same
|
||||
CUniquePointer(CUniquePointer<U>& ref) noexcept {
|
||||
std::swap(impl_, ref.impl_);
|
||||
}
|
||||
|
||||
|
@ -59,12 +58,13 @@ namespace Hyprutils {
|
|||
CUniquePointer& operator=(const CUniquePointer& rhs) = delete;
|
||||
|
||||
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_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
CUniquePointer& operator=(CUniquePointer&& rhs) {
|
||||
CUniquePointer& operator=(CUniquePointer&& rhs) noexcept {
|
||||
std::swap(impl_, rhs.impl_);
|
||||
return *this;
|
||||
}
|
||||
|
@ -138,7 +138,6 @@ namespace Hyprutils {
|
|||
static CUniquePointer<U> makeUnique(Args&&... args) {
|
||||
return CUniquePointer<U>(new U(std::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -9,15 +9,15 @@
|
|||
See SharedPtr.hpp for more info on how it's different.
|
||||
*/
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Memory {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Memory {
|
||||
template <typename T>
|
||||
class CWeakPointer {
|
||||
public:
|
||||
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>
|
||||
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 */
|
||||
template <typename U, typename = isConstructible<U>>
|
||||
|
@ -58,7 +58,8 @@ namespace Hyprutils {
|
|||
}
|
||||
|
||||
template <typename U, typename = isConstructible<U>>
|
||||
CWeakPointer(CWeakPointer<U>&& ref) noexcept {
|
||||
// Same
|
||||
CWeakPointer(CWeakPointer<U>& ref) noexcept {
|
||||
std::swap(impl_, ref.impl_);
|
||||
}
|
||||
|
||||
|
@ -68,6 +69,7 @@ namespace Hyprutils {
|
|||
|
||||
/* create a weak ptr from another weak ptr with assignment */
|
||||
template <typename U>
|
||||
// Same
|
||||
validHierarchy<const CWeakPointer<U>&> operator=(const CWeakPointer<U>& rhs) {
|
||||
if (impl_ == rhs.impl_)
|
||||
return *this;
|
||||
|
@ -77,7 +79,7 @@ namespace Hyprutils {
|
|||
incrementWeak();
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Same
|
||||
CWeakPointer<T>& operator=(const CWeakPointer& rhs) {
|
||||
if (impl_ == rhs.impl_)
|
||||
return *this;
|
||||
|
@ -90,6 +92,7 @@ namespace Hyprutils {
|
|||
|
||||
/* create a weak ptr from a shared ptr with assignment */
|
||||
template <typename U>
|
||||
// Same...
|
||||
validHierarchy<const CWeakPointer<U>&> operator=(const CSharedPointer<U>& rhs) {
|
||||
if (reinterpret_cast<uintptr_t>(impl_) == reinterpret_cast<uintptr_t>(rhs.impl_))
|
||||
return *this;
|
||||
|
@ -208,7 +211,6 @@ namespace Hyprutils {
|
|||
impl_->incWeak();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <fcntl.h>
|
||||
namespace Hyprutils {
|
||||
namespace OS {
|
||||
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::OS {
|
||||
class CFileDescriptor {
|
||||
public:
|
||||
CFileDescriptor() = default;
|
||||
explicit CFileDescriptor(int const fd);
|
||||
CFileDescriptor(CFileDescriptor&&);
|
||||
CFileDescriptor& operator=(CFileDescriptor&&);
|
||||
CFileDescriptor(CFileDescriptor&&) noexcept;
|
||||
CFileDescriptor& operator=(CFileDescriptor&&) noexcept;
|
||||
~CFileDescriptor();
|
||||
|
||||
CFileDescriptor(const CFileDescriptor&) = delete;
|
||||
|
@ -35,5 +36,4 @@ namespace Hyprutils {
|
|||
private:
|
||||
int m_fd = -1;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#include <utility>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace OS {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::OS {
|
||||
class CProcess {
|
||||
public:
|
||||
/* Creates a process object, doesn't run yet */
|
||||
|
@ -25,7 +25,7 @@ namespace Hyprutils {
|
|||
const std::string& stdErr();
|
||||
|
||||
// only populated when ran async
|
||||
const pid_t pid();
|
||||
pid_t pid();
|
||||
|
||||
private:
|
||||
std::string binary, out, err;
|
||||
|
@ -33,5 +33,4 @@ namespace Hyprutils {
|
|||
std::vector<std::pair<std::string, std::string>> env;
|
||||
pid_t grandchildPid = 0;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -4,8 +4,8 @@
|
|||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Path {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Path {
|
||||
/** Check whether a config in the form basePath/hypr/programName.conf exists.
|
||||
@param basePath the path where the config will be searched
|
||||
@param programName name of the program (and config file) to search for
|
||||
|
@ -38,5 +38,4 @@ namespace Hyprutils {
|
|||
|
||||
using T = std::optional<std::string>;
|
||||
std::pair<T, T> findConfig(const std::string programName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#include <functional>
|
||||
#include <hyprutils/memory/SharedPtr.hpp>
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Signal {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Signal {
|
||||
class CSignal;
|
||||
|
||||
class CSignalListener {
|
||||
|
@ -40,5 +40,4 @@ namespace Hyprutils {
|
|||
void* m_pOwner = nullptr;
|
||||
std::function<void(void*, std::any)> m_fHandler;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#include <hyprutils/memory/WeakPtr.hpp>
|
||||
#include "./Listener.hpp"
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Signal {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Signal {
|
||||
class CSignal {
|
||||
public:
|
||||
void emit(std::any data = {});
|
||||
|
@ -24,5 +24,4 @@ namespace Hyprutils {
|
|||
std::vector<Hyprutils::Memory::CWeakPointer<CSignalListener>> m_vListeners;
|
||||
std::vector<std::unique_ptr<CStaticSignalListener>> m_vStaticListeners;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace String {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::String {
|
||||
// trims beginning and end of whitespace characters
|
||||
std::string trim(const std::string& in);
|
||||
bool isNumber(const std::string& str, bool allowfloat = false);
|
||||
void replaceInString(std::string& string, const std::string& what, const std::string& to);
|
||||
};
|
||||
};
|
|
@ -3,8 +3,8 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace String {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::String {
|
||||
class CVarList {
|
||||
public:
|
||||
/** Split string into arg list
|
||||
|
@ -63,5 +63,4 @@ namespace Hyprutils {
|
|||
private:
|
||||
std::vector<std::string> m_vArgs;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include <functional>
|
||||
|
||||
namespace Hyprutils {
|
||||
namespace Utils {
|
||||
//NOLINTNEXTLINE
|
||||
namespace Hyprutils::Utils {
|
||||
// calls a function when it goes out of scope
|
||||
class CScopeGuard {
|
||||
public:
|
||||
|
@ -13,5 +13,4 @@ namespace Hyprutils {
|
|||
private:
|
||||
std::function<void()> fn;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -99,7 +99,7 @@ bool CAnimationManager::bezierExists(const std::string& bezier) {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -35,14 +35,14 @@ float CBezierCurve::getXForT(float const& t) const {
|
|||
float t2 = t * 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 t2 = t * 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
|
||||
|
@ -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
|
||||
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 {
|
||||
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 {
|
||||
|
@ -233,5 +233,5 @@ Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const {
|
|||
}
|
||||
|
||||
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) {
|
||||
//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});
|
||||
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);
|
||||
}
|
||||
|
||||
// What to do with const_cast?
|
||||
Hyprutils::Math::CRegion::CRegion(const CRegion& other) {
|
||||
pixman_region32_init(&m_rRegion);
|
||||
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_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) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -118,7 +119,7 @@ CRegion& Hyprutils::Math::CRegion::expand(double units) {
|
|||
clear();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,23 +4,18 @@
|
|||
|
||||
using namespace Hyprutils::Math;
|
||||
|
||||
Hyprutils::Math::Vector2D::Vector2D(double xx, double yy) {
|
||||
x = xx;
|
||||
y = yy;
|
||||
Hyprutils::Math::Vector2D::Vector2D(double xx, double yy) : x(xx), y(yy) {
|
||||
;
|
||||
}
|
||||
|
||||
Hyprutils::Math::Vector2D::Vector2D(int xx, int yy) {
|
||||
x = (double)xx;
|
||||
y = (double)yy;
|
||||
Hyprutils::Math::Vector2D::Vector2D(int xx, int yy) : x((double)xx), y((double)yy) {
|
||||
;
|
||||
}
|
||||
|
||||
Hyprutils::Math::Vector2D::Vector2D() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
;
|
||||
}
|
||||
|
||||
Hyprutils::Math::Vector2D::~Vector2D() {}
|
||||
|
||||
double Hyprutils::Math::Vector2D::normalize() {
|
||||
// get max abs
|
||||
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 {
|
||||
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 {
|
||||
return std::sqrt(x * x + y * y);
|
||||
return std::sqrt((x * x) + (y * y));
|
||||
}
|
||||
|
||||
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(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
|
||||
abort();
|
||||
|
||||
|
@ -37,10 +37,7 @@ int CFileDescriptor::getFlags() const {
|
|||
}
|
||||
|
||||
bool CFileDescriptor::setFlags(int flags) {
|
||||
if (fcntl(m_fd, F_SETFD, flags) == -1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return fcntl(m_fd, F_SETFD, flags) != -1;
|
||||
}
|
||||
|
||||
int CFileDescriptor::take() {
|
||||
|
|
|
@ -6,7 +6,6 @@ using namespace Hyprutils::OS;
|
|||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <array>
|
||||
#include <thread>
|
||||
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
|
@ -89,7 +88,7 @@ bool Hyprutils::OS::CProcess::runSync() {
|
|||
{.fd = outPipe[0], .events = POLLIN, .revents = 0},
|
||||
{.fd = errPipe[0], .events = POLLIN, .revents = 0},
|
||||
};
|
||||
|
||||
// Maybe bool or just leave it as it is?
|
||||
while (1337) {
|
||||
int ret = poll(pollfds, 2, 5000);
|
||||
|
||||
|
@ -171,7 +170,7 @@ bool Hyprutils::OS::CProcess::runAsync() {
|
|||
// run in child
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
sigprocmask(SIG_SETMASK, &set, NULL);
|
||||
sigprocmask(SIG_SETMASK, &set, nullptr);
|
||||
|
||||
grandchild = fork();
|
||||
if (grandchild == 0) {
|
||||
|
@ -225,6 +224,6 @@ const std::string& Hyprutils::OS::CProcess::stdErr() {
|
|||
return err;
|
||||
}
|
||||
|
||||
const pid_t Hyprutils::OS::CProcess::pid() {
|
||||
pid_t Hyprutils::OS::CProcess::pid() {
|
||||
return grandchildPid;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using namespace Hyprutils;
|
|||
|
||||
namespace Hyprutils::Path {
|
||||
std::string fullConfigPath(std::string basePath, std::string programName) {
|
||||
//no lint or...?
|
||||
return basePath + "/hypr/" + programName + ".conf";
|
||||
}
|
||||
|
||||
|
@ -62,7 +63,7 @@ namespace Hyprutils::Path {
|
|||
|
||||
static const auto xdgConfigDirs = getXdgConfigDirs();
|
||||
if (xdgConfigDirs.has_value()) {
|
||||
for (auto dir : xdgConfigDirs.value()) {
|
||||
for (auto& dir : xdgConfigDirs.value()) {
|
||||
if (checkConfigExists(dir, programName))
|
||||
return std::make_pair(fullConfigPath(dir, programName), std::nullopt);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include <hyprutils/signal/Signal.hpp>
|
||||
#include <hyprutils/memory/WeakPtr.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace Hyprutils::Signal;
|
||||
using namespace Hyprutils::Memory;
|
||||
|
@ -18,6 +17,7 @@ void Hyprutils::Signal::CSignal::emit(std::any data) {
|
|||
}
|
||||
|
||||
std::vector<CStaticSignalListener*> statics;
|
||||
statics.reserve(m_vStaticListeners.size());
|
||||
for (auto& l : m_vStaticListeners) {
|
||||
statics.emplace_back(l.get());
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@ using namespace Hyprutils::String;
|
|||
std::string Hyprutils::String::trim(const std::string& in) {
|
||||
if (in.empty())
|
||||
return in;
|
||||
|
||||
int countBefore = 0;
|
||||
//Wsign-compare
|
||||
size_t countBefore = 0;
|
||||
while (countBefore < in.length() && std::isspace(in.at(countBefore))) {
|
||||
countBefore++;
|
||||
}
|
||||
|
||||
int countAfter = 0;
|
||||
//Wsign-compare
|
||||
size_t countAfter = 0;
|
||||
while (countAfter < in.length() - countBefore && std::isspace(in.at(in.length() - countAfter - 1))) {
|
||||
countAfter++;
|
||||
}
|
||||
|
@ -55,10 +55,7 @@ bool Hyprutils::String::isNumber(const std::string& str, bool allowfloat) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!isdigit(str.back()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return isdigit(str.back()) != 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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/UniquePtr.hpp>
|
||||
#include "shared.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
#define SP CSharedPointer
|
||||
#define WP CWeakPointer
|
||||
|
@ -24,7 +25,7 @@ using PANIMVAR = SP<CAnimatedVariable<VarType>>;
|
|||
template <typename VarType>
|
||||
using PANIMVARREF = WP<CAnimatedVariable<VarType>>;
|
||||
|
||||
enum eAVTypes {
|
||||
enum eAVTypes : uint8_t {
|
||||
INT = 1,
|
||||
TEST,
|
||||
};
|
||||
|
@ -34,12 +35,13 @@ struct SomeTestType {
|
|||
bool operator==(const SomeTestType& other) const {
|
||||
return done == other.done;
|
||||
}
|
||||
// Trivial copy assignment?
|
||||
SomeTestType& operator=(const SomeTestType& other) {
|
||||
done = other.done;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
// Do this static?
|
||||
CAnimationConfigTree animationTree;
|
||||
|
||||
class CMyAnimationManager : public CAnimationManager {
|
||||
|
@ -106,7 +108,7 @@ class CMyAnimationManager : public CAnimationManager {
|
|||
;
|
||||
}
|
||||
};
|
||||
|
||||
// Same
|
||||
UP<CMyAnimationManager> pAnimationManager;
|
||||
|
||||
class Subject {
|
||||
|
@ -120,7 +122,7 @@ class Subject {
|
|||
PANIMVAR<int> m_iB;
|
||||
PANIMVAR<SomeTestType> m_iC;
|
||||
};
|
||||
|
||||
// Same
|
||||
int config() {
|
||||
pAnimationManager = makeUnique<CMyAnimationManager>();
|
||||
|
||||
|
@ -299,7 +301,7 @@ int main(int argc, char** argv, char** envp) {
|
|||
if (v.lock() != vars.back())
|
||||
vars.back()->warp();
|
||||
});
|
||||
s.m_iA->setCallbackOnEnd([&s, &vars](auto) {
|
||||
s.m_iA->setCallbackOnEnd([&vars](auto) {
|
||||
vars.resize(vars.size() + 1);
|
||||
pAnimationManager->createAnimation(1, vars.back(), "default");
|
||||
*vars.back() = 1337;
|
||||
|
@ -313,7 +315,7 @@ int main(int argc, char** argv, char** envp) {
|
|||
|
||||
EXPECT(s.m_iA->value(), 1000000);
|
||||
// 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
|
||||
s.m_iA->resetAllCallbacks();
|
||||
|
|
Loading…
Reference in a new issue