equal
deleted
inserted
replaced
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 |
7 typedef struct { |
10 typedef struct { |
8 const char *symbol; |
11 const char *symbol; |
9 void (*arrange)(void); |
12 void (*arrange)(void); |
10 } Layout; |
13 } Layout; |
11 |
14 |
12 unsigned int blw = 0; |
15 unsigned int blw = 0; |
|
16 static char prop[128]; |
13 static unsigned int ltidx = 0; /* default */ |
17 static unsigned int ltidx = 0; /* default */ |
14 |
18 |
15 static void |
19 static void |
16 floating(void) { /* default floating layout */ |
20 floating(void) { /* default floating layout */ |
17 Client *c; |
21 Client *c; |
98 nlayouts = sizeof layouts / sizeof layouts[0]; |
102 nlayouts = sizeof layouts / sizeof layouts[0]; |
99 for(blw = i = 0; i < nlayouts; i++) { |
103 for(blw = i = 0; i < nlayouts; i++) { |
100 w = textw(layouts[i].symbol); |
104 w = textw(layouts[i].symbol); |
101 if(w > blw) |
105 if(w > blw) |
102 blw = w; |
106 blw = w; |
|
107 } |
|
108 } |
|
109 |
|
110 void |
|
111 loaddwmprops(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 } |
103 } |
129 } |
104 } |
130 } |
105 |
131 |
106 Client * |
132 Client * |
107 nexttiled(Client *c) { |
133 nexttiled(Client *c) { |
137 XSync(dpy, False); |
163 XSync(dpy, False); |
138 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
164 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
139 } |
165 } |
140 |
166 |
141 void |
167 void |
|
168 savedwmprops(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 |
|
180 void |
142 setlayout(const char *arg) { |
181 setlayout(const char *arg) { |
143 int i; |
182 int i; |
144 |
183 |
145 if(!arg) { |
184 if(!arg) { |
146 if(++ltidx == nlayouts) |
185 if(++ltidx == nlayouts) |
154 } |
193 } |
155 if(sel) |
194 if(sel) |
156 arrange(); |
195 arrange(); |
157 else |
196 else |
158 drawstatus(); |
197 drawstatus(); |
|
198 savedwmprops(); |
159 } |
199 } |
160 |
200 |
161 void |
201 void |
162 togglebar(const char *arg) { |
202 togglebar(const char *arg) { |
163 if(bpos == BarOff) |
203 if(bpos == BarOff) |