From 72300460c1c1fa294cc4d1f1026d203a5adf4d28 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Tue, 26 Nov 2024 15:21:56 +1300 Subject: feat: Added a program (YATmsg) to communicate with YATwm Currently just sends a hello message and nothing else, more to come later --- YATmsg/YATmsg.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 YATmsg/YATmsg.cpp (limited to 'YATmsg/YATmsg.cpp') 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 +#include + +#include +#include +#include +#include + +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; +} -- cgit v1.2.3 From 0dce4c8ae122267b466eec98626f5629a29447a4 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Tue, 26 Nov 2024 16:04:52 +1300 Subject: feat: Made it so that YATmsg can now take input from the args It will now send whatever is in the args to YATwm --- YATmsg/YATmsg.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'YATmsg/YATmsg.cpp') diff --git a/YATmsg/YATmsg.cpp b/YATmsg/YATmsg.cpp index dbc09b9..7013861 100644 --- a/YATmsg/YATmsg.cpp +++ b/YATmsg/YATmsg.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -8,8 +9,13 @@ using std::cout, std::endl; -int main() +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); @@ -43,8 +49,16 @@ int main() XFree(sockPath); return 1; } - const char* command = "echo Hello from YATmsg!!!"; - if(write(sockfd, command, 22) == -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); -- cgit v1.2.3