/* 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 unsigned int sellayout = 0; /* default */
+static char prop[128];
+static unsigned int ltidx = 0; /* default */
static void
floating(void) { /* default floating layout */
unban(c);
else
ban(c);
- layouts[sellayout].arrange();
+ layouts[ltidx].arrange();
focus(NULL);
restack();
}
const char *
getsymbol(void)
{
- return layouts[sellayout].symbol;
+ return layouts[ltidx].symbol;
}
Bool
isfloating(void) {
- return layouts[sellayout].arrange == floating;
+ return layouts[ltidx].arrange == floating;
}
Bool
isarrange(void (*func)())
{
- return func == layouts[sellayout].arrange;
+ return func == layouts[ltidx].arrange;
}
void
initlayouts(void) {
unsigned int i, w;
- /* TODO deserialize sellayout if present */
nlayouts = sizeof layouts / sizeof layouts[0];
for(blw = i = 0; i < nlayouts; i++) {
w = textw(layouts[i].symbol);
}
}
+void
+loaddwmprops(void) {
+ unsigned int i;
+
+ if(gettextprop(root, dwmprops, prop, sizeof prop)) {
+ 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') {
+ if(prop[i] < nlayouts)
+ ltidx = prop[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;
if(!arg) {
- if(++sellayout == nlayouts)
- sellayout = 0;;
+ if(++ltidx == nlayouts)
+ ltidx = 0;;
}
else {
i = atoi(arg);
if(i < 0 || i >= nlayouts)
return;
- sellayout = i;
+ ltidx = i;
}
if(sel)
arrange();
else
drawstatus();
+ savedwmprops();
}
void