aboutsummaryrefslogtreecommitdiffhomepage
path: root/hyprctl
diff options
context:
space:
mode:
authorvaxerski <[email protected]>2023-01-22 16:38:17 +0100
committervaxerski <[email protected]>2023-01-22 16:38:17 +0100
commit8f57db28f7a2376a2e43bef79e94cc844931e0a6 (patch)
treeead2fe4d4d468da45e42b8099fdab554e63e411f /hyprctl
parent7d754b7c22a2e49126e4d49b6240a7ff7d38c976 (diff)
downloadHyprland-8f57db28f7a2376a2e43bef79e94cc844931e0a6.tar.gz
Hyprland-8f57db28f7a2376a2e43bef79e94cc844931e0a6.zip
added hyprctl seterror
Diffstat (limited to 'hyprctl')
-rw-r--r--hyprctl/main.cpp84
1 files changed, 43 insertions, 41 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp
index acb7b1b1..299a5007 100644
--- a/hyprctl/main.cpp
+++ b/hyprctl/main.cpp
@@ -45,74 +45,74 @@ flags:
--batch -> execute a batch of commands, separated by ';'
)#";
-void request(std::string arg, int minArgs = 0) {
- const auto SERVERSOCKET = socket(AF_UNIX, SOCK_STREAM, 0);
+void request(std::string arg, int minArgs = 0) {
+ const auto SERVERSOCKET = socket(AF_UNIX, SOCK_STREAM, 0);
- const auto ARGS = std::count(arg.begin(), arg.end(), ' ');
+ const auto ARGS = std::count(arg.begin(), arg.end(), ' ');
- if (ARGS < minArgs) {
- std::cout << "Not enough arguments, expected at least " << minArgs;
- return;
+ if (ARGS < minArgs) {
+ std::cout << "Not enough arguments, expected at least " << minArgs;
+ return;
}
- if (SERVERSOCKET < 0) {
- std::cout << "Couldn't open a socket (1)";
- return;
+ if (SERVERSOCKET < 0) {
+ std::cout << "Couldn't open a socket (1)";
+ return;
}
- // get the instance signature
- auto instanceSig = getenv("HYPRLAND_INSTANCE_SIGNATURE");
+ // get the instance signature
+ auto instanceSig = getenv("HYPRLAND_INSTANCE_SIGNATURE");
- if (!instanceSig) {
- std::cout << "HYPRLAND_INSTANCE_SIGNATURE was not set! (Is Hyprland running?)";
- return;
+ if (!instanceSig) {
+ std::cout << "HYPRLAND_INSTANCE_SIGNATURE was not set! (Is Hyprland running?)";
+ return;
}
- std::string instanceSigStr = std::string(instanceSig);
+ std::string instanceSigStr = std::string(instanceSig);
- sockaddr_un serverAddress = {0};
- serverAddress.sun_family = AF_UNIX;
+ sockaddr_un serverAddress = {0};
+ serverAddress.sun_family = AF_UNIX;
- std::string socketPath = "/tmp/hypr/" + instanceSigStr + "/.socket.sock";
+ std::string socketPath = "/tmp/hypr/" + instanceSigStr + "/.socket.sock";
- strcpy(serverAddress.sun_path, socketPath.c_str());
+ strcpy(serverAddress.sun_path, socketPath.c_str());
- if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, SUN_LEN(&serverAddress)) < 0) {
- std::cout << "Couldn't connect to " << socketPath << ". (3)";
- return;
+ if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, SUN_LEN(&serverAddress)) < 0) {
+ std::cout << "Couldn't connect to " << socketPath << ". (3)";
+ return;
}
- auto sizeWritten = write(SERVERSOCKET, arg.c_str(), arg.length());
+ auto sizeWritten = write(SERVERSOCKET, arg.c_str(), arg.length());
- if (sizeWritten < 0) {
- std::cout << "Couldn't write (4)";
- return;
+ if (sizeWritten < 0) {
+ std::cout << "Couldn't write (4)";
+ return;
}
- std::string reply = "";
- char buffer[8192] = {0};
+ std::string reply = "";
+ char buffer[8192] = {0};
- sizeWritten = read(SERVERSOCKET, buffer, 8192);
+ sizeWritten = read(SERVERSOCKET, buffer, 8192);
- if (sizeWritten < 0) {
- std::cout << "Couldn't read (5)";
- return;
+ if (sizeWritten < 0) {
+ std::cout << "Couldn't read (5)";
+ return;
}
- reply += std::string(buffer, sizeWritten);
+ reply += std::string(buffer, sizeWritten);
- while (sizeWritten == 8192) {
- sizeWritten = read(SERVERSOCKET, buffer, 8192);
- if (sizeWritten < 0) {
- std::cout << "Couldn't read (5)";
- return;
+ while (sizeWritten == 8192) {
+ sizeWritten = read(SERVERSOCKET, buffer, 8192);
+ if (sizeWritten < 0) {
+ std::cout << "Couldn't read (5)";
+ return;
}
- reply += std::string(buffer, sizeWritten);
+ reply += std::string(buffer, sizeWritten);
}
- close(SERVERSOCKET);
+ close(SERVERSOCKET);
- std::cout << reply;
+ std::cout << reply;
}
void requestHyprpaper(std::string arg) {
@@ -341,6 +341,8 @@ int main(int argc, char** argv) {
request(fullRequest);
else if (fullRequest.contains("/switchxkblayout"))
request(fullRequest, 2);
+ else if (fullRequest.contains("/seterror"))
+ request(fullRequest, 1);
else if (fullRequest.contains("/output"))
exitStatus = outputRequest(argc, argv);
else if (fullRequest.contains("/setcursor"))