From 8cea9df3b45e16ee122e899c08dccfc58a60f17c Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Tue, 13 Sep 2022 14:23:52 +1200 Subject: Logging --- config.h | 2 +- main.cpp | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/config.h b/config.h index 4d7c4f5..dcce4fd 100644 --- a/config.h +++ b/config.h @@ -69,7 +69,7 @@ const char* suspend[] = {"systemctl", "suspend", NULL}; {MOD, K, changeWS, {.num = X}}, \ {MOD|SHIFT, K, wToWS, {.num = X}} -static struct Key keyBinds[] = { +static Key keyBinds[] = { //Modifiers //Key //Func //Args //General {MOD, XK_e, exit, {NULL}}, diff --git a/main.cpp b/main.cpp index dbbfd19..3f9fae0 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,17 @@ -//DEV BRANCH #include #include #include #include +#include #include #include +#include +#include +#include #include #include +#include #include #include #include @@ -26,6 +30,10 @@ using std::map; using std::pair; using std::vector; +std::ofstream yatlog; + +#define log(x) yatlog << x << std::endl + Display* dpy; Window root; int sW, sH; @@ -40,6 +48,9 @@ map frames; int currFrameID = 1; map frameIDS; +#define getClient(c) clients.find(c)->second +#define getFrame(f) frames.find(f)->second + Window bar; int currWS = 1; @@ -282,7 +293,6 @@ void wMove(const KeyArg arg) frames.find(fID)->second.pID = pID; pSF.push_back(fID); - cout << "Moving to: " << pID << "\n"; } else { @@ -325,7 +335,7 @@ void keyPress(XKeyEvent e) KeySym keysym = XLookupKeysym(&e, 0); for(int i = 0; i < sizeof(keyBinds)/sizeof(keyBinds[0]); i++) { - if(keyBinds[i].keysym == keysym && keyBinds[i].modifiers == e.state) + if(keyBinds[i].keysym == keysym && (e.state & keyBinds[i].modifiers) == keyBinds[i].modifiers) { keyBinds[i].function(keyBinds[i].arg); } @@ -349,11 +359,18 @@ void mapRequest(XMapRequestEvent e) { XMapWindow(dpy, e.window); + XTextProperty name; + XGetWMName(dpy, e.window, &name); + log("Mapping window: " << name.value); + log("\tWindow ID: " << e.window); + + unsigned char* data; Atom type; int status = getProp(e.window, "_NET_WM_WINDOW_TYPE", &type, &data); if (status == Success && ((Atom*)data)[0] == XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", false)) { + log("\tWindow was bar"); XWindowAttributes attr; XGetWindowAttributes(dpy, e.window, &attr); bH = attr.height; @@ -392,6 +409,7 @@ void mapRequest(XMapRequestEvent e) status = 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))) { + log("\tWindow floating"); clients.find(c.ID)->second.floating = true; frames.find(pID)->second.floatingFrameIDs.push_back(f.ID); frames.insert(pair(f.ID, f)); @@ -452,7 +470,8 @@ void destroyNotify(XDestroyWindowEvent e) { if(frameIDS.count(e.window)<1) return; - cout << "Destroy notif\n"; + log("Destroy notif"); + log("\tWindow ID: " << e.window); int fID = frameIDS.find(e.window)->second; int pID = frames.find(fID)->second.pID; vector& pS = frames.find(pID)->second.subFrameIDs; @@ -496,7 +515,7 @@ void destroyNotify(XDestroyWindowEvent e) } void clientMessage(XClientMessageEvent e) { - //cout << "Client message: " << XGetAtomName(dpy, e.message_type) << "\n"; + log("Client message: " << XGetAtomName(dpy, e.message_type)); if(e.message_type == XInternAtom(dpy, "_NET_CURRENT_DESKTOP", false)) { int nextWS = (long)e.data.l[0] + 1; @@ -518,10 +537,7 @@ void clientMessage(XClientMessageEvent e) static int OnXError(Display* display, XErrorEvent* e) { - cout << "XError " << e->type << ":\n"; - char buffer_return[100]; - XGetErrorText(dpy, e->type, buffer_return, sizeof(buffer_return)); - printf("\t%s\n", buffer_return); + log("XError " << e->type); return 0; } @@ -593,6 +609,12 @@ int main(int argc, char** argv) dpy = XOpenDisplay(nullptr); root = Window(DefaultRootWindow(dpy)); + yatlog.open("/tmp/yatlog.txt", std::ios_base::app); + + auto timeUnformatted = std::chrono::system_clock::now(); + std::time_t time = std::chrono::system_clock::to_time_t(timeUnformatted); + log("\nYAT STARTING: " << std::ctime(&time) << "--------------------------------------" ); + int screenNum = DefaultScreen(dpy); sW = DisplayWidth(dpy, screenNum); sH = DisplayHeight(dpy, screenNum); -- cgit v1.2.3