quick commit
This commit is contained in:
69
include/helpers/hypr.hpp
Normal file
69
include/helpers/hypr.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "helpers/command.hpp"
|
||||
|
||||
class HyprctlHelper {
|
||||
public:
|
||||
static nlohmann::json getMonitorData() {
|
||||
std::string result = CommandHelper::exec("hyprctl -j monitors");
|
||||
assert(!result.empty() && "Failed to get monitor data from hyprctl");
|
||||
|
||||
auto json = nlohmann::json::parse(result);
|
||||
|
||||
assert(json.is_array());
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
static nlohmann::json getWorkspaceData() {
|
||||
std::string result = CommandHelper::exec("hyprctl -j workspaces");
|
||||
assert(!result.empty() && "Failed to get workspace data from hyprctl");
|
||||
|
||||
auto json = nlohmann::json::parse(result);
|
||||
|
||||
assert(json.is_array());
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
static nlohmann::json getClientData() {
|
||||
std::string result = CommandHelper::exec("hyprctl -j clients");
|
||||
assert(!result.empty() && "Failed to get client data from hyprctl");
|
||||
|
||||
auto json = nlohmann::json::parse(result);
|
||||
|
||||
assert(json.is_array());
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
static void dispatchWorkspace(int workspaceNumber) {
|
||||
std::string out = "hyprctl dispatch workspace " + std::to_string(workspaceNumber);
|
||||
CommandHelper::execNoOutput(out.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class HyprSocketHelper {
|
||||
public:
|
||||
static std::string getHyprlandSocketPath() {
|
||||
const char *hyprlandInstanceSignature = std::getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
||||
const char *xdgRuntimeDir = std::getenv("XDG_RUNTIME_DIR");
|
||||
|
||||
if (!xdgRuntimeDir || !hyprlandInstanceSignature) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string basePath = std::string(xdgRuntimeDir) + "/hypr/" + std::string(hyprlandInstanceSignature) + "/";
|
||||
std::string sock1 = basePath + ".socket2.sock";
|
||||
if (access(sock1.c_str(), F_OK) == 0) {
|
||||
return sock1;
|
||||
}
|
||||
|
||||
return std::string();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user