/* static */
-static char config[128];
+static char prop[128];
static void
attachstack(Client *c) {
}
Bool
-loadconfig(Client *c) {
+loadprops(Client *c) {
unsigned int i;
Bool result = False;
XTextProperty name;
/* check if window has set a property */
name.nitems = 0;
- XGetTextProperty(dpy, c->win, &name, dwmconfig);
+ XGetTextProperty(dpy, c->win, &name, dwmprops);
if(name.nitems && name.encoding == XA_STRING) {
- strncpy(config, (char *)name.value, sizeof config - 1);
- config[sizeof config - 1] = '\0';
+ strncpy(prop, (char *)name.value, sizeof prop - 1);
+ prop[sizeof prop - 1] = '\0';
XFree(name.value);
- for(i = 0; i < ntags && i < sizeof config - 1 && config[i] != '\0'; i++)
- if((c->tags[i] = config[i] == '1'))
+ for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
+ if((c->tags[i] = prop[i] == '1'))
result = True;
- if(i < sizeof config - 1 && config[i] != '\0')
- c->isfloating = config[i] == '1';
+ if(i < sizeof prop - 1 && prop[i] != '\0')
+ c->isfloating = prop[i] == '1';
}
return result;
}
if(t)
for(i = 0; i < ntags; i++)
c->tags[i] = t->tags[i];
- if(!loadconfig(c))
+ if(!loadprops(c))
applyrules(c);
if(!c->isfloating)
c->isfloating = (rettrans == Success) || c->isfixed;
- saveconfig(c);
+ saveprops(c);
attach(c);
attachstack(c);
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
}
void
-saveconfig(Client *c) {
+saveprops(Client *c) {
unsigned int i;
- for(i = 0; i < ntags && i < sizeof config - 1; i++)
- config[i] = c->tags[i] ? '1' : '0';
- if(i < sizeof config - 1)
- config[i++] = c->isfloating ? '1' : '0';
- config[i] = '\0';
- XChangeProperty(dpy, c->win, dwmconfig, XA_STRING, 8,
- PropModeReplace, (unsigned char *)config, i);
+ for(i = 0; i < ntags && i < sizeof prop - 1; i++)
+ prop[i] = c->tags[i] ? '1' : '0';
+ if(i < sizeof prop - 1)
+ prop[i++] = c->isfloating ? '1' : '0';
+ prop[i] = '\0';
+ XChangeProperty(dpy, c->win, dwmprops, XA_STRING, 8,
+ PropModeReplace, (unsigned char *)prop, i);
}
void
# flags
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
LDFLAGS = -s ${LIBS}
-#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
-#LDFLAGS = -g ${LIBS}
+CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
+LDFLAGS = -g ${LIBS}
# Solaris
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
extern unsigned int bh, blw, bpos; /* bar height, bar layout label width, bar position */
extern unsigned int ntags, numlockmask; /* number of tags, numlock mask */
extern void (*handler[LASTEvent])(XEvent *); /* event handler */
-extern Atom dwmconfig, wmatom[WMLast], netatom[NetLast];
+extern Atom dwmprops, wmatom[WMLast], netatom[NetLast];
extern Bool selscreen, *seltags; /* seltags is array of Bool */
extern Client *clients, *sel, *stack; /* global client list and stack */
extern Cursor cursor[CurLast];
void detach(Client *c); /* detaches c from global client list */
void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */
void killclient(const char *arg); /* kill sel nicely */
-Bool loadconfig(Client *c); /* loads client properties */
+Bool loadprops(Client *c); /* loads client properties */
void manage(Window w, XWindowAttributes *wa); /* manage new client */
void resize(Client *c, int x, int y,
int w, int h, Bool sizehints); /* resize with given coordinates c*/
-void saveconfig(Client *c); /* saves client properties */
+void saveprops(Client *c); /* saves client properties */
void unban(Client *c); /* unbans c */
void unmanage(Client *c, long state); /* unmanage c */
void updatesizehints(Client *c); /* update the size hint variables of c */
Bool isfloating(void); /* returns True if floating layout is enabled */
Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */
void initlayouts(void); /* initialize layout array */
+void loaddwmprops(void); /* loads dwm properties */
Client *nexttiled(Client *c); /* returns tiled successor of c */
void restack(void); /* restores z layers of all clients */
+void savedwmprops(void); /* saves dwm properties */
void setlayout(const char *arg); /* sets layout, NULL means next layout */
void togglebar(const char *arg); /* shows/hides the bar */
void togglemax(const char *arg); /* toggles maximization of floating client */
/* See LICENSE file for copyright and license details. */
#include "dwm.h"
#include <stdlib.h>
+#include <string.h>
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
/* static */
} Layout;
unsigned int blw = 0;
+static char prop[128];
static unsigned int ltidx = 0; /* default */
static void
}
}
+void
+loaddwmprops(void) {
+ unsigned int i;
+ XTextProperty name;
+
+ /* check if window has set a property */
+ name.nitems = 0;
+ XGetTextProperty(dpy, root, &name, dwmprops);
+ if(name.nitems && name.encoding == XA_STRING) {
+ strncpy(prop, (char *)name.value, sizeof prop - 1);
+ prop[sizeof prop - 1] = '\0';
+ XFree(name.value);
+ for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
+ seltags[i] = prop[i] == '1';
+ if(i < sizeof prop - 1 && prop[i] != '\0') {
+ i = prop[i] - '0';
+ if(i < nlayouts)
+ ltidx = i;
+ }
+ }
+}
+
Client *
nexttiled(Client *c) {
for(; c && (c->isfloating || !isvisible(c)); c = c->next);
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
+void
+savedwmprops(void) {
+ unsigned int i;
+
+ for(i = 0; i < ntags && i < sizeof prop - 1; i++)
+ prop[i] = seltags[i] ? '1' : '0';
+ if(i < sizeof prop - 1)
+ prop[i++] = (char)ltidx;
+ prop[i] = '\0';
+ XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
+ PropModeReplace, (unsigned char *)prop, i);
+}
+
void
setlayout(const char *arg) {
int i;
arrange();
else
drawstatus();
+ savedwmprops();
}
void
unsigned int bh, ntags;
unsigned int bpos = BARPOS;
unsigned int numlockmask = 0;
-Atom dwmconfig, wmatom[WMLast], netatom[NetLast];
+Atom dwmprops, wmatom[WMLast], netatom[NetLast];
Bool *seltags;
Bool selscreen = True;
Client *clients = NULL;
XSetWindowAttributes wa;
/* init atoms */
- dwmconfig = XInternAtom(dpy, "_DWM_CONFIG", False);
+ dwmprops = XInternAtom(dpy, "_DWM_PROPERTIES", False);
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
XSetFont(dpy, dc.gc, dc.font.xfont->fid);
/* multihead support */
selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
+ loaddwmprops();
}
/*
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
-#include <X11/Xatom.h>
#include <X11/Xutil.h>
/* static */
i = idxoftag(arg);
if(i >= 0 && i < ntags)
sel->tags[i] = True;
- saveconfig(sel);
+ saveprops(sel);
arrange();
}
sel->isfloating = !sel->isfloating;
if(sel->isfloating) {
resize(sel, sel->x, sel->y, sel->w, sel->h, True);
- saveconfig(sel);
+ saveprops(sel);
}
arrange();
}
for(j = 0; j < ntags && !sel->tags[j]; j++);
if(j == ntags)
sel->tags[i] = True;
- saveconfig(sel);
+ saveprops(sel);
arrange();
}
for(j = 0; j < ntags && !seltags[j]; j++);
if(j == ntags)
seltags[i] = True; /* cannot toggle last view */
+ savedwmprops();
arrange();
}
i = idxoftag(arg);
if(i >= 0 && i < ntags)
seltags[i] = True;
+ savedwmprops();
arrange();
}