]>
Dogcows Code - chaz/openbox/blob - util/bsetroot.cc
1 // bsetroot.cc for Openbox
2 // Copyright (c) 2002 - 2002 Ben Janens (ben@orodu.net)
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh at debian.org>
4 // Copyright (c) 1997 - 2000, 2002 Brad Hughes <bhughes at trolltech.com>
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
25 # include "../config.h"
26 #endif // HAVE_CONFIG_H
30 #endif // HAVE_STRING_H
34 #endif // HAVE_STDLIB_H
38 #endif // HAVE_STDIO_H
40 #include "../src/i18n.h"
41 #include "../src/BaseDisplay.h"
42 #include "../src/Image.h"
47 bsetroot::bsetroot(int argc
, char **argv
, char *dpy_name
)
48 : BaseDisplay(argv
[0], dpy_name
)
50 grad
= fore
= back
= (char *) 0;
52 Bool mod
= False
, sol
= False
, grd
= False
;
53 int mod_x
= 0, mod_y
= 0;
55 for (int i
= 1; i
< argc
; i
++) {
56 if (! strcmp("-help", argv
[i
])) {
58 } else if ((! strcmp("-fg", argv
[i
])) ||
59 (! strcmp("-foreground", argv
[i
])) ||
60 (! strcmp("-from", argv
[i
]))) {
61 if ((++i
) >= argc
) usage(1);
64 } else if ((! strcmp("-bg", argv
[i
])) ||
65 (! strcmp("-background", argv
[i
])) ||
66 (! strcmp("-to", argv
[i
]))) {
67 if ((++i
) >= argc
) usage(1);
70 } else if (! strcmp("-solid", argv
[i
])) {
71 if ((++i
) >= argc
) usage(1);
75 } else if (! strcmp("-mod", argv
[i
])) {
76 if ((++i
) >= argc
) usage();
78 mod_x
= atoi(argv
[i
]);
80 if ((++i
) >= argc
) usage();
82 mod_y
= atoi(argv
[i
]);
84 if (mod_x
< 1) mod_x
= 1;
85 if (mod_y
< 1) mod_y
= 1;
88 } else if (! strcmp("-gradient", argv
[i
])) {
89 if ((++i
) >= argc
) usage();
93 } else if (! strcmp("-display", argv
[i
])) {
94 // -display passed through tests ealier... we just skip it now
100 if ((mod
+ sol
+ grd
) != True
) {
102 i18n
->getMessage(bsetrootSet
, bsetrootMustSpecify
,
103 "%s: error: must specify one of: "
104 "-solid, -mod, -gradient\n"),
105 getApplicationName());
110 img_ctrl
= new BImageControl
*[getNumberOfScreens()];
111 for (unsigned int s
= 0; s
< getNumberOfScreens(); ++s
)
112 img_ctrl
[s
] = new BImageControl(*this, *getScreenInfo(s
), true);
114 if (sol
&& fore
) solid();
115 else if (mod
&& mod_x
&& mod_y
&& fore
&& back
) modula(mod_x
, mod_y
);
116 else if (grd
&& grad
&& fore
&& back
) gradient();
121 bsetroot::~bsetroot(void) {
122 XSetCloseDownMode(getXDisplay(), RetainPermanent
);
124 XKillClient(getXDisplay(), AllTemporary
);
126 std::for_each(img_ctrl
, img_ctrl
+ getNumberOfScreens(), PointerAssassin());
132 // adapted from wmsetbg
133 void bsetroot::setPixmapProperty(int screen
, Pixmap pixmap
) {
134 static Atom rootpmap_id
= None
, esetroot_id
= None
;
137 unsigned long length
, after
;
139 int mode
= PropModeAppend
;
140 int emode
= PropModeAppend
;
141 const ScreenInfo
*screen_info
= getScreenInfo(screen
);
143 if (rootpmap_id
== None
) {
144 rootpmap_id
= XInternAtom(getXDisplay(), "_XROOTPMAP_ID", True
);
145 esetroot_id
= XInternAtom(getXDisplay(), "ESETROOT_PMAP_ID", True
);
148 XGrabServer(getXDisplay());
150 // Clear out the old pixmap?
151 XGetWindowProperty(getXDisplay(), screen_info
->getRootWindow(),
152 rootpmap_id
, 0L, 1L, False
, AnyPropertyType
,
153 &type
, &format
, &length
, &after
, &data
);
154 if ((type
== XA_PIXMAP
) && (format
== 32) && (length
== 1)) {
155 XKillClient(getXDisplay(), *((Pixmap
*) data
));
156 XSync(getXDisplay(), False
);
157 mode
= PropModeReplace
;
160 // Clear out the old esetroot pixmap?
161 XGetWindowProperty(getXDisplay(), screen_info
->getRootWindow(),
162 esetroot_id
, 0L, 1L, False
, AnyPropertyType
,
163 &type
, &format
, &length
, &after
, &data
);
164 if ((type
== XA_PIXMAP
) && (format
== 32) && (length
== 1))
165 emode
= PropModeReplace
;
168 XChangeProperty(getXDisplay(), screen_info
->getRootWindow(),
169 rootpmap_id
, XA_PIXMAP
, 32, mode
,
170 (unsigned char *) &pixmap
, 1);
171 XChangeProperty(getXDisplay(), screen_info
->getRootWindow(),
172 esetroot_id
, XA_PIXMAP
, 32, emode
,
173 (unsigned char *) &pixmap
, 1);
175 XDeleteProperty(getXDisplay(), screen_info
->getRootWindow(),
177 XDeleteProperty(getXDisplay(), screen_info
->getRootWindow(),
181 XUngrabServer(getXDisplay());
182 XFlush(getXDisplay());
186 // adapted from wmsetbg
187 Pixmap
bsetroot::duplicatePixmap(int screen
, Pixmap pixmap
,
188 int width
, int height
) {
189 XSync(getXDisplay(), False
);
191 Pixmap copyP
= XCreatePixmap(getXDisplay(),
192 getScreenInfo(screen
)->getRootWindow(),
194 DefaultDepth(getXDisplay(), screen
));
195 XCopyArea(getXDisplay(), pixmap
, copyP
, DefaultGC(getXDisplay(), screen
),
196 0, 0, width
, height
, 0, 0);
197 XSync(getXDisplay(), False
);
203 void bsetroot::solid(void) {
204 for (unsigned int screen
= 0; screen
< getNumberOfScreens(); screen
++) {
207 img_ctrl
[screen
]->parseColor(&c
, fore
);
208 if (! c
.isAllocated()) c
.setPixel(BlackPixel(getXDisplay(), screen
));
210 const ScreenInfo
*screen_info
= getScreenInfo(screen
);
212 XSetWindowBackground(getXDisplay(), screen_info
->getRootWindow(),
214 XClearWindow(getXDisplay(), screen_info
->getRootWindow());
216 Pixmap pixmap
= XCreatePixmap(getXDisplay(),
217 screen_info
->getRootWindow(),
218 8, 8, DefaultDepth(getXDisplay(), screen
));
220 XSetForeground(getXDisplay(), DefaultGC(getXDisplay(), screen
),
222 XFillRectangle(getXDisplay(), pixmap
, DefaultGC(getXDisplay(), screen
),
225 setPixmapProperty(screen
, duplicatePixmap(screen
, pixmap
, 8, 8));
227 XFreePixmap(getXDisplay(), pixmap
);
232 void bsetroot::modula(int x
, int y
) {
236 unsigned int screen
, i
;
238 for (pattern
= 0, screen
= 0; screen
< getNumberOfScreens(); screen
++) {
239 for (i
= 0; i
< 16; i
++) {
245 for (i
= 0; i
< 16; i
++) {
247 data
[(i
* 2)] = (char) 0xff;
248 data
[(i
* 2) + 1] = (char) 0xff;
250 data
[(i
* 2)] = pattern
& 0xff;
251 data
[(i
* 2) + 1] = (pattern
>> 8) & 0xff;
259 const ScreenInfo
*screen_info
= getScreenInfo(screen
);
262 XCreateBitmapFromData(getXDisplay(),
263 screen_info
->getRootWindow(), data
,
266 img_ctrl
[screen
]->parseColor(&f
, fore
);
267 img_ctrl
[screen
]->parseColor(&b
, back
);
269 if (! f
.isAllocated()) f
.setPixel(WhitePixel(getXDisplay(), screen
));
270 if (! b
.isAllocated()) b
.setPixel(BlackPixel(getXDisplay(), screen
));
273 gcv
.foreground
= f
.getPixel();
274 gcv
.background
= b
.getPixel();
276 gc
= XCreateGC(getXDisplay(), screen_info
->getRootWindow(),
277 GCForeground
| GCBackground
, &gcv
);
279 Pixmap pixmap
= XCreatePixmap(getXDisplay(),
280 screen_info
->getRootWindow(),
281 16, 16, screen_info
->getDepth());
283 XCopyPlane(getXDisplay(), bitmap
, pixmap
, gc
,
284 0, 0, 16, 16, 0, 0, 1l);
285 XSetWindowBackgroundPixmap(getXDisplay(),
286 screen_info
->getRootWindow(),
288 XClearWindow(getXDisplay(), screen_info
->getRootWindow());
290 setPixmapProperty(screen
,
291 duplicatePixmap(screen
, pixmap
, 16, 16));
293 XFreeGC(getXDisplay(), gc
);
294 XFreePixmap(getXDisplay(), bitmap
);
296 if (! (screen_info
->getVisual()->c_class
& 1))
297 XFreePixmap(getXDisplay(), pixmap
);
302 void bsetroot::gradient(void) {
303 for (unsigned int screen
= 0; screen
< getNumberOfScreens(); screen
++) {
305 img_ctrl
[screen
]->parseTexture(&texture
, grad
);
306 img_ctrl
[screen
]->parseColor(texture
.getColor(), fore
);
307 img_ctrl
[screen
]->parseColor(texture
.getColorTo(), back
);
308 const ScreenInfo
*screen_info
= getScreenInfo(screen
);
310 if (! texture
.getColor()->isAllocated())
311 texture
.getColor()->setPixel(WhitePixel(getXDisplay(), screen
));
312 if (! texture
.getColorTo()->isAllocated())
313 texture
.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen
));
316 img_ctrl
[screen
]->renderImage(screen_info
->size().w(),
317 screen_info
->size().h(),
320 XSetWindowBackgroundPixmap(getXDisplay(),
321 screen_info
->getRootWindow(),
323 XClearWindow(getXDisplay(), screen_info
->getRootWindow());
325 setPixmapProperty(screen
,
326 duplicatePixmap(screen
, pixmap
,
327 screen_info
->size().w(),
328 screen_info
->size().h()));
330 if (! (screen_info
->getVisual()->c_class
& 1)) {
331 img_ctrl
[screen
]->removeImage(pixmap
);
337 void bsetroot::usage(int exit_code
) {
339 i18n
->getMessage(bsetrootSet
, bsetrootUsage
,
341 "Copyright (c) 1997-2000, 2002 Bradley T Hughes\n"
342 "Copyright (c) 2001-2002 Sean 'Shaleh' Perry\n\n"
343 " -display <string> display connection\n"
344 " -mod <x> <y> modula pattern\n"
345 " -foreground, -fg <color> modula foreground color\n"
346 " -background, -bg <color> modula background color\n\n"
347 " -gradient <texture> gradient texture\n"
348 " -from <color> gradient start color\n"
349 " -to <color> gradient end color\n\n"
350 " -solid <color> solid color\n\n"
351 " -help print this help text and exit\n"),
352 getApplicationName());
357 int main(int argc
, char **argv
) {
358 char *display_name
= (char *) 0;
360 NLSInit("openbox.cat");
362 for (int i
= 1; i
< argc
; i
++) {
363 if (! strcmp(argv
[i
], "-display")) {
364 // check for -display option
367 fprintf(stderr
, i18n
->getMessage(mainSet
, mainDISPLAYRequiresArg
,
368 "error: '-display' requires an argument\n"));
373 display_name
= argv
[i
];
377 bsetroot
app(argc
, argv
, display_name
);
This page took 0.050621 seconds and 4 git commands to generate.