Skip to content

Commit

Permalink
core: move to hyprutils for utils (hyprwm#6385)
Browse files Browse the repository at this point in the history
* core: move to hyprutils for utils

Nix: add hyprutils dep

* Meson: add hyprutils dep

* flake.lock: update

---------

Co-authored-by: Mihai Fufezan <[email protected]>
  • Loading branch information
vaxerski and fufexan authored Jun 11, 2024
1 parent 1f46296 commit 8c64a4b
Show file tree
Hide file tree
Showing 57 changed files with 158 additions and 873 deletions.
5 changes: 5 additions & 0 deletions .github/actions/setup_base/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
45 changes: 36 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 4 additions & 0 deletions hyprctl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 2 additions & 6 deletions hyprctl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <filesystem>
#include <stdarg.h>
#include <regex>
#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;

#include "Strings.hpp"

Expand Down Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions hyprctl/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
executable('hyprctl', 'main.cpp',
dependencies: [
dependency('hyprutils', version: '>= 0.1.1'),
],
install: true
)

Expand Down
4 changes: 2 additions & 2 deletions hyprpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 4 additions & 20 deletions hyprpm/src/core/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions hyprpm/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ src = globber.stdout().strip().split('\n')

executable('hyprpm', src,
dependencies: [
dependency('hyprutils', version: '>= 0.1.1'),
dependency('threads'),
dependency('tomlplusplus')
],
Expand Down
2 changes: 2 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
git,
hyprcursor,
hyprlang,
hyprutils,
hyprwayland-scanner,
jq,
libGL,
Expand Down Expand Up @@ -110,6 +111,7 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov
git
hyprcursor.dev
hyprlang
hyprutils
libGL
libdrm
libdatrie
Expand Down
1 change: 1 addition & 0 deletions nix/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion src/config/ConfigDataValues.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "../defines.hpp"
#include "../helpers/VarList.hpp"
#include "../helpers/varlist/VarList.hpp"
#include <vector>

enum eConfigValueDataTypes {
Expand Down
22 changes: 12 additions & 10 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -13,14 +13,16 @@
#include <sys/types.h>
#include <unistd.h>
#include <glob.h>
#include <xkbcommon/xkbcommon.h>

#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
#include <ranges>
#include <unordered_set>
#include <xkbcommon/xkbcommon.h>
#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;

extern "C" char** environ;

Expand Down Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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") {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {};
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading

0 comments on commit 8c64a4b

Please sign in to comment.