Skip to content

Commit

Permalink
feat: properly implemented EWMH for workspaces and desktops
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-clarke committed Nov 11, 2024
1 parent 09fe1fb commit 833dba4
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

include config.mk

SRC = draw.c atlas.c util.c layouts.c configurer.c ipc.c windows.c events.c ewmh.c input.c focus.c monitor.c client.c actions.c
SRC = draw.c atlas.c util.c layouts.c configurer.c ipc.c windows.c events.c input.c focus.c monitor.c client.c actions.c
OBJ = ${SRC:.c=.o}

all: atlaswm
Expand Down
3 changes: 3 additions & 0 deletions actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void toggletag(const Arg *arg) {
focus(NULL);
arrange(selectedMonitor);
}
updateCurrentDesktop();
}

void toggleview(const Arg *arg) {
Expand All @@ -153,6 +154,7 @@ void toggleview(const Arg *arg) {
focus(NULL);
arrange(selectedMonitor);
}
updateCurrentDesktop();
}

void view(const Arg *arg) {
Expand All @@ -165,6 +167,7 @@ void view(const Arg *arg) {
arg->ui & WORKSPACEMASK;
focus(NULL);
arrange(selectedMonitor);
updateCurrentDesktop();
}

void zoom(const Arg *arg) {
Expand Down
28 changes: 23 additions & 5 deletions atlas.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ void startupPrograms() {
void setup(void) {
XSetWindowAttributes wa;
struct sigaction sa;
Atom utf8string;

// Load configuration
char config_path[256];
Expand Down Expand Up @@ -283,21 +284,32 @@ void setup(void) {
netatom[NetWMWindowTypeDialog] =
XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
netatom[NetDesktopViewport] =
XInternAtom(dpy, "_NET_DESKTOP_VIEWPORT", False);
netatom[NetNumberOfDesktops] =
XInternAtom(dpy, "_NET_NUMBER_OF_DESKTOPS", False);
netatom[NetCurrentDesktop] = XInternAtom(dpy, "_NET_CURRENT_DESKTOP", False);
netatom[NetDesktopNames] = XInternAtom(dpy, "_NET_DESKTOP_NAMES", False);
/* init cursors */
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
setup_ipc(dpy);
Window check = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0);
XChangeProperty(dpy, check, netatom[NetWMName], XA_STRING, 8, PropModeReplace,
(unsigned char *)"AtlasWM", 7);
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
XChangeProperty(dpy, check, netatom[NetWMName], utf8string, 8,
PropModeReplace, (unsigned char *)"AtlasWM", 7);
XChangeProperty(dpy, check, netatom[NetWMCheck], XA_WINDOW, 32,
PropModeReplace, (unsigned char *)&check, 1);
XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32,
PropModeReplace, (unsigned char *)&check, 1);

XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
PropModeReplace, (unsigned char *)netatom, NetLast);
setNumDesktops();
setCurrentDesktop();
setDesktopNames();
setViewport();
XDeleteProperty(dpy, root, netatom[NetClientList]);
/* select events */
wa.cursor = cursor[CurNormal]->cursor;
Expand Down Expand Up @@ -344,9 +356,15 @@ int xerror(Display *dpy, XErrorEvent *ee) {
(ee->request_code == X_GrabKey && ee->error_code == BadAccess) ||
(ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
return 0;
LOG_ERROR("Xerror: request_code=%d, error_code=%d", ee->request_code,
ee->error_code);
return xerrorxlib(dpy, ee); /* may call exit */

char error_text[1024];
XGetErrorText(dpy, ee->error_code, error_text, sizeof(error_text));

LOG_ERROR("X Error: request=%d error=%d (%s) resourceid=%lu serial=%lu",
ee->request_code, ee->error_code, error_text, ee->resourceid,
ee->serial);

return xerrorxlib(dpy, ee);
}

int xerrordummy(Display *dpy, XErrorEvent *ee) { return 0; }
Expand Down
12 changes: 9 additions & 3 deletions atlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ enum {
NetWMWindowType,
NetWMWindowTypeDialog,
NetClientList,
NetDesktopNames,
NetDesktopViewport,
NetNumberOfDesktops,
NetCurrentDesktop,
NetLast
};

Expand Down Expand Up @@ -325,9 +329,11 @@ int xerror(Display *dpy, XErrorEvent *ee);
int xerrordummy(Display *dpy, XErrorEvent *ee);
int xerrorstart(Display *dpy, XErrorEvent *ee);

/* EWMH Functions */
void ewmh_update_client_list(void);
void ewmh_update_active_window(void);
void setCurrentDesktop(void);
void setDesktopNames(void);
void setNumDesktops(void);
void setViewport(void);
void updateCurrentDesktop(void);

/* External Variables */
extern Display *dpy;
Expand Down
6 changes: 6 additions & 0 deletions configurer.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "configurer.h" // Includes "atlas.h"
#include "atlas.h"
#include "util.h"
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -358,6 +359,11 @@ void update_window_manager_state(void) {
m->numMasterWindows = cfg.numMasterWindows;
}

setNumDesktops();
setCurrentDesktop();
setDesktopNames();
setViewport();

// Rearrange all monitors to apply gap changes and new layouts
arrange(NULL);

Expand Down
41 changes: 0 additions & 41 deletions ewmh.c

This file was deleted.

17 changes: 0 additions & 17 deletions test.sh

This file was deleted.

43 changes: 43 additions & 0 deletions windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,46 @@ int gettextprop(Window w, Atom atom, char *text, unsigned int size) {
XFree(name.value);
return 1;
}

void setCurrentDesktop(void) {
long data[] = {0};
XChangeProperty(dpy, root, netatom[NetCurrentDesktop], XA_CARDINAL, 32,
PropModeReplace, (unsigned char *)data, 1);
}
void setDesktopNames(void) {
XTextProperty text;
// Create list of workspace names
char **list = ecalloc(cfg.workspaceCount, sizeof(char *));
for (size_t i = 0; i < cfg.workspaceCount; i++) {
list[i] = strdup(cfg.workspaces[i].name);
}

// Convert list to text property
Xutf8TextListToTextProperty(dpy, list, cfg.workspaceCount, XUTF8StringStyle,
&text);
XSetTextProperty(dpy, root, &text, netatom[NetDesktopNames]);
}

void setNumDesktops(void) {
long data[] = {cfg.workspaceCount};
XChangeProperty(dpy, root, netatom[NetNumberOfDesktops], XA_CARDINAL, 32,
PropModeReplace, (unsigned char *)data, 1);
}

void setViewport(void) {
long data[] = {0, 0};
XChangeProperty(dpy, root, netatom[NetDesktopViewport], XA_CARDINAL, 32,
PropModeReplace, (unsigned char *)data, 2);
}

void updateCurrentDesktop(void) {
long rawdata[] = {
selectedMonitor->workspaceset[selectedMonitor->selectedWorkspaces]};
int i = 0;
while (*rawdata >> (i + 1)) {
i++;
}
long data[] = {i};
XChangeProperty(dpy, root, netatom[NetCurrentDesktop], XA_CARDINAL, 32,
PropModeReplace, (unsigned char *)data, 1);
}

0 comments on commit 833dba4

Please sign in to comment.