summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--util/fbsetroot.cc212
-rw-r--r--util/fbsetroot.hh6
3 files changed, 99 insertions, 121 deletions
diff --git a/ChangeLog b/ChangeLog
index 3d9e9d3..2c6bc8d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
1 (Format: Year/Month/Day) 1 (Format: Year/Month/Day)
2Changes for 1.0rc2: 2Changes for 1.0rc2:
3*06/06/29: 3*06/06/29:
4 * Make fbsetroot set one screen at a time (Mark)
5 util/fbsetroot.cc/hh
4 * Fix fbsetroot segfault when DISPLAY is unset (Mark) 6 * Fix fbsetroot segfault when DISPLAY is unset (Mark)
5 util/fbsetroot.cc 7 util/fbsetroot.cc
6*06/06/28: 8*06/06/28:
diff --git a/util/fbsetroot.cc b/util/fbsetroot.cc
index 24d8c50..e5ae64c 100644
--- a/util/fbsetroot.cc
+++ b/util/fbsetroot.cc
@@ -55,18 +55,16 @@ using namespace std;
55fbsetroot::fbsetroot(int argc, char **argv, char *dpy_name) 55fbsetroot::fbsetroot(int argc, char **argv, char *dpy_name)
56 : FbTk::App(dpy_name), m_app_name(argv[0]) { 56 : FbTk::App(dpy_name), m_app_name(argv[0]) {
57 57
58 pixmaps = (Pixmap *) 0; 58 pixmap = (Pixmap *) 0;
59 screen = DefaultScreen(FbTk::App::instance()->display());
59 grad = fore = back = (char *) 0; 60 grad = fore = back = (char *) 0;
60 61
61 bool mod = false, sol = false, grd = false; 62 bool mod = false, sol = false, grd = false;
62 int mod_x = 0, mod_y = 0, i = 0; 63 int mod_x = 0, mod_y = 0, i = 1;
63 64
64 img_ctrl = new FbTk::ImageControl*[ScreenCount(display())]; 65 img_ctrl = new FbTk::ImageControl(screen);
65 for (; i < ScreenCount(display()); i++) {
66 img_ctrl[i] = new FbTk::ImageControl(i, true);
67 }
68 66
69 for (i = 1; i < argc; i++) { 67 for (; i < argc; i++) {
70 if (! strcmp("-help", argv[i])) { 68 if (! strcmp("-help", argv[i])) {
71 usage(); 69 usage();
72 70
@@ -127,8 +125,6 @@ fbsetroot::fbsetroot(int argc, char **argv, char *dpy_name)
127 exit(2); 125 exit(2);
128 } 126 }
129 127
130 num_screens = ScreenCount(display());
131
132 if (sol && fore) 128 if (sol && fore)
133 solid(); 129 solid();
134 else if (mod && mod_x && mod_y && fore && back) 130 else if (mod && mod_x && mod_y && fore && back)
@@ -144,18 +140,13 @@ fbsetroot::fbsetroot(int argc, char **argv, char *dpy_name)
144fbsetroot::~fbsetroot() { 140fbsetroot::~fbsetroot() {
145 XKillClient(display(), AllTemporary); 141 XKillClient(display(), AllTemporary);
146 142
147 if (pixmaps) { // should always be true 143 if (pixmap) { // should always be true
148 XSetCloseDownMode(display(), RetainTemporary); 144 XSetCloseDownMode(display(), RetainTemporary);
149 145
150 delete [] pixmaps; 146 delete pixmap;
151 } 147 }
152 148
153 if (img_ctrl != 0) { 149 delete img_ctrl;
154 for (int i=0; i < num_screens; i++)
155 delete img_ctrl[i];
156
157 delete [] img_ctrl;
158 }
159} 150}
160 151
161/** 152/**
@@ -209,34 +200,27 @@ void fbsetroot::setRootAtoms(Pixmap pixmap, int screen) {
209 Draws pixmaps with a single color 200 Draws pixmaps with a single color
210*/ 201*/
211void fbsetroot::solid() { 202void fbsetroot::solid() {
212 register int screen = 0; 203 FbTk::Color c(fore, screen);
213 204 if (! c.isAllocated())
214 pixmaps = new Pixmap[ScreenCount(display())]; 205 c.setPixel(BlackPixel(display(), screen));
215
216 for (; screen < ScreenCount(display()); screen++) {
217 206
218 FbTk::Color c(fore, screen); 207 FbRootWindow root(screen);
219 if (! c.isAllocated())
220 c.setPixel(BlackPixel(display(), screen));
221
222 FbRootWindow root(screen);
223 208
224 FbTk::GContext gc(root); 209 FbTk::GContext gc(root);
225 gc.setForeground(c); 210 gc.setForeground(c);
226 211
227 pixmaps[screen] = XCreatePixmap(display(), 212 pixmap = new Pixmap(XCreatePixmap(display(),
228 root.window(), 213 root.window(),
229 root.width(), root.height(), 214 root.width(), root.height(),
230 root.depth()); 215 root.depth()));
231 216
232 XFillRectangle(display(), pixmaps[screen], gc.gc(), 0, 0, 217 XFillRectangle(display(), *pixmap, gc.gc(), 0, 0,
233 root.width(), root.height()); 218 root.width(), root.height());
234 219
235 setRootAtoms(pixmaps[screen], screen); 220 setRootAtoms(*pixmap, screen);
236 221
237 root.setBackgroundPixmap(pixmaps[screen]); 222 root.setBackgroundPixmap(*pixmap);
238 root.clear(); 223 root.clear();
239 }
240} 224}
241 225
242/** 226/**
@@ -245,77 +229,73 @@ void fbsetroot::solid() {
245*/ 229*/
246void fbsetroot::modula(int x, int y) { 230void fbsetroot::modula(int x, int y) {
247 char data[32]; 231 char data[32];
248 long pattern; 232 long pattern = 0;
249 233
250 register int screen, i; 234 register int i;
251 235
252 pixmaps = new Pixmap[ScreenCount(display())]; 236 FbRootWindow root(screen);
253
254 for (pattern = 0, screen = 0; screen < ScreenCount(display()); screen++) {
255 FbRootWindow root(screen);
256 237
257 for (i = 0; i < 16; i++) { 238 for (i = 0; i < 16; i++) {
258 pattern <<= 1; 239 pattern <<= 1;
259 if ((i % x) == 0) 240 if ((i % x) == 0)
260 pattern |= 0x0001; 241 pattern |= 0x0001;
261 } 242 }
262 243
263 for (i = 0; i < 16; i++) { 244 for (i = 0; i < 16; i++) {
264 if ((i % y) == 0) { 245 if ((i % y) == 0) {
265 data[(i * 2)] = (char) 0xff; 246 data[(i * 2)] = (char) 0xff;
266 data[(i * 2) + 1] = (char) 0xff; 247 data[(i * 2) + 1] = (char) 0xff;
267 } else { 248 } else {
268 data[(i * 2)] = pattern & 0xff; 249 data[(i * 2)] = pattern & 0xff;
269 data[(i * 2) + 1] = (pattern >> 8) & 0xff; 250 data[(i * 2) + 1] = (pattern >> 8) & 0xff;
270 }
271 } 251 }
252 }
272 253
273 254
274 Pixmap bitmap, r_bitmap; 255 Pixmap bitmap, r_bitmap;
275 256
276 257
277 bitmap = XCreateBitmapFromData(display(), 258 bitmap = XCreateBitmapFromData(display(),
278 root.window(), data, 16, 16); 259 root.window(), data, 16, 16);
279 260
280 // bitmap used as tile, needs to have the same depth as background pixmap 261 // bitmap used as tile, needs to have the same depth as background pixmap
281 r_bitmap = XCreatePixmap(display(), 262 r_bitmap = XCreatePixmap(display(),
282 root.window(), 16, 16, 263 root.window(), 16, 16,
283 root.depth()); 264 root.depth());
284 265
285 FbTk::Color f(fore, screen), b(back, screen); 266 FbTk::Color f(fore, screen), b(back, screen);
286 267
287 if (! f.isAllocated()) 268 if (! f.isAllocated())
288 f.setPixel(WhitePixel(display(), screen)); 269 f.setPixel(WhitePixel(display(), screen));
289 if (! b.isAllocated()) 270 if (! b.isAllocated())
290 b.setPixel(BlackPixel(display(), screen)); 271 b.setPixel(BlackPixel(display(), screen));
291 272
292 FbTk::GContext gc(root); 273 FbTk::GContext gc(root);
293 274
294 gc.setForeground(f); 275 gc.setForeground(f);
295 gc.setBackground(b); 276 gc.setBackground(b);
296 277
297 // copying bitmap to the one going to be used as tile 278 // copying bitmap to the one going to be used as tile
298 XCopyPlane(display(), bitmap, r_bitmap, gc.gc(), 279 XCopyPlane(display(), bitmap, r_bitmap, gc.gc(),
299 0, 0, 16, 16, 0, 0, 1l); 280 0, 0, 16, 16, 0, 0, 1l);
300 281
301 gc.setTile(r_bitmap); 282 gc.setTile(r_bitmap);
302 gc.setFillStyle(FillTiled); 283 gc.setFillStyle(FillTiled);
303 284
304 pixmaps[screen] = XCreatePixmap(display(), 285 pixmap = new Pixmap(XCreatePixmap(display(),
305 root.window(), 286 root.window(),
306 root.width(), root.height(), 287 root.width(), root.height(),
307 root.depth()); 288 root.depth()));
308 289
309 XFillRectangle(display(), pixmaps[screen], gc.gc(), 0, 0, 290 XFillRectangle(display(), *pixmap, gc.gc(), 0, 0,
310 root.width(), root.height()); 291 root.width(), root.height());
311 292
312 setRootAtoms(pixmaps[screen], screen); 293 setRootAtoms(*pixmap, screen);
313 root.setBackgroundPixmap(pixmaps[screen]); 294 root.setBackgroundPixmap(*pixmap);
314 root.clear(); 295 root.clear();
315 296
316 XFreePixmap(display(), bitmap); 297 XFreePixmap(display(), bitmap);
317 XFreePixmap(display(), r_bitmap); 298 XFreePixmap(display(), r_bitmap);
318 }
319} 299}
320 300
321/** 301/**
@@ -326,52 +306,48 @@ void fbsetroot::gradient() {
326 // get crashed somewhere on the way causing apps like XChat chrashing 306 // get crashed somewhere on the way causing apps like XChat chrashing
327 // as the pixmap has been destroyed 307 // as the pixmap has been destroyed
328 Pixmap tmp; 308 Pixmap tmp;
329 pixmaps = new Pixmap[ScreenCount(display())];
330 // we must insert gradient text 309 // we must insert gradient text
331 string texture_value = grad ? grad : "solid"; 310 string texture_value = grad ? grad : "solid";
332 texture_value.insert(0, "gradient "); 311 texture_value.insert(0, "gradient ");
333 FbTk::Texture texture; 312 FbTk::Texture texture;
334 texture.setFromString(texture_value.c_str()); 313 texture.setFromString(texture_value.c_str());
335
336 for (int screen = 0; screen < ScreenCount(display()); screen++) {
337 FbRootWindow root(screen);
338 314
315 FbRootWindow root(screen);
339 316
340 FbTk::GContext gc(root);
341 texture.color().setFromString(fore, screen);
342 texture.colorTo().setFromString(back, screen);
343 317
318 FbTk::GContext gc(root);
319 texture.color().setFromString(fore, screen);
320 texture.colorTo().setFromString(back, screen);
344 321
345 if (! texture.color().isAllocated())
346 texture.color().setPixel(WhitePixel(display(), screen));
347 322
348 if (! texture.colorTo().isAllocated()) 323 if (! texture.color().isAllocated())
349 texture.colorTo().setPixel(BlackPixel(display(), screen)); 324 texture.color().setPixel(WhitePixel(display(), screen));
350 325
351 tmp = img_ctrl[screen]->renderImage(root.width(), root.height(), 326 if (! texture.colorTo().isAllocated())
352 texture); 327 texture.colorTo().setPixel(BlackPixel(display(), screen));
353 328
354 pixmaps[screen] = XCreatePixmap(display(), 329 tmp = img_ctrl->renderImage(root.width(), root.height(), texture);
355 root.window(),
356 root.width(), root.height(),
357 root.depth());
358 330
359 331 pixmap = new Pixmap(XCreatePixmap(display(),
360 XCopyArea(display(), tmp, pixmaps[screen], gc.gc(), 0, 0, 332 root.window(),
361 root.width(), root.height(), 333 root.width(), root.height(),
362 0, 0); 334 root.depth()));
363 335
364 setRootAtoms(pixmaps[screen], screen);
365 336
366 root.setBackgroundPixmap(pixmaps[screen]); 337 XCopyArea(display(), tmp, *pixmap, gc.gc(), 0, 0,
367 root.clear(); 338 root.width(), root.height(),
339 0, 0);
368 340
369 if (! (root.visual()->c_class & 1)) { 341 setRootAtoms(*pixmap, screen);
370 img_ctrl[screen]->removeImage(tmp);
371 img_ctrl[screen]->cleanCache();
372 }
373 342
343 root.setBackgroundPixmap(*pixmap);
344 root.clear();
345
346 if (! (root.visual()->c_class & 1)) {
347 img_ctrl->removeImage(tmp);
348 img_ctrl->cleanCache();
374 } 349 }
350
375} 351}
376 352
377/** 353/**
diff --git a/util/fbsetroot.hh b/util/fbsetroot.hh
index 21edaa9..6deb4b6 100644
--- a/util/fbsetroot.hh
+++ b/util/fbsetroot.hh
@@ -43,11 +43,11 @@ public:
43 void setRootAtoms(Pixmap pixmap, int screen); 43 void setRootAtoms(Pixmap pixmap, int screen);
44 44
45private: 45private:
46 FbTk::ImageControl **img_ctrl; 46 FbTk::ImageControl *img_ctrl;
47 Pixmap *pixmaps; 47 Pixmap *pixmap;
48 int screen;
48 49
49 char *fore, *back, *grad; 50 char *fore, *back, *grad;
50 int num_screens;
51 char *m_app_name; 51 char *m_app_name;
52}; 52};
53 53