aboutsummaryrefslogtreecommitdiff
path: root/util/bsetroot.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2001-12-11 20:47:02 (GMT)
committerfluxgen <fluxgen>2001-12-11 20:47:02 (GMT)
commit18830ac9add80cbd3bf7369307d7e35a519dca9b (patch)
tree4759a5434a34ba317fe77bbf8b0ed9bb57bb6018 /util/bsetroot.cc
parent1523b48bff07dead084af3064ad11c79a9b25df0 (diff)
downloadfluxbox-18830ac9add80cbd3bf7369307d7e35a519dca9b.zip
fluxbox-18830ac9add80cbd3bf7369307d7e35a519dca9b.tar.bz2
Initial revision
Diffstat (limited to 'util/bsetroot.cc')
-rw-r--r--util/bsetroot.cc300
1 files changed, 300 insertions, 0 deletions
diff --git a/util/bsetroot.cc b/util/bsetroot.cc
new file mode 100644
index 0000000..7f13854
--- /dev/null
+++ b/util/bsetroot.cc
@@ -0,0 +1,300 @@
1#ifdef HAVE_CONFIG_H
2# include "../config.h"
3#endif // HAVE_CONFIG_H
4
5#ifdef STDC_HEADERS
6# include <string.h>
7# include <stdlib.h>
8#endif // STDC_HEADERS
9
10#ifdef HAVE_STDIO_H
11# include <stdio.h>
12#endif // HAVE_STDIO_H
13
14#include "../src/i18n.hh"
15#include "bsetroot.hh"
16
17
18bsetroot::bsetroot(int argc, char **argv, char *dpy_name)
19 : BaseDisplay(argv[0], dpy_name)
20{
21 pixmaps = (Pixmap *) 0;
22 grad = fore = back = (char *) 0;
23
24 Bool mod = False, sol = False, grd = False;
25 int mod_x = 0, mod_y = 0, i = 0;
26 img_ctrl = new BImageControl*[10];
27 for (; i < getNumberOfScreens(); i++) {
28 img_ctrl[i] = new BImageControl(this, getScreenInfo(i), True);
29
30 }
31
32 for (i = 1; i < argc; i++) {
33 if (! strcmp("-help", argv[i])) {
34 usage();
35 } else if ((! strcmp("-fg", argv[i])) ||
36 (! strcmp("-foreground", argv[i])) ||
37 (! strcmp("-from", argv[i]))) {
38 if ((++i) >= argc) usage(1);
39
40 fore = argv[i];
41 } else if ((! strcmp("-bg", argv[i])) ||
42 (! strcmp("-background", argv[i])) ||
43 (! strcmp("-to", argv[i]))) {
44 if ((++i) >= argc) usage(1);
45
46 back = argv[i];
47 } else if (! strcmp("-solid", argv[i])) {
48 if ((++i) >= argc) usage(1);
49
50 fore = argv[i];
51 sol = True;
52 } else if (! strcmp("-mod", argv[i])) {
53 if ((++i) >= argc) usage();
54
55 mod_x = atoi(argv[i]);
56
57 if ((++i) >= argc) usage();
58
59 mod_y = atoi(argv[i]);
60
61 if (mod_x < 1) mod_x = 1;
62 if (mod_y < 1) mod_y = 1;
63
64 mod = True;
65 } else if (! strcmp("-gradient", argv[i])) {
66 if ((++i) >= argc) usage();
67
68 grad = argv[i];
69 grd = True;
70 } else if (! strcmp("-display", argv[i])) {
71 // -display passed through tests ealier... we just skip it now
72 i++;
73 } else
74 usage();
75 }
76
77 if ((mod + sol + grd) != True) {
78 fprintf(stderr,
79 I18n::instance()->
80 getMessage(
81#ifdef NLS
82 bsetrootSet, bsetrootMustSpecify,
83#else // !NLS
84 0, 0,
85#endif // NLS
86 "%s: error: must specify on of: -solid, -mod, -gradient\n"),
87 getApplicationName());
88
89 usage(2);
90 }
91
92 if (sol && fore) solid();
93 else if (mod && mod_x && mod_y && fore && back) modula(mod_x, mod_y);
94 else if (grd && grad && fore && back) gradient();
95 else usage();
96 display = getXDisplay();
97 num_screens = getNumberOfScreens();
98}
99
100
101bsetroot::~bsetroot(void) {
102 XKillClient(display, AllTemporary);
103
104 if (pixmaps) {
105 int i;
106 for (i = 0; i < num_screens; i++)
107 if (pixmaps[i] != None) {
108 XSetCloseDownMode(display, RetainTemporary);
109 break;
110 }
111
112 delete [] pixmaps;
113 }
114
115 if (img_ctrl) {
116 int i = 0;
117 for (; i < num_screens; i++)
118 delete img_ctrl[i];
119
120 delete [] img_ctrl;
121 }
122
123}
124
125
126void bsetroot::solid(void) {
127 register int screen = 0;
128
129 for (; screen < getNumberOfScreens(); screen++) {
130 BColor c;
131
132 img_ctrl[screen]->parseColor(&c, fore);
133 if (! c.isAllocated()) c.setPixel(BlackPixel(getXDisplay(), screen));
134
135 XSetWindowBackground(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
136 c.getPixel());
137 XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
138 }
139}
140
141
142void bsetroot::modula(int x, int y) {
143 char data[32];
144 long pattern;
145
146 register int screen, i;
147
148 pixmaps = new Pixmap[getNumberOfScreens()];
149
150 for (pattern = 0, screen = 0; screen < getNumberOfScreens(); screen++) {
151 for (i = 0; i < 16; i++) {
152 pattern <<= 1;
153 if ((i % x) == 0)
154 pattern |= 0x0001;
155 }
156
157 for (i = 0; i < 16; i++)
158 if ((i % y) == 0) {
159 data[(i * 2)] = (char) 0xff;
160 data[(i * 2) + 1] = (char) 0xff;
161 } else {
162 data[(i * 2)] = pattern & 0xff;
163 data[(i * 2) + 1] = (pattern >> 8) & 0xff;
164 }
165
166 BColor f, b;
167 GC gc;
168 Pixmap bitmap;
169 XGCValues gcv;
170
171 bitmap =
172 XCreateBitmapFromData(getXDisplay(),
173 getScreenInfo(screen)->getRootWindow(), data,
174 16, 16);
175
176 img_ctrl[screen]->parseColor(&f, fore);
177 img_ctrl[screen]->parseColor(&b, back);
178
179 if (! f.isAllocated()) f.setPixel(WhitePixel(getXDisplay(), screen));
180 if (! b.isAllocated()) b.setPixel(BlackPixel(getXDisplay(), screen));
181
182 gcv.foreground = f.getPixel();
183 gcv.background = b.getPixel();
184
185 gc = XCreateGC(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
186 GCForeground | GCBackground, &gcv);
187
188 pixmaps[screen] =
189 XCreatePixmap(getXDisplay(), getScreenInfo(screen)->getRootWindow(),
190 16, 16, getScreenInfo(screen)->getDepth());
191
192 XCopyPlane(getXDisplay(), bitmap, pixmaps[screen], gc,
193 0, 0, 16, 16, 0, 0, 1l);
194 XSetWindowBackgroundPixmap(getXDisplay(),
195 getScreenInfo(screen)->getRootWindow(),
196 pixmaps[screen]);
197 XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
198
199 XFreeGC(getXDisplay(), gc);
200 XFreePixmap(getXDisplay(), bitmap);
201
202 if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) {
203 XFreePixmap(getXDisplay(), pixmaps[screen]);
204 pixmaps[screen] = None;
205 }
206 }
207}
208
209
210void bsetroot::gradient(void) {
211 register int screen;
212
213 pixmaps = new Pixmap[getNumberOfScreens()];
214
215 for (screen = 0; screen < getNumberOfScreens(); screen++) {
216 BTexture texture;
217 img_ctrl[screen]->parseTexture(&texture, grad);
218 img_ctrl[screen]->parseColor(texture.getColor(), fore);
219 img_ctrl[screen]->parseColor(texture.getColorTo(), back);
220
221 if (! texture.getColor()->isAllocated())
222 texture.getColor()->setPixel(WhitePixel(getXDisplay(), screen));
223 if (! texture.getColorTo()->isAllocated())
224 texture.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen));
225
226 pixmaps[screen] =
227 img_ctrl[screen]->renderImage(getScreenInfo(screen)->getWidth(),
228 getScreenInfo(screen)->getHeight(),
229 &texture);
230
231 XSetWindowBackgroundPixmap(getXDisplay(),
232 getScreenInfo(screen)->getRootWindow(),
233 pixmaps[screen]);
234 XClearWindow(getXDisplay(), getScreenInfo(screen)->getRootWindow());
235
236 if (! (getScreenInfo(screen)->getVisual()->c_class & 1)) {
237 img_ctrl[screen]->removeImage(pixmaps[screen]);
238 img_ctrl[screen]->timeout();
239 pixmaps[screen] = None;
240 }
241 }
242}
243
244
245void bsetroot::usage(int exit_code) {
246 fprintf(stderr,
247 I18n::instance()->
248 getMessage(
249#ifdef NLS
250 bsetrootSet, bsetrootUsage,
251#else // !NLS
252 0, 0,
253#endif // NLS
254 "%s 2.0 : (c) 1997-1999 Brad Hughes\n\n"
255 " -display <string> display connection\n"
256 " -mod <x> <y> modula pattern\n"
257 " -foreground, -fg <color> modula foreground color\n"
258 " -background, -bg <color> modula background color\n\n"
259 " -gradient <texture> gradient texture\n"
260 " -from <color> gradient start color\n"
261 " -to <color> gradient end color\n\n"
262 " -solid <color> solid color\n\n"
263 " -help print this help text and exit\n"),
264 getApplicationName());
265
266 exit(exit_code);
267}
268
269
270int main(int argc, char **argv) {
271 char *display_name = (char *) 0;
272 int i = 1;
273
274 NLSInit("blackbox.cat");
275
276 for (; i < argc; i++) {
277 if (! strcmp(argv[i], "-display")) {
278 // check for -display option
279
280 if ((++i) >= argc) {
281 fprintf(stderr,
282 I18n::instance()->getMessage(
283#ifdef NLS
284 mainSet, mainDISPLAYRequiresArg,
285#else // !NLS
286 0, 0,
287#endif // NLS
288 "error: '-display' requires an argument\n"));
289
290 ::exit(1);
291 }
292
293 display_name = argv[i];
294 }
295 }
296
297 bsetroot app(argc, argv, display_name);
298
299 return 0;
300}