From d1d4a63d4473cd4910b678cf5b385f622186fbd3 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Thu, 19 Dec 2024 15:00:45 +1300 Subject: feat: Added IPC client side to main binary Updated command line arguments to use `getopt_long' Made it so both -v and --version work Made it so that if you give it non recognised arguments they are sent through the socket to the running window manager if possible. --- YATmsg/YATmsg.cpp | 75 ------------------------------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 YATmsg/YATmsg.cpp (limited to 'YATmsg/YATmsg.cpp') diff --git a/YATmsg/YATmsg.cpp b/YATmsg/YATmsg.cpp deleted file mode 100644 index 7013861..0000000 --- a/YATmsg/YATmsg.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include - -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; -} -- cgit v1.2.3