]>
Dogcows Code - chaz/openbox/blob - util/bsetroot.cc
2 # include "../config.h"
3 #endif // HAVE_CONFIG_H
12 #endif // HAVE_STDIO_H
14 #include "../src/i18n.h"
15 #include "../src/BaseDisplay.h"
16 #include "../src/Image.h"
20 bsetroot::bsetroot(int argc
, char **argv
, char *dpy_name
)
21 : BaseDisplay(argv
[0], dpy_name
)
23 grad
= fore
= back
= (char *) 0;
25 Bool mod
= False
, sol
= False
, grd
= False
;
26 int mod_x
= 0, mod_y
= 0;
28 for (int i
= 1; i
< argc
; i
++) {
29 if (! strcmp("-help", argv
[i
])) {
31 } else if ((! strcmp("-fg", argv
[i
])) ||
32 (! strcmp("-foreground", argv
[i
])) ||
33 (! strcmp("-from", argv
[i
]))) {
34 if ((++i
) >= argc
) usage(1);
37 } else if ((! strcmp("-bg", argv
[i
])) ||
38 (! strcmp("-background", argv
[i
])) ||
39 (! strcmp("-to", argv
[i
]))) {
40 if ((++i
) >= argc
) usage(1);
43 } else if (! strcmp("-solid", argv
[i
])) {
44 if ((++i
) >= argc
) usage(1);
48 } else if (! strcmp("-mod", argv
[i
])) {
49 if ((++i
) >= argc
) usage();
51 mod_x
= atoi(argv
[i
]);
53 if ((++i
) >= argc
) usage();
55 mod_y
= atoi(argv
[i
]);
57 if (mod_x
< 1) mod_x
= 1;
58 if (mod_y
< 1) mod_y
= 1;
61 } else if (! strcmp("-gradient", argv
[i
])) {
62 if ((++i
) >= argc
) usage();
66 } else if (! strcmp("-display", argv
[i
])) {
67 // -display passed through tests ealier... we just skip it now
73 if ((mod
+ sol
+ grd
) != True
) {
75 i18n
->getMessage(bsetrootSet
, bsetrootMustSpecify
,
76 "%s: error: must specify one of: -solid, -mod, -gradient\n"),
77 getApplicationName());
82 img_ctrl
= new BImageControl
*[getNumberOfScreens()];
83 for (int i
= 0; i
< getNumberOfScreens(); i
++)
84 img_ctrl
[i
] = new BImageControl(*this, *getScreenInfo(i
), True
);
86 if (sol
&& fore
) solid();
87 else if (mod
&& mod_x
&& mod_y
&& fore
&& back
) modula(mod_x
, mod_y
);
88 else if (grd
&& grad
&& fore
&& back
) gradient();
93 bsetroot::~bsetroot(void) {
94 XSetCloseDownMode(getXDisplay(), RetainPermanent
);
96 XKillClient(getXDisplay(), AllTemporary
);
98 for (int i
= 0; i
< getNumberOfScreens(); i
++)
104 // adapted from wmsetbg
105 void bsetroot::setPixmapProperty(int screen
, Pixmap pixmap
) {
106 static Atom rootpmap_id
= None
;
109 unsigned long length
, after
;
113 if (rootpmap_id
== None
)
114 rootpmap_id
= XInternAtom(getXDisplay(), "_XROOTPMAP_ID", False
);
116 XGrabServer(getXDisplay());
118 /* Clear out the old pixmap */
119 XGetWindowProperty(getXDisplay(), getScreenInfo(screen
)->getRootWindow(),
120 rootpmap_id
, 0L, 1L, False
, AnyPropertyType
,
121 &type
, &format
, &length
, &after
, &data
);
123 if ((type
== XA_PIXMAP
) && (format
== 32) && (length
== 1)) {
124 XKillClient(getXDisplay(), *((Pixmap
*)data
));
125 XSync(getXDisplay(), False
);
126 mode
= PropModeReplace
;
128 mode
= PropModeAppend
;
131 XChangeProperty(getXDisplay(), getScreenInfo(screen
)->getRootWindow(),
132 rootpmap_id
, XA_PIXMAP
, 32, mode
,
133 (unsigned char *) &pixmap
, 1);
135 XDeleteProperty(getXDisplay(), getScreenInfo(screen
)->getRootWindow(),
139 XUngrabServer(getXDisplay());
140 XFlush(getXDisplay());
144 // adapted from wmsetbg
145 Pixmap
bsetroot::duplicatePixmap(int screen
, Pixmap pixmap
,
146 int width
, int height
) {
147 XSync(getXDisplay(), False
);
149 Pixmap copyP
= XCreatePixmap(getXDisplay(),
150 getScreenInfo(screen
)->getRootWindow(),
152 DefaultDepth(getXDisplay(), screen
));
153 XCopyArea(getXDisplay(), pixmap
, copyP
, DefaultGC(getXDisplay(), screen
),
154 0, 0, width
, height
, 0, 0);
155 XSync(getXDisplay(), False
);
161 void bsetroot::solid(void) {
162 for (int screen
= 0; screen
< getNumberOfScreens(); screen
++) {
165 img_ctrl
[screen
]->parseColor(&c
, fore
);
166 if (! c
.isAllocated()) c
.setPixel(BlackPixel(getXDisplay(), screen
));
168 XSetWindowBackground(getXDisplay(), getScreenInfo(screen
)->getRootWindow(),
170 XClearWindow(getXDisplay(), getScreenInfo(screen
)->getRootWindow());
172 Pixmap pixmap
= XCreatePixmap(getXDisplay(),
173 getScreenInfo(screen
)->getRootWindow(),
174 8, 8, DefaultDepth(getXDisplay(), screen
));
175 XSetForeground(getXDisplay(), DefaultGC(getXDisplay(), screen
),
177 XFillRectangle(getXDisplay(), pixmap
, DefaultGC(getXDisplay(), screen
),
180 setPixmapProperty(screen
, duplicatePixmap(screen
, pixmap
, 8, 8));
182 XFreePixmap(getXDisplay(), pixmap
);
187 void bsetroot::modula(int x
, int y
) {
193 for (pattern
= 0, screen
= 0; screen
< getNumberOfScreens(); screen
++) {
194 for (i
= 0; i
< 16; i
++) {
200 for (i
= 0; i
< 16; i
++) {
202 data
[(i
* 2)] = (char) 0xff;
203 data
[(i
* 2) + 1] = (char) 0xff;
205 data
[(i
* 2)] = pattern
& 0xff;
206 data
[(i
* 2) + 1] = (pattern
>> 8) & 0xff;
216 XCreateBitmapFromData(getXDisplay(),
217 getScreenInfo(screen
)->getRootWindow(), data
,
220 img_ctrl
[screen
]->parseColor(&f
, fore
);
221 img_ctrl
[screen
]->parseColor(&b
, back
);
223 if (! f
.isAllocated()) f
.setPixel(WhitePixel(getXDisplay(), screen
));
224 if (! b
.isAllocated()) b
.setPixel(BlackPixel(getXDisplay(), screen
));
226 gcv
.foreground
= f
.getPixel();
227 gcv
.background
= b
.getPixel();
229 gc
= XCreateGC(getXDisplay(), getScreenInfo(screen
)->getRootWindow(),
230 GCForeground
| GCBackground
, &gcv
);
232 Pixmap pixmap
= XCreatePixmap(getXDisplay(),
233 getScreenInfo(screen
)->getRootWindow(),
234 16, 16, getScreenInfo(screen
)->getDepth());
236 XCopyPlane(getXDisplay(), bitmap
, pixmap
, gc
,
237 0, 0, 16, 16, 0, 0, 1l);
238 XSetWindowBackgroundPixmap(getXDisplay(),
239 getScreenInfo(screen
)->getRootWindow(),
241 XClearWindow(getXDisplay(), getScreenInfo(screen
)->getRootWindow());
243 setPixmapProperty(screen
,
244 duplicatePixmap(screen
, pixmap
, 16, 16));
246 XFreeGC(getXDisplay(), gc
);
247 XFreePixmap(getXDisplay(), bitmap
);
249 if (! (getScreenInfo(screen
)->getVisual()->c_class
& 1))
250 XFreePixmap(getXDisplay(), pixmap
);
255 void bsetroot::gradient(void) {
256 for (int screen
= 0; screen
< getNumberOfScreens(); screen
++) {
258 img_ctrl
[screen
]->parseTexture(&texture
, grad
);
259 img_ctrl
[screen
]->parseColor(texture
.getColor(), fore
);
260 img_ctrl
[screen
]->parseColor(texture
.getColorTo(), back
);
262 if (! texture
.getColor()->isAllocated())
263 texture
.getColor()->setPixel(WhitePixel(getXDisplay(), screen
));
264 if (! texture
.getColorTo()->isAllocated())
265 texture
.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen
));
268 img_ctrl
[screen
]->renderImage(getScreenInfo(screen
)->size().w(),
269 getScreenInfo(screen
)->size().h(),
272 XSetWindowBackgroundPixmap(getXDisplay(),
273 getScreenInfo(screen
)->getRootWindow(),
275 XClearWindow(getXDisplay(), getScreenInfo(screen
)->getRootWindow());
277 setPixmapProperty(screen
,
278 duplicatePixmap(screen
, pixmap
,
279 getScreenInfo(screen
)->size().w(),
280 getScreenInfo(screen
)->size().h()));
282 if (! (getScreenInfo(screen
)->getVisual()->c_class
& 1)) {
283 img_ctrl
[screen
]->removeImage(pixmap
);
289 void bsetroot::usage(int exit_code
) {
292 getMessage(bsetrootSet
, bsetrootUsage
,
293 "%s 2.0 : (c) 1997-1999 Brad Hughes\n\n"
294 " -display <string> display connection\n"
295 " -mod <x> <y> modula pattern\n"
296 " -foreground, -fg <color> modula foreground color\n"
297 " -background, -bg <color> modula background color\n\n"
298 " -gradient <texture> gradient texture\n"
299 " -from <color> gradient start color\n"
300 " -to <color> gradient end color\n\n"
301 " -solid <color> solid color\n\n"
302 " -help print this help text and exit\n"),
303 getApplicationName());
309 int main(int argc
, char **argv
) {
310 char *display_name
= (char *) 0;
312 NLSInit("openbox.cat");
314 for (int i
= 1; i
< argc
; i
++) {
315 if (! strcmp(argv
[i
], "-display")) {
316 // check for -display option
320 i18n
->getMessage(mainSet
, mainDISPLAYRequiresArg
,
321 "error: '-display' requires an argument\n"));
326 display_name
= argv
[i
];
330 bsetroot
app(argc
, argv
, display_name
);
This page took 0.048628 seconds and 4 git commands to generate.