summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client.c38
-rw-r--r--config.mk4
-rw-r--r--dwm.h8
-rw-r--r--layout.c40
-rw-r--r--main.c5
-rw-r--r--tag.c10
6 files changed, 74 insertions, 31 deletions
diff --git a/client.c b/client.c
index 882b8ee..d11ef7f 100644
--- a/client.c
+++ b/client.c
@@ -7,7 +7,7 @@
7 7
8/* static */ 8/* static */
9 9
10static char config[128]; 10static char prop[128];
11 11
12static void 12static void
13attachstack(Client *c) { 13attachstack(Client *c) {
@@ -182,23 +182,23 @@ killclient(const char *arg) {
182} 182}
183 183
184Bool 184Bool
185loadconfig(Client *c) { 185loadprops(Client *c) {
186 unsigned int i; 186 unsigned int i;
187 Bool result = False; 187 Bool result = False;
188 XTextProperty name; 188 XTextProperty name;
189 189
190 /* check if window has set a property */ 190 /* check if window has set a property */
191 name.nitems = 0; 191 name.nitems = 0;
192 XGetTextProperty(dpy, c->win, &name, dwmconfig); 192 XGetTextProperty(dpy, c->win, &name, dwmprops);
193 if(name.nitems && name.encoding == XA_STRING) { 193 if(name.nitems && name.encoding == XA_STRING) {
194 strncpy(config, (char *)name.value, sizeof config - 1); 194 strncpy(prop, (char *)name.value, sizeof prop - 1);
195 config[sizeof config - 1] = '\0'; 195 prop[sizeof prop - 1] = '\0';
196 XFree(name.value); 196 XFree(name.value);
197 for(i = 0; i < ntags && i < sizeof config - 1 && config[i] != '\0'; i++) 197 for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
198 if((c->tags[i] = config[i] == '1')) 198 if((c->tags[i] = prop[i] == '1'))
199 result = True; 199 result = True;
200 if(i < sizeof config - 1 && config[i] != '\0') 200 if(i < sizeof prop - 1 && prop[i] != '\0')
201 c->isfloating = config[i] == '1'; 201 c->isfloating = prop[i] == '1';
202 } 202 }
203 return result; 203 return result;
204} 204}
@@ -249,11 +249,11 @@ manage(Window w, XWindowAttributes *wa) {
249 if(t) 249 if(t)
250 for(i = 0; i < ntags; i++) 250 for(i = 0; i < ntags; i++)
251 c->tags[i] = t->tags[i]; 251 c->tags[i] = t->tags[i];
252 if(!loadconfig(c)) 252 if(!loadprops(c))
253 applyrules(c); 253 applyrules(c);
254 if(!c->isfloating) 254 if(!c->isfloating)
255 c->isfloating = (rettrans == Success) || c->isfixed; 255 c->isfloating = (rettrans == Success) || c->isfixed;
256 saveconfig(c); 256 saveprops(c);
257 attach(c); 257 attach(c);
258 attachstack(c); 258 attachstack(c);
259 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */ 259 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
@@ -325,16 +325,16 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
325} 325}
326 326
327void 327void
328saveconfig(Client *c) { 328saveprops(Client *c) {
329 unsigned int i; 329 unsigned int i;
330 330
331 for(i = 0; i < ntags && i < sizeof config - 1; i++) 331 for(i = 0; i < ntags && i < sizeof prop - 1; i++)
332 config[i] = c->tags[i] ? '1' : '0'; 332 prop[i] = c->tags[i] ? '1' : '0';
333 if(i < sizeof config - 1) 333 if(i < sizeof prop - 1)
334 config[i++] = c->isfloating ? '1' : '0'; 334 prop[i++] = c->isfloating ? '1' : '0';
335 config[i] = '\0'; 335 prop[i] = '\0';
336 XChangeProperty(dpy, c->win, dwmconfig, XA_STRING, 8, 336 XChangeProperty(dpy, c->win, dwmprops, XA_STRING, 8,
337 PropModeReplace, (unsigned char *)config, i); 337 PropModeReplace, (unsigned char *)prop, i);
338} 338}
339 339
340void 340void
diff --git a/config.mk b/config.mk
index 320aea1..682bb41 100644
--- a/config.mk
+++ b/config.mk
@@ -20,8 +20,8 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
20# flags 20# flags
21CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" 21CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
22LDFLAGS = -s ${LIBS} 22LDFLAGS = -s ${LIBS}
23#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" 23CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
24#LDFLAGS = -g ${LIBS} 24LDFLAGS = -g ${LIBS}
25 25
26# Solaris 26# Solaris
27#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" 27#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
diff --git a/dwm.h b/dwm.h
index fde6b96..9dd764f 100644
--- a/dwm.h
+++ b/dwm.h
@@ -81,7 +81,7 @@ extern int wax, way, wah, waw; /* windowarea geometry */
81extern unsigned int bh, blw, bpos; /* bar height, bar layout label width, bar position */ 81extern unsigned int bh, blw, bpos; /* bar height, bar layout label width, bar position */
82extern unsigned int ntags, numlockmask; /* number of tags, numlock mask */ 82extern unsigned int ntags, numlockmask; /* number of tags, numlock mask */
83extern void (*handler[LASTEvent])(XEvent *); /* event handler */ 83extern void (*handler[LASTEvent])(XEvent *); /* event handler */
84extern Atom dwmconfig, wmatom[WMLast], netatom[NetLast]; 84extern Atom dwmprops, wmatom[WMLast], netatom[NetLast];
85extern Bool selscreen, *seltags; /* seltags is array of Bool */ 85extern Bool selscreen, *seltags; /* seltags is array of Bool */
86extern Client *clients, *sel, *stack; /* global client list and stack */ 86extern Client *clients, *sel, *stack; /* global client list and stack */
87extern Cursor cursor[CurLast]; 87extern Cursor cursor[CurLast];
@@ -96,11 +96,11 @@ void configure(Client *c); /* send synthetic configure event */
96void detach(Client *c); /* detaches c from global client list */ 96void detach(Client *c); /* detaches c from global client list */
97void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */ 97void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */
98void killclient(const char *arg); /* kill sel nicely */ 98void killclient(const char *arg); /* kill sel nicely */
99Bool loadconfig(Client *c); /* loads client properties */ 99Bool loadprops(Client *c); /* loads client properties */
100void manage(Window w, XWindowAttributes *wa); /* manage new client */ 100void manage(Window w, XWindowAttributes *wa); /* manage new client */
101void resize(Client *c, int x, int y, 101void resize(Client *c, int x, int y,
102 int w, int h, Bool sizehints); /* resize with given coordinates c*/ 102 int w, int h, Bool sizehints); /* resize with given coordinates c*/
103void saveconfig(Client *c); /* saves client properties */ 103void saveprops(Client *c); /* saves client properties */
104void unban(Client *c); /* unbans c */ 104void unban(Client *c); /* unbans c */
105void unmanage(Client *c, long state); /* unmanage c */ 105void unmanage(Client *c, long state); /* unmanage c */
106void updatesizehints(Client *c); /* update the size hint variables of c */ 106void updatesizehints(Client *c); /* update the size hint variables of c */
@@ -122,8 +122,10 @@ const char *getsymbol(void); /* returns symbol of enabled layout */
122Bool isfloating(void); /* returns True if floating layout is enabled */ 122Bool isfloating(void); /* returns True if floating layout is enabled */
123Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */ 123Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */
124void initlayouts(void); /* initialize layout array */ 124void initlayouts(void); /* initialize layout array */
125void loaddwmprops(void); /* loads dwm properties */
125Client *nexttiled(Client *c); /* returns tiled successor of c */ 126Client *nexttiled(Client *c); /* returns tiled successor of c */
126void restack(void); /* restores z layers of all clients */ 127void restack(void); /* restores z layers of all clients */
128void savedwmprops(void); /* saves dwm properties */
127void setlayout(const char *arg); /* sets layout, NULL means next layout */ 129void setlayout(const char *arg); /* sets layout, NULL means next layout */
128void togglebar(const char *arg); /* shows/hides the bar */ 130void togglebar(const char *arg); /* shows/hides the bar */
129void togglemax(const char *arg); /* toggles maximization of floating client */ 131void togglemax(const char *arg); /* toggles maximization of floating client */
diff --git a/layout.c b/layout.c
index 030c282..aa3bff5 100644
--- a/layout.c
+++ b/layout.c
@@ -1,6 +1,9 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2#include "dwm.h" 2#include "dwm.h"
3#include <stdlib.h> 3#include <stdlib.h>
4#include <string.h>
5#include <X11/Xatom.h>
6#include <X11/Xutil.h>
4 7
5/* static */ 8/* static */
6 9
@@ -10,6 +13,7 @@ typedef struct {
10} Layout; 13} Layout;
11 14
12unsigned int blw = 0; 15unsigned int blw = 0;
16static char prop[128];
13static unsigned int ltidx = 0; /* default */ 17static unsigned int ltidx = 0; /* default */
14 18
15static void 19static void
@@ -103,6 +107,28 @@ initlayouts(void) {
103 } 107 }
104} 108}
105 109
110void
111loaddwmprops(void) {
112 unsigned int i;
113 XTextProperty name;
114
115 /* check if window has set a property */
116 name.nitems = 0;
117 XGetTextProperty(dpy, root, &name, dwmprops);
118 if(name.nitems && name.encoding == XA_STRING) {
119 strncpy(prop, (char *)name.value, sizeof prop - 1);
120 prop[sizeof prop - 1] = '\0';
121 XFree(name.value);
122 for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
123 seltags[i] = prop[i] == '1';
124 if(i < sizeof prop - 1 && prop[i] != '\0') {
125 i = prop[i] - '0';
126 if(i < nlayouts)
127 ltidx = i;
128 }
129 }
130}
131
106Client * 132Client *
107nexttiled(Client *c) { 133nexttiled(Client *c) {
108 for(; c && (c->isfloating || !isvisible(c)); c = c->next); 134 for(; c && (c->isfloating || !isvisible(c)); c = c->next);
@@ -139,6 +165,19 @@ restack(void) {
139} 165}
140 166
141void 167void
168savedwmprops(void) {
169 unsigned int i;
170
171 for(i = 0; i < ntags && i < sizeof prop - 1; i++)
172 prop[i] = seltags[i] ? '1' : '0';
173 if(i < sizeof prop - 1)
174 prop[i++] = (char)ltidx;
175 prop[i] = '\0';
176 XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
177 PropModeReplace, (unsigned char *)prop, i);
178}
179
180void
142setlayout(const char *arg) { 181setlayout(const char *arg) {
143 int i; 182 int i;
144 183
@@ -156,6 +195,7 @@ setlayout(const char *arg) {
156 arrange(); 195 arrange();
157 else 196 else
158 drawstatus(); 197 drawstatus();
198 savedwmprops();
159} 199}
160 200
161void 201void
diff --git a/main.c b/main.c
index 0ae288c..7cc5ecf 100644
--- a/main.c
+++ b/main.c
@@ -20,7 +20,7 @@ int screen, sx, sy, sw, sh, wax, way, waw, wah;
20unsigned int bh, ntags; 20unsigned int bh, ntags;
21unsigned int bpos = BARPOS; 21unsigned int bpos = BARPOS;
22unsigned int numlockmask = 0; 22unsigned int numlockmask = 0;
23Atom dwmconfig, wmatom[WMLast], netatom[NetLast]; 23Atom dwmprops, wmatom[WMLast], netatom[NetLast];
24Bool *seltags; 24Bool *seltags;
25Bool selscreen = True; 25Bool selscreen = True;
26Client *clients = NULL; 26Client *clients = NULL;
@@ -140,7 +140,7 @@ setup(void) {
140 XSetWindowAttributes wa; 140 XSetWindowAttributes wa;
141 141
142 /* init atoms */ 142 /* init atoms */
143 dwmconfig = XInternAtom(dpy, "_DWM_CONFIG", False); 143 dwmprops = XInternAtom(dpy, "_DWM_PROPERTIES", False);
144 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); 144 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
145 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); 145 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
146 wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False); 146 wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
@@ -205,6 +205,7 @@ setup(void) {
205 XSetFont(dpy, dc.gc, dc.font.xfont->fid); 205 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
206 /* multihead support */ 206 /* multihead support */
207 selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 207 selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
208 loaddwmprops();
208} 209}
209 210
210/* 211/*
diff --git a/tag.c b/tag.c
index 1dd542b..685308a 100644
--- a/tag.c
+++ b/tag.c
@@ -3,8 +3,6 @@
3#include <regex.h> 3#include <regex.h>
4#include <stdio.h> 4#include <stdio.h>
5#include <stdlib.h> 5#include <stdlib.h>
6#include <string.h>
7#include <X11/Xatom.h>
8#include <X11/Xutil.h> 6#include <X11/Xutil.h>
9 7
10/* static */ 8/* static */
@@ -118,7 +116,7 @@ tag(const char *arg) {
118 i = idxoftag(arg); 116 i = idxoftag(arg);
119 if(i >= 0 && i < ntags) 117 if(i >= 0 && i < ntags)
120 sel->tags[i] = True; 118 sel->tags[i] = True;
121 saveconfig(sel); 119 saveprops(sel);
122 arrange(); 120 arrange();
123} 121}
124 122
@@ -129,7 +127,7 @@ togglefloating(const char *arg) {
129 sel->isfloating = !sel->isfloating; 127 sel->isfloating = !sel->isfloating;
130 if(sel->isfloating) { 128 if(sel->isfloating) {
131 resize(sel, sel->x, sel->y, sel->w, sel->h, True); 129 resize(sel, sel->x, sel->y, sel->w, sel->h, True);
132 saveconfig(sel); 130 saveprops(sel);
133 } 131 }
134 arrange(); 132 arrange();
135} 133}
@@ -145,7 +143,7 @@ toggletag(const char *arg) {
145 for(j = 0; j < ntags && !sel->tags[j]; j++); 143 for(j = 0; j < ntags && !sel->tags[j]; j++);
146 if(j == ntags) 144 if(j == ntags)
147 sel->tags[i] = True; 145 sel->tags[i] = True;
148 saveconfig(sel); 146 saveprops(sel);
149 arrange(); 147 arrange();
150} 148}
151 149
@@ -158,6 +156,7 @@ toggleview(const char *arg) {
158 for(j = 0; j < ntags && !seltags[j]; j++); 156 for(j = 0; j < ntags && !seltags[j]; j++);
159 if(j == ntags) 157 if(j == ntags)
160 seltags[i] = True; /* cannot toggle last view */ 158 seltags[i] = True; /* cannot toggle last view */
159 savedwmprops();
161 arrange(); 160 arrange();
162} 161}
163 162
@@ -170,5 +169,6 @@ view(const char *arg) {
170 i = idxoftag(arg); 169 i = idxoftag(arg);
171 if(i >= 0 && i < ntags) 170 if(i >= 0 && i < ntags)
172 seltags[i] = True; 171 seltags[i] = True;
172 savedwmprops();
173 arrange(); 173 arrange();
174} 174}