summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2024-12-01 19:24:09 +1300
committerBossCode45 <human.cyborg42@gmail.com>2024-12-01 19:24:09 +1300
commit8dca89a1be23f0de2dd1676b95feb6b46cbdd5f2 (patch)
tree7ebc1a5161bbe70d6ab6a0e5353a1a622240c915
parente162dff48c251e262f475de9261f0ecfa0f39dc4 (diff)
parent434ec6542d0d79190c6aa7003aac91b03cad4398 (diff)
downloadYATwm-8dca89a1be23f0de2dd1676b95feb6b46cbdd5f2.tar.gz
YATwm-8dca89a1be23f0de2dd1676b95feb6b46cbdd5f2.zip
Merge branch 'IPC'
l---------.direnv/flake-profile1
l---------.direnv/flake-profile-1-link1
-rw-r--r--YATmsg/YATmsgbin0 -> 16680 bytes
-rw-r--r--YATmsg/YATmsg.cpp75
-rw-r--r--YATmsg/makefile32
-rw-r--r--compile_commands.json78
-rw-r--r--makefile13
-rw-r--r--src/IPC.cpp91
-rw-r--r--src/IPC.h27
-rw-r--r--src/commands.cpp (renamed from commands.cpp)121
-rw-r--r--src/commands.h (renamed from commands.h)0
-rw-r--r--src/config.cpp (renamed from config.cpp)8
-rw-r--r--src/config.h (renamed from config.h)0
-rw-r--r--src/error.h (renamed from error.h)0
-rw-r--r--src/ewmh.cpp (renamed from ewmh.cpp)16
-rw-r--r--src/ewmh.h (renamed from ewmh.h)2
-rw-r--r--src/keybinds.cpp (renamed from keybinds.cpp)2
-rw-r--r--src/keybinds.h (renamed from keybinds.h)0
-rw-r--r--src/main.cpp (renamed from main.cpp)101
-rw-r--r--src/structs.h (renamed from structs.h)0
-rw-r--r--src/util.cpp (renamed from util.cpp)0
-rw-r--r--src/util.h (renamed from util.h)0
-rw-r--r--test2
23 files changed, 428 insertions, 142 deletions
diff --git a/.direnv/flake-profile b/.direnv/flake-profile
deleted file mode 120000
index 0c05709..0000000
--- a/.direnv/flake-profile
+++ /dev/null
@@ -1 +0,0 @@
-flake-profile-1-link \ No newline at end of file
diff --git a/.direnv/flake-profile-1-link b/.direnv/flake-profile-1-link
deleted file mode 120000
index 2c4bfed..0000000
--- a/.direnv/flake-profile-1-link
+++ /dev/null
@@ -1 +0,0 @@
-/nix/store/lgavdfyjs3pawq8cpcbrd0idpxkw2xi8-nix-shell-env \ No newline at end of file
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..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;
+}
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)
diff --git a/compile_commands.json b/compile_commands.json
index e5199c2..3a2baf6 100644
--- a/compile_commands.json
+++ b/compile_commands.json
@@ -1,7 +1,7 @@
[
{
"arguments": [
- "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.0/bin/g++",
+ "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++",
"-std=c++17",
"-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include",
"-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0",
@@ -10,16 +10,16 @@
"-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include",
"-c",
"-o",
- "ewmh.o",
- "ewmh.cpp"
+ "build/main.o",
+ "src/main.cpp"
],
"directory": "/home/boss/Documents/Coding/WM/YATwm",
- "file": "/home/boss/Documents/Coding/WM/YATwm/ewmh.cpp",
- "output": "/home/boss/Documents/Coding/WM/YATwm/ewmh.o"
+ "file": "/home/boss/Documents/Coding/WM/YATwm/src/main.cpp",
+ "output": "/home/boss/Documents/Coding/WM/YATwm/build/main.o"
},
{
"arguments": [
- "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.0/bin/g++",
+ "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++",
"-std=c++17",
"-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include",
"-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0",
@@ -28,16 +28,16 @@
"-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include",
"-c",
"-o",
- "config.o",
- "config.cpp"
+ "build/config.o",
+ "src/config.cpp"
],
"directory": "/home/boss/Documents/Coding/WM/YATwm",
- "file": "/home/boss/Documents/Coding/WM/YATwm/config.cpp",
- "output": "/home/boss/Documents/Coding/WM/YATwm/config.o"
+ "file": "/home/boss/Documents/Coding/WM/YATwm/src/config.cpp",
+ "output": "/home/boss/Documents/Coding/WM/YATwm/build/config.o"
},
{
"arguments": [
- "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.0/bin/g++",
+ "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++",
"-std=c++17",
"-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include",
"-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0",
@@ -46,16 +46,16 @@
"-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include",
"-c",
"-o",
- "keybinds.o",
- "keybinds.cpp"
+ "build/ewmh.o",
+ "src/ewmh.cpp"
],
"directory": "/home/boss/Documents/Coding/WM/YATwm",
- "file": "/home/boss/Documents/Coding/WM/YATwm/keybinds.cpp",
- "output": "/home/boss/Documents/Coding/WM/YATwm/keybinds.o"
+ "file": "/home/boss/Documents/Coding/WM/YATwm/src/ewmh.cpp",
+ "output": "/home/boss/Documents/Coding/WM/YATwm/build/ewmh.o"
},
{
"arguments": [
- "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.0/bin/g++",
+ "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++",
"-std=c++17",
"-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include",
"-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0",
@@ -64,16 +64,16 @@
"-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include",
"-c",
"-o",
- "commands.o",
- "commands.cpp"
+ "build/util.o",
+ "src/util.cpp"
],
"directory": "/home/boss/Documents/Coding/WM/YATwm",
- "file": "/home/boss/Documents/Coding/WM/YATwm/commands.cpp",
- "output": "/home/boss/Documents/Coding/WM/YATwm/commands.o"
+ "file": "/home/boss/Documents/Coding/WM/YATwm/src/util.cpp",
+ "output": "/home/boss/Documents/Coding/WM/YATwm/build/util.o"
},
{
"arguments": [
- "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.0/bin/g++",
+ "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++",
"-std=c++17",
"-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include",
"-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0",
@@ -82,16 +82,16 @@
"-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include",
"-c",
"-o",
- "util.o",
- "util.cpp"
+ "build/IPC.o",
+ "src/IPC.cpp"
],
"directory": "/home/boss/Documents/Coding/WM/YATwm",
- "file": "/home/boss/Documents/Coding/WM/YATwm/util.cpp",
- "output": "/home/boss/Documents/Coding/WM/YATwm/util.o"
+ "file": "/home/boss/Documents/Coding/WM/YATwm/src/IPC.cpp",
+ "output": "/home/boss/Documents/Coding/WM/YATwm/build/IPC.o"
},
{
"arguments": [
- "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.0/bin/g++",
+ "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++",
"-std=c++17",
"-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include",
"-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0",
@@ -100,11 +100,29 @@
"-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include",
"-c",
"-o",
- "main.o",
- "main.cpp"
+ "build/commands.o",
+ "src/commands.cpp"
],
"directory": "/home/boss/Documents/Coding/WM/YATwm",
- "file": "/home/boss/Documents/Coding/WM/YATwm/main.cpp",
- "output": "/home/boss/Documents/Coding/WM/YATwm/main.o"
+ "file": "/home/boss/Documents/Coding/WM/YATwm/src/commands.cpp",
+ "output": "/home/boss/Documents/Coding/WM/YATwm/build/commands.o"
+ },
+ {
+ "arguments": [
+ "/nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g++",
+ "-std=c++17",
+ "-I/nix/store/drrf5w7pcc5q9h4si9i8vm2hclg0zijg-libnotify-0.8.3-dev/include",
+ "-I/nix/store/a45ri2jgzpv6q36va2y6wq471y88hpnl-gdk-pixbuf-2.42.10-dev/include/gdk-pixbuf-2.0",
+ "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include",
+ "-I/nix/store/s0nl17v1827bl7qyjgkkar90c2a40ykb-glib-2.78.4-dev/include/glib-2.0",
+ "-I/nix/store/k1qjs35nw1lbssg1l1xpmh0082hy7wl4-glib-2.78.4/lib/glib-2.0/include",
+ "-c",
+ "-o",
+ "build/keybinds.o",
+ "src/keybinds.cpp"
+ ],
+ "directory": "/home/boss/Documents/Coding/WM/YATwm",
+ "file": "/home/boss/Documents/Coding/WM/YATwm/src/keybinds.cpp",
+ "output": "/home/boss/Documents/Coding/WM/YATwm/build/keybinds.o"
}
]
diff --git a/makefile b/makefile
index df4304a..883bc26 100644
--- a/makefile
+++ b/makefile
@@ -2,9 +2,9 @@
CXX := g++
CXXFLAGS := -std=c++17 `pkg-config --cflags --libs libnotify`# -g -fsanitize=address -fno-omit-frame-pointer
LINKFLAGS := -lX11 -lXrandr
-OBJS_DIR := .
-OUT_DIR := .
-SOURCE_DIR := .
+OBJS_DIR := build
+OUT_DIR := out
+SOURCE_DIR := src
EXEC := YATwm
SOURCE_FILES := $(wildcard $(SOURCE_DIR)/*.cpp)
SOURCE_HEADERS := $(wildcard $(SOURCE_DIR)/*.h)
@@ -12,7 +12,7 @@ OBJS := $(subst $(SOURCE_DIR),$(OBJS_DIR), $(patsubst %.cpp,%.o,$(SOURCE_FILES))
INSTALL_DIR = /
$(EXEC): $(OBJS)
- $(CXX) $(OBJS) $(CXXFLAGS) $(LINKFLAGS) -o $(OUT_DIR)/$(EXEC)
+ $(CXX) $(OBJS) $(CXXFLAGS) $(LINKFLAGS) -o $(EXEC)
$(OBJS_DIR)/%.o : $(SOURCE_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
@@ -33,9 +33,10 @@ $(OBJS_DIR)/main.o: $(SOURCE_FILES) $(SOURCE_HEADERS)
$(OBJS_DIR)/ewmh.o: $(SOURCE_DIR)/ewmh.cpp $(SOURCE_DIR)/ewmh.h
$(OBJS_DIR)/util.o: $(SOURCE_DIR)/util.cpp $(SOURCE_DIR)/util.h
$(OBJS_DIR)/commands.o: $(SOURCE_DIR)/commands.cpp $(SOURCE_DIR)/commands.h
-$(OBJS_DIR)/config.o: $(SOURCE_DIR)/config.cpp $(SOURCE_DIR)/config.h
+$(OBJS_DIR)/config.o: $(SOURCE_DIR)/config.cpp $(SOURCE_DIR)/config.h $(SOURCE_DIR)/commands.h
$(OBJS_DIR)/keybinds.o: $(SOURCE_DIR)/keybinds.cpp $(SOURCE_DIR)/keybinds.h $(SOURCE_DIR)/commands.h
+$(OBJS_DIR)/ipc.o: $(SOURCE_DIR)/ipc.cpp $(SOURCE_DIR)/ipc.h $(SOURCE_DIR)/commands.h $(SOURCE_DIR)/ewmh.h
clean:
rm $(OBJS_DIR)/*.o
- rm $(OUT_DIR)/$(EXEC)
+ rm $(EXEC)
diff --git a/src/IPC.cpp b/src/IPC.cpp
new file mode 100644
index 0000000..709cc5c
--- /dev/null
+++ b/src/IPC.cpp
@@ -0,0 +1,91 @@
+#include "IPC.h"
+#include "ewmh.h"
+
+#include <cstring>
+#include <string>
+#include <sys/socket.h>
+#include <iostream>
+#include <unistd.h>
+
+using std::cout, std::endl;
+
+static const char* path = "/tmp/YATwm.sock";
+
+IPCModule::IPCModule(CommandsModule& commandsModule, Config& cfg, Globals& globals)
+ :commandsModule(commandsModule),
+ cfg(cfg),
+ globals(globals)
+{
+}
+
+void IPCModule::init()
+{
+ sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
+ address.sun_family = AF_UNIX;
+ strcpy(address.sun_path, path);
+ unlink(address.sun_path);
+ len = strlen(address.sun_path) + sizeof(address.sun_family);
+
+ if(bind(sockfd, (sockaddr*)&address, len) == -1)
+ {
+ cout << "ERROR " << errno << endl;
+ }
+ cout << "SOCKETED" << endl;
+ setIPCPath((unsigned char*)path, strlen(path));
+ ready = true;
+}
+
+void IPCModule::doListen()
+{
+ if(!ready)
+ return;
+ if(listen(sockfd, 1) != 0)
+ {
+ cout << "ERROR 2" << endl;
+ return;
+ }
+ if(first)
+ {
+ first = false;
+ return;
+ }
+ unsigned int socklen = 0;
+ sockaddr_un remote;
+ int newsock = accept(sockfd, (sockaddr*)&remote, &socklen);
+ char buffer[256];
+ memset(buffer, 0, 256);
+ read(newsock, buffer, 256);
+ std::string command(buffer);
+ while(command[command.size() - 1] == 0 || command[command.size() - 1] == '\n')
+ command = command.substr(0, command.size() - 1);
+ //cout << '"' << command << '"' << endl;
+ try
+ {
+ commandsModule.runCommand(command);
+ }
+ catch(Err e)
+ {
+ cout << e.code << " " << e.message << endl;
+ }
+ const char* message = "RAN COMMAND";
+ send(newsock, message, strlen(message), 0);
+ shutdown(newsock, SHUT_RDWR);
+ close(newsock);
+}
+
+void IPCModule::quitIPC()
+{
+ if(!ready)
+ return;
+ close(sockfd);
+ ready = false;
+}
+
+int IPCModule::getFD()
+{
+ if(!ready)
+ return -1;
+ if(sockfd > 0)
+ return sockfd;
+ return -1;
+}
diff --git a/src/IPC.h b/src/IPC.h
new file mode 100644
index 0000000..97716bb
--- /dev/null
+++ b/src/IPC.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include "commands.h"
+#include "config.h"
+#include "util.h"
+
+class IPCModule
+{
+public:
+ IPCModule(CommandsModule& commandsModule, Config& cfg, Globals& globals);
+ void init();
+ void doListen();
+ void quitIPC();
+ int getFD();
+private:
+ CommandsModule& commandsModule;
+ Config& cfg;
+ Globals& globals;
+ int sockfd;
+ int len;
+ bool first = true;
+ bool ready = false;
+ sockaddr_un address;
+};
diff --git a/commands.cpp b/src/commands.cpp
index 54fe891..5688da4 100644
--- a/commands.cpp
+++ b/src/commands.cpp
@@ -5,6 +5,7 @@
#include <cctype>
#include <iostream>
#include <algorithm>
+#include <iterator>
#include <stdexcept>
#include <string>
#include <utility>
@@ -143,70 +144,70 @@ CommandArg* CommandsModule::getCommandArgs(vector<string>& split, const CommandA
{
switch(argTypes[i-1])
{
- case STR: args[i-1].str = (char*)split[i].c_str(); break;
- case NUM:
- {
- try
- {
- args[i-1].num = std::stoi(split[i]);
- break;
- }
- catch(std::invalid_argument e)
- {
- delete[] args;
- throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!");
- }
- }
- case MOVDIR:
- {
- if(lowercase(split[i]) == "up")
- args[i-1].dir = UP;
- else if(lowercase(split[i]) == "down")
- args[i-1].dir = DOWN;
- else if(lowercase(split[i]) == "left")
- args[i-1].dir = LEFT;
- else if(lowercase(split[i]) == "right")
- args[i-1].dir = RIGHT;
- else
- {
- delete[] args;
- throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a direction!");
- }
- break;
- }
- case STR_REST:
+ case STR: args[i-1].str = (char*)split[i].c_str(); break;
+ case NUM:
+ {
+ try
+ {
+ args[i-1].num = std::stoi(split[i]);
+ break;
+ }
+ catch(std::invalid_argument e)
+ {
+ delete[] args;
+ throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!");
+ }
+ }
+ case MOVDIR:
+ {
+ if(lowercase(split[i]) == "up")
+ args[i-1].dir = UP;
+ else if(lowercase(split[i]) == "down")
+ args[i-1].dir = DOWN;
+ else if(lowercase(split[i]) == "left")
+ args[i-1].dir = LEFT;
+ else if(lowercase(split[i]) == "right")
+ args[i-1].dir = RIGHT;
+ else
+ {
+ delete[] args;
+ throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a direction!");
+ }
+ break;
+ }
+ case STR_REST:
+ {
+ string rest = "";
+ for(int j = i; j < split.size(); j++)
+ {
+ rest += split[j];
+ if(j != split.size() - 1)
+ rest += " ";
+ }
+ args[i-1].str = new char[rest.size()];
+ strncpy(args[i-1].str, rest.c_str(), rest.size());
+ return args;
+ }
+ case NUM_ARR_REST:
+ {
+ int* rest = new int[split.size() - i];
+ for(int j = 0; j < split.size() - i; j++)
+ {
+ try
{
- string rest = "";
- for(int j = i; j < split.size(); j++)
- {
- rest += split[j];
- if(j != split.size() - 1)
- rest += " ";
- }
- args[i-1].str = new char[rest.size()];
- strcpy(args[i-1].str, rest.c_str());
- return args;
+ rest[j] = std::stoi(split[j + i]);
}
- case NUM_ARR_REST:
+ catch(std::invalid_argument e)
{
- int* rest = new int[split.size() - i];
- for(int j = 0; j < split.size() - i; j++)
- {
- try
- {
- rest[j] = std::stoi(split[j + i]);
- }
- catch(std::invalid_argument e)
- {
- delete[] rest;
- delete[] args;
- throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!");
- }
- }
- args[i-1].numArr = {rest, (int) split.size() - i};
- return args;
+ delete[] rest;
+ delete[] args;
+ throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!");
}
- default: cout << "UH OH SOMETHING IS VERY WRONG" << endl;
+ }
+ args[i-1].numArr = {rest, (int) split.size() - i};
+ return args;
+ }
+ default: cout << "UH OH SOMETHING IS VERY WRONG" << endl;
}
}
return args;
diff --git a/commands.h b/src/commands.h
index af4a4a0..af4a4a0 100644
--- a/commands.h
+++ b/src/commands.h
diff --git a/config.cpp b/src/config.cpp
index 3af2491..925e6ea 100644
--- a/config.cpp
+++ b/src/config.cpp
@@ -4,13 +4,10 @@
#include <X11/Xlib.h>
-#include <cstdio>
-#include <cstring>
#include <fstream>
-#include <ios>
+#include <ostream>
#include <string>
#include <vector>
-#include <sstream>
#include <unistd.h>
#include <fcntl.h>
@@ -94,9 +91,8 @@ std::vector<Err> Config::loadFromFile(std::string path)
//Probably need something for workspaces and binds too...
- string cmd;
int line = 0;
- while(getline(config, cmd))
+ for(string cmd; std::getline(config, cmd);)
{
line++;
if(cmd.size() == 0)
diff --git a/config.h b/src/config.h
index 452db9c..452db9c 100644
--- a/config.h
+++ b/src/config.h
diff --git a/error.h b/src/error.h
index f0a67a5..f0a67a5 100644
--- a/error.h
+++ b/src/error.h
diff --git a/ewmh.cpp b/src/ewmh.cpp
index 5878e82..a3cc505 100644
--- a/ewmh.cpp
+++ b/src/ewmh.cpp
@@ -1,5 +1,9 @@
#include "ewmh.h"
+#include <X11/X.h>
+#include <X11/Xatom.h>
#include <X11/Xlib.h>
+#include <iostream>
+#include <ostream>
#include <string>
Display** dpy_;
@@ -67,16 +71,22 @@ void setCurrentDesktop(int desktop)
void setFullscreen(Window w, bool fullscreen)
{
- Atom netWMState = XInternAtom(*dpy_, "_NET_WM_STATE", true);
+ Atom netWMState = XInternAtom(*dpy_, "_NET_WM_STATE", false);
Atom netWMStateVal;
if(fullscreen)
- netWMStateVal = XInternAtom(*dpy_, "_NET_WM_STATE_FULLSCREEN", true);
+ netWMStateVal = XInternAtom(*dpy_, "_NET_WM_STATE_FULLSCREEN", false);
else
- netWMStateVal = XInternAtom(*dpy_, "", true);
+ netWMStateVal = XInternAtom(*dpy_, "", false);
XChangeProperty(*dpy_, w, netWMState, XA_ATOM, 32, PropModeReplace, (unsigned char*)&netWMStateVal, 1);
}
+void setIPCPath(unsigned char* path, int len)
+{
+ Atom socketPathAtom = XInternAtom(*dpy_, "YATWM_SOCKET_PATH", false);
+ XChangeProperty(*dpy_, *root_, socketPathAtom, XA_STRING, 8, PropModeReplace, path, len);
+}
+
int getProp(Window w, char* propName, Atom* type, unsigned char** data)
{
Atom prop_type = XInternAtom(*dpy_, propName, false);
diff --git a/ewmh.h b/src/ewmh.h
index e8bae0c..9473d5d 100644
--- a/ewmh.h
+++ b/src/ewmh.h
@@ -20,4 +20,6 @@ void setCurrentDesktop(int desktop);
void setFullscreen(Window w, bool fullscreen);
+void setIPCPath(unsigned char* path, int len);
+
int getProp(Window w, char* propName, Atom* type, unsigned char** data);
diff --git a/keybinds.cpp b/src/keybinds.cpp
index c41452f..235f8c1 100644
--- a/keybinds.cpp
+++ b/src/keybinds.cpp
@@ -12,7 +12,7 @@
#include "keybinds.h"
#include "util.h"
-using std::string;
+using std::string, std::cout, std::endl;
bool Keybind::operator<(const Keybind &o) const {
if(key != o.key)
diff --git a/keybinds.h b/src/keybinds.h
index a742240..a742240 100644
--- a/keybinds.h
+++ b/src/keybinds.h
diff --git a/main.cpp b/src/main.cpp
index b16b8cb..a11b203 100644
--- a/main.cpp
+++ b/src/main.cpp
@@ -2,13 +2,12 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/Xrandr.h>
#include <libnotify/notification.h>
-
#include <libnotify/notify.h>
-#include <X11/Xutil.h>
-#include <X11/extensions/Xrandr.h>
#include <chrono>
#include <cstdio>
#include <cstdlib>
@@ -19,12 +18,16 @@
#include <map>
#include <ostream>
#include <string>
+#include <sys/poll.h>
+#include <sys/select.h>
#include <vector>
#include <unistd.h>
#include <cstring>
#include <algorithm>
#include <fcntl.h>
+#include <poll.h>
+#include "IPC.h"
#include "commands.h"
#include "keybinds.h"
#include "structs.h"
@@ -59,6 +62,7 @@ void updateMousePos();
CommandsModule commandsModule;
Config cfg(commandsModule);
KeybindsModule keybindsModule(commandsModule, cfg, globals, &updateMousePos);
+IPCModule ipc(commandsModule, cfg, globals);
int sW, sH;
int bH;
@@ -282,10 +286,6 @@ const void spawn(const CommandArg* argv)
{
if(fork() == 0)
{
- int null = open("/dev/null", O_WRONLY);
- dup2(null, 0);
- dup2(null, 1);
- dup2(null, 2);
const std::string argsStr = argv[0].str;
vector<std::string> args = split(argsStr, ' ');
char** execvpArgs = new char*[args.size()];
@@ -293,6 +293,10 @@ const void spawn(const CommandArg* argv)
{
execvpArgs[i] = strdup(args[i].c_str());
}
+ int null = open("/dev/null", O_WRONLY);
+ dup2(null, 0);
+ dup2(null, 1);
+ dup2(null, 2);
execvp(execvpArgs[0], execvpArgs);
exit(0);
}
@@ -1024,11 +1028,11 @@ int main(int argc, char** argv)
return 0;
}
}
+
//Important init stuff
mX = mY = 0;
dpy = XOpenDisplay(nullptr);
root = Window(DefaultRootWindow(dpy));
-
// Adding commands
commandsModule.addCommand("exit", exit, 0, {});
commandsModule.addCommand("spawn", spawn, 1, {STR_REST});
@@ -1047,6 +1051,8 @@ int main(int argc, char** argv)
//Config
std::vector<Err> cfgErr;
+
+ cout << "Registered commands" << endl;
char* confDir = getenv("XDG_CONFIG_HOME");
if(confDir != NULL)
@@ -1059,6 +1065,8 @@ int main(int argc, char** argv)
cfgErr = cfg.loadFromFile(home + "/.config/YATwm/config");
}
+ cout << "Done config" << endl;
+
//Log
yatlog.open(cfg.logFile, std::ios_base::app);
yatlog << "\n" << endl;
@@ -1088,6 +1096,8 @@ int main(int argc, char** argv)
initEWMH(&dpy, &root, cfg.workspaces.size(), cfg.workspaces);
setCurrentDesktop(1);
+ ipc.init();
+
for(int i = 1; i < cfg.numWS + 1; i++)
{
vector<int> v;
@@ -1101,39 +1111,64 @@ int main(int argc, char** argv)
focusWindow(root);
XWarpPointer(dpy, root, root, 0, 0, 0, 0, 960, 540);
+ fd_set fdset;
+ int x11fd = ConnectionNumber(dpy);
+ FD_ZERO(&fdset);
+ FD_SET(x11fd, &fdset);
+ FD_SET(ipc.getFD(), &fdset);
+
log("Begin mainloop");
while(keepGoing)
{
- XEvent e;
- XNextEvent(dpy, &e);
+ FD_ZERO(&fdset);
+ FD_SET(x11fd, &fdset);
+ FD_SET(ipc.getFD(), &fdset);
+ int ready = select(std::max(x11fd, ipc.getFD()) + 1, &fdset, NULL, NULL, NULL);
+ if(FD_ISSET(ipc.getFD(), &fdset))
+ {
+ ipc.doListen();
+ }
+ if(FD_ISSET(x11fd, &fdset))
+ {
+ XEvent e;
+ while(XPending(dpy))
+ {
+ XNextEvent(dpy, &e);
- switch(e.type)
+ switch(e.type)
+ {
+ case KeyPress:
+ keybindsModule.handleKeypress(e.xkey);
+ break;
+ case ConfigureRequest:
+ configureRequest(e.xconfigurerequest);
+ break;
+ case MapRequest:
+ mapRequest(e.xmaprequest);
+ break;
+ case DestroyNotify:
+ destroyNotify(e.xdestroywindow);
+ break;
+ case EnterNotify:
+ enterNotify(e.xcrossing);
+ break;
+ case ClientMessage:
+ clientMessage(e.xclient);
+ break;
+ default:
+ // cout << "Unhandled event: " << getEventName(e.type) << endl;
+ break;
+ }
+ }
+ }
+ if(ready == -1)
{
- case KeyPress:
- keybindsModule.handleKeypress(e.xkey);
- break;
- case ConfigureRequest:
- configureRequest(e.xconfigurerequest);
- break;
- case MapRequest:
- mapRequest(e.xmaprequest);
- break;
- case DestroyNotify:
- destroyNotify(e.xdestroywindow);
- break;
- case EnterNotify:
- enterNotify(e.xcrossing);
- break;
- case ClientMessage:
- clientMessage(e.xclient);
- break;
- default:
- // cout << "Unhandled event: " << getEventName(e.type) << endl;
- break;
+ cout << "E" << endl;
+ log("ERROR");
}
}
//Kill children
-
+ ipc.quitIPC();
XCloseDisplay(dpy);
}
diff --git a/structs.h b/src/structs.h
index 5273f52..5273f52 100644
--- a/structs.h
+++ b/src/structs.h
diff --git a/util.cpp b/src/util.cpp
index 58116d0..58116d0 100644
--- a/util.cpp
+++ b/src/util.cpp
diff --git a/util.h b/src/util.h
index 66ecf76..66ecf76 100644
--- a/util.h
+++ b/src/util.h
diff --git a/test b/test
index 49cbf49..fba98d4 100644
--- a/test
+++ b/test
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
make