summaryrefslogtreecommitdiff
path: root/YATmsg/YATmsg.cpp
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2024-11-26 15:21:56 +1300
committerBossCode45 <human.cyborg42@gmail.com>2024-11-26 15:21:56 +1300
commit72300460c1c1fa294cc4d1f1026d203a5adf4d28 (patch)
treebabbfba0ca2c9994609238b49e281476660a356d /YATmsg/YATmsg.cpp
parent8b48a9cfc4b0795a62a515e2519e7194d1d57347 (diff)
downloadYATwm-72300460c1c1fa294cc4d1f1026d203a5adf4d28.tar.gz
YATwm-72300460c1c1fa294cc4d1f1026d203a5adf4d28.zip
feat: Added a program (YATmsg) to communicate with YATwm
Currently just sends a hello message and nothing else, more to come later
Diffstat (limited to 'YATmsg/YATmsg.cpp')
-rw-r--r--YATmsg/YATmsg.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/YATmsg/YATmsg.cpp b/YATmsg/YATmsg.cpp
new file mode 100644
index 0000000..dbc09b9
--- /dev/null
+++ b/YATmsg/YATmsg.cpp
@@ -0,0 +1,61 @@
+#include <X11/X.h>
+#include <X11/Xlib.h>
+
+#include <iostream>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+using std::cout, std::endl;
+
+int main()
+{
+ 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;
+ }
+ const char* command = "echo Hello from YATmsg!!!";
+ if(write(sockfd, command, 22) == -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;
+}