From dc06bd2da1bc071f6a3680bd3877a6bda393a41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Wed, 11 Jun 2025 12:15:47 +0200 Subject: [PATCH] Config file path is now user-specified --- include/HyprlandService.h | 28 ++++++++++++++++------------ include/Macros.h | 3 --- src/HyprlandService.cpp | 22 +++++++++++++++++++--- src/main.cpp | 10 +++++++++- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/include/HyprlandService.h b/include/HyprlandService.h index 6c48e4d..4c62e75 100644 --- a/include/HyprlandService.h +++ b/include/HyprlandService.h @@ -7,17 +7,21 @@ #include "WindowRule.h" class HyprlandService { - public: - static Workspace getCurrentWorkspace(); - static std::list getClients(); - static std::list getClientsOnActiveWorkspace(); - static std::list getWindowRules(); - static std::optional findConflictingRule(WindowRule); - static void setFloatingRule(bool); - static void removeRule(WindowRule); - static void setClientFloating(Client&); - static void setClientTiled(Client&); - static void toggleClientFloating(Client&); - static bool isFloatingRulePresent(); + private: + static std::string configFilePath; + public: + static void setConfigFilePath(std::string); + static std::string getConfigFilePath(); + static Workspace getCurrentWorkspace(); + static std::list getClients(); + static std::list getClientsOnActiveWorkspace(); + static std::list getWindowRules(); + static std::optional findConflictingRule(WindowRule); + static void setFloatingRule(bool); + static void removeRule(WindowRule); + static void setClientFloating(Client&); + static void setClientTiled(Client&); + static void toggleClientFloating(Client&); + static bool isFloatingRulePresent(); }; #endif diff --git a/include/Macros.h b/include/Macros.h index c53623d..c8efbc1 100644 --- a/include/Macros.h +++ b/include/Macros.h @@ -1,9 +1,6 @@ #ifndef MACROS_H #define MACROS_H -#define HYPRLAND_CONF_DIR ".config/hypr/" -#define FLOATING_RULE_CONF_FILE HYPRLAND_CONF_DIR "hyprland/floatbydefault.conf" - #define HYPRCTL_BINARY "/usr/bin/hyprctl" #define NULL_PATH "/dev/null" #define ECHO_PATH "/usr/bin/echo" diff --git a/src/HyprlandService.cpp b/src/HyprlandService.cpp index e3d62e4..91c5377 100644 --- a/src/HyprlandService.cpp +++ b/src/HyprlandService.cpp @@ -6,6 +6,22 @@ using json = nlohmann::json; +std::string HyprlandService::configFilePath; + +void HyprlandService::setConfigFilePath(std::string path) { + //Look for substring "~/". If found, expand it + const std::string tilde = "~/"; + size_t pos = path.find(tilde); + if (pos != std::string::npos) { + path.replace(pos, tilde.length(), ShellService::getHomePath()); + } + configFilePath = path; +}; + +std::string HyprlandService::getConfigFilePath() { + return configFilePath; +}; + Workspace HyprlandService::getCurrentWorkspace() { json j = json::parse(ShellService::exec(HYPRCTL_BINARY " activeworkspace -j")); return j.get(); @@ -34,7 +50,7 @@ std::list HyprlandService::getClientsOnActiveWorkspace() { std::list HyprlandService::getWindowRules() { std::list rules; - for (auto& line : FileService::readLines(ShellService::getHomePath()+FLOATING_RULE_CONF_FILE)) { + for (auto& line : FileService::readLines(getConfigFilePath())) { rules.push_back(WindowRule::parse(line)); } @@ -63,7 +79,7 @@ void HyprlandService::setFloatingRule(bool on) { } FileService::appendToFile( - ShellService::getHomePath() + FLOATING_RULE_CONF_FILE, + getConfigFilePath(), rule.toString() ); }; @@ -98,7 +114,7 @@ void HyprlandService::removeRule(WindowRule rule) { if (foundIndex != -1) { FileService::deleteNthLine( - ShellService::getHomePath() + FLOATING_RULE_CONF_FILE, + getConfigFilePath(), foundIndex ); } diff --git a/src/main.cpp b/src/main.cpp index 1c2473a..0cb0d2a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,14 @@ +#include #include "../include/HyprlandService.h" -int main(int, char**){ +int main(int argc, char** argv){ + if (argc < 2) { + std::cerr << "Usage: " << argv[0] << " \n"; + exit(1); + } + + HyprlandService::setConfigFilePath(argv[1]); + if (HyprlandService::isFloatingRulePresent()) { for (auto& c : HyprlandService::getClientsOnActiveWorkspace()) { HyprlandService::setClientTiled(c);