Config file path is now user-specified

This commit is contained in:
2025-06-11 12:15:47 +02:00
parent b400cb539f
commit dc06bd2da1
4 changed files with 44 additions and 19 deletions

View File

@@ -7,17 +7,21 @@
#include "WindowRule.h" #include "WindowRule.h"
class HyprlandService { class HyprlandService {
public: private:
static Workspace getCurrentWorkspace(); static std::string configFilePath;
static std::list<Client> getClients(); public:
static std::list<Client> getClientsOnActiveWorkspace(); static void setConfigFilePath(std::string);
static std::list<WindowRule> getWindowRules(); static std::string getConfigFilePath();
static std::optional<WindowRule> findConflictingRule(WindowRule); static Workspace getCurrentWorkspace();
static void setFloatingRule(bool); static std::list<Client> getClients();
static void removeRule(WindowRule); static std::list<Client> getClientsOnActiveWorkspace();
static void setClientFloating(Client&); static std::list<WindowRule> getWindowRules();
static void setClientTiled(Client&); static std::optional<WindowRule> findConflictingRule(WindowRule);
static void toggleClientFloating(Client&); static void setFloatingRule(bool);
static bool isFloatingRulePresent(); static void removeRule(WindowRule);
static void setClientFloating(Client&);
static void setClientTiled(Client&);
static void toggleClientFloating(Client&);
static bool isFloatingRulePresent();
}; };
#endif #endif

View File

@@ -1,9 +1,6 @@
#ifndef MACROS_H #ifndef MACROS_H
#define 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 HYPRCTL_BINARY "/usr/bin/hyprctl"
#define NULL_PATH "/dev/null" #define NULL_PATH "/dev/null"
#define ECHO_PATH "/usr/bin/echo" #define ECHO_PATH "/usr/bin/echo"

View File

@@ -6,6 +6,22 @@
using json = nlohmann::json; 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() { Workspace HyprlandService::getCurrentWorkspace() {
json j = json::parse(ShellService::exec(HYPRCTL_BINARY " activeworkspace -j")); json j = json::parse(ShellService::exec(HYPRCTL_BINARY " activeworkspace -j"));
return j.get<Workspace>(); return j.get<Workspace>();
@@ -34,7 +50,7 @@ std::list<Client> HyprlandService::getClientsOnActiveWorkspace() {
std::list<WindowRule> HyprlandService::getWindowRules() { std::list<WindowRule> HyprlandService::getWindowRules() {
std::list<WindowRule> rules; std::list<WindowRule> rules;
for (auto& line : FileService::readLines(ShellService::getHomePath()+FLOATING_RULE_CONF_FILE)) { for (auto& line : FileService::readLines(getConfigFilePath())) {
rules.push_back(WindowRule::parse(line)); rules.push_back(WindowRule::parse(line));
} }
@@ -63,7 +79,7 @@ void HyprlandService::setFloatingRule(bool on) {
} }
FileService::appendToFile( FileService::appendToFile(
ShellService::getHomePath() + FLOATING_RULE_CONF_FILE, getConfigFilePath(),
rule.toString() rule.toString()
); );
}; };
@@ -98,7 +114,7 @@ void HyprlandService::removeRule(WindowRule rule) {
if (foundIndex != -1) { if (foundIndex != -1) {
FileService::deleteNthLine( FileService::deleteNthLine(
ShellService::getHomePath() + FLOATING_RULE_CONF_FILE, getConfigFilePath(),
foundIndex foundIndex
); );
} }

View File

@@ -1,6 +1,14 @@
#include <iostream>
#include "../include/HyprlandService.h" #include "../include/HyprlandService.h"
int main(int, char**){ int main(int argc, char** argv){
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <config_file_path>\n";
exit(1);
}
HyprlandService::setConfigFilePath(argv[1]);
if (HyprlandService::isFloatingRulePresent()) { if (HyprlandService::isFloatingRulePresent()) {
for (auto& c : HyprlandService::getClientsOnActiveWorkspace()) { for (auto& c : HyprlandService::getClientsOnActiveWorkspace()) {
HyprlandService::setClientTiled(c); HyprlandService::setClientTiled(c);