diff options
author | Riley Martin <[email protected]> | 2022-10-25 12:04:11 -0400 |
---|---|---|
committer | Riley Martin <[email protected]> | 2022-10-27 10:39:21 -0400 |
commit | c064711d2a397e13b5a57375461804401a231ca0 (patch) | |
tree | bc7b8e78f6ca4848ee7b4ebdfe48ba02f1cba128 /hyprctl/main.cpp | |
parent | 7d6ccca69537b65ef4fe165fed92085ffe8cf990 (diff) | |
download | Hyprland-c064711d2a397e13b5a57375461804401a231ca0.tar.gz Hyprland-c064711d2a397e13b5a57375461804401a231ca0.zip |
Improve hyprctl
Added better help for some hyprctl commands.
Failed commands should now 'fail' by returning a nonzero status to the shell
Fix typos
Diffstat (limited to 'hyprctl/main.cpp')
-rw-r--r-- | hyprctl/main.cpp | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index bc0e8f01..f4de085f 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -158,11 +158,12 @@ void requestHyprpaper(std::string arg) { std::cout << std::string(buffer); } -void dispatchRequest(int argc, char** argv) { +int dispatchRequest(int argc, char** argv) { if (argc < 4) { - std::cout << "dispatch requires 2 params"; - return; + std::cout << "Usage: hyprctl dispatch <dispatcher> <arg>\n\ + Execute a hyprland keybind dispatcher with the given argument"; + return 1; } std::string rq = "/dispatch"; @@ -171,12 +172,14 @@ void dispatchRequest(int argc, char** argv) { rq += " " + std::string(argv[i]); request(rq); + return 0; } -void keywordRequest(int argc, char** argv) { +int keywordRequest(int argc, char** argv) { if (argc < 4) { - std::cout << "keyword requires 2 params"; - return; + std::cout << "Usage: hyprctl keyword <keyword> <arg>\n\ + Execute a hyprland keyword with the given argument"; + return 1; } std::string rq = "/keyword"; @@ -185,28 +188,33 @@ void keywordRequest(int argc, char** argv) { rq += " " + std::string(argv[i]); request(rq); + return 0; } -void hyprpaperRequest(int argc, char** argv) { +int hyprpaperRequest(int argc, char** argv) { if (argc < 4) { - std::cout << "hyprpaper requires 2 params"; - return; + std::cout << "Usage: hyprctl hyprpaper <command> <arg>\n\ + Execute a hyprpaper command with the given argument"; + return 1; } std::string rq = std::string(argv[2]) + " " + std::string(argv[3]); requestHyprpaper(rq); + return 0; } -void setcursorRequest(int argc, char** argv) { +int setcursorRequest(int argc, char** argv) { if (argc < 4) { - std::cout << "setcursor requires 2 params"; - return; + std::cout << "Usage: hyprctl setcursor <theme> <size>\n\ + Sets the cursor theme for everything except GTK and reloads the cursor"; + return 1; } std::string rq = "setcursor " + std::string(argv[2]) + " " + std::string(argv[3]); request(rq); + return 0; } void batchRequest(std::string arg) { @@ -266,6 +274,8 @@ int main(int argc, char** argv) { fullRequest.pop_back(); // remove trailing space fullRequest = fullArgs + "/" + fullRequest; + + int exitStatus = 0; if (fullRequest.contains("/--batch")) batchRequest(fullRequest); else if (fullRequest.contains("/monitors")) request(fullRequest); @@ -280,10 +290,10 @@ int main(int argc, char** argv) { else if (fullRequest.contains("/reload")) request(fullRequest); else if (fullRequest.contains("/getoption")) request(fullRequest); else if (fullRequest.contains("/cursorpos")) request(fullRequest); - else if (fullRequest.contains("/setcursor")) setcursorRequest(argc, argv); - else if (fullRequest.contains("/dispatch")) dispatchRequest(argc, argv); - else if (fullRequest.contains("/keyword")) keywordRequest(argc, argv); - else if (fullRequest.contains("/hyprpaper")) hyprpaperRequest(argc, argv); + else if (fullRequest.contains("/setcursor")) exitStatus = setcursorRequest(argc, argv); + else if (fullRequest.contains("/dispatch")) exitStatus = dispatchRequest(argc, argv); + else if (fullRequest.contains("/keyword")) exitStatus = keywordRequest(argc, argv); + else if (fullRequest.contains("/hyprpaper")) exitStatus = hyprpaperRequest(argc, argv); else if (fullRequest.contains("/--help")) printf("%s", USAGE.c_str()); else { printf("%s\n", USAGE.c_str()); @@ -291,5 +301,5 @@ int main(int argc, char** argv) { } printf("\n"); - return 0; + return exitStatus; } |