aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.github/actions/setup_base/action.yml5
-rw-r--r--CMakeLists.txt2
-rw-r--r--flake.lock45
-rw-r--r--flake.nix7
-rw-r--r--hyprctl/CMakeLists.txt4
-rw-r--r--hyprctl/main.cpp8
-rw-r--r--hyprctl/meson.build3
-rw-r--r--hyprpm/CMakeLists.txt4
-rw-r--r--hyprpm/src/core/PluginManager.cpp24
-rw-r--r--hyprpm/src/meson.build1
-rw-r--r--nix/default.nix2
-rw-r--r--nix/overlays.nix1
-rw-r--r--src/Compositor.cpp5
-rw-r--r--src/config/ConfigDataValues.hpp2
-rw-r--r--src/config/ConfigManager.cpp22
-rw-r--r--src/config/ConfigManager.hpp2
-rw-r--r--src/debug/HyprCtl.cpp9
-rw-r--r--src/desktop/Popup.hpp2
-rw-r--r--src/desktop/Window.cpp5
-rw-r--r--src/desktop/Workspace.cpp5
-rw-r--r--src/devices/IKeyboard.cpp2
-rw-r--r--src/events/Windows.cpp7
-rw-r--r--src/helpers/MiscFunctions.cpp61
-rw-r--r--src/helpers/MiscFunctions.hpp3
-rw-r--r--src/helpers/Monitor.cpp5
-rw-r--r--src/helpers/VarList.cpp37
-rw-r--r--src/helpers/VarList.hpp64
-rw-r--r--src/helpers/WLClasses.hpp2
-rw-r--r--src/helpers/memory/Memory.hpp9
-rw-r--r--src/helpers/memory/SharedPtr.hpp302
-rw-r--r--src/helpers/memory/WeakPtr.hpp190
-rw-r--r--src/helpers/signal/Listener.cpp21
-rw-r--r--src/helpers/signal/Listener.hpp41
-rw-r--r--src/helpers/signal/Signal.cpp51
-rw-r--r--src/helpers/signal/Signal.hpp23
-rw-r--r--src/helpers/varlist/VarList.hpp5
-rw-r--r--src/macros.hpp4
-rw-r--r--src/managers/EventManager.hpp2
-rw-r--r--src/managers/KeybindManager.cpp7
-rw-r--r--src/managers/ProtocolManager.hpp4
-rw-r--r--src/managers/SessionLockManager.hpp2
-rw-r--r--src/managers/TokenManager.hpp2
-rw-r--r--src/managers/eventLoop/EventLoopTimer.hpp2
-rw-r--r--src/managers/input/InputManager.hpp2
-rw-r--r--src/managers/input/InputMethodPopup.hpp2
-rw-r--r--src/managers/input/InputMethodRelay.hpp2
-rw-r--r--src/managers/input/TextInput.hpp2
-rw-r--r--src/meson.build1
-rw-r--r--src/plugins/HookSystem.cpp2
-rw-r--r--src/protocols/AlphaModifier.hpp2
-rw-r--r--src/protocols/FocusGrab.hpp2
-rw-r--r--src/protocols/GammaControl.hpp2
-rw-r--r--src/protocols/OutputManagement.hpp2
-rw-r--r--src/protocols/OutputPower.hpp2
-rw-r--r--src/protocols/PointerConstraints.hpp2
-rw-r--r--src/protocols/core/Output.hpp2
-rw-r--r--src/xwayland/XWM.hpp2
57 files changed, 158 insertions, 873 deletions
diff --git a/.github/actions/setup_base/action.yml b/.github/actions/setup_base/action.yml
index ea3eecd3..a7b9994c 100644
--- a/.github/actions/setup_base/action.yml
+++ b/.github/actions/setup_base/action.yml
@@ -68,6 +68,11 @@ runs:
cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
cmake --install build
+ - name: Get hyprutils-git
+ shell: bash
+ run: |
+ git clone https://github.com/hyprwm/hyprutils && cd hyprutils && cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -B build && cmake --build build --target hyprutils && cmake --install build
+
- name: Get Xorg pacman pkgs
shell: bash
if: inputs.INSTALL_XORG_PKGS == 'true'
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 43cbb50c..7aa2bf5c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -113,7 +113,7 @@ pkg_check_modules(deps REQUIRED IMPORTED_TARGET
wayland-server wayland-client wayland-cursor wayland-protocols
cairo pango pangocairo pixman-1
libdrm libinput hwdata libseat libdisplay-info libliftoff libudev gbm
- hyprlang>=0.3.2 hyprcursor>=0.1.7
+ hyprlang>=0.3.2 hyprcursor>=0.1.7 hyprutils>=0.1.1
)
find_package(hyprwayland-scanner 0.3.10 REQUIRED)
diff --git a/flake.lock b/flake.lock
index ab886a15..477db69b 100644
--- a/flake.lock
+++ b/flake.lock
@@ -53,6 +53,9 @@
},
"hyprlang": {
"inputs": {
+ "hyprutils": [
+ "hyprutils"
+ ],
"nixpkgs": [
"nixpkgs"
],
@@ -61,11 +64,11 @@
]
},
"locked": {
- "lastModified": 1716473782,
- "narHash": "sha256-+qLn4lsHU6iL3+HTo1gTQ1tWzet8K9h+IfVemzEQZj8=",
+ "lastModified": 1717881852,
+ "narHash": "sha256-XeeVoKHQgfKuXoP6q90sUqKyl7EYy3ol2dVZGM+Jj94=",
"owner": "hyprwm",
"repo": "hyprlang",
- "rev": "87d5d984109c839482b88b4795db073eb9ed446f",
+ "rev": "ec6938c66253429192274d612912649a0cfe4d28",
"type": "github"
},
"original": {
@@ -74,6 +77,29 @@
"type": "github"
}
},
+ "hyprutils": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ],
+ "systems": [
+ "systems"
+ ]
+ },
+ "locked": {
+ "lastModified": 1717881334,
+ "narHash": "sha256-a0inRgJhPL6v9v7RPM/rx1kbXdfe3xJA1c9z0ZkYnh4=",
+ "owner": "hyprwm",
+ "repo": "hyprutils",
+ "rev": "0693f9398ab693d89c9a0aa3b3d062dd61b7a60e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "hyprwm",
+ "repo": "hyprutils",
+ "type": "github"
+ }
+ },
"hyprwayland-scanner": {
"inputs": {
"nixpkgs": [
@@ -99,11 +125,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1717602782,
- "narHash": "sha256-pL9jeus5QpX5R+9rsp3hhZ+uplVHscNJh8n8VpqscM0=",
+ "lastModified": 1717974879,
+ "narHash": "sha256-GTO3C88+5DX171F/gVS3Qga/hOs/eRMxPFpiHq2t+D8=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "e8057b67ebf307f01bdcc8fba94d94f75039d1f6",
+ "rev": "c7b821ba2e1e635ba5a76d299af62821cbcb09f3",
"type": "github"
},
"original": {
@@ -117,6 +143,7 @@
"inputs": {
"hyprcursor": "hyprcursor",
"hyprlang": "hyprlang",
+ "hyprutils": "hyprutils",
"hyprwayland-scanner": "hyprwayland-scanner",
"nixpkgs": "nixpkgs",
"systems": "systems",
@@ -152,11 +179,11 @@
]
},
"locked": {
- "lastModified": 1716290197,
- "narHash": "sha256-1u9Exrc7yx9qtES2brDh7/DDZ8w8ap1nboIOAtCgeuM=",
+ "lastModified": 1717918856,
+ "narHash": "sha256-I38bmPLqamvOfVSArd1hhZtkVRAYBK38fOHZCU1P9Qg=",
"owner": "hyprwm",
"repo": "xdg-desktop-portal-hyprland",
- "rev": "91e48d6acd8a5a611d26f925e51559ab743bc438",
+ "rev": "72907822c19afc0983c69d59d299204381623725",
"type": "github"
},
"original": {
diff --git a/flake.nix b/flake.nix
index 82e3e4bb..c1be8720 100644
--- a/flake.nix
+++ b/flake.nix
@@ -18,6 +18,13 @@
url = "github:hyprwm/hyprlang";
inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems";
+ inputs.hyprutils.follows = "hyprutils";
+ };
+
+ hyprutils = {
+ url = "github:hyprwm/hyprutils";
+ inputs.nixpkgs.follows = "nixpkgs";
+ inputs.systems.follows = "systems";
};
hyprwayland-scanner = {
diff --git a/hyprctl/CMakeLists.txt b/hyprctl/CMakeLists.txt
index 6f70ace8..64b983e6 100644
--- a/hyprctl/CMakeLists.txt
+++ b/hyprctl/CMakeLists.txt
@@ -5,8 +5,12 @@ project(
DESCRIPTION "Control utility for Hyprland"
)
+pkg_check_modules(deps REQUIRED IMPORTED_TARGET hyprutils>=0.1.1)
+
add_executable(hyprctl "main.cpp")
+target_link_libraries(hyprctl PUBLIC PkgConfig::deps)
+
# binary
install(TARGETS hyprctl)
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp
index 34abe46f..8fb9194c 100644
--- a/hyprctl/main.cpp
+++ b/hyprctl/main.cpp
@@ -24,6 +24,8 @@
#include <filesystem>
#include <stdarg.h>
#include <regex>
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
#include "Strings.hpp"
@@ -270,12 +272,6 @@ std::deque<std::string> splitArgs(int argc, char** argv) {
return result;
}
-bool isNumber(const std::string& str, bool allowfloat) {
- if (str.empty())
- return false;
- return std::ranges::all_of(str.begin(), str.end(), [&](char c) { return isdigit(c) != 0 || c == '-' || (allowfloat && c == '.'); });
-}
-
int main(int argc, char** argv) {
bool parseArgs = true;
diff --git a/hyprctl/meson.build b/hyprctl/meson.build
index 94e98b4b..5488845f 100644
--- a/hyprctl/meson.build
+++ b/hyprctl/meson.build
@@ -1,4 +1,7 @@
executable('hyprctl', 'main.cpp',
+ dependencies: [
+ dependency('hyprutils', version: '>= 0.1.1'),
+ ],
install: true
)
diff --git a/hyprpm/CMakeLists.txt b/hyprpm/CMakeLists.txt
index 8b6a8320..692e8da1 100644
--- a/hyprpm/CMakeLists.txt
+++ b/hyprpm/CMakeLists.txt
@@ -9,11 +9,11 @@ file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp")
set(CMAKE_CXX_STANDARD 23)
-pkg_check_modules(tomlplusplus REQUIRED IMPORTED_TARGET tomlplusplus)
+pkg_check_modules(deps REQUIRED IMPORTED_TARGET tomlplusplus hyprutils>=0.1.1)
add_executable(hyprpm ${SRCFILES})
-target_link_libraries(hyprpm PUBLIC PkgConfig::tomlplusplus)
+target_link_libraries(hyprpm PUBLIC PkgConfig::deps)
# binary
install(TARGETS hyprpm)
diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp
index fb338d25..446d6af3 100644
--- a/hyprpm/src/core/PluginManager.cpp
+++ b/hyprpm/src/core/PluginManager.cpp
@@ -19,24 +19,8 @@
#include <toml++/toml.hpp>
-static std::string removeBeginEndSpacesTabs(std::string str) {
- if (str.empty())
- return str;
-
- int countBefore = 0;
- while (str[countBefore] == ' ' || str[countBefore] == '\t') {
- countBefore++;
- }
-
- int countAfter = 0;
- while ((int)str.length() - countAfter - 1 >= 0 && (str[str.length() - countAfter - 1] == ' ' || str[str.length() - 1 - countAfter] == '\t')) {
- countAfter++;
- }
-
- str = str.substr(countBefore, str.length() - countBefore - countAfter);
-
- return str;
-}
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
static std::string execAndGet(std::string cmd) {
cmd += " 2>&1";
@@ -374,7 +358,7 @@ eHeadersErrors CPluginManager::headersValid() {
if (PATH.ends_with("protocols") || PATH.ends_with("wlroots-hyprland"))
continue;
- verHeader = removeBeginEndSpacesTabs(PATH.substr(2)) + "/hyprland/src/version.h";
+ verHeader = trim(PATH.substr(2)) + "/hyprland/src/version.h";
break;
}
@@ -447,7 +431,7 @@ bool CPluginManager::updateHeaders(bool force) {
// let us give a bit of leg-room for shallowing
// due to timezones, etc.
const std::string SHALLOW_DATE =
- removeBeginEndSpacesTabs(HLVER.date).empty() ? "" : execAndGet("LC_TIME=\"en_US.UTF-8\" date --date='" + HLVER.date + " - 1 weeks' '+\%a \%b \%d \%H:\%M:\%S \%Y'");
+ trim(HLVER.date).empty() ? "" : execAndGet("LC_TIME=\"en_US.UTF-8\" date --date='" + HLVER.date + " - 1 weeks' '+\%a \%b \%d \%H:\%M:\%S \%Y'");
if (m_bVerbose && bShallow)
progress.printMessageAbove(std::string{Colors::BLUE} + "[v] " + Colors::RESET + "will shallow since: " + SHALLOW_DATE);
diff --git a/hyprpm/src/meson.build b/hyprpm/src/meson.build
index a8644169..e2c512a5 100644
--- a/hyprpm/src/meson.build
+++ b/hyprpm/src/meson.build
@@ -3,6 +3,7 @@ src = globber.stdout().strip().split('\n')
executable('hyprpm', src,
dependencies: [
+ dependency('hyprutils', version: '>= 0.1.1'),
dependency('threads'),
dependency('tomlplusplus')
],
diff --git a/nix/default.nix b/nix/default.nix
index 5da00d72..0493abc1 100644
--- a/nix/default.nix
+++ b/nix/default.nix
@@ -13,6 +13,7 @@
git,
hyprcursor,
hyprlang,
+ hyprutils,
hyprwayland-scanner,
jq,
libGL,
@@ -110,6 +111,7 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov
git
hyprcursor.dev
hyprlang
+ hyprutils
libGL
libdrm
libdatrie
diff --git a/nix/overlays.nix b/nix/overlays.nix
index fbd7e9fc..cc66e1b5 100644
--- a/nix/overlays.nix
+++ b/nix/overlays.nix
@@ -23,6 +23,7 @@ in {
# Dependencies
inputs.hyprcursor.overlays.default
inputs.hyprlang.overlays.default
+ inputs.hyprutils.overlays.default
inputs.hyprwayland-scanner.overlays.default
self.overlays.xwayland
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index 5cb7c7be..8b19f010 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -14,7 +14,7 @@
#include <helpers/SdDaemon.hpp> // for SdNotify
#endif
#include <ranges>
-#include "helpers/VarList.hpp"
+#include "helpers/varlist/VarList.hpp"
#include "protocols/FractionalScale.hpp"
#include "protocols/PointerConstraints.hpp"
#include "protocols/LayerShell.hpp"
@@ -24,6 +24,9 @@
#include "desktop/LayerSurface.hpp"
#include "xwayland/XWayland.hpp"
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
+
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/src/config/ConfigDataValues.hpp b/src/config/ConfigDataValues.hpp
index c162bb40..322bd14a 100644
--- a/src/config/ConfigDataValues.hpp
+++ b/src/config/ConfigDataValues.hpp
@@ -1,6 +1,6 @@
#pragma once
#include "../defines.hpp"
-#include "../helpers/VarList.hpp"
+#include "../helpers/varlist/VarList.hpp"
#include <vector>
enum eConfigValueDataTypes {
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp
index e10522d9..6bb24e46 100644
--- a/src/config/ConfigManager.cpp
+++ b/src/config/ConfigManager.cpp
@@ -3,7 +3,7 @@
#include "../render/decorations/CHyprGroupBarDecoration.hpp"
#include "config/ConfigDataValues.hpp"
-#include "helpers/VarList.hpp"
+#include "helpers/varlist/VarList.hpp"
#include "../protocols/LayerShell.hpp"
#include <cstdint>
@@ -13,6 +13,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <glob.h>
+#include <xkbcommon/xkbcommon.h>
#include <algorithm>
#include <fstream>
@@ -20,7 +21,8 @@
#include <sstream>
#include <ranges>
#include <unordered_set>
-#include <xkbcommon/xkbcommon.h>
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
extern "C" char** environ;
@@ -2087,8 +2089,8 @@ bool layerRuleValid(const std::string& RULE) {
}
std::optional<std::string> CConfigManager::handleWindowRule(const std::string& command, const std::string& value) {
- const auto RULE = removeBeginEndSpacesTabs(value.substr(0, value.find_first_of(',')));
- const auto VALUE = removeBeginEndSpacesTabs(value.substr(value.find_first_of(',') + 1));
+ const auto RULE = trim(value.substr(0, value.find_first_of(',')));
+ const auto VALUE = trim(value.substr(value.find_first_of(',') + 1));
// check rule and value
if (RULE.empty() || VALUE.empty())
@@ -2114,8 +2116,8 @@ std::optional<std::string> CConfigManager::handleWindowRule(const std::string& c
}
std::optional<std::string> CConfigManager::handleLayerRule(const std::string& command, const std::string& value) {
- const auto RULE = removeBeginEndSpacesTabs(value.substr(0, value.find_first_of(',')));
- const auto VALUE = removeBeginEndSpacesTabs(value.substr(value.find_first_of(',') + 1));
+ const auto RULE = trim(value.substr(0, value.find_first_of(',')));
+ const auto VALUE = trim(value.substr(value.find_first_of(',') + 1));
// check rule and value
if (RULE.empty() || VALUE.empty())
@@ -2142,7 +2144,7 @@ std::optional<std::string> CConfigManager::handleLayerRule(const std::string& co
}
std::optional<std::string> CConfigManager::handleWindowRuleV2(const std::string& command, const std::string& value) {
- const auto RULE = removeBeginEndSpacesTabs(value.substr(0, value.find_first_of(',')));
+ const auto RULE = trim(value.substr(0, value.find_first_of(',')));
const auto VALUE = value.substr(value.find_first_of(',') + 1);
if (!windowRuleValid(RULE) && RULE != "unset") {
@@ -2219,7 +2221,7 @@ std::optional<std::string> CConfigManager::handleWindowRuleV2(const std::string&
result = result.substr(0, min - pos);
- result = removeBeginEndSpacesTabs(result);
+ result = trim(result);
if (!result.empty() && result.back() == ',')
result.pop_back();
@@ -2341,7 +2343,7 @@ void CConfigManager::updateBlurredLS(const std::string& name, const bool forceBl
std::optional<std::string> CConfigManager::handleBlurLS(const std::string& command, const std::string& value) {
if (value.starts_with("remove,")) {
- const auto TOREMOVE = removeBeginEndSpacesTabs(value.substr(7));
+ const auto TOREMOVE = trim(value.substr(7));
if (std::erase_if(m_dBlurLSNamespaces, [&](const auto& other) { return other == TOREMOVE; }))
updateBlurredLS(TOREMOVE, false);
return {};
@@ -2358,7 +2360,7 @@ std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::strin
const auto FIRST_DELIM = value.find_first_of(',');
std::string name = "";
- auto first_ident = removeBeginEndSpacesTabs(value.substr(0, FIRST_DELIM));
+ auto first_ident = trim(value.substr(0, FIRST_DELIM));
int id = getWorkspaceIDFromString(first_ident, name);
auto rules = value.substr(FIRST_DELIM + 1);
diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp
index ca22904d..c43cb020 100644
--- a/src/config/ConfigManager.hpp
+++ b/src/config/ConfigManager.hpp
@@ -15,7 +15,7 @@
#include <xf86drmMode.h>
#include "../helpers/WLClasses.hpp"
#include "../helpers/Monitor.hpp"
-#include "../helpers/VarList.hpp"
+#include "../helpers/varlist/VarList.hpp"
#include "../desktop/Window.hpp"
#include "../desktop/LayerSurface.hpp"
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp
index bdb12e58..6f4d74b7 100644
--- a/src/debug/HyprCtl.cpp
+++ b/src/debug/HyprCtl.cpp
@@ -16,6 +16,9 @@
#include <typeindex>
#include <numeric>
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
+
#include "../config/ConfigDataValues.hpp"
#include "../config/ConfigValue.hpp"
#include "../managers/CursorManager.hpp"
@@ -826,7 +829,7 @@ std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) {
std::string versionRequest(eHyprCtlOutputFormat format, std::string request) {
- auto commitMsg = removeBeginEndSpacesTabs(GIT_COMMIT_MESSAGE);
+ auto commitMsg = trim(GIT_COMMIT_MESSAGE);
std::replace(commitMsg.begin(), commitMsg.end(), '#', ' ');
if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) {
@@ -1051,7 +1054,7 @@ std::string dispatchBatch(eHyprCtlOutputFormat format, std::string request) {
request = "";
}
- curitem = removeBeginEndSpacesTabs(curitem);
+ curitem = trim(curitem);
};
nextItem();
@@ -1305,7 +1308,7 @@ std::string dispatchGetOption(eHyprCtlOutputFormat format, std::string request)
request = "";
}
- curitem = removeBeginEndSpacesTabs(curitem);
+ curitem = trim(curitem);
};
nextItem();
diff --git a/src/desktop/Popup.hpp b/src/desktop/Popup.hpp
index 91e569e7..47e180a8 100644
--- a/src/desktop/Popup.hpp
+++ b/src/desktop/Popup.hpp
@@ -3,7 +3,7 @@
#include <vector>
#include <memory>
#include "Subsurface.hpp"
-#include "../helpers/signal/Listener.hpp"
+#include "../helpers/signal/Signal.hpp"
class CXDGPopupResource;
diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp
index 5d6e32e9..b02a53e0 100644
--- a/src/desktop/Window.cpp
+++ b/src/desktop/Window.cpp
@@ -12,6 +12,9 @@
#include "../protocols/core/Compositor.hpp"
#include "../xwayland/XWayland.hpp"
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
+
PHLWINDOW CWindow::create(SP<CXWaylandSurface> surface) {
PHLWINDOW pWindow = SP<CWindow>(new CWindow(surface));
@@ -687,7 +690,7 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
CGradientValueData activeBorderGradient = {};
CGradientValueData inactiveBorderGradient = {};
bool active = true;
- CVarList colorsAndAngles = CVarList(removeBeginEndSpacesTabs(r.szRule.substr(r.szRule.find_first_of(' ') + 1)), 0, 's', true);
+ CVarList colorsAndAngles = CVarList(trim(r.szRule.substr(r.szRule.find_first_of(' ') + 1)), 0, 's', true);
// Basic form has only two colors, everything else can be parsed as a gradient
if (colorsAndAngles.size() == 2 && !colorsAndAngles[1].contains("deg")) {
diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp
index 7a836b3b..ed09fbc0 100644
--- a/src/desktop/Workspace.cpp
+++ b/src/desktop/Workspace.cpp
@@ -2,6 +2,9 @@
#include "../Compositor.hpp"
#include "../config/ConfigValue.hpp"
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
+
PHLWORKSPACE CWorkspace::create(int id, int monitorID, std::string name, bool special, bool isEmtpy) {
PHLWORKSPACE workspace = makeShared<CWorkspace>(id, monitorID, name, special, isEmtpy);
workspace->init(workspace);
@@ -219,7 +222,7 @@ std::string CWorkspace::getConfigName() {
}
bool CWorkspace::matchesStaticSelector(const std::string& selector_) {
- auto selector = removeBeginEndSpacesTabs(selector_);
+ auto selector = trim(selector_);
if (selector.empty())
return true;
diff --git a/src/devices/IKeyboard.cpp b/src/devices/IKeyboard.cpp
index 7e4dd912..cb294d1a 100644
--- a/src/devices/IKeyboard.cpp
+++ b/src/devices/IKeyboard.cpp
@@ -1,6 +1,6 @@
#include "IKeyboard.hpp"
#include "../defines.hpp"
-#include "../helpers/VarList.hpp"
+#include "../helpers/varlist/VarList.hpp"
#include "../managers/input/InputManager.hpp"
uint32_t IKeyboard::getCapabilities() {
diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp
index 88b28c87..899318ce 100644
--- a/src/events/Windows.cpp
+++ b/src/events/Windows.cpp
@@ -12,6 +12,9 @@
#include "../protocols/core/Compositor.hpp"
#include "../xwayland/XSurface.hpp"
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
+
// ------------------------------------------------------------ //
// __ _______ _ _ _____ ______ _______ //
// \ \ / /_ _| \ | | __ \ / __ \ \ / / ____| //
@@ -140,7 +143,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
for (auto& r : PWINDOW->m_vMatchedRules) {
if (r.szRule.starts_with("monitor")) {
try {
- const auto MONITORSTR = removeBeginEndSpacesTabs(r.szRule.substr(r.szRule.find(' ')));
+ const auto MONITORSTR = trim(r.szRule.substr(r.szRule.find(' ')));
if (MONITORSTR == "unset") {
PWINDOW->m_iMonitorID = PMONITOR->ID;
@@ -235,7 +238,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
continue;
// `group` is a shorthand of `group set`
- if (removeBeginEndSpacesTabs(r.szRule) == "group") {
+ if (trim(r.szRule) == "group") {
PWINDOW->m_eGroupRules |= GROUP_SET;
continue;
}
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index 32cd9868..b1d734c8 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -13,6 +13,8 @@
#ifdef HAS_EXECINFO
#include <execinfo.h>
#endif
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/sysctl.h>
@@ -195,25 +197,6 @@ std::string escapeJSONStrings(const std::string& str) {
return oss.str();
}
-std::string removeBeginEndSpacesTabs(std::string str) {
- if (str.empty())
- return str;
-
- int countBefore = 0;
- while (str[countBefore] == ' ' || str[countBefore] == '\t') {
- countBefore++;
- }
-
- int countAfter = 0;
- while ((int)str.length() - countAfter - 1 >= 0 && (str[str.length() - countAfter - 1] == ' ' || str[str.length() - 1 - countAfter] == '\t')) {
- countAfter++;
- }
-
- str = str.substr(countBefore, str.length() - countBefore - countAfter);
-
- return str;
-}
-
std::optional<float> getPlusMinusKeywordResult(std::string source, float relative) {
try {
return relative + stof(source);
@@ -223,31 +206,6 @@ std::optional<float> getPlusMinusKeywordResult(std::string source, float relativ
}
}
-bool isNumber(const std::string& str, bool allowfloat) {
-
- std::string copy = str;
- if (*copy.begin() == '-')
- copy = copy.substr(1);
-
- if (copy.empty())
- return false;
-
- bool point = !allowfloat;
- for (auto& c : copy) {
- if (c == '.') {
- if (point)
- return false;
- point = true;
- continue;
- }
-
- if (!std::isdigit(c))
- return false;
- }
-
- return true;
-}
-
bool isDirection(const std::string& arg) {
return arg == "l" || arg == "r" || arg == "u" || arg == "d" || arg == "t" || arg == "b";
}
@@ -579,7 +537,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
std::optional<std::string> cleanCmdForWorkspace(const std::string& inWorkspaceName, std::string dirtyCmd) {
- std::string cmd = removeBeginEndSpacesTabs(dirtyCmd);
+ std::string cmd = trim(dirtyCmd);
if (!cmd.empty()) {
std::string rules;
@@ -748,7 +706,7 @@ int64_t configStringToInt(const std::string& VALUE) {
} else if (VALUE.starts_with("rgba(") && VALUE.ends_with(')')) {
const auto VALUEWITHOUTFUNC = VALUE.substr(5, VALUE.length() - 6);
- if (removeBeginEndSpacesTabs(VALUEWITHOUTFUNC).length() != 8) {
+ if (trim(VALUEWITHOUTFUNC).length() != 8) {
Debug::log(WARN, "invalid length {} for rgba", VALUEWITHOUTFUNC.length());
throw std::invalid_argument("rgba() expects length of 8 characters (4 bytes)");
}
@@ -760,7 +718,7 @@ int64_t configStringToInt(const std::string& VALUE) {
} else if (VALUE.starts_with("rgb(") && VALUE.ends_with(')')) {
const auto VALUEWITHOUTFUNC = VALUE.substr(4, VALUE.length() - 5);
- if (removeBeginEndSpacesTabs(VALUEWITHOUTFUNC).length() != 6) {
+ if (trim(VALUEWITHOUTFUNC).length() != 6) {
Debug::log(WARN, "invalid length {} for rgb", VALUEWITHOUTFUNC.length());
throw std::invalid_argument("rgb() expects length of 6 characters (3 bytes)");
}
@@ -822,15 +780,6 @@ double normalizeAngleRad(double ang) {
return ang;
}
-std::string replaceInString(std::string subject, const std::string& search, const std::string& replace) {
- size_t pos = 0;
- while ((pos = subject.find(search, pos)) != std::string::npos) {
- subject.replace(pos, search.length(), replace);
- pos += replace.length();
- }
- return subject;
-}
-
std::vector<SCallstackFrameInfo> getBacktrace() {
std::vector<SCallstackFrameInfo> callstack;
diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp
index 9d34174c..feb0380b 100644
--- a/src/helpers/MiscFunctions.hpp
+++ b/src/helpers/MiscFunctions.hpp
@@ -17,8 +17,6 @@ std::string absolutePath(const std::string&, const std::str
void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString);
void removeWLSignal(wl_listener*);
std::string escapeJSONStrings(const std::string& str);
-std::string removeBeginEndSpacesTabs(std::string);
-bool isNumber(const std::string&, bool allowfloat = false);
bool isDirection(const std::string&);
bool isDirection(const char&);
int getWorkspaceIDFromString(const std::string&, std::string&);
@@ -32,7 +30,6 @@ Vector2D configStringToVector2D(const std::string&);
std::optional<float> getPlusMinusKeywordResult(std::string in, float relative);
void matrixProjection(float mat[9], int w, int h, wl_output_transform tr);
double normalizeAngleRad(double ang);
-std::string replaceInString(std::string subject, const std::string& search, const std::string& replace);
std::vector<SCallstackFrameInfo> getBacktrace();
void throwError(const std::string& err);
bool envEnabled(const std::string& env);
diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp
index a30f1057..027b47bd 100644
--- a/src/helpers/Monitor.cpp
+++ b/src/helpers/Monitor.cpp
@@ -6,6 +6,8 @@
#include "../devices/ITouch.hpp"
#include "../protocols/LayerShell.hpp"
#include "../protocols/PresentationTime.hpp"
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
int ratHandler(void* data) {
g_pHyprRenderer->renderMonitor((CMonitor*)data);
@@ -71,8 +73,7 @@ void CMonitor::onConnect(bool noRule) {
std::erase(szDescription, ',');
// field is backwards-compatible with intended usage of `szDescription` but excludes the parenthesized DRM node name suffix
- szShortDescription =
- removeBeginEndSpacesTabs(std::format("{} {} {}", output->make ? output->make : "", output->model ? output->model : "", output->serial ? output->serial : ""));
+ szShortDescription = trim(std::format("{} {} {}", output->make ? output->make : "", output->model ? output->model : "", output->serial ? output->serial : ""));
std::erase(szShortDescription, ',');
if (!wlr_backend_is_drm(output->backend))
diff --git a/src/helpers/VarList.cpp b/src/helpers/VarList.cpp
deleted file mode 100644
index 780ea9a0..00000000
--- a/src/helpers/VarList.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "MiscFunctions.hpp"
-#include "VarList.hpp"
-#include <ranges>
-#include <algorithm>
-
-CVarList::CVarList(const std::string& in, const size_t lastArgNo, const char delim, const bool removeEmpty) {
- if (in.empty())
- m_vArgs.emplace_back("");
-
- std::string args{in};
- size_t idx = 0;
- size_t pos = 0;
- std::ranges::replace_if(
- args, [&](const char& c) { return delim == 's' ? std::isspace(c) : c == delim; }, 0);
-
- for (const auto& s : args | std::views::split(0)) {
- if (removeEmpty && s.empty())
- continue;
- if (++idx == lastArgNo) {
- m_vArgs.emplace_back(removeBeginEndSpacesTabs(in.substr(pos)));
- break;
- }
- pos += s.size() + 1;
- m_vArgs.emplace_back(removeBeginEndSpacesTabs(std::string_view{s}.data()));
- }
-}
-
-std::string CVarList::join(const std::string& joiner, size_t from, size_t to) const {
- size_t last = to == 0 ? size() : to;
-
- std::string rolling;
- for (size_t i = from; i < last; ++i) {
- rolling += m_vArgs[i] + (i + 1 < last ? joiner : "");
- }
-
- return rolling;
-} \ No newline at end of file
diff --git a/src/helpers/VarList.hpp b/src/helpers/VarList.hpp
deleted file mode 100644
index d70f2c3f..00000000
--- a/src/helpers/VarList.hpp
+++ /dev/null
@@ -1,64 +0,0 @@
-#pragma once
-#include <functional>
-#include <vector>
-#include <string>
-#include "../macros.hpp"
-
-class CVarList {
- public:
- /** Split string into arg list
- @param lastArgNo stop splitting after argv reaches maximum size, last arg will contain rest of unsplit args
- @param delim if delimiter is 's', use std::isspace
- @param removeEmpty remove empty args from argv
- */
- CVarList(const std::string& in, const size_t maxSize = 0, const char delim = ',', const bool removeEmpty = false);
-
- ~CVarList() = default;
-
- size_t size() const {
- return m_vArgs.size();
- }
-
- std::string join(const std::string& joiner, size_t from = 0, size_t to = 0) const;
-
- void map(std::function<void(std::string&)> func) {
- for (auto& s : m_vArgs)
- func(s);
- }
-
- void append(const std::string arg) {
- m_vArgs.emplace_back(arg);
- }
-
- std::string operator[](const size_t& idx) const {
- if (idx >= m_vArgs.size())
- return "";
- return m_vArgs[idx];
- }
-
- // for range-based loops
- std::vector<std::string>::iterator begin() {
- return m_vArgs.begin();
- }
- std::vector<std::string>::const_iterator begin() const {
- return m_vArgs.begin();
- }
- std::vector<std::string>::iterator end() {
- return m_vArgs.end();
- }
- std::vector<std::string>::const_iterator end() const {
- return m_vArgs.end();
- }
-
- bool contains(const std::string& el) {
- for (auto& a : m_vArgs) {
- if (a == el)
- return true;
- }
-
- return false;
- }
-
- private:
- std::vector<std::string> m_vArgs;
-}; \ No newline at end of file
diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp
index d5be9f40..247aa8f0 100644
--- a/src/helpers/WLClasses.hpp
+++ b/src/helpers/WLClasses.hpp
@@ -7,7 +7,7 @@
#include "../desktop/Popup.hpp"
#include "AnimatedVariable.hpp"
#include "../desktop/WLSurface.hpp"
-#include "signal/Listener.hpp"
+#include "signal/Signal.hpp"
#include "Region.hpp"
class CMonitor;
diff --git a/src/helpers/memory/Memory.hpp b/src/helpers/memory/Memory.hpp
new file mode 100644
index 00000000..135a84af
--- /dev/null
+++ b/src/helpers/memory/Memory.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+#include <hyprutils/memory/WeakPtr.hpp>
+
+using namespace Hyprutils::Memory;
+
+#define SP Hyprutils::Memory::CSharedPointer
+#define WP Hyprutils::Memory::CWeakPointer
+#define UP std::unique_ptr
diff --git a/src/helpers/memory/SharedPtr.hpp b/src/helpers/memory/SharedPtr.hpp
deleted file mode 100644
index 02900911..00000000
--- a/src/helpers/memory/SharedPtr.hpp
+++ /dev/null
@@ -1,302 +0,0 @@
-#pragma once
-
-#include <typeinfo>
-#include <typeindex>
-#include <cstddef>
-#include <cstdint>
-#include <memory>
-
-#define SP CSharedPointer
-
-/*
- This is a custom impl of std::shared_ptr.
- It is not thread-safe like the STL one,
- but Hyprland is single-threaded anyways.
-
- It differs a bit from how the STL one works,
- namely in the fact that it keeps the T* inside the
- control block, and that you can still make a CWeakPtr
- or deref an existing one inside the destructor.
-*/
-namespace CSharedPointer_ {
-
- class impl_base {
- public:
- virtual ~impl_base(){};
-
- virtual void inc() noexcept = 0;
- virtual void dec() noexcept = 0;
- virtual void incWeak() noexcept = 0;
- virtual void decWeak() noexcept = 0;
- virtual unsigned int ref() noexcept = 0;
- virtual unsigned int wref() noexcept = 0;
- virtual void destroy() noexcept = 0;
- virtual bool destroying() noexcept = 0;
- virtual bool dataNonNull() noexcept = 0;
- };
-
- template <typename T>
- class impl : public impl_base {
- public:
- impl(T* data) noexcept : _data(data) {
- ;
- }
-
- /* strong refcount */
- unsigned int _ref = 0;
- /* weak refcount */
- unsigned int _weak = 0;
-
- T* _data = nullptr;
-
- friend void swap(impl*& a, impl*& b) {
- impl* tmp = a;
- a = b;
- b = tmp;
- }
-
- /* if the destructor was called,
- creating shared_ptrs is no longer valid */
- bool _destroying = false;
-
- void _destroy() {
- if (!_data || _destroying)
- return;
-
- // first, we destroy the data, but keep the pointer.
- // this way, weak pointers will still be able to
- // reference and use, but no longer create shared ones.
- _destroying = true;
- __deleter(_data);
- // now, we can reset the data and call it a day.
- _data = nullptr;
- _destroying = false;
- }
-
- std::default_delete<T> __deleter{};
-
- //
- virtual void inc() noexcept {
- _ref++;
- }
-
- virtual void dec() noexcept {
- _ref--;
- }
-
- virtual void incWeak() noexcept {
- _weak++;
- }
-
- virtual void decWeak() noexcept {
- _weak--;
- }
-
- virtual unsigned int ref() noexcept {
- return _ref;
- }
-
- virtual unsigned int wref() noexcept {
- return _weak;
- }
-
- virtual void destroy() noexcept {
- _destroy();
- }
-
- virtual bool destroying() noexcept {
- return _destroying;
- }
-
- virtual bool dataNonNull() noexcept {
- return _data;
- }
-
- virtual ~impl() {
- destroy();
- }
- };
-};
-
-template <typename T>
-class CSharedPointer {
- public:
- template <typename X>
- using validHierarchy = typename std::enable_if<std::is_assignable<CSharedPointer<T>&, X>::value, CSharedPointer&>::type;
- template <typename X>
- using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
-
- /* creates a new shared pointer managing a resource
- avoid calling. Could duplicate ownership. Prefer makeShared */
- explicit CSharedPointer(T* object) noexcept {
- impl_ = new CSharedPointer_::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_;
- increment();
- }
-
- CSharedPointer(const CSharedPointer& ref) noexcept {
- impl_ = ref.impl_;
- increment();
- }
-
- template <typename U, typename = isConstructible<U>>
- CSharedPointer(CSharedPointer<U>&& ref) noexcept {
- std::swap(impl_, ref.impl_);
- }
-
- CSharedPointer(CSharedPointer&& ref) noexcept {
- std::swap(impl_, ref.impl_);
- }
-
- /* allows weakPointer to create from an impl */
- CSharedPointer(CSharedPointer_::impl_base* implementation) noexcept {
- impl_ = implementation;
- increment();
- }
-
- /* creates an empty shared pointer with no implementation */
- CSharedPointer() noexcept {
- ; // empty
- }
-
- /* creates an empty shared pointer with no implementation */
- CSharedPointer(std::nullptr_t) noexcept {
- ; // empty
- }
-
- ~CSharedPointer() {
- // we do not decrement here,
- // because we want to preserve the pointer
- // in case this is the last owner.
- if (impl_ && impl_->ref() == 1)
- destroyImpl();
- else
- decrement();
- }
-
- template <typename U>
- validHierarchy<const CSharedPointer<U>&> operator=(const CSharedPointer<U>& rhs) {
- if (impl_ == rhs.impl_)
- return *this;
-
- decrement();
- impl_ = rhs.impl_;
- increment();
- return *this;
- }
-
- CSharedPointer& operator=(const CSharedPointer& rhs) {
- if (impl_ == rhs.impl_)
- return *this;
-
- decrement();
- impl_ = rhs.impl_;
- increment();
- return *this;
- }
-
- template <typename U>
- validHierarchy<const CSharedPointer<U>&> operator=(CSharedPointer<U>&& rhs) {
- std::swap(impl_, rhs.impl_);
- return *this;
- }
-
- CSharedPointer& operator=(CSharedPointer&& rhs) {
- std::swap(impl_, rhs.impl_);
- return *this;
- }
-
- operator bool() const {
- return impl_ && impl_->dataNonNull();
- }
-
- bool operator==(const CSharedPointer& rhs) const {
- return impl_ == rhs.impl_;
- }
-
- bool operator()(const CSharedPointer& lhs, const CSharedPointer& rhs) const {
- return (uintptr_t)lhs.impl_ < (uintptr_t)rhs.impl_;
- }
-
- bool operator<(const CSharedPointer& rhs) const {
- return (uintptr_t)impl_ < (uintptr_t)rhs.impl_;
- }
-
- T* operator->() const {
- return get();
- }
-
- T& operator*() const {
- return *get();
- }
-
- void reset() {
- decrement();
- impl_ = nullptr;
- }
-
- T* get() const {
- return (T*)(impl_ ? static_cast<CSharedPointer_::impl<T>*>(impl_)->_data : nullptr);
- }
-
- unsigned int strongRef() const {
- return impl_ ? impl_->ref() : 0;
- }
-
- CSharedPointer_::impl_base* impl_ = nullptr;
-
- private:
- /*
- no-op if there is no impl_
- may delete the stored object if ref == 0
- may delete and reset impl_ if ref == 0 and weak == 0
- */
- void decrement() {
- if (!impl_)
- return;
-
- impl_->dec();
-
- // if ref == 0, we can destroy impl
- if (impl_->ref() == 0)
- destroyImpl();
- }
- /* no-op if there is no impl_ */
- void increment() {
- if (!impl_)
- return;
-
- impl_->inc();
- }
-
- /* destroy the pointed-to object
- if able, will also destroy impl */
- void destroyImpl() {
- // destroy the impl contents
- impl_->destroy();
-
- // check for weak refs, if zero, we can also delete impl_
- if (impl_->wref() == 0) {
- delete impl_;
- impl_ = nullptr;
- }
- }
-};
-
-template <typename U, typename... Args>
-static CSharedPointer<U> makeShared(Args&&... args) {
- return CSharedPointer<U>(new U(std::forward<Args>(args)...));
-}
-
-template <typename T>
-struct std::hash<CSharedPointer<T>> {
- std::size_t operator()(const CSharedPointer<T>& p) const noexcept {
- return std::hash<void*>{}(p.impl_);
- }
-};
diff --git a/src/helpers/memory/WeakPtr.hpp b/src/helpers/memory/WeakPtr.hpp
deleted file mode 100644
index 872f8e55..00000000
--- a/src/helpers/memory/WeakPtr.hpp
+++ /dev/null
@@ -1,190 +0,0 @@
-#pragma once
-
-#include "SharedPtr.hpp"
-
-#define WP CWeakPointer
-
-/*
- This is a Hyprland implementation of std::weak_ptr.
-
- See SharedPtr.hpp for more info on how it's different.
-*/
-
-template <typename T>
-class CWeakPointer {
- public:
- template <typename X>
- using validHierarchy = typename std::enable_if<std::is_assignable<CWeakPointer<T>&, X>::value, CWeakPointer&>::type;
- template <typename X>
- using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
-
- /* create a weak ptr from a reference */
- template <typename U, typename = isConstructible<U>>
- CWeakPointer(const CSharedPointer<U>& ref) noexcept {
- if (!ref.impl_)
- return;
-
- impl_ = ref.impl_;
- incrementWeak();
- }
-
- /* create a weak ptr from another weak ptr */
- template <typename U, typename = isConstructible<U>>
- CWeakPointer(const CWeakPointer<U>& ref) noexcept {
- if (!ref.impl_)
- return;
-
- impl_ = ref.impl_;
- incrementWeak();
- }
-
- CWeakPointer(const CWeakPointer& ref) noexcept {
- if (!ref.impl_)
- return;
-
- impl_ = ref.impl_;
- incrementWeak();
- }
-
- template <typename U, typename = isConstructible<U>>
- CWeakPointer(CWeakPointer<U>&& ref) noexcept {
- std::swap(impl_, ref.impl_);
- }
-
- CWeakPointer(CWeakPointer&& ref) noexcept {
- std::swap(impl_, ref.impl_);
- }
-
- /* create a weak ptr from another weak ptr with assignment */
- template <typename U>
- validHierarchy<const CWeakPointer<U>&> operator=(const CWeakPointer<U>& rhs) {
- if (impl_ == rhs.impl_)
- return *this;
-
- decrementWeak();
- impl_ = rhs.impl_;
- incrementWeak();
- return *this;
- }
-
- CWeakPointer<T>& operator=(const CWeakPointer& rhs) {
- if (impl_ == rhs.impl_)
- return *this;
-
- decrementWeak();
- impl_ = rhs.impl_;
- incrementWeak();
- return *this;
- }
-
- /* create a weak ptr from a shared ptr with assignment */
- template <typename U>
- validHierarchy<const CWeakPointer<U>&> operator=(const CSharedPointer<U>& rhs) {
- if ((uintptr_t)impl_ == (uintptr_t)rhs.impl_)
- return *this;
-
- decrementWeak();
- impl_ = rhs.impl_;
- incrementWeak();
- return *this;
- }
-
- /* create an empty weak ptr */
- CWeakPointer() {
- ;
- }
-
- ~CWeakPointer() {
- decrementWeak();
- }
-
- /* expired MAY return true even if the pointer is still stored.
- the situation would be e.g. self-weak pointer in a destructor.
- for pointer validity, use valid() */
- bool expired() const {
- return !impl_ || !impl_->dataNonNull() || impl_->destroying();
- }
-
- /* this means the pointed-to object is not yet deleted and can still be
- referenced, but it might be in the process of being deleted.
- check !expired() if you want to check whether it's valid and
- assignable to a SP. */
- bool valid() const {
- return impl_ && impl_->dataNonNull();
- }
-
- void reset() {
- decrementWeak();
- impl_ = nullptr;
- }
-
- CSharedPointer<T> lock() const {
- if (!impl_ || !impl_->dataNonNull() || impl_->destroying())
- return {};
-
- return CSharedPointer<T>(impl_);
- }
-
- /* this returns valid() */
- operator bool() const {
- return valid();
- }
-
- bool operator==(const CWeakPointer<T>& rhs) const {
- return impl_ == rhs.impl_;
- }
-
- bool operator==(const CSharedPointer<T>& rhs) const {
- return impl_ == rhs.impl_;
- }
-
- bool operator()(const CWeakPointer& lhs, const CWeakPointer& rhs) const {
- return (uintptr_t)lhs.impl_ < (uintptr_t)rhs.impl_;
- }
-
- bool operator<(const CWeakPointer& rhs) const {
- return (uintptr_t)impl_ < (uintptr_t)rhs.impl_;
- }
-
- T* get() const {
- return (T*)(impl_ ? static_cast<CSharedPointer_::impl<T>*>(impl_)->_data : nullptr);
- }
-
- T* operator->() const {
- return get();
- }
-
- CSharedPointer_::impl_base* impl_ = nullptr;
-
- private:
- /* no-op if there is no impl_ */
- void decrementWeak() {
- if (!impl_)
- return;
-
- impl_->decWeak();
-
- // we need to check for ->destroying,
- // because otherwise we could destroy here
- // and have a shared_ptr destroy the same thing
- // later (in situations where we have a weak_ptr to self)
- if (impl_->wref() == 0 && impl_->ref() == 0 && !impl_->destroying()) {
- delete impl_;
- impl_ = nullptr;
- }
- }
- /* no-op if there is no impl_ */
- void incrementWeak() {
- if (!impl_)
- return;
-
- impl_->incWeak();
- }
-};
-
-template <typename T>
-struct std::hash<CWeakPointer<T>> {
- std::size_t operator()(const CWeakPointer<T>& p) const noexcept {
- return std::hash<void*>{}(p.impl_);
- }
-};
diff --git a/src/helpers/signal/Listener.cpp b/src/helpers/signal/Listener.cpp
deleted file mode 100644
index 4023477f..00000000
--- a/src/helpers/signal/Listener.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "Listener.hpp"
-#include "Signal.hpp"
-
-CSignalListener::CSignalListener(std::function<void(std::any)> handler) : m_fHandler(handler) {
- ;
-}
-
-void CSignalListener::emit(std::any data) {
- if (!m_fHandler)
- return;
-
- m_fHandler(data);
-}
-
-CStaticSignalListener::CStaticSignalListener(std::function<void(void*, std::any)> handler, void* owner) : m_pOwner(owner), m_fHandler(handler) {
- ;
-}
-
-void CStaticSignalListener::emit(std::any data) {
- m_fHandler(m_pOwner, data);
-}
diff --git a/src/helpers/signal/Listener.hpp b/src/helpers/signal/Listener.hpp
deleted file mode 100644
index e6aa8d73..00000000
--- a/src/helpers/signal/Listener.hpp
+++ /dev/null
@@ -1,41 +0,0 @@
-#pragma once
-
-#include <any>
-#include <memory>
-#include <functional>
-#include "../../macros.hpp"
-
-class CSignal;
-
-class CSignalListener {
- public:
- CSignalListener(std::function<void(std::any)> handler);
-
- CSignalListener(CSignalListener&&) = delete;
- CSignalListener(CSignalListener&) = delete;
- CSignalListener(const CSignalListener&) = delete;
- CSignalListener(const CSignalListener&&) = delete;
-
- void emit(std::any data);
-
- private:
- std::function<void(std::any)> m_fHandler;
-};
-
-typedef SP<CSignalListener> CHyprSignalListener;
-
-class CStaticSignalListener {
- public:
- CStaticSignalListener(std::function<void(void*, std::any)> handler, void* owner);
-
- CStaticSignalListener(CStaticSignalListener&&) = delete;
- CStaticSignalListener(CStaticSignalListener&) = delete;
- CStaticSignalListener(const CStaticSignalListener&) = delete;
- CStaticSignalListener(const CStaticSignalListener&&) = delete;
-
- void emit(std::any data);
-
- private:
- void* m_pOwner = nullptr;
- std::function<void(void*, std::any)> m_fHandler;
-}; \ No newline at end of file
diff --git a/src/helpers/signal/Signal.cpp b/src/helpers/signal/Signal.cpp
deleted file mode 100644
index fd2d11c8..00000000
--- a/src/helpers/signal/Signal.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "Signal.hpp"
-#include <algorithm>
-
-void CSignal::emit(std::any data) {
- bool dirty = false;
-
- std::vector<SP<CSignalListener>> listeners;
- for (auto& l : m_vListeners) {
- if (l.expired()) {
- dirty = true;
- continue;
- }
-
- listeners.emplace_back(l.lock());
- }
-
- std::vector<CStaticSignalListener*> statics;
- for (auto& l : m_vStaticListeners) {
- statics.emplace_back(l.get());
- }
-
- for (auto& l : listeners) {
- // if there is only one lock, it means the event is only held by the listeners
- // vector and was removed during our iteration
- if (l.strongRef() == 1) {
- dirty = true;
- continue;
- }
- l->emit(data);
- }
-
- for (auto& l : statics) {
- l->emit(data);
- }
-
- // release SPs
- listeners.clear();
-
- if (dirty)
- std::erase_if(m_vListeners, [](const auto& other) { return other.expired(); });
-}
-
-CHyprSignalListener CSignal::registerListener(std::function<void(std::any)> handler) {
- CHyprSignalListener listener = makeShared<CSignalListener>(handler);
- m_vListeners.emplace_back(WP<CSignalListener>(listener));
- return listener;
-}
-
-void CSignal::registerStaticListener(std::function<void(void*, std::any)> handler, void* owner) {
- m_vStaticListeners.emplace_back(std::make_unique<CStaticSignalListener>(handler, owner));
-} \ No newline at end of file
diff --git a/src/helpers/signal/Signal.hpp b/src/helpers/signal/Signal.hpp
index 3d04f7de..9eea3671 100644
--- a/src/helpers/signal/Signal.hpp
+++ b/src/helpers/signal/Signal.hpp
@@ -1,24 +1,5 @@
#pragma once
-#include <functional>
-#include <any>
-#include <vector>
-#include <memory>
+#include <hyprutils/signal/Signal.hpp>
-#include "Listener.hpp"
-
-class CSignal {
- public:
- void emit(std::any data = {});
-
- //
- [[nodiscard("Listener is unregistered when the ptr is lost")]] CHyprSignalListener registerListener(std::function<void(std::any)> handler);
-
- // this is for static listeners. They die with this signal.
- // TODO: can we somehow rid of the void* data and make it a custom this?
- void registerStaticListener(std::function<void(void*, std::any)> handler, void* owner);
-
- private:
- std::vector<WP<CSignalListener>> m_vListeners;
- std::vector<std::unique_ptr<CStaticSignalListener>> m_vStaticListeners;
-};
+using namespace Hyprutils::Signal;
diff --git a/src/helpers/varlist/VarList.hpp b/src/helpers/varlist/VarList.hpp
new file mode 100644
index 00000000..34629e4c
--- /dev/null
+++ b/src/helpers/varlist/VarList.hpp
@@ -0,0 +1,5 @@
+#pragma once
+
+#include <hyprutils/string/VarList.hpp>
+
+using namespace Hyprutils::String;
diff --git a/src/macros.hpp b/src/macros.hpp
index 4c6d621c..cca088d8 100644
--- a/src/macros.hpp
+++ b/src/macros.hpp
@@ -4,9 +4,7 @@
#include <csignal>
#include <utility>
-#include "helpers/memory/WeakPtr.hpp"
-
-#define UP std::unique_ptr
+#include "helpers/memory/Memory.hpp"
#ifndef NDEBUG
#ifdef HYPRLAND_DEBUG
diff --git a/src/managers/EventManager.hpp b/src/managers/EventManager.hpp
index 94dbab59..383d3246 100644
--- a/src/managers/EventManager.hpp
+++ b/src/managers/EventManager.hpp
@@ -3,7 +3,7 @@
#include <vector>
#include "../defines.hpp"
-#include "../helpers/memory/SharedPtr.hpp"
+#include "../helpers/memory/Memory.hpp"
struct SHyprIPCEvent {
std::string event;
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index 5811f4a1..49ea39a3 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -6,13 +6,16 @@
#include "KeybindManager.hpp"
#include "TokenManager.hpp"
#include "debug/Log.hpp"
-#include "helpers/VarList.hpp"
+#include "helpers/varlist/VarList.hpp"
#include <optional>
#include <iterator>
#include <string>
#include <string_view>
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
+
#include <sys/ioctl.h>
#include <fcntl.h>
#include <vector>
@@ -836,7 +839,7 @@ bool CKeybindManager::handleInternalKeybinds(xkb_keysym_t keysym) {
void CKeybindManager::spawn(std::string args) {
- args = removeBeginEndSpacesTabs(args);
+ args = trim(args);
std::string RULES = "";
diff --git a/src/managers/ProtocolManager.hpp b/src/managers/ProtocolManager.hpp
index 52a54253..91fb82a0 100644
--- a/src/managers/ProtocolManager.hpp
+++ b/src/managers/ProtocolManager.hpp
@@ -5,8 +5,8 @@
#include "../protocols/TextInputV1.hpp"
#include "../protocols/GlobalShortcuts.hpp"
#include "../protocols/Screencopy.hpp"
-#include "../helpers/memory/WeakPtr.hpp"
-#include "../helpers/signal/Listener.hpp"
+#include "../helpers/memory/Memory.hpp"
+#include "../helpers/signal/Signal.hpp"
#include <unordered_map>
class CProtocolManager {
diff --git a/src/managers/SessionLockManager.hpp b/src/managers/SessionLockManager.hpp
index ea1b2029..fe4a4434 100644
--- a/src/managers/SessionLockManager.hpp
+++ b/src/managers/SessionLockManager.hpp
@@ -2,7 +2,7 @@
#include "../defines.hpp"
#include "../helpers/Timer.hpp"
-#include "../helpers/signal/Listener.hpp"
+#include "../helpers/signal/Signal.hpp"
#include <cstdint>
#include <unordered_map>
diff --git a/src/managers/TokenManager.hpp b/src/managers/TokenManager.hpp
index afe8c55b..4587f556 100644
--- a/src/managers/TokenManager.hpp
+++ b/src/managers/TokenManager.hpp
@@ -5,7 +5,7 @@
#include <unordered_map>
#include <string>
-#include "../helpers/memory/SharedPtr.hpp"
+#include "../helpers/memory/Memory.hpp"
class CUUIDToken {
public:
diff --git a/src/managers/eventLoop/EventLoopTimer.hpp b/src/managers/eventLoop/EventLoopTimer.hpp
index fc0b2522..73f5dc73 100644
--- a/src/managers/eventLoop/EventLoopTimer.hpp
+++ b/src/managers/eventLoop/EventLoopTimer.hpp
@@ -4,7 +4,7 @@
#include <functional>
#include <optional>
-#include "../../helpers/memory/SharedPtr.hpp"
+#include "../../helpers/memory/Memory.hpp"
class CEventLoopTimer {
public:
diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp
index 9fdf061c..930f3025 100644
--- a/src/managers/input/InputManager.hpp
+++ b/src/managers/input/InputManager.hpp
@@ -6,7 +6,7 @@
#include "../../helpers/WLClasses.hpp"
#include "../../helpers/Timer.hpp"
#include "InputMethodRelay.hpp"
-#include "../../helpers/signal/Listener.hpp"
+#include "../../helpers/signal/Signal.hpp"
#include "../../devices/IPointer.hpp"
#include "../../devices/ITouch.hpp"
#include "../../devices/Tablet.hpp"
diff --git a/src/managers/input/InputMethodPopup.hpp b/src/managers/input/InputMethodPopup.hpp
index 9c5491bf..3151aedb 100644
--- a/src/managers/input/InputMethodPopup.hpp
+++ b/src/managers/input/InputMethodPopup.hpp
@@ -4,7 +4,7 @@
#include "../../desktop/WLSurface.hpp"
#include "../../macros.hpp"
#include "../../helpers/Box.hpp"
-#include "../../helpers/signal/Listener.hpp"
+#include "../../helpers/signal/Signal.hpp"
class CInputMethodPopupV2;
diff --git a/src/managers/input/InputMethodRelay.hpp b/src/managers/input/InputMethodRelay.hpp
index e942add8..e13a1f1c 100644
--- a/src/managers/input/InputMethodRelay.hpp
+++ b/src/managers/input/InputMethodRelay.hpp
@@ -3,7 +3,7 @@
#include <list>
#include "../../defines.hpp"
#include "../../helpers/WLClasses.hpp"
-#include "../../helpers/signal/Listener.hpp"
+#include "../../helpers/signal/Signal.hpp"
#include "TextInput.hpp"
#include "InputMethodPopup.hpp"
#include <any>
diff --git a/src/managers/input/TextInput.hpp b/src/managers/input/TextInput.hpp
index 30fbb4cc..61a664b9 100644
--- a/src/managers/input/TextInput.hpp
+++ b/src/managers/input/TextInput.hpp
@@ -3,7 +3,7 @@
#include "../../helpers/WLListener.hpp"
#include "../../macros.hpp"
#include "../../helpers/Box.hpp"
-#include "../../helpers/signal/Listener.hpp"
+#include "../../helpers/signal/Signal.hpp"
#include <memory>
struct wl_client;
diff --git a/src/meson.build b/src/meson.build
index ef00d4e0..ccb1922a 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -13,6 +13,7 @@ executable('Hyprland', src,
dependency('cairo'),
dependency('hyprcursor'),
dependency('hyprlang', version: '>= 0.3.2'),
+ dependency('hyprutils', version: '>= 0.1.1'),
dependency('libdrm'),
dependency('egl'),
dependency('xkbcommon'),
diff --git a/src/plugins/HookSystem.cpp b/src/plugins/HookSystem.cpp
index 84faec4e..9118456b 100644
--- a/src/plugins/HookSystem.cpp
+++ b/src/plugins/HookSystem.cpp
@@ -1,6 +1,6 @@
#include "HookSystem.hpp"
#include "../debug/Log.hpp"
-#include "../helpers/VarList.hpp"
+#include "../helpers/varlist/VarList.hpp"
#include "../managers/TokenManager.hpp"
#include "../Compositor.hpp"
diff --git a/src/protocols/AlphaModifier.hpp b/src/protocols/AlphaModifier.hpp
index d49d1e4e..1bb9cf23 100644
--- a/src/protocols/AlphaModifier.hpp
+++ b/src/protocols/AlphaModifier.hpp
@@ -5,7 +5,7 @@
#include <unordered_map>
#include "WaylandProtocol.hpp"
#include "alpha-modifier-v1.hpp"
-#include "../helpers/signal/Listener.hpp"
+#include "../helpers/signal/Signal.hpp"
class CWLSurfaceResource;
diff --git a/src/protocols/FocusGrab.hpp b/src/protocols/FocusGrab.hpp
index 80166f9f..a2d545c5 100644
--- a/src/protocols/FocusGrab.hpp
+++ b/src/protocols/FocusGrab.hpp
@@ -6,7 +6,7 @@
#include <cstdint>
#include <unordered_map>
#include <vector>
-#include "../helpers/signal/Listener.hpp"
+#include "../helpers/signal/Signal.hpp"
class CFocusGrab;
class CSeatGrab;
diff --git a/src/protocols/GammaControl.hpp b/src/protocols/GammaControl.hpp
index 074a51f0..93465b81 100644
--- a/src/protocols/GammaControl.hpp
+++ b/src/protocols/GammaControl.hpp
@@ -5,7 +5,7 @@
#include <cstdint>
#include "WaylandProtocol.hpp"
#include "wlr-gamma-control-unstable-v1.hpp"
-#include "../helpers/signal/Listener.hpp"
+#include "../helpers/signal/Signal.hpp"
class CMonitor;
diff --git a/src/protocols/OutputManagement.hpp b/src/protocols/OutputManagement.hpp
index 12e324b7..81ae9a71 100644
--- a/src/protocols/OutputManagement.hpp
+++ b/src/protocols/OutputManagement.hpp
@@ -5,7 +5,7 @@
#include <cstdint>
#include "WaylandProtocol.hpp"
#include "wlr-output-management-unstable-v1.hpp"
-#include "../helpers/signal/Listener.hpp"
+#include "../helpers/signal/Signal.hpp"
class CMonitor;
diff --git a/src/protocols/OutputPower.hpp b/src/protocols/OutputPower.hpp
index 44788a8f..410742ca 100644
--- a/src/protocols/OutputPower.hpp
+++ b/src/protocols/OutputPower.hpp
@@ -5,7 +5,7 @@
#include <cstdint>
#include "WaylandProtocol.hpp"
#include "wlr-output-power-management-unstable-v1.hpp"
-#include "../helpers/signal/Listener.hpp"
+#include "../helpers/signal/Signal.hpp"
class CMonitor;
diff --git a/src/protocols/PointerConstraints.hpp b/src/protocols/PointerConstraints.hpp
index 06bebb02..8a78de99 100644
--- a/src/protocols/PointerConstraints.hpp
+++ b/src/protocols/PointerConstraints.hpp
@@ -9,7 +9,7 @@
#include "pointer-constraints-unstable-v1.hpp"
#include "../helpers/Vector2D.hpp"
#include "../helpers/Region.hpp"
-#include "../helpers/signal/Listener.hpp"
+#include "../helpers/signal/Signal.hpp"
class CWLSurface;
class CWLSurfaceResource;
diff --git a/src/protocols/core/Output.hpp b/src/protocols/core/Output.hpp
index b17a8272..46981635 100644
--- a/src/protocols/core/Output.hpp
+++ b/src/protocols/core/Output.hpp
@@ -5,7 +5,7 @@
#include <cstdint>
#include "../WaylandProtocol.hpp"
#include "wayland.hpp"
-#include "../../helpers/signal/Listener.hpp"
+#include "../../helpers/signal/Signal.hpp"
class CMonitor;
diff --git a/src/xwayland/XWM.hpp b/src/xwayland/XWM.hpp
index bdf4fac2..7f68454c 100644
--- a/src/xwayland/XWM.hpp
+++ b/src/xwayland/XWM.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "../helpers/signal/Listener.hpp"
+#include "../helpers/signal/Signal.hpp"
#include "../helpers/WLListener.hpp"
#include "../macros.hpp"