X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=layout.c;h=2763d2c86c464331a694924ce87ea619a7d9f257;hb=96d7fe16eaf6b656800f08da3156bacd75ca3b08;hp=573de575c62934ac64ea928892867e8d195957dc;hpb=55d8dda9f45503f25804a9dbfeb4c878284a6576;p=dwm.git diff --git a/layout.c b/layout.c index 573de57..2763d2c 100644 --- a/layout.c +++ b/layout.c @@ -1,6 +1,9 @@ /* See LICENSE file for copyright and license details. */ #include "dwm.h" #include +#include +#include +#include /* static */ @@ -10,7 +13,8 @@ typedef struct { } 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 */ @@ -36,7 +40,7 @@ arrange(void) { unban(c); else ban(c); - layouts[sellayout].arrange(); + layouts[ltidx].arrange(); focus(NULL); restack(); } @@ -76,25 +80,24 @@ focusprev(const char *arg) { 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); @@ -103,6 +106,20 @@ initlayouts(void) { } } +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); @@ -139,23 +156,37 @@ restack(void) { } 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