mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 20:05:58 +01:00
Added hyprctl dispatch
This commit is contained in:
parent
422eaad420
commit
c02afa0c27
2 changed files with 43 additions and 6 deletions
|
@ -22,6 +22,7 @@ usage: hyprctl [command] [(opt)args]
|
||||||
clients
|
clients
|
||||||
activewindow
|
activewindow
|
||||||
layers
|
layers
|
||||||
|
dispatch
|
||||||
)#";
|
)#";
|
||||||
|
|
||||||
void request(std::string arg) {
|
void request(std::string arg) {
|
||||||
|
@ -96,6 +97,18 @@ void request(std::string arg) {
|
||||||
std::cout << std::string(buffer);
|
std::cout << std::string(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dispatchRequest(int argc, char** argv) {
|
||||||
|
|
||||||
|
if (argc < 4) {
|
||||||
|
std::cout << "dispatch requires 2 params";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string rq = "dispatch " + std::string(argv[2]) + " " + std::string(argv[3]);
|
||||||
|
|
||||||
|
request(rq);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
int bflag = 0, sflag = 0, index, c;
|
int bflag = 0, sflag = 0, index, c;
|
||||||
|
|
||||||
|
@ -109,6 +122,7 @@ int main(int argc, char** argv) {
|
||||||
else if (!strcmp(argv[1], "workspaces")) request("workspaces");
|
else if (!strcmp(argv[1], "workspaces")) request("workspaces");
|
||||||
else if (!strcmp(argv[1], "activewindow")) request("activewindow");
|
else if (!strcmp(argv[1], "activewindow")) request("activewindow");
|
||||||
else if (!strcmp(argv[1], "layers")) request("layers");
|
else if (!strcmp(argv[1], "layers")) request("layers");
|
||||||
|
else if (!strcmp(argv[1], "dispatch")) dispatchRequest(argc, argv);
|
||||||
else {
|
else {
|
||||||
printf(USAGE.c_str());
|
printf(USAGE.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -71,6 +71,23 @@ std::string layersRequest() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string dispatchRequest(std::string in) {
|
||||||
|
// get rid of the dispatch keyword
|
||||||
|
in = in.substr(in.find_first_of(' ') + 1);
|
||||||
|
|
||||||
|
const auto DISPATCHSTR = in.substr(0, in.find_first_of(' '));
|
||||||
|
|
||||||
|
const auto DISPATCHARG = in.substr(in.find_first_of(' ') + 1);
|
||||||
|
|
||||||
|
const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find(DISPATCHSTR);
|
||||||
|
if (DISPATCHER == g_pKeybindManager->m_mDispatchers.end())
|
||||||
|
return "Invalid dispatcher";
|
||||||
|
|
||||||
|
DISPATCHER->second(DISPATCHARG);
|
||||||
|
|
||||||
|
return "ok";
|
||||||
|
}
|
||||||
|
|
||||||
void HyprCtl::startHyprCtlSocket() {
|
void HyprCtl::startHyprCtlSocket() {
|
||||||
std::thread([&]() {
|
std::thread([&]() {
|
||||||
uint16_t connectPort = 9187;
|
uint16_t connectPort = 9187;
|
||||||
|
@ -125,12 +142,18 @@ void HyprCtl::startHyprCtlSocket() {
|
||||||
std::string request(readBuffer);
|
std::string request(readBuffer);
|
||||||
|
|
||||||
std::string reply = "";
|
std::string reply = "";
|
||||||
if (request == "monitors") reply = monitorsRequest();
|
try {
|
||||||
if (request == "workspaces") reply = workspacesRequest();
|
if (request == "monitors") reply = monitorsRequest();
|
||||||
if (request == "clients") reply = clientsRequest();
|
else if (request == "workspaces") reply = workspacesRequest();
|
||||||
if (request == "activewindow") reply = activeWindowRequest();
|
else if (request == "clients") reply = clientsRequest();
|
||||||
if (request == "layers") reply = layersRequest();
|
else if (request == "activewindow") reply = activeWindowRequest();
|
||||||
|
else if (request == "layers") reply = layersRequest();
|
||||||
|
else if (request.find("dispatch") == 0) reply = dispatchRequest(request);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
Debug::log(ERR, "Error in request: %s", e.what());
|
||||||
|
reply = "Err: " + std::string(e.what());
|
||||||
|
}
|
||||||
|
|
||||||
write(ACCEPTEDCONNECTION, reply.c_str(), reply.length());
|
write(ACCEPTEDCONNECTION, reply.c_str(), reply.length());
|
||||||
|
|
||||||
close(ACCEPTEDCONNECTION);
|
close(ACCEPTEDCONNECTION);
|
||||||
|
|
Loading…
Reference in a new issue