diff options
| author | BossCode45 <human.cyborg42@gmail.com> | 2023-10-29 18:34:27 +1300 |
|---|---|---|
| committer | BossCode45 <human.cyborg42@gmail.com> | 2023-11-12 15:03:34 +1300 |
| commit | f998705c5a0e50021875a811537962083b73ed26 (patch) | |
| tree | 113406756207737ca3cee23809d1b020ee001cab | |
| parent | 5dacf6d6d24eab71994e02b6b3c4fc6f6e309958 (diff) | |
| download | YATwm-f998705c5a0e50021875a811537962083b73ed26.tar.gz YATwm-f998705c5a0e50021875a811537962083b73ed26.zip | |
feat: Pretty much done IPC
Still need to add a program that uses the IPC, this potentially
requires restructuring the files
| -rw-r--r-- | IPC.cpp | 10 | ||||
| -rw-r--r-- | IPC.h | 1 | ||||
| -rw-r--r-- | commands.cpp | 121 | ||||
| -rw-r--r-- | ewmh.cpp | 16 | ||||
| -rw-r--r-- | ewmh.h | 2 | ||||
| -rw-r--r-- | main.cpp | 12 | ||||
| -rw-r--r-- | makefile | 3 | ||||
| -rw-r--r-- | test | 2 |
8 files changed, 94 insertions, 73 deletions
@@ -1,6 +1,8 @@ #include "IPC.h" +#include "ewmh.h" #include <cstring> +#include <string> #include <sys/socket.h> #include <iostream> #include <unistd.h> @@ -22,11 +24,16 @@ IPCModule::IPCModule(CommandsModule& commandsModule, Config& cfg, Globals& globa if(bind(sockfd, (sockaddr*)&address, len) == -1) { - cout << "ERROR" << endl; + cout << "ERROR " << errno << endl; } cout << "SOCKETED" << endl; } +void IPCModule::init() +{ + setIPCPath((unsigned char*)path, strlen(path)); +} + void IPCModule::doListen() { if(listen(sockfd, 1) != 0) @@ -69,7 +76,6 @@ void IPCModule::doListen() void IPCModule::quitIPC() { close(sockfd); - cout << path << endl; } int IPCModule::getFD() @@ -11,6 +11,7 @@ class IPCModule { public: IPCModule(CommandsModule& commandsModule, Config& cfg, Globals& globals); + void init(); void doListen(); void quitIPC(); int getFD(); diff --git a/commands.cpp b/commands.cpp index 54fe891..57cfd0b 100644 --- a/commands.cpp +++ b/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; @@ -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); @@ -231,10 +231,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()]; @@ -242,6 +238,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); } @@ -1083,6 +1083,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; @@ -1147,7 +1149,7 @@ int main(int argc, char** argv) if(ready == -1) { cout << "E" << endl; - cout << "ERROR" << endl; + log("ERROR"); } } @@ -33,8 +33,9 @@ $(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 @@ -7,8 +7,6 @@ Xephyr -screen 1600x900+2080+90 :1 & sleep 0.1 -rm /tmp/YATwm.sock - DISPLAY=:1 ./YATwm pkill Xephyr |
