Config file path is now user-specified
This commit is contained in:
@@ -7,17 +7,21 @@
|
||||
#include "WindowRule.h"
|
||||
|
||||
class HyprlandService {
|
||||
public:
|
||||
static Workspace getCurrentWorkspace();
|
||||
static std::list<Client> getClients();
|
||||
static std::list<Client> getClientsOnActiveWorkspace();
|
||||
static std::list<WindowRule> getWindowRules();
|
||||
static std::optional<WindowRule> 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<Client> getClients();
|
||||
static std::list<Client> getClientsOnActiveWorkspace();
|
||||
static std::list<WindowRule> getWindowRules();
|
||||
static std::optional<WindowRule> 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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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<Workspace>();
|
||||
@@ -34,7 +50,7 @@ std::list<Client> HyprlandService::getClientsOnActiveWorkspace() {
|
||||
std::list<WindowRule> HyprlandService::getWindowRules() {
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
10
src/main.cpp
10
src/main.cpp
@@ -1,6 +1,14 @@
|
||||
#include <iostream>
|
||||
#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()) {
|
||||
for (auto& c : HyprlandService::getClientsOnActiveWorkspace()) {
|
||||
HyprlandService::setClientTiled(c);
|
||||
|
||||
Reference in New Issue
Block a user