mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-16 23:05:58 +01:00
core: move to hyprutils for utils (#362)
* core: move to hyprutils for utils * Nix: add hyprutils dep --------- Co-authored-by: Mihai Fufezan <mihai@fufexan.net>
This commit is contained in:
parent
e07d4110dc
commit
c5b8ad03d0
8 changed files with 52 additions and 143 deletions
|
@ -39,7 +39,7 @@ message(STATUS "Checking deps...")
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols wayland-egl hyprlang>=0.4.0 egl opengl xkbcommon libjpeg libwebp libmagic cairo pangocairo libdrm gbm)
|
pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols wayland-egl hyprlang>=0.4.0 egl opengl xkbcommon libjpeg libwebp libmagic cairo pangocairo libdrm gbm hyprutils>=0.1.1)
|
||||||
|
|
||||||
file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp")
|
file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp")
|
||||||
add_executable(hyprlock ${SRCFILES})
|
add_executable(hyprlock ${SRCFILES})
|
||||||
|
|
60
flake.lock
60
flake.lock
|
@ -2,17 +2,22 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"hyprlang": {
|
"hyprlang": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"hyprutils": [
|
||||||
|
"hyprutils"
|
||||||
|
],
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
],
|
],
|
||||||
"systems": "systems"
|
"systems": [
|
||||||
|
"systems"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1713121246,
|
"lastModified": 1717881852,
|
||||||
"narHash": "sha256-502X0Q0fhN6tJK7iEUA8CghONKSatW/Mqj4Wappd++0=",
|
"narHash": "sha256-XeeVoKHQgfKuXoP6q90sUqKyl7EYy3ol2dVZGM+Jj94=",
|
||||||
"owner": "hyprwm",
|
"owner": "hyprwm",
|
||||||
"repo": "hyprlang",
|
"repo": "hyprlang",
|
||||||
"rev": "78fcaa27ae9e1d782faa3ff06c8ea55ddce63706",
|
"rev": "ec6938c66253429192274d612912649a0cfe4d28",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -21,13 +26,36 @@
|
||||||
"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"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1712963716,
|
"lastModified": 1717602782,
|
||||||
"narHash": "sha256-WKm9CvgCldeIVvRz87iOMi8CFVB1apJlkUT4GGvA0iM=",
|
"narHash": "sha256-pL9jeus5QpX5R+9rsp3hhZ+uplVHscNJh8n8VpqscM0=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "cfd6b5fc90b15709b780a5a1619695a88505a176",
|
"rev": "e8057b67ebf307f01bdcc8fba94d94f75039d1f6",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -40,8 +68,9 @@
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"hyprlang": "hyprlang",
|
"hyprlang": "hyprlang",
|
||||||
|
"hyprutils": "hyprutils",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"systems": "systems_2"
|
"systems": "systems"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"systems": {
|
"systems": {
|
||||||
|
@ -58,21 +87,6 @@
|
||||||
"repo": "default-linux",
|
"repo": "default-linux",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"systems_2": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1689347949,
|
|
||||||
"narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=",
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default-linux",
|
|
||||||
"rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default-linux",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|
|
@ -5,9 +5,17 @@
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
systems.url = "github:nix-systems/default-linux";
|
systems.url = "github:nix-systems/default-linux";
|
||||||
|
|
||||||
|
hyprutils = {
|
||||||
|
url = "github:hyprwm/hyprutils";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
inputs.systems.follows = "systems";
|
||||||
|
};
|
||||||
|
|
||||||
hyprlang = {
|
hyprlang = {
|
||||||
url = "github:hyprwm/hyprlang";
|
url = "github:hyprwm/hyprlang";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
inputs.systems.follows = "systems";
|
||||||
|
inputs.hyprutils.follows = "hyprutils";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
libxkbcommon,
|
libxkbcommon,
|
||||||
mesa,
|
mesa,
|
||||||
hyprlang,
|
hyprlang,
|
||||||
|
hyprutils,
|
||||||
pam,
|
pam,
|
||||||
pango,
|
pango,
|
||||||
wayland,
|
wayland,
|
||||||
|
@ -39,6 +40,7 @@ stdenv.mkDerivation {
|
||||||
libxkbcommon
|
libxkbcommon
|
||||||
mesa
|
mesa
|
||||||
hyprlang
|
hyprlang
|
||||||
|
hyprutils
|
||||||
pam
|
pam
|
||||||
pango
|
pango
|
||||||
wayland
|
wayland
|
||||||
|
|
|
@ -12,6 +12,7 @@ in {
|
||||||
|
|
||||||
hyprlock = lib.composeManyExtensions [
|
hyprlock = lib.composeManyExtensions [
|
||||||
inputs.hyprlang.overlays.default
|
inputs.hyprlang.overlays.default
|
||||||
|
inputs.hyprutils.overlays.default
|
||||||
(final: prev: {
|
(final: prev: {
|
||||||
hyprlock = prev.callPackage ./default.nix {
|
hyprlock = prev.callPackage ./default.nix {
|
||||||
stdenv = prev.gcc13Stdenv;
|
stdenv = prev.gcc13Stdenv;
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
#include "VarList.hpp"
|
|
||||||
#include <ranges>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <functional>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
|
@ -1,10 +1,12 @@
|
||||||
#include "IWidget.hpp"
|
#include "IWidget.hpp"
|
||||||
#include "../../helpers/Log.hpp"
|
#include "../../helpers/Log.hpp"
|
||||||
#include "../../helpers/VarList.hpp"
|
|
||||||
#include "../../core/hyprlock.hpp"
|
#include "../../core/hyprlock.hpp"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#include <hyprutils/string/VarList.hpp>
|
||||||
|
|
||||||
|
using namespace Hyprutils::String;
|
||||||
|
|
||||||
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 190100
|
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 190100
|
||||||
#pragma comment(lib, "date-tz")
|
#pragma comment(lib, "date-tz")
|
||||||
|
|
Loading…
Reference in a new issue