]>
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
*[numberOfScreens()];
111 for (unsigned int s
= 0, n
= numberOfScreens(); s
< n
; ++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
+ numberOfScreens(), 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 const ScreenInfo
*screen_info
= getScreenInfo(screen
);
141 if (rootpmap_id
== None
) {
142 rootpmap_id
= XInternAtom(getXDisplay(), "_XROOTPMAP_ID", False
);
143 esetroot_id
= XInternAtom(getXDisplay(), "ESETROOT_PMAP_ID", False
);
146 XGrabServer(getXDisplay());
148 // Clear out the old pixmap
149 XGetWindowProperty(getXDisplay(), screen_info
->getRootWindow(),
150 rootpmap_id
, 0L, 1L, False
, XA_PIXMAP
,
151 &type
, &format
, &length
, &after
, &data
);
152 if (type
== XA_PIXMAP
&& format
== 32) {
153 XKillClient(getXDisplay(), *((Pixmap
*) data
));
154 XSync(getXDisplay(), False
);
159 XChangeProperty(getXDisplay(), screen_info
->getRootWindow(),
160 rootpmap_id
, XA_PIXMAP
, 32, PropModeReplace
,
161 (unsigned char *) &pixmap
, 1);
162 XChangeProperty(getXDisplay(), screen_info
->getRootWindow(),
163 esetroot_id
, XA_PIXMAP
, 32, PropModeReplace
,
164 (unsigned char *) &pixmap
, 1);
166 XDeleteProperty(getXDisplay(), screen_info
->getRootWindow(),
168 XDeleteProperty(getXDisplay(), screen_info
->getRootWindow(),
172 XUngrabServer(getXDisplay());
173 XFlush(getXDisplay());
177 // adapted from wmsetbg
178 Pixmap
bsetroot::duplicatePixmap(int screen
, Pixmap pixmap
,
179 int width
, int height
) {
180 XSync(getXDisplay(), False
);
182 Pixmap copyP
= XCreatePixmap(getXDisplay(),
183 getScreenInfo(screen
)->getRootWindow(),
185 DefaultDepth(getXDisplay(), screen
));
186 XCopyArea(getXDisplay(), pixmap
, copyP
, DefaultGC(getXDisplay(), screen
),
187 0, 0, width
, height
, 0, 0);
188 XSync(getXDisplay(), False
);
194 void bsetroot::solid(void) {
195 for (unsigned int screen
= 0, n
= numberOfScreens(); screen
< n
; screen
++) {
198 img_ctrl
[screen
]->parseColor(&c
, fore
);
199 if (! c
.isAllocated()) c
.setPixel(BlackPixel(getXDisplay(), screen
));
201 const ScreenInfo
*screen_info
= getScreenInfo(screen
);
203 XSetWindowBackground(getXDisplay(), screen_info
->getRootWindow(),
205 XClearWindow(getXDisplay(), screen_info
->getRootWindow());
207 Pixmap pixmap
= XCreatePixmap(getXDisplay(),
208 screen_info
->getRootWindow(),
209 8, 8, DefaultDepth(getXDisplay(), screen
));
211 XSetForeground(getXDisplay(), DefaultGC(getXDisplay(), screen
),
213 XFillRectangle(getXDisplay(), pixmap
, DefaultGC(getXDisplay(), screen
),
216 setPixmapProperty(screen
, duplicatePixmap(screen
, pixmap
, 8, 8));
218 XFreePixmap(getXDisplay(), pixmap
);
223 void bsetroot::modula(int x
, int y
) {
227 unsigned int screen
, i
;
228 unsigned int n
= numberOfScreens();
230 for (pattern
= 0, screen
= 0; screen
< n
; screen
++) {
231 for (i
= 0; i
< 16; i
++) {
237 for (i
= 0; i
< 16; i
++) {
239 data
[(i
* 2)] = (char) 0xff;
240 data
[(i
* 2) + 1] = (char) 0xff;
242 data
[(i
* 2)] = pattern
& 0xff;
243 data
[(i
* 2) + 1] = (pattern
>> 8) & 0xff;
251 const ScreenInfo
*screen_info
= getScreenInfo(screen
);
254 XCreateBitmapFromData(getXDisplay(),
255 screen_info
->getRootWindow(), data
,
258 img_ctrl
[screen
]->parseColor(&f
, fore
);
259 img_ctrl
[screen
]->parseColor(&b
, back
);
261 if (! f
.isAllocated()) f
.setPixel(WhitePixel(getXDisplay(), screen
));
262 if (! b
.isAllocated()) b
.setPixel(BlackPixel(getXDisplay(), screen
));
265 gcv
.foreground
= f
.getPixel();
266 gcv
.background
= b
.getPixel();
268 gc
= XCreateGC(getXDisplay(), screen_info
->getRootWindow(),
269 GCForeground
| GCBackground
, &gcv
);
271 Pixmap pixmap
= XCreatePixmap(getXDisplay(),
272 screen_info
->getRootWindow(),
273 16, 16, screen_info
->getDepth());
275 XCopyPlane(getXDisplay(), bitmap
, pixmap
, gc
,
276 0, 0, 16, 16, 0, 0, 1l);
277 XSetWindowBackgroundPixmap(getXDisplay(),
278 screen_info
->getRootWindow(),
280 XClearWindow(getXDisplay(), screen_info
->getRootWindow());
282 setPixmapProperty(screen
,
283 duplicatePixmap(screen
, pixmap
, 16, 16));
285 XFreeGC(getXDisplay(), gc
);
286 XFreePixmap(getXDisplay(), bitmap
);
288 if (! (screen_info
->getVisual()->c_class
& 1))
289 XFreePixmap(getXDisplay(), pixmap
);
294 void bsetroot::gradient(void) {
295 for (unsigned int screen
= 0, n
= numberOfScreens(); screen
< n
; screen
++) {
297 img_ctrl
[screen
]->parseTexture(&texture
, grad
);
298 img_ctrl
[screen
]->parseColor(texture
.getColor(), fore
);
299 img_ctrl
[screen
]->parseColor(texture
.getColorTo(), back
);
300 const ScreenInfo
*screen_info
= getScreenInfo(screen
);
302 if (! texture
.getColor()->isAllocated())
303 texture
.getColor()->setPixel(WhitePixel(getXDisplay(), screen
));
304 if (! texture
.getColorTo()->isAllocated())
305 texture
.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen
));
308 img_ctrl
[screen
]->renderImage(screen_info
->size().w(),
309 screen_info
->size().h(),
312 XSetWindowBackgroundPixmap(getXDisplay(),
313 screen_info
->getRootWindow(),
315 XClearWindow(getXDisplay(), screen_info
->getRootWindow());
317 setPixmapProperty(screen
,
318 duplicatePixmap(screen
, pixmap
,
319 screen_info
->size().w(),
320 screen_info
->size().h()));
322 if (! (screen_info
->getVisual()->c_class
& 1)) {
323 img_ctrl
[screen
]->removeImage(pixmap
);
329 void bsetroot::usage(int exit_code
) {
331 i18n
->getMessage(bsetrootSet
, bsetrootUsage
,
333 "Copyright (c) 1997-2000, 2002 Bradley T Hughes\n"
334 "Copyright (c) 2001-2002 Sean 'Shaleh' Perry\n\n"
335 " -display <string> display connection\n"
336 " -mod <x> <y> modula pattern\n"
337 " -foreground, -fg <color> modula foreground color\n"
338 " -background, -bg <color> modula background color\n\n"
339 " -gradient <texture> gradient texture\n"
340 " -from <color> gradient start color\n"
341 " -to <color> gradient end color\n\n"
342 " -solid <color> solid color\n\n"
343 " -help print this help text and exit\n"),
344 getApplicationName());
349 int main(int argc
, char **argv
) {
350 char *display_name
= (char *) 0;
352 NLSInit("openbox.cat");
354 for (int i
= 1; i
< argc
; i
++) {
355 if (! strcmp(argv
[i
], "-display")) {
356 // check for -display option
359 fprintf(stderr
, i18n
->getMessage(mainSet
, mainDISPLAYRequiresArg
,
360 "error: '-display' requires an argument\n"));
365 display_name
= argv
[i
];
369 bsetroot
app(argc
, argv
, display_name
);
This page took 0.057817 seconds and 4 git commands to generate.