diff options
| author | BossCode45 <human.cyborg42@gmail.com> | 2024-12-01 19:24:09 +1300 |
|---|---|---|
| committer | BossCode45 <human.cyborg42@gmail.com> | 2024-12-01 19:24:09 +1300 |
| commit | 8dca89a1be23f0de2dd1676b95feb6b46cbdd5f2 (patch) | |
| tree | 7ebc1a5161bbe70d6ab6a0e5353a1a622240c915 /YATmsg/YATmsg.cpp | |
| parent | e162dff48c251e262f475de9261f0ecfa0f39dc4 (diff) | |
| parent | 434ec6542d0d79190c6aa7003aac91b03cad4398 (diff) | |
| download | YATwm-8dca89a1be23f0de2dd1676b95feb6b46cbdd5f2.tar.gz YATwm-8dca89a1be23f0de2dd1676b95feb6b46cbdd5f2.zip | |
Merge branch 'IPC'
Diffstat (limited to 'YATmsg/YATmsg.cpp')
| -rw-r--r-- | YATmsg/YATmsg.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/YATmsg/YATmsg.cpp b/YATmsg/YATmsg.cpp new file mode 100644 index 0000000..7013861 --- /dev/null +++ b/YATmsg/YATmsg.cpp @@ -0,0 +1,75 @@ +#include <X11/X.h> +#include <X11/Xlib.h> + +#include <cstring> +#include <iostream> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> + +using std::cout, std::endl; + +int main(int argc, const char** argv) +{ + if(argc < 2) + { + cout << "Not enough args" << endl; + return 1; + } + Display* dpy = XOpenDisplay(nullptr); + Window root = Window(DefaultRootWindow(dpy)); + Atom propName = XInternAtom(dpy, "YATWM_SOCKET_PATH", false); + Atom propType = XInternAtom(dpy, "STRING", false); + int format; + unsigned long length; + unsigned long after; + Atom type; + unsigned char* sockPath; + + if(XGetWindowProperty(dpy, root, propName, 0L, 32L, False, propType, &type, &format, &length, &after, &sockPath) != Success) + { + cout << "Failed to get path" << endl; + XFree(sockPath); + return 1; + } + + int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if(sockfd == -1) + { + cout << "Failed to create socket" << endl; + XFree(sockPath); + return 1; + } + sockaddr_un address; + address.sun_family = AF_UNIX; + strcpy(address.sun_path, (const char*)sockPath); + if(connect(sockfd, (sockaddr*) &address, sizeof(address)) == -1) + { + cout << "Failed connect" << endl; + XFree(sockPath); + return 1; + } + + std::string message; + for(int i = 1; i < argc; i++) + { + message += argv[i]; + if(i != argc - 1) + message += " "; + } + cout << "Sending: " << message << endl; + if(write(sockfd, message.c_str(), message.length()) == -1) + { + cout << "Failed write" << endl; + XFree(sockPath); + return 1; + } + + char recv[128]; + read(sockfd, recv, 128); + cout << recv << endl; + + close(sockfd); + XFree(sockPath); + return 0; +} |
