diff --git a/include/Macros.h b/include/Macros.h index 62a0bcd..923d71e 100644 --- a/include/Macros.h +++ b/include/Macros.h @@ -1,7 +1,7 @@ #ifndef MACROS_H #define MACROS_H -#define HYPRLAND_CONF_DIR "/home/typo/.config/hypr/" +#define HYPRLAND_CONF_DIR ".config/hypr/" #define FLOATING_RULE_CONF_FILE HYPRLAND_CONF_DIR "hyprland/floatbydefault.conf" #define HYPRCTL_BINARY "/usr/bin/hyprctl" @@ -10,7 +10,5 @@ #define CAT_PATH "/usr/bin/cat" #define FLOATING_RULE "windowrule = float,class:.*" -#define SET_FLOATING_RULE ECHO_PATH " 'windowrule = float,class:.*' > " FLOATING_RULE_CONF_FILE -#define REMOVE_FLOATING_RULE CAT_PATH " " NULL_PATH " > " FLOATING_RULE_CONF_FILE #endif \ No newline at end of file diff --git a/include/ShellService.h b/include/ShellService.h index 2ffe314..72a629c 100644 --- a/include/ShellService.h +++ b/include/ShellService.h @@ -6,6 +6,7 @@ class ShellService { public: static std::string exec(const std::string& command); + static std::string getHomePath(); }; #endif \ No newline at end of file diff --git a/src/HyprlandService.cpp b/src/HyprlandService.cpp index 54d32f5..52dd0e2 100644 --- a/src/HyprlandService.cpp +++ b/src/HyprlandService.cpp @@ -45,13 +45,13 @@ void HyprlandService::toggleClientFloating(Client& c) { void HyprlandService::setFloatingRule(bool b) { if (b) { - FileServices::createOrOverwriteFile(FLOATING_RULE_CONF_FILE, FLOATING_RULE); + FileServices::createOrOverwriteFile(ShellService::getHomePath()+FLOATING_RULE_CONF_FILE, FLOATING_RULE); } else { - FileServices::emptyFile(FLOATING_RULE_CONF_FILE); + FileServices::emptyFile(ShellService::getHomePath()+FLOATING_RULE_CONF_FILE); } }; bool HyprlandService::isFloatingRulePresent() { - return FileServices::doesNonEmptyFileExist(FLOATING_RULE_CONF_FILE); + return FileServices::doesNonEmptyFileExist(ShellService::getHomePath()+FLOATING_RULE_CONF_FILE); }; \ No newline at end of file diff --git a/src/ShellService.cpp b/src/ShellService.cpp index 4c300c0..972998c 100644 --- a/src/ShellService.cpp +++ b/src/ShellService.cpp @@ -1,4 +1,6 @@ #include "../include/ShellService.h" +#include +#include std::string ShellService::exec(const std::string& command) { char buffer[128]; @@ -19,4 +21,22 @@ std::string ShellService::exec(const std::string& command) { } return result; -}; \ No newline at end of file +}; + +std::string ShellService::getHomePath() +{ + char* home = getenv("HOME"); + if (home && *home) { + return std::string(home); + } + + // Fallback: try to get home directory from passwd if HOME is not set + // This assumes that the 'htt' process is ran with the user as the process owner. Should it be run with systemd or some other wonky method, it will behave unexpectedly + struct passwd* pw = getpwuid(getuid()); + if (pw && pw->pw_dir) { + return std::string(pw->pw_dir); + } + + // As a last resort, exit + exit(1); +} \ No newline at end of file