summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2022-08-31 19:03:47 +1200
committerBossCode45 <human.cyborg42@gmail.com>2022-08-31 19:03:47 +1200
commit6cd20823086b831b78c393857bb46f9e8bbe61d8 (patch)
tree2743e9184cff4480089ff9a302c165178db6d82c
parentcda9283495096867ffa5805b270a8113f592ae7e (diff)
downloadYATwm-6cd20823086b831b78c393857bb46f9e8bbe61d8.tar.gz
YATwm-6cd20823086b831b78c393857bb46f9e8bbe61d8.zip
ewmh.cpp
-rw-r--r--ewmh.cpp79
-rw-r--r--ewmh.h19
-rw-r--r--logs.txt19
3 files changed, 117 insertions, 0 deletions
diff --git a/ewmh.cpp b/ewmh.cpp
new file mode 100644
index 0000000..c1e5e75
--- /dev/null
+++ b/ewmh.cpp
@@ -0,0 +1,79 @@
+#include "ewmh.h"
+#include <X11/Xlib.h>
+#include <string>
+
+Display** dpy_;
+Window* root_;
+
+void initEWMH(Display** dpy, Window* root, int numWS, std::string workspaceNames[])
+{
+ dpy_ = dpy;
+ root_ = root;
+
+ Atom supported[] = {XInternAtom(*dpy_, "_NET_NUMBER_OF_DESKTOPS", false), XInternAtom(*dpy_, "_NET_DESKTOP_NAMES", false), XInternAtom(*dpy_, "_NET_CLIENT_LIST", false), XInternAtom(*dpy_, "_NET_CURRENT_DESKTOP", false)};
+ int wsNamesLen = numWS; //For null bytes
+ for(int i = 0; i < numWS; i++)
+ {
+ wsNamesLen += workspaceNames[i].length();
+ }
+ char wsNames[wsNamesLen];
+ int pos = 0;
+ for(int i = 0; i < numWS; i++)
+ {
+ for(char toAdd : workspaceNames[i])
+ {
+ wsNames[pos++] = toAdd;
+ }
+ wsNames[pos++] = '\0';
+ }
+ unsigned long numDesktops = numWS;
+ Atom netSupportedAtom = XInternAtom(*dpy_, "_NET_SUPPORTED", false);
+ Atom netNumDesktopsAtom = XInternAtom(*dpy_, "_NET_NUMBER_OF_DESKTOPS", false);
+ Atom netDesktopNamesAtom = XInternAtom(*dpy_, "_NET_DESKTOP_NAMES", false);
+ Atom XA_UTF8STRING = XInternAtom(*dpy_, "UTF8_STRING", false);
+ XChangeProperty(*dpy_, *root_, netSupportedAtom, XA_ATOM, 32, PropModeReplace, (unsigned char*)supported, 3);
+ XChangeProperty(*dpy_, *root_, netDesktopNamesAtom, XA_UTF8STRING, 8, PropModeReplace, (unsigned char*)&wsNames, wsNamesLen);
+ XChangeProperty(*dpy_, *root_, netNumDesktopsAtom, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&numDesktops, 1);
+
+
+}
+
+void updateClientList(std::map<int, Client> clients)
+{
+ Atom netClientList = XInternAtom(*dpy_, "_NET_CLIENT_LIST", false);
+ XDeleteProperty(*dpy_, *root_, netClientList);
+
+ std::map<int, Client>::iterator cItr;
+ for(cItr = clients.begin(); cItr != clients.end(); cItr++)
+ {
+ XChangeProperty(*dpy_, *root_, netClientList, XA_WINDOW, 32, PropModeAppend, (unsigned char*)&cItr->second.w, 1);
+ }
+
+}
+
+void setWindowDesktop(Window w, int desktop)
+{
+ unsigned long currDesktop = desktop - 1;
+ Atom netWMDesktop = XInternAtom(*dpy_, "_NET_WM_DESKTOP", false);
+ XChangeProperty(*dpy_, w, netWMDesktop, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&currDesktop, 1);
+}
+
+void setCurrentDesktop(int desktop)
+{
+ unsigned long currDesktop = desktop - 1;
+ Atom netCurrentDesktop = XInternAtom(*dpy_, "_NET_CURRENT_DESKTOP", false);
+ XChangeProperty(*dpy_, *root_, netCurrentDesktop, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&currDesktop, 1);
+}
+
+int getProp(Window w, char* propName, Atom* type, unsigned char** data)
+{
+ Atom prop_type = XInternAtom(*dpy_, propName, false);
+ int format;
+ unsigned long length;
+ unsigned long after;
+ int status = XGetWindowProperty(*dpy_, w, prop_type,
+ 0L, 1L, False,
+ AnyPropertyType, type, &format,
+ &length, &after, data);
+ return(status);
+}
diff --git a/ewmh.h b/ewmh.h
new file mode 100644
index 0000000..d7b0741
--- /dev/null
+++ b/ewmh.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <X11/X.h>
+#include <X11/Xatom.h>
+
+#include <map>
+#include <string>
+
+#include "structs.h"
+
+void initEWMH(Display** dpy, Window* root, int numWS, std::string workspaceNames[]);
+
+void updateClientList(std::map<int, Client> clients);
+
+void setWindowDesktop(Window w, int desktop);
+
+void setCurrentDesktop(int desktop);
+
+int getProp(Window w, char* propName, Atom* type, unsigned char** data);
diff --git a/logs.txt b/logs.txt
new file mode 100644
index 0000000..ff03f10
--- /dev/null
+++ b/logs.txt
@@ -0,0 +1,19 @@
+---
+Bars launched...
+Successfully wrote command 'quit' to PID 196086
+---
+Bars launched...
+Successfully wrote command 'quit' to PID 204881
+---
+Bars launched...
+Successfully wrote command 'quit' to PID 207764
+---
+Bars launched...
+---
+Bars launched...
+---
+Bars launched...
+Successfully wrote command 'quit' to PID 215833
+Successfully wrote command 'quit' to PID 215841
+---
+Bars launched...