From 5dacf6d6d24eab71994e02b6b3c4fc6f6e309958 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Fri, 29 Sep 2023 00:55:29 +1300 Subject: feat: IPC works kinda Still quite buggy, but first version --- main.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 28 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index cc3d2bb..eb5f8a9 100644 --- a/main.cpp +++ b/main.cpp @@ -2,13 +2,12 @@ #include #include #include +#include +#include #include - #include -#include -#include #include #include #include @@ -19,12 +18,16 @@ #include #include #include +#include +#include #include #include #include #include #include +#include +#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; @@ -1090,39 +1094,64 @@ int main(int argc, char** argv) XSetInputFocus(dpy, root, RevertToNone, CurrentTime); 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; + cout << "ERROR" << endl; } } //Kill children - + ipc.quitIPC(); XCloseDisplay(dpy); } -- cgit v1.2.3