core: move to hyprutils for utils

Nix: add hyprutils dep
This commit is contained in:
Vaxry 2024-06-09 13:16:10 +02:00
parent ea2501d455
commit 075e71b462
54 changed files with 141 additions and 864 deletions

View file

@ -68,6 +68,11 @@ runs:
cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
cmake --install build 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 - name: Get Xorg pacman pkgs
shell: bash shell: bash
if: inputs.INSTALL_XORG_PKGS == 'true' if: inputs.INSTALL_XORG_PKGS == 'true'

View file

@ -113,7 +113,7 @@ pkg_check_modules(deps REQUIRED IMPORTED_TARGET
wayland-server wayland-client wayland-cursor wayland-protocols wayland-server wayland-client wayland-cursor wayland-protocols
cairo pango pangocairo pixman-1 cairo pango pangocairo pixman-1
libdrm libinput hwdata libseat libdisplay-info libliftoff libudev gbm 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) find_package(hyprwayland-scanner 0.3.10 REQUIRED)

View file

@ -74,6 +74,29 @@
"type": "github" "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": { "hyprwayland-scanner": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -117,6 +140,7 @@
"inputs": { "inputs": {
"hyprcursor": "hyprcursor", "hyprcursor": "hyprcursor",
"hyprlang": "hyprlang", "hyprlang": "hyprlang",
"hyprutils": "hyprutils",
"hyprwayland-scanner": "hyprwayland-scanner", "hyprwayland-scanner": "hyprwayland-scanner",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"systems": "systems", "systems": "systems",

View file

@ -18,6 +18,13 @@
url = "github:hyprwm/hyprlang"; url = "github:hyprwm/hyprlang";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems"; inputs.systems.follows = "systems";
inputs.hyprutils.follows = "hyprutils";
};
hyprutils = {
url = "github:hyprwm/hyprutils";
inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems";
}; };
hyprwayland-scanner = { hyprwayland-scanner = {

View file

@ -5,8 +5,12 @@ project(
DESCRIPTION "Control utility for Hyprland" DESCRIPTION "Control utility for Hyprland"
) )
pkg_check_modules(deps REQUIRED IMPORTED_TARGET hyprutils>=0.1.1)
add_executable(hyprctl "main.cpp") add_executable(hyprctl "main.cpp")
target_link_libraries(hyprctl PUBLIC PkgConfig::deps)
# binary # binary
install(TARGETS hyprctl) install(TARGETS hyprctl)

View file

@ -24,6 +24,8 @@
#include <filesystem> #include <filesystem>
#include <stdarg.h> #include <stdarg.h>
#include <regex> #include <regex>
#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;
#include "Strings.hpp" #include "Strings.hpp"
@ -270,12 +272,6 @@ std::deque<std::string> splitArgs(int argc, char** argv) {
return result; 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) { int main(int argc, char** argv) {
bool parseArgs = true; bool parseArgs = true;

View file

@ -9,11 +9,11 @@ file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp")
set(CMAKE_CXX_STANDARD 23) 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}) add_executable(hyprpm ${SRCFILES})
target_link_libraries(hyprpm PUBLIC PkgConfig::tomlplusplus) target_link_libraries(hyprpm PUBLIC PkgConfig::deps)
# binary # binary
install(TARGETS hyprpm) install(TARGETS hyprpm)

View file

@ -19,24 +19,8 @@
#include <toml++/toml.hpp> #include <toml++/toml.hpp>
static std::string removeBeginEndSpacesTabs(std::string str) { #include <hyprutils/string/String.hpp>
if (str.empty()) using namespace Hyprutils::String;
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;
}
static std::string execAndGet(std::string cmd) { static std::string execAndGet(std::string cmd) {
cmd += " 2>&1"; cmd += " 2>&1";
@ -374,7 +358,7 @@ eHeadersErrors CPluginManager::headersValid() {
if (PATH.ends_with("protocols") || PATH.ends_with("wlroots-hyprland")) if (PATH.ends_with("protocols") || PATH.ends_with("wlroots-hyprland"))
continue; continue;
verHeader = removeBeginEndSpacesTabs(PATH.substr(2)) + "/hyprland/src/version.h"; verHeader = trim(PATH.substr(2)) + "/hyprland/src/version.h";
break; break;
} }
@ -447,7 +431,7 @@ bool CPluginManager::updateHeaders(bool force) {
// let us give a bit of leg-room for shallowing // let us give a bit of leg-room for shallowing
// due to timezones, etc. // due to timezones, etc.
const std::string SHALLOW_DATE = 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) if (m_bVerbose && bShallow)
progress.printMessageAbove(std::string{Colors::BLUE} + "[v] " + Colors::RESET + "will shallow since: " + SHALLOW_DATE); progress.printMessageAbove(std::string{Colors::BLUE} + "[v] " + Colors::RESET + "will shallow since: " + SHALLOW_DATE);

View file

@ -13,6 +13,7 @@
git, git,
hyprcursor, hyprcursor,
hyprlang, hyprlang,
hyprutils,
hyprwayland-scanner, hyprwayland-scanner,
jq, jq,
libGL, libGL,
@ -110,6 +111,7 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov
git git
hyprcursor.dev hyprcursor.dev
hyprlang hyprlang
hyprutils
libGL libGL
libdrm libdrm
libdatrie libdatrie

View file

@ -23,6 +23,7 @@ in {
# Dependencies # Dependencies
inputs.hyprcursor.overlays.default inputs.hyprcursor.overlays.default
inputs.hyprlang.overlays.default inputs.hyprlang.overlays.default
inputs.hyprutils.overlays.default
inputs.hyprwayland-scanner.overlays.default inputs.hyprwayland-scanner.overlays.default
self.overlays.xwayland self.overlays.xwayland

View file

@ -14,7 +14,7 @@
#include <helpers/SdDaemon.hpp> // for SdNotify #include <helpers/SdDaemon.hpp> // for SdNotify
#endif #endif
#include <ranges> #include <ranges>
#include "helpers/VarList.hpp" #include "helpers/varlist/VarList.hpp"
#include "protocols/FractionalScale.hpp" #include "protocols/FractionalScale.hpp"
#include "protocols/PointerConstraints.hpp" #include "protocols/PointerConstraints.hpp"
#include "protocols/LayerShell.hpp" #include "protocols/LayerShell.hpp"
@ -24,6 +24,9 @@
#include "desktop/LayerSurface.hpp" #include "desktop/LayerSurface.hpp"
#include "xwayland/XWayland.hpp" #include "xwayland/XWayland.hpp"
#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../defines.hpp" #include "../defines.hpp"
#include "../helpers/VarList.hpp" #include "../helpers/varlist/VarList.hpp"
#include <vector> #include <vector>
enum eConfigValueDataTypes { enum eConfigValueDataTypes {

View file

@ -3,7 +3,7 @@
#include "../render/decorations/CHyprGroupBarDecoration.hpp" #include "../render/decorations/CHyprGroupBarDecoration.hpp"
#include "config/ConfigDataValues.hpp" #include "config/ConfigDataValues.hpp"
#include "helpers/VarList.hpp" #include "helpers/varlist/VarList.hpp"
#include "../protocols/LayerShell.hpp" #include "../protocols/LayerShell.hpp"
#include <cstdint> #include <cstdint>
@ -13,6 +13,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <glob.h> #include <glob.h>
#include <xkbcommon/xkbcommon.h>
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
@ -20,7 +21,8 @@
#include <sstream> #include <sstream>
#include <ranges> #include <ranges>
#include <unordered_set> #include <unordered_set>
#include <xkbcommon/xkbcommon.h> #include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;
extern "C" char** environ; 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) { 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 RULE = trim(value.substr(0, value.find_first_of(',')));
const auto VALUE = removeBeginEndSpacesTabs(value.substr(value.find_first_of(',') + 1)); const auto VALUE = trim(value.substr(value.find_first_of(',') + 1));
// check rule and value // check rule and value
if (RULE.empty() || VALUE.empty()) 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) { 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 RULE = trim(value.substr(0, value.find_first_of(',')));
const auto VALUE = removeBeginEndSpacesTabs(value.substr(value.find_first_of(',') + 1)); const auto VALUE = trim(value.substr(value.find_first_of(',') + 1));
// check rule and value // check rule and value
if (RULE.empty() || VALUE.empty()) 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) { 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); const auto VALUE = value.substr(value.find_first_of(',') + 1);
if (!windowRuleValid(RULE) && RULE != "unset") { 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 = result.substr(0, min - pos);
result = removeBeginEndSpacesTabs(result); result = trim(result);
if (!result.empty() && result.back() == ',') if (!result.empty() && result.back() == ',')
result.pop_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) { std::optional<std::string> CConfigManager::handleBlurLS(const std::string& command, const std::string& value) {
if (value.starts_with("remove,")) { 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; })) if (std::erase_if(m_dBlurLSNamespaces, [&](const auto& other) { return other == TOREMOVE; }))
updateBlurredLS(TOREMOVE, false); updateBlurredLS(TOREMOVE, false);
return {}; return {};
@ -2358,7 +2360,7 @@ std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::strin
const auto FIRST_DELIM = value.find_first_of(','); const auto FIRST_DELIM = value.find_first_of(',');
std::string name = ""; 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); int id = getWorkspaceIDFromString(first_ident, name);
auto rules = value.substr(FIRST_DELIM + 1); auto rules = value.substr(FIRST_DELIM + 1);

View file

@ -15,7 +15,7 @@
#include <xf86drmMode.h> #include <xf86drmMode.h>
#include "../helpers/WLClasses.hpp" #include "../helpers/WLClasses.hpp"
#include "../helpers/Monitor.hpp" #include "../helpers/Monitor.hpp"
#include "../helpers/VarList.hpp" #include "../helpers/varlist/VarList.hpp"
#include "../desktop/Window.hpp" #include "../desktop/Window.hpp"
#include "../desktop/LayerSurface.hpp" #include "../desktop/LayerSurface.hpp"

View file

@ -16,6 +16,9 @@
#include <typeindex> #include <typeindex>
#include <numeric> #include <numeric>
#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;
#include "../config/ConfigDataValues.hpp" #include "../config/ConfigDataValues.hpp"
#include "../config/ConfigValue.hpp" #include "../config/ConfigValue.hpp"
#include "../managers/CursorManager.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) { 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(), '#', ' '); std::replace(commitMsg.begin(), commitMsg.end(), '#', ' ');
if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) { if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) {
@ -1051,7 +1054,7 @@ std::string dispatchBatch(eHyprCtlOutputFormat format, std::string request) {
request = ""; request = "";
} }
curitem = removeBeginEndSpacesTabs(curitem); curitem = trim(curitem);
}; };
nextItem(); nextItem();
@ -1305,7 +1308,7 @@ std::string dispatchGetOption(eHyprCtlOutputFormat format, std::string request)
request = ""; request = "";
} }
curitem = removeBeginEndSpacesTabs(curitem); curitem = trim(curitem);
}; };
nextItem(); nextItem();

View file

@ -3,7 +3,7 @@
#include <vector> #include <vector>
#include <memory> #include <memory>
#include "Subsurface.hpp" #include "Subsurface.hpp"
#include "../helpers/signal/Listener.hpp" #include "../helpers/signal/Signal.hpp"
class CXDGPopupResource; class CXDGPopupResource;

View file

@ -12,6 +12,9 @@
#include "../protocols/core/Compositor.hpp" #include "../protocols/core/Compositor.hpp"
#include "../xwayland/XWayland.hpp" #include "../xwayland/XWayland.hpp"
#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;
PHLWINDOW CWindow::create(SP<CXWaylandSurface> surface) { PHLWINDOW CWindow::create(SP<CXWaylandSurface> surface) {
PHLWINDOW pWindow = SP<CWindow>(new CWindow(surface)); PHLWINDOW pWindow = SP<CWindow>(new CWindow(surface));
@ -687,7 +690,7 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
CGradientValueData activeBorderGradient = {}; CGradientValueData activeBorderGradient = {};
CGradientValueData inactiveBorderGradient = {}; CGradientValueData inactiveBorderGradient = {};
bool active = true; 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 // Basic form has only two colors, everything else can be parsed as a gradient
if (colorsAndAngles.size() == 2 && !colorsAndAngles[1].contains("deg")) { if (colorsAndAngles.size() == 2 && !colorsAndAngles[1].contains("deg")) {

View file

@ -2,6 +2,9 @@
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../config/ConfigValue.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 CWorkspace::create(int id, int monitorID, std::string name, bool special, bool isEmtpy) {
PHLWORKSPACE workspace = makeShared<CWorkspace>(id, monitorID, name, special, isEmtpy); PHLWORKSPACE workspace = makeShared<CWorkspace>(id, monitorID, name, special, isEmtpy);
workspace->init(workspace); workspace->init(workspace);
@ -219,7 +222,7 @@ std::string CWorkspace::getConfigName() {
} }
bool CWorkspace::matchesStaticSelector(const std::string& selector_) { bool CWorkspace::matchesStaticSelector(const std::string& selector_) {
auto selector = removeBeginEndSpacesTabs(selector_); auto selector = trim(selector_);
if (selector.empty()) if (selector.empty())
return true; return true;

View file

@ -1,6 +1,6 @@
#include "IKeyboard.hpp" #include "IKeyboard.hpp"
#include "../defines.hpp" #include "../defines.hpp"
#include "../helpers/VarList.hpp" #include "../helpers/varlist/VarList.hpp"
#include "../managers/input/InputManager.hpp" #include "../managers/input/InputManager.hpp"
uint32_t IKeyboard::getCapabilities() { uint32_t IKeyboard::getCapabilities() {

View file

@ -12,6 +12,9 @@
#include "../protocols/core/Compositor.hpp" #include "../protocols/core/Compositor.hpp"
#include "../xwayland/XSurface.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) { for (auto& r : PWINDOW->m_vMatchedRules) {
if (r.szRule.starts_with("monitor")) { if (r.szRule.starts_with("monitor")) {
try { try {
const auto MONITORSTR = removeBeginEndSpacesTabs(r.szRule.substr(r.szRule.find(' '))); const auto MONITORSTR = trim(r.szRule.substr(r.szRule.find(' ')));
if (MONITORSTR == "unset") { if (MONITORSTR == "unset") {
PWINDOW->m_iMonitorID = PMONITOR->ID; PWINDOW->m_iMonitorID = PMONITOR->ID;
@ -235,7 +238,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
continue; continue;
// `group` is a shorthand of `group set` // `group` is a shorthand of `group set`
if (removeBeginEndSpacesTabs(r.szRule) == "group") { if (trim(r.szRule) == "group") {
PWINDOW->m_eGroupRules |= GROUP_SET; PWINDOW->m_eGroupRules |= GROUP_SET;
continue; continue;
} }

View file

@ -13,6 +13,8 @@
#ifdef HAS_EXECINFO #ifdef HAS_EXECINFO
#include <execinfo.h> #include <execinfo.h>
#endif #endif
#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/sysctl.h> #include <sys/sysctl.h>
@ -195,25 +197,6 @@ std::string escapeJSONStrings(const std::string& str) {
return oss.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) { std::optional<float> getPlusMinusKeywordResult(std::string source, float relative) {
try { try {
return relative + stof(source); 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) { bool isDirection(const std::string& arg) {
return arg == "l" || arg == "r" || arg == "u" || arg == "d" || arg == "t" || arg == "b"; 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::optional<std::string> cleanCmdForWorkspace(const std::string& inWorkspaceName, std::string dirtyCmd) {
std::string cmd = removeBeginEndSpacesTabs(dirtyCmd); std::string cmd = trim(dirtyCmd);
if (!cmd.empty()) { if (!cmd.empty()) {
std::string rules; std::string rules;
@ -748,7 +706,7 @@ int64_t configStringToInt(const std::string& VALUE) {
} else if (VALUE.starts_with("rgba(") && VALUE.ends_with(')')) { } else if (VALUE.starts_with("rgba(") && VALUE.ends_with(')')) {
const auto VALUEWITHOUTFUNC = VALUE.substr(5, VALUE.length() - 6); 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()); Debug::log(WARN, "invalid length {} for rgba", VALUEWITHOUTFUNC.length());
throw std::invalid_argument("rgba() expects length of 8 characters (4 bytes)"); 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(')')) { } else if (VALUE.starts_with("rgb(") && VALUE.ends_with(')')) {
const auto VALUEWITHOUTFUNC = VALUE.substr(4, VALUE.length() - 5); 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()); Debug::log(WARN, "invalid length {} for rgb", VALUEWITHOUTFUNC.length());
throw std::invalid_argument("rgb() expects length of 6 characters (3 bytes)"); throw std::invalid_argument("rgb() expects length of 6 characters (3 bytes)");
} }
@ -822,15 +780,6 @@ double normalizeAngleRad(double ang) {
return 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> getBacktrace() {
std::vector<SCallstackFrameInfo> callstack; std::vector<SCallstackFrameInfo> callstack;

View file

@ -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 addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString);
void removeWLSignal(wl_listener*); void removeWLSignal(wl_listener*);
std::string escapeJSONStrings(const std::string& str); 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 std::string&);
bool isDirection(const char&); bool isDirection(const char&);
int getWorkspaceIDFromString(const std::string&, std::string&); 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); std::optional<float> getPlusMinusKeywordResult(std::string in, float relative);
void matrixProjection(float mat[9], int w, int h, wl_output_transform tr); void matrixProjection(float mat[9], int w, int h, wl_output_transform tr);
double normalizeAngleRad(double ang); double normalizeAngleRad(double ang);
std::string replaceInString(std::string subject, const std::string& search, const std::string& replace);
std::vector<SCallstackFrameInfo> getBacktrace(); std::vector<SCallstackFrameInfo> getBacktrace();
void throwError(const std::string& err); void throwError(const std::string& err);
bool envEnabled(const std::string& env); bool envEnabled(const std::string& env);

View file

@ -6,6 +6,8 @@
#include "../devices/ITouch.hpp" #include "../devices/ITouch.hpp"
#include "../protocols/LayerShell.hpp" #include "../protocols/LayerShell.hpp"
#include "../protocols/PresentationTime.hpp" #include "../protocols/PresentationTime.hpp"
#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;
int ratHandler(void* data) { int ratHandler(void* data) {
g_pHyprRenderer->renderMonitor((CMonitor*)data); g_pHyprRenderer->renderMonitor((CMonitor*)data);
@ -71,8 +73,7 @@ void CMonitor::onConnect(bool noRule) {
std::erase(szDescription, ','); std::erase(szDescription, ',');
// field is backwards-compatible with intended usage of `szDescription` but excludes the parenthesized DRM node name suffix // field is backwards-compatible with intended usage of `szDescription` but excludes the parenthesized DRM node name suffix
szShortDescription = szShortDescription = trim(std::format("{} {} {}", output->make ? output->make : "", output->model ? output->model : "", output->serial ? output->serial : ""));
removeBeginEndSpacesTabs(std::format("{} {} {}", output->make ? output->make : "", output->model ? output->model : "", output->serial ? output->serial : ""));
std::erase(szShortDescription, ','); std::erase(szShortDescription, ',');
if (!wlr_backend_is_drm(output->backend)) if (!wlr_backend_is_drm(output->backend))

View file

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

View file

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

View file

@ -7,7 +7,7 @@
#include "../desktop/Popup.hpp" #include "../desktop/Popup.hpp"
#include "AnimatedVariable.hpp" #include "AnimatedVariable.hpp"
#include "../desktop/WLSurface.hpp" #include "../desktop/WLSurface.hpp"
#include "signal/Listener.hpp" #include "signal/Signal.hpp"
#include "Region.hpp" #include "Region.hpp"
class CMonitor; class CMonitor;

View file

@ -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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,24 +1,5 @@
#pragma once #pragma once
#include <functional> #include <hyprutils/signal/Signal.hpp>
#include <any>
#include <vector>
#include <memory>
#include "Listener.hpp" using namespace Hyprutils::Signal;
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;
};

View file

@ -0,0 +1,5 @@
#pragma once
#include <hyprutils/string/VarList.hpp>
using namespace Hyprutils::String;

View file

@ -4,9 +4,7 @@
#include <csignal> #include <csignal>
#include <utility> #include <utility>
#include "helpers/memory/WeakPtr.hpp" #include "helpers/memory/Memory.hpp"
#define UP std::unique_ptr
#ifndef NDEBUG #ifndef NDEBUG
#ifdef HYPRLAND_DEBUG #ifdef HYPRLAND_DEBUG

View file

@ -3,7 +3,7 @@
#include <vector> #include <vector>
#include "../defines.hpp" #include "../defines.hpp"
#include "../helpers/memory/SharedPtr.hpp" #include "../helpers/memory/Memory.hpp"
struct SHyprIPCEvent { struct SHyprIPCEvent {
std::string event; std::string event;

View file

@ -6,13 +6,16 @@
#include "KeybindManager.hpp" #include "KeybindManager.hpp"
#include "TokenManager.hpp" #include "TokenManager.hpp"
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "helpers/VarList.hpp" #include "helpers/varlist/VarList.hpp"
#include <optional> #include <optional>
#include <iterator> #include <iterator>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <fcntl.h> #include <fcntl.h>
#include <vector> #include <vector>
@ -836,7 +839,7 @@ bool CKeybindManager::handleInternalKeybinds(xkb_keysym_t keysym) {
void CKeybindManager::spawn(std::string args) { void CKeybindManager::spawn(std::string args) {
args = removeBeginEndSpacesTabs(args); args = trim(args);
std::string RULES = ""; std::string RULES = "";

View file

@ -5,8 +5,8 @@
#include "../protocols/TextInputV1.hpp" #include "../protocols/TextInputV1.hpp"
#include "../protocols/GlobalShortcuts.hpp" #include "../protocols/GlobalShortcuts.hpp"
#include "../protocols/Screencopy.hpp" #include "../protocols/Screencopy.hpp"
#include "../helpers/memory/WeakPtr.hpp" #include "../helpers/memory/Memory.hpp"
#include "../helpers/signal/Listener.hpp" #include "../helpers/signal/Signal.hpp"
#include <unordered_map> #include <unordered_map>
class CProtocolManager { class CProtocolManager {

View file

@ -2,7 +2,7 @@
#include "../defines.hpp" #include "../defines.hpp"
#include "../helpers/Timer.hpp" #include "../helpers/Timer.hpp"
#include "../helpers/signal/Listener.hpp" #include "../helpers/signal/Signal.hpp"
#include <cstdint> #include <cstdint>
#include <unordered_map> #include <unordered_map>

View file

@ -5,7 +5,7 @@
#include <unordered_map> #include <unordered_map>
#include <string> #include <string>
#include "../helpers/memory/SharedPtr.hpp" #include "../helpers/memory/Memory.hpp"
class CUUIDToken { class CUUIDToken {
public: public:

View file

@ -4,7 +4,7 @@
#include <functional> #include <functional>
#include <optional> #include <optional>
#include "../../helpers/memory/SharedPtr.hpp" #include "../../helpers/memory/Memory.hpp"
class CEventLoopTimer { class CEventLoopTimer {
public: public:

View file

@ -6,7 +6,7 @@
#include "../../helpers/WLClasses.hpp" #include "../../helpers/WLClasses.hpp"
#include "../../helpers/Timer.hpp" #include "../../helpers/Timer.hpp"
#include "InputMethodRelay.hpp" #include "InputMethodRelay.hpp"
#include "../../helpers/signal/Listener.hpp" #include "../../helpers/signal/Signal.hpp"
#include "../../devices/IPointer.hpp" #include "../../devices/IPointer.hpp"
#include "../../devices/ITouch.hpp" #include "../../devices/ITouch.hpp"
#include "../../devices/Tablet.hpp" #include "../../devices/Tablet.hpp"

View file

@ -4,7 +4,7 @@
#include "../../desktop/WLSurface.hpp" #include "../../desktop/WLSurface.hpp"
#include "../../macros.hpp" #include "../../macros.hpp"
#include "../../helpers/Box.hpp" #include "../../helpers/Box.hpp"
#include "../../helpers/signal/Listener.hpp" #include "../../helpers/signal/Signal.hpp"
class CInputMethodPopupV2; class CInputMethodPopupV2;

View file

@ -3,7 +3,7 @@
#include <list> #include <list>
#include "../../defines.hpp" #include "../../defines.hpp"
#include "../../helpers/WLClasses.hpp" #include "../../helpers/WLClasses.hpp"
#include "../../helpers/signal/Listener.hpp" #include "../../helpers/signal/Signal.hpp"
#include "TextInput.hpp" #include "TextInput.hpp"
#include "InputMethodPopup.hpp" #include "InputMethodPopup.hpp"
#include <any> #include <any>

View file

@ -3,7 +3,7 @@
#include "../../helpers/WLListener.hpp" #include "../../helpers/WLListener.hpp"
#include "../../macros.hpp" #include "../../macros.hpp"
#include "../../helpers/Box.hpp" #include "../../helpers/Box.hpp"
#include "../../helpers/signal/Listener.hpp" #include "../../helpers/signal/Signal.hpp"
#include <memory> #include <memory>
struct wl_client; struct wl_client;

View file

@ -1,6 +1,6 @@
#include "HookSystem.hpp" #include "HookSystem.hpp"
#include "../debug/Log.hpp" #include "../debug/Log.hpp"
#include "../helpers/VarList.hpp" #include "../helpers/varlist/VarList.hpp"
#include "../managers/TokenManager.hpp" #include "../managers/TokenManager.hpp"
#include "../Compositor.hpp" #include "../Compositor.hpp"

View file

@ -5,7 +5,7 @@
#include <unordered_map> #include <unordered_map>
#include "WaylandProtocol.hpp" #include "WaylandProtocol.hpp"
#include "alpha-modifier-v1.hpp" #include "alpha-modifier-v1.hpp"
#include "../helpers/signal/Listener.hpp" #include "../helpers/signal/Signal.hpp"
class CWLSurfaceResource; class CWLSurfaceResource;

View file

@ -6,7 +6,7 @@
#include <cstdint> #include <cstdint>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "../helpers/signal/Listener.hpp" #include "../helpers/signal/Signal.hpp"
class CFocusGrab; class CFocusGrab;
class CSeatGrab; class CSeatGrab;

View file

@ -5,7 +5,7 @@
#include <cstdint> #include <cstdint>
#include "WaylandProtocol.hpp" #include "WaylandProtocol.hpp"
#include "wlr-gamma-control-unstable-v1.hpp" #include "wlr-gamma-control-unstable-v1.hpp"
#include "../helpers/signal/Listener.hpp" #include "../helpers/signal/Signal.hpp"
class CMonitor; class CMonitor;

View file

@ -5,7 +5,7 @@
#include <cstdint> #include <cstdint>
#include "WaylandProtocol.hpp" #include "WaylandProtocol.hpp"
#include "wlr-output-management-unstable-v1.hpp" #include "wlr-output-management-unstable-v1.hpp"
#include "../helpers/signal/Listener.hpp" #include "../helpers/signal/Signal.hpp"
class CMonitor; class CMonitor;

View file

@ -5,7 +5,7 @@
#include <cstdint> #include <cstdint>
#include "WaylandProtocol.hpp" #include "WaylandProtocol.hpp"
#include "wlr-output-power-management-unstable-v1.hpp" #include "wlr-output-power-management-unstable-v1.hpp"
#include "../helpers/signal/Listener.hpp" #include "../helpers/signal/Signal.hpp"
class CMonitor; class CMonitor;

View file

@ -9,7 +9,7 @@
#include "pointer-constraints-unstable-v1.hpp" #include "pointer-constraints-unstable-v1.hpp"
#include "../helpers/Vector2D.hpp" #include "../helpers/Vector2D.hpp"
#include "../helpers/Region.hpp" #include "../helpers/Region.hpp"
#include "../helpers/signal/Listener.hpp" #include "../helpers/signal/Signal.hpp"
class CWLSurface; class CWLSurface;
class CWLSurfaceResource; class CWLSurfaceResource;

View file

@ -5,7 +5,7 @@
#include <cstdint> #include <cstdint>
#include "../WaylandProtocol.hpp" #include "../WaylandProtocol.hpp"
#include "wayland.hpp" #include "wayland.hpp"
#include "../../helpers/signal/Listener.hpp" #include "../../helpers/signal/Signal.hpp"
class CMonitor; class CMonitor;

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../helpers/signal/Listener.hpp" #include "../helpers/signal/Signal.hpp"
#include "../helpers/WLListener.hpp" #include "../helpers/WLListener.hpp"
#include "../macros.hpp" #include "../macros.hpp"