summaryrefslogtreecommitdiff
path: root/hyprctl/main.cpp
diff options
context:
space:
mode:
authorxDarksome <dev@darkso.me>2022-07-02 19:43:52 +0300
committerGitHub <noreply@github.com>2022-07-02 19:43:52 +0300
commit185c4d6ea13ad5f4483aa2e389e43bd09106002f (patch)
treea7bc4a9510c39e367317b5ce64d2ee0e0a72d4f0 /hyprctl/main.cpp
parentfc4b10d13c14c4eb08febb0637f27177cb6a1940 (diff)
parentb7b3344188e3ebd2baed14bc288ee42a1ae8d6f2 (diff)
Merge branch 'hyprwm:main' into main
Diffstat (limited to 'hyprctl/main.cpp')
-rw-r--r--hyprctl/main.cpp75
1 files changed, 74 insertions, 1 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp
index f60fb600..a1a1122d 100644
--- a/hyprctl/main.cpp
+++ b/hyprctl/main.cpp
@@ -26,6 +26,8 @@ const std::string USAGE = R"#(usage: hyprctl [command] [(opt)args]
dispatch
keyword
version
+ kill
+ hyprpaper
reload)#";
void request(std::string arg) {
@@ -74,7 +76,65 @@ void request(std::string arg) {
char buffer[8192] = {0};
- sizeWritten = read(SERVERSOCKET,buffer, 8192);
+ sizeWritten = read(SERVERSOCKET, buffer, 8192);
+
+ if (sizeWritten < 0) {
+ std::cout << "Couldn't read (5)";
+ return;
+ }
+
+ close(SERVERSOCKET);
+
+ std::cout << std::string(buffer);
+}
+
+void requestHyprpaper(std::string arg) {
+ const auto SERVERSOCKET = socket(AF_UNIX, SOCK_STREAM, 0);
+
+ if (SERVERSOCKET < 0) {
+ std::cout << "Couldn't open a socket (1)";
+ return;
+ }
+
+ const auto SERVER = gethostbyname("localhost");
+
+ if (!SERVER) {
+ std::cout << "Couldn't get host (2)";
+ return;
+ }
+
+ // get the instance signature
+ auto instanceSig = getenv("HYPRLAND_INSTANCE_SIGNATURE");
+
+ if (!instanceSig) {
+ std::cout << "HYPRLAND_INSTANCE_SIGNATURE was not set! (Is Hyprland running?)";
+ return;
+ }
+
+ std::string instanceSigStr = std::string(instanceSig);
+
+ sockaddr_un serverAddress = {0};
+ serverAddress.sun_family = AF_UNIX;
+
+ std::string socketPath = "/tmp/hypr/" + instanceSigStr + "/.hyprpaper.sock";
+
+ 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;
+ }
+
+ auto sizeWritten = write(SERVERSOCKET, arg.c_str(), arg.length());
+
+ if (sizeWritten < 0) {
+ std::cout << "Couldn't write (4)";
+ return;
+ }
+
+ char buffer[8192] = {0};
+
+ sizeWritten = read(SERVERSOCKET, buffer, 8192);
if (sizeWritten < 0) {
std::cout << "Couldn't read (5)";
@@ -109,6 +169,17 @@ void keywordRequest(int argc, char** argv) {
request(rq);
}
+void hyprpaperRequest(int argc, char** argv) {
+ if (argc < 4) {
+ std::cout << "hyprpaper requires 2 params";
+ return;
+ }
+
+ std::string rq = std::string(argv[2]) + " " + std::string(argv[3]);
+
+ requestHyprpaper(rq);
+}
+
void batchRequest(int argc, char** argv) {
std::string rq = "[[BATCH]]" + std::string(argv[2]);
@@ -129,10 +200,12 @@ int main(int argc, char** argv) {
else if (!strcmp(argv[1], "activewindow")) request("activewindow");
else if (!strcmp(argv[1], "layers")) request("layers");
else if (!strcmp(argv[1], "version")) request("version");
+ else if (!strcmp(argv[1], "kill")) request("kill");
else if (!strcmp(argv[1], "devices")) request("devices");
else if (!strcmp(argv[1], "reload")) request("reload");
else if (!strcmp(argv[1], "dispatch")) dispatchRequest(argc, argv);
else if (!strcmp(argv[1], "keyword")) keywordRequest(argc, argv);
+ else if (!strcmp(argv[1], "hyprpaper")) hyprpaperRequest(argc, argv);
else if (!strcmp(argv[1], "--batch")) batchRequest(argc, argv);
else if (!strcmp(argv[1], "--help")) printf("%s", USAGE.c_str());
else {