mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 13:45:59 +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 ';'
|
--batch -> execute a batch of commands, separated by ';'
|
||||||
)#";
|
)#";
|
||||||
|
|
||||||
void request(std::string arg, int minArgs = 0) {
|
void request(std::string arg, int minArgs = 0) {
|
||||||
const auto SERVERSOCKET = socket(AF_UNIX, SOCK_STREAM, 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) {
|
if (ARGS < minArgs) {
|
||||||
std::cout << "Not enough arguments, expected at least " << minArgs;
|
std::cout << "Not enough arguments, expected at least " << minArgs;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SERVERSOCKET < 0) {
|
if (SERVERSOCKET < 0) {
|
||||||
std::cout << "Couldn't open a socket (1)";
|
std::cout << "Couldn't open a socket (1)";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the instance signature
|
// get the instance signature
|
||||||
auto instanceSig = getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
auto instanceSig = getenv("HYPRLAND_INSTANCE_SIGNATURE");
|
||||||
|
|
||||||
if (!instanceSig) {
|
if (!instanceSig) {
|
||||||
std::cout << "HYPRLAND_INSTANCE_SIGNATURE was not set! (Is Hyprland running?)";
|
std::cout << "HYPRLAND_INSTANCE_SIGNATURE was not set! (Is Hyprland running?)";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string instanceSigStr = std::string(instanceSig);
|
std::string instanceSigStr = std::string(instanceSig);
|
||||||
|
|
||||||
sockaddr_un serverAddress = {0};
|
sockaddr_un serverAddress = {0};
|
||||||
serverAddress.sun_family = AF_UNIX;
|
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) {
|
if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, SUN_LEN(&serverAddress)) < 0) {
|
||||||
std::cout << "Couldn't connect to " << socketPath << ". (3)";
|
std::cout << "Couldn't connect to " << socketPath << ". (3)";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sizeWritten = write(SERVERSOCKET, arg.c_str(), arg.length());
|
auto sizeWritten = write(SERVERSOCKET, arg.c_str(), arg.length());
|
||||||
|
|
||||||
if (sizeWritten < 0) {
|
if (sizeWritten < 0) {
|
||||||
std::cout << "Couldn't write (4)";
|
std::cout << "Couldn't write (4)";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string reply = "";
|
std::string reply = "";
|
||||||
char buffer[8192] = {0};
|
char buffer[8192] = {0};
|
||||||
|
|
||||||
sizeWritten = read(SERVERSOCKET, buffer, 8192);
|
sizeWritten = read(SERVERSOCKET, buffer, 8192);
|
||||||
|
|
||||||
if (sizeWritten < 0) {
|
if (sizeWritten < 0) {
|
||||||
std::cout << "Couldn't read (5)";
|
std::cout << "Couldn't read (5)";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
reply += std::string(buffer, sizeWritten);
|
reply += std::string(buffer, sizeWritten);
|
||||||
|
|
||||||
while (sizeWritten == 8192) {
|
while (sizeWritten == 8192) {
|
||||||
sizeWritten = read(SERVERSOCKET, buffer, 8192);
|
sizeWritten = read(SERVERSOCKET, buffer, 8192);
|
||||||
if (sizeWritten < 0) {
|
if (sizeWritten < 0) {
|
||||||
std::cout << "Couldn't read (5)";
|
std::cout << "Couldn't read (5)";
|
||||||
return;
|
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) {
|
void requestHyprpaper(std::string arg) {
|
||||||
|
@ -341,6 +341,8 @@ int main(int argc, char** argv) {
|
||||||
request(fullRequest);
|
request(fullRequest);
|
||||||
else if (fullRequest.contains("/switchxkblayout"))
|
else if (fullRequest.contains("/switchxkblayout"))
|
||||||
request(fullRequest, 2);
|
request(fullRequest, 2);
|
||||||
|
else if (fullRequest.contains("/seterror"))
|
||||||
|
request(fullRequest, 1);
|
||||||
else if (fullRequest.contains("/output"))
|
else if (fullRequest.contains("/output"))
|
||||||
exitStatus = outputRequest(argc, argv);
|
exitStatus = outputRequest(argc, argv);
|
||||||
else if (fullRequest.contains("/setcursor"))
|
else if (fullRequest.contains("/setcursor"))
|
||||||
|
|
|
@ -805,6 +805,31 @@ std::string switchXKBLayoutRequest(const std::string& request) {
|
||||||
return "ok";
|
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 dispatchGetOption(std::string request, HyprCtl::eHyprCtlOutputFormat format) {
|
||||||
std::string curitem = "";
|
std::string curitem = "";
|
||||||
|
|
||||||
|
@ -973,6 +998,8 @@ std::string getReply(std::string request) {
|
||||||
return cursorPosRequest(format);
|
return cursorPosRequest(format);
|
||||||
else if (request == "binds")
|
else if (request == "binds")
|
||||||
return bindsRequest(format);
|
return bindsRequest(format);
|
||||||
|
else if (request.find("seterror") == 0)
|
||||||
|
return dispatchSeterror(request);
|
||||||
else if (request.find("switchxkblayout") == 0)
|
else if (request.find("switchxkblayout") == 0)
|
||||||
return switchXKBLayoutRequest(request);
|
return switchXKBLayoutRequest(request);
|
||||||
else if (request.find("output") == 0)
|
else if (request.find("output") == 0)
|
||||||
|
|
Loading…
Reference in a new issue