diff options
| -rw-r--r-- | YATmsg/main.cpp | 0 | ||||
| -rw-r--r-- | compile_commands.json | 110 | ||||
| -rw-r--r-- | makefile | 13 | ||||
| -rw-r--r-- | old.compile_commands.json | 128 | ||||
| -rw-r--r-- | src/IPC.cpp | 86 | ||||
| -rw-r--r-- | src/IPC.h | 26 | ||||
| -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) | 0 | ||||
| -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) | 0 | ||||
| -rw-r--r-- | src/keybinds.h (renamed from keybinds.h) | 0 | ||||
| -rw-r--r-- | src/main.cpp (renamed from main.cpp) | 95 | ||||
| -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-- | test | 2 |
20 files changed, 387 insertions, 212 deletions
diff --git a/YATmsg/main.cpp b/YATmsg/main.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/YATmsg/main.cpp diff --git a/compile_commands.json b/compile_commands.json deleted file mode 100644 index e5199c2..0000000 --- a/compile_commands.json +++ /dev/null @@ -1,110 +0,0 @@ -[ - { - "arguments": [ - "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.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", - "ewmh.o", - "ewmh.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" - }, - { - "arguments": [ - "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.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", - "config.o", - "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" - }, - { - "arguments": [ - "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.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", - "keybinds.o", - "keybinds.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" - }, - { - "arguments": [ - "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.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", - "commands.o", - "commands.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" - }, - { - "arguments": [ - "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.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", - "util.o", - "util.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" - }, - { - "arguments": [ - "/nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.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", - "main.o", - "main.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" - } -] @@ -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/old.compile_commands.json b/old.compile_commands.json new file mode 100644 index 0000000..3997f42 --- /dev/null +++ b/old.compile_commands.json @@ -0,0 +1,128 @@ +[ + { + "arguments": [ + "/usr/bin/g++", + "-std=c++17", + "-I/usr/include/gdk-pixbuf-2.0", + "-I/usr/include/glib-2.0", + "-I/usr/lib64/glib-2.0/include", + "-I/usr/include/sysprof-4", + "-I/usr/include/libpng16", + "-I/usr/include/libmount", + "-I/usr/include/blkid", + "-pthread", + "-c", + "-o", + "ewmh.o", + "ewmh.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" + }, + { + "arguments": [ + "/usr/bin/g++", + "-std=c++17", + "-I/usr/include/gdk-pixbuf-2.0", + "-I/usr/include/glib-2.0", + "-I/usr/lib64/glib-2.0/include", + "-I/usr/include/sysprof-4", + "-I/usr/include/libpng16", + "-I/usr/include/libmount", + "-I/usr/include/blkid", + "-pthread", + "-c", + "-o", + "main.o", + "main.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" + }, + { + "arguments": [ + "/usr/bin/g++", + "-std=c++17", + "-I/usr/include/gdk-pixbuf-2.0", + "-I/usr/include/glib-2.0", + "-I/usr/lib64/glib-2.0/include", + "-I/usr/include/sysprof-4", + "-I/usr/include/libpng16", + "-I/usr/include/libmount", + "-I/usr/include/blkid", + "-pthread", + "-c", + "-o", + "util.o", + "util.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" + }, + { + "arguments": [ + "/usr/bin/g++", + "-std=c++17", + "-I/usr/include/gdk-pixbuf-2.0", + "-I/usr/include/glib-2.0", + "-I/usr/lib64/glib-2.0/include", + "-I/usr/include/sysprof-4", + "-I/usr/include/libpng16", + "-I/usr/include/libmount", + "-I/usr/include/blkid", + "-pthread", + "-c", + "-o", + "config.o", + "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" + }, + { + "arguments": [ + "/usr/bin/g++", + "-std=c++17", + "-I/usr/include/gdk-pixbuf-2.0", + "-I/usr/include/glib-2.0", + "-I/usr/lib64/glib-2.0/include", + "-I/usr/include/sysprof-4", + "-I/usr/include/libpng16", + "-I/usr/include/libmount", + "-I/usr/include/blkid", + "-pthread", + "-c", + "-o", + "keybinds.o", + "keybinds.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" + }, + { + "arguments": [ + "/usr/bin/g++", + "-std=c++17", + "-I/usr/include/gdk-pixbuf-2.0", + "-I/usr/include/glib-2.0", + "-I/usr/lib64/glib-2.0/include", + "-I/usr/include/sysprof-4", + "-I/usr/include/libpng16", + "-I/usr/include/libmount", + "-I/usr/include/blkid", + "-pthread", + "-c", + "-o", + "commands.o", + "commands.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" + } +] diff --git a/src/IPC.cpp b/src/IPC.cpp new file mode 100644 index 0000000..0aed97e --- /dev/null +++ b/src/IPC.cpp @@ -0,0 +1,86 @@ +#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) +{ + 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; +} + +void IPCModule::init() +{ + setIPCPath((unsigned char*)path, strlen(path)); +} + +void IPCModule::doListen() +{ + if(listen(sockfd, 1) != 0) + { + cout << "ERROR 2" << endl; + return; + } + if(first) + { + first = false; + return; + } + cout << "DOLISTEN" << endl; + unsigned int socklen = 0; + sockaddr_un remote; + int newsock = accept(sockfd, (sockaddr*)&remote, &socklen); + cout << "LISTENING" << endl; + 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; + } + char* message = "RAN COMMAND"; + send(newsock, message, strlen(message), 0); + cout << "RAN COMMAND" << endl; + shutdown(newsock, SHUT_RDWR); + close(newsock); +} + +void IPCModule::quitIPC() +{ + close(sockfd); +} + +int IPCModule::getFD() +{ + if(sockfd > 0) + return sockfd; + return -1; +} diff --git a/src/IPC.h b/src/IPC.h new file mode 100644 index 0000000..89e67e5 --- /dev/null +++ b/src/IPC.h @@ -0,0 +1,26 @@ +#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; + sockaddr_un address; +}; diff --git a/commands.cpp b/src/commands.cpp index 54fe891..57cfd0b 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()]; + strcpy(args[i-1].str, rest.c_str()); + 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..3af2491 100644 --- a/config.cpp +++ b/src/config.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); @@ -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..c41452f 100644 --- a/keybinds.cpp +++ b/src/keybinds.cpp diff --git a/keybinds.h b/src/keybinds.h index a742240..a742240 100644 --- a/keybinds.h +++ b/src/keybinds.h @@ -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); } @@ -1088,6 +1092,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 +1107,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(x11fd + 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 @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash make |
