summaryrefslogtreecommitdiff
path: root/YATmsg
diff options
context:
space:
mode:
Diffstat (limited to 'YATmsg')
-rw-r--r--YATmsg/YATmsgbin0 -> 16680 bytes
-rw-r--r--YATmsg/YATmsg.cpp61
-rw-r--r--YATmsg/main.cpp0
-rw-r--r--YATmsg/makefile32
4 files changed, 93 insertions, 0 deletions
diff --git a/YATmsg/YATmsg b/YATmsg/YATmsg
new file mode 100644
index 0000000..ee34c4f
--- /dev/null
+++ b/YATmsg/YATmsg
Binary files differ
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;
+}
diff --git a/YATmsg/main.cpp b/YATmsg/main.cpp
deleted file mode 100644
index e69de29..0000000
--- a/YATmsg/main.cpp
+++ /dev/null
diff --git a/YATmsg/makefile b/YATmsg/makefile
new file mode 100644
index 0000000..6aeee67
--- /dev/null
+++ b/YATmsg/makefile
@@ -0,0 +1,32 @@
+.PHONY: clean
+CXX := g++
+CXXFLAGS := -std=c++17 # -g -fsanitize=address -fno-omit-frame-pointer
+LINKFLAGS := -lX11
+OBJS_DIR := ../build
+OUT_DIR := ../out/
+SOURCE_DIR := ./
+EXEC := YATmsg
+SOURCE_FILES := $(wildcard $(SOURCE_DIR)/*.cpp)
+SOURCE_HEADERS := $(wildcard $(SOURCE_DIR)/*.h)
+OBJS := $(subst $(SOURCE_DIR),$(OBJS_DIR), $(patsubst %.cpp,%.o,$(SOURCE_FILES)))
+INSTALL_DIR = /
+
+$(EXEC): $(OBJS)
+ $(CXX) $(OBJS) $(CXXFLAGS) $(LINKFLAGS) -o $(EXEC)
+
+$(OBJS_DIR)/%.o : $(SOURCE_DIR)/%.cpp
+ $(CXX) $(CXXFLAGS) -c $< -o $@
+
+i: $(EXEC)
+ sudo install -D -m 755 $(EXEC) $(INSTALL_DIR)usr/bin/$(EXEC)
+install: i
+r:
+ sudo rm $(INSTALL_DIR)usr/bin/$(EXEC)
+remove: r
+
+#Files to be compiled
+$(OBJS_DIR)/YATmsg.o: $(SOURCE_FILES) $(SOURCE_HEADERS)
+
+clean:
+ rm $(OBJS_DIR)/*.o
+ rm $(EXEC)