diff options
| author | BossCode45 <boss@tehbox.org> | 2025-05-11 18:17:27 +1200 |
|---|---|---|
| committer | BossCode45 <boss@tehbox.org> | 2025-06-08 23:29:33 +1200 |
| commit | 6698e92f6d7574a31a6d0e17acf63edf9f689102 (patch) | |
| tree | 96dec36f65651889a5f6ee80bb917b5bfc0f2bc3 /src/main.cpp | |
| parent | 7dd44834f0af18cca87786a2050ae69928b7a397 (diff) | |
| download | YATwm-6698e92f6d7574a31a6d0e17acf63edf9f689102.tar.gz YATwm-6698e92f6d7574a31a6d0e17acf63edf9f689102.zip | |
Fixed keybinding errors
Hopefully fixed multiple monitor status bar workspaces
Refactored EWMH module
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 109 |
1 files changed, 68 insertions, 41 deletions
diff --git a/src/main.cpp b/src/main.cpp index 45e4eba..dc7b86b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,11 +4,12 @@ #include <X11/cursorfont.h> #include <X11/Xutil.h> #include <X11/extensions/Xrandr.h> +#include <X11/extensions/Xinerama.h> +#include <cstdint> #include <libnotify/notification.h> #include <libnotify/notify.h> -#include <chrono> #include <cstdio> #include <cstdlib> #include <ctime> @@ -17,7 +18,6 @@ #include <iostream> #include <map> #include <ostream> -#include <regex> #include <string> #include <sys/poll.h> #include <sys/select.h> @@ -54,6 +54,9 @@ char nowString[80]; updateTime(); \ yatlog << nowString << x << std::endl + +const char* version = "YATwm for X - v0.0.2"; + Display* dpy; Window root; @@ -64,7 +67,8 @@ void updateMousePos(); CommandsModule commandsModule; Config cfg(commandsModule); KeybindsModule keybindsModule(commandsModule, cfg, globals, &updateMousePos); -IPCServerModule ipc(commandsModule, cfg, globals); +EWMHModule ewmh(globals, cfg); +IPCServerModule ipc(globals, cfg, commandsModule, ewmh); int sW, sH; int bH; @@ -113,7 +117,7 @@ static int OnXError(Display* display, XErrorEvent* e); // Tiling // Call this one to tile everything (it does all the fancy stuff trust me just call this one) void tileRoots(); -// Call this one to until everything (it handles multiple monitors) +// Call this one to untile everything (it handles multiple monitors) void untileRoots(); // This is to be called by tileRoots, it takes in the x, y, w, and h of where it's allowed to tile windows to, and returns the ID of a fullscreen client if one is found, or noID (-1) if none are found int tile(int frameID, int x, int y, int w, int h); @@ -132,6 +136,9 @@ void detectScreens() delete[] screens; delete[] focusedWorkspaces; log("Detecting screens: "); + + + XRRMonitorInfo* monitors = XRRGetMonitors(dpy, root, true, &nscreens); log("\t" << nscreens << " monitors"); screens = new ScreenInfo[nscreens]; @@ -146,14 +153,26 @@ void detectScreens() log("\t\tw: " << screens[i].w << ", h: " << screens[i].h); XFree(name); } - for(int i = 0; i < cfg.workspaces.size(); i++) + + /* + XineramaScreenInfo* monitors = XineramaQueryScreens(dpy, &nscreens); + log("\t" << nscreens << " monitors"); + if(XineramaIsActive(dpy)) + log("\tXinerama active"); + screens = new ScreenInfo[nscreens]; + for(int i = 0; i < nscreens; i++) { - if(cfg.workspaces[i].screenPreferences[0] < nscreens && focusedWorkspaces[cfg.workspaces[i].screenPreferences[0]] == 0) - { - //focusedWorkspaces[screenPreferences[i][0]] = i+1; - } - } + screens[i] = {"", (uint16_t)monitors[i].x_org, (uint16_t)monitors[i].y_org, (uint16_t)monitors[i].width, (uint16_t)monitors[i].height}; + log("\tMonitor " << i + 1); + log("\t\tx: " << screens[i].x << ", y: " << screens[i].y); + log("\t\tw: " << screens[i].w << ", h: " << screens[i].h); + }; + */ + + XFree(monitors); + + ewmh.updateScreens(screens, nscreens); } void updateMousePos() { @@ -271,7 +290,7 @@ void cWS(int newWS) focusWindow(getFrame(currWS).rootData->focus); //EWMH - setCurrentDesktop(currWS); + ewmh.setCurrentDesktop(currWS); } void focusWindow(Window w) { @@ -393,7 +412,7 @@ const void wToWS(const CommandArg* argv) frames.find(argv[0].num)->second.subFrameIDs.push_back(fID); //EWMH - setWindowDesktop(focusedWindow, argv[0].num); + ewmh.setWindowDesktop(focusedWindow, argv[0].num); XUnmapWindow(dpy, focusedWindow); //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); @@ -611,7 +630,7 @@ const void fullscreen(const CommandArg* arg) int cID = getFrame(fID).cID; getClient(cID).fullscreen ^= true; tileRoots(); - setFullscreen(focusedWindow, getClient(cID).fullscreen); + ewmh.setFullscreen(focusedWindow, getClient(cID).fullscreen); } void configureRequest(XConfigureRequestEvent e) @@ -697,7 +716,7 @@ void mapRequest(XMapRequestEvent e) unsigned char* data; Atom type; - int status = getProp(e.window, "_NET_WM_WINDOW_TYPE", &type, &data); + int status = ewmh.getProp(e.window, "_NET_WM_WINDOW_TYPE", &type, &data); if (status == Success && type != None && ((Atom*)data)[0] == XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", false)) { log("\tWindow was bar"); @@ -730,15 +749,15 @@ void mapRequest(XMapRequestEvent e) //Add ID to frameIDS map frameIDS.insert(pair<Window, int>(e.window, f.ID)); - status = getProp(e.window, "_NET_WM_STATE", &type, &data); + status = ewmh.getProp(e.window, "_NET_WM_STATE", &type, &data); if(status == Success && type!=None && (((Atom*)data)[0] == XInternAtom(dpy, "_NET_WM_STATE_MODAL", false) || ((Atom*)data)[0] == XInternAtom(dpy, "_NET_WM_STATE_ABOVE", false))) { cout << "Floating" << endl; clients.find(c.ID)->second.floating = true; frames.find(pID)->second.rootData->floatingFrameIDs.push_back(f.ID); frames.insert(pair<int, Frame>(f.ID, f)); - setWindowDesktop(e.window, currWS); - updateClientList(clients); + ewmh.setWindowDesktop(e.window, currWS); + ewmh.updateClientList(clients); XFree(data); //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); tileRoots(); @@ -785,8 +804,8 @@ void mapRequest(XMapRequestEvent e) //Add to frames map frames.insert(pair<int, Frame>(f.ID, f)); - setWindowDesktop(e.window, currWS); - updateClientList(clients); + ewmh.setWindowDesktop(e.window, currWS); + ewmh.updateClientList(clients); //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); focusWindow(e.window); @@ -839,7 +858,7 @@ void destroyNotify(XDestroyWindowEvent e) //tile(currWS, outerGaps, outerGaps, sW - outerGaps*2, sH - outerGaps*2 - bH); tileRoots(); - updateClientList(clients); + ewmh.updateClientList(clients); } void enterNotify(XEnterWindowEvent e) { @@ -902,7 +921,7 @@ void clientMessage(XClientMessageEvent e) int fID = getFrameID(e.window); int cID = getFrame(fID).cID; getClient(cID).fullscreen = (Atom) e.data.l[0] > 0; - setFullscreen(e.window, (Atom) e.data.l[0] > 0); + ewmh.setFullscreen(e.window, (Atom) e.data.l[0] > 0); tileRoots(); } XFree(prop1); @@ -976,7 +995,7 @@ int tile(int frameID, int x, int y, int w, int h) return fullscreenClientID; continue; } - Client c = clients.find(f.cID)->second; + Client c = getClient(f.cID); if(c.fullscreen) return c.ID; wX += cfg.gaps; @@ -1019,25 +1038,24 @@ void untile(int frameID) void printVersion() { - const char* version = - "YATwm for X\n" - "version 0.0.1"; cout << version << endl; } int main(int argc, char** argv) { int versionFlag = 0; + int noSocketFlag = 0; bool immediateExit = false; string configLocation = ""; while(1) { static option long_options[] = {{"version", no_argument, &versionFlag, 1}, {"config", required_argument, NULL, 'c'}, + {"nosocket", no_argument, &noSocketFlag, 1}, {0, 0, 0, 0}}; int optionIndex; - char c = getopt_long(argc, argv, "c:v", long_options, &optionIndex); + char c = getopt_long(argc, argv, "c:nv", long_options, &optionIndex); if(c == -1) break; @@ -1055,6 +1073,8 @@ int main(int argc, char** argv) case 'v': versionFlag = 1; break; + case 'n': + noSocketFlag = 1; case '?': //Error?? break; @@ -1130,21 +1150,25 @@ int main(int argc, char** argv) cout << "Registered commands" << endl; - if(configLocation != "") - cfgErr = cfg.loadFromFile(configLocation); - else + // if(configLocation != "") + // cfgErr = cfg.loadFromFile(configLocation); + if(configLocation == "") { char* confDir = getenv("XDG_CONFIG_HOME"); if(confDir != NULL) - cfgErr = cfg.loadFromFile(string(confDir) + "/YATwm/config"); + configLocation = string(confDir) + "/YATwm/config"; + // cfgErr = cfg.loadFromFile(string(confDir) + "/YATwm/config"); else { string home = getenv("HOME"); - cfgErr = cfg.loadFromFile(home + "/.config/YATwm/config"); + configLocation = home + "/.config/YATwm/config"; + // cfgErr = cfg.loadFromFile(home + "/.config/YATwm/config"); } } - cout << "Done config" << endl; + cfgErr = cfg.loadFromFile(configLocation); + + cout << "Loaded config" << endl; //Log yatlog.open(cfg.logFile, std::ios_base::app); @@ -1152,6 +1176,9 @@ int main(int argc, char** argv) //Print starting message log("-------- YATWM STARTING --------"); + log(version); + log("Running from command: " << argv[0]); + log("Reading config from file: " << configLocation); //Notifications notify_init("YATwm"); @@ -1172,10 +1199,11 @@ int main(int argc, char** argv) XDefineCursor(dpy, root, XCreateFontCursor(dpy, XC_top_left_arrow)); //EWMH - initEWMH(&dpy, &root, cfg.workspaces.size(), cfg.workspaces); - setCurrentDesktop(1); + ewmh.init(); + ewmh.setCurrentDesktop(1); - ipc.init(); + if(!noSocketFlag) + ipc.init(); for(int i = 1; i < cfg.numWS + 1; i++) { @@ -1192,18 +1220,15 @@ int main(int argc, char** argv) fd_set fdset; int x11fd = ConnectionNumber(dpy); - FD_ZERO(&fdset); - FD_SET(x11fd, &fdset); - FD_SET(ipc.getFD(), &fdset); - log("Begin mainloop"); while(keepGoing) { FD_ZERO(&fdset); FD_SET(x11fd, &fdset); - FD_SET(ipc.getFD(), &fdset); + if(!noSocketFlag) + FD_SET(ipc.getFD(), &fdset); int ready = select(std::max(x11fd, ipc.getFD()) + 1, &fdset, NULL, NULL, NULL); - if(FD_ISSET(ipc.getFD(), &fdset)) + if(!noSocketFlag && FD_ISSET(ipc.getFD(), &fdset)) { ipc.doListen(); } @@ -1248,5 +1273,7 @@ int main(int argc, char** argv) //Kill children ipc.quitIPC(); + delete[] screens; + delete[] focusedWorkspaces; XCloseDisplay(dpy); } |
