mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-02 12:26:00 +01:00
added hyprctl seterror
This commit is contained in:
parent
7d754b7c22
commit
8f57db28f7
2 changed files with 70 additions and 41 deletions
|
@ -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"))
|
||||
|
|
|
@ -805,6 +805,31 @@ std::string switchXKBLayoutRequest(const std::string& request) {
|
|||
return "ok";
|
||||
}
|
||||
|
||||
std::string dispatchSeterror(std::string request) {
|
||||
CVarList vars(request, 0, ' ');
|
||||
|
||||
std::string errorMessage = "";
|
||||
|
||||
if (vars.size() < 3) {
|
||||
g_pHyprError->destroy();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
const CColor COLOR = configStringToInt(vars[1]);
|
||||
|
||||
for (size_t i = 2; i < vars.size(); ++i)
|
||||
errorMessage += vars[i] + ' ';
|
||||
|
||||
if (errorMessage.empty()) {
|
||||
g_pHyprError->destroy();
|
||||
} else {
|
||||
errorMessage.pop_back(); // pop last space
|
||||
g_pHyprError->queueCreate(errorMessage, COLOR);
|
||||
}
|
||||
|
||||
return "ok";
|
||||
}
|
||||
|
||||
std::string dispatchGetOption(std::string request, HyprCtl::eHyprCtlOutputFormat format) {
|
||||
std::string curitem = "";
|
||||
|
||||
|
@ -973,6 +998,8 @@ std::string getReply(std::string request) {
|
|||
return cursorPosRequest(format);
|
||||
else if (request == "binds")
|
||||
return bindsRequest(format);
|
||||
else if (request.find("seterror") == 0)
|
||||
return dispatchSeterror(request);
|
||||
else if (request.find("switchxkblayout") == 0)
|
||||
return switchXKBLayoutRequest(request);
|
||||
else if (request.find("output") == 0)
|
||||
|
|
Loading…
Reference in a new issue