]>
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"
18 bsetroot::bsetroot(int argc
, char **argv
, char *dpy_name
)
19 : BaseDisplay(argv
[0], dpy_name
)
21 pixmaps
= (Pixmap
*) 0;
22 grad
= fore
= back
= (char *) 0;
24 Bool mod
= False
, sol
= False
, grd
= False
;
25 int mod_x
= 0, mod_y
= 0, i
= 0;
27 img_ctrl
= new BImageControl
*[getNumberOfScreens()];
28 for (; i
< getNumberOfScreens(); i
++)
29 img_ctrl
[i
] = new BImageControl(*this, *getScreenInfo(i
), True
);
31 for (i
= 1; i
< argc
; i
++) {
32 if (! strcmp("-help", argv
[i
])) {
34 } else if ((! strcmp("-fg", argv
[i
])) ||
35 (! strcmp("-foreground", argv
[i
])) ||
36 (! strcmp("-from", argv
[i
]))) {
37 if ((++i
) >= argc
) usage(1);
40 } else if ((! strcmp("-bg", argv
[i
])) ||
41 (! strcmp("-background", argv
[i
])) ||
42 (! strcmp("-to", argv
[i
]))) {
43 if ((++i
) >= argc
) usage(1);
46 } else if (! strcmp("-solid", argv
[i
])) {
47 if ((++i
) >= argc
) usage(1);
51 } else if (! strcmp("-mod", argv
[i
])) {
52 if ((++i
) >= argc
) usage();
54 mod_x
= atoi(argv
[i
]);
56 if ((++i
) >= argc
) usage();
58 mod_y
= atoi(argv
[i
]);
60 if (mod_x
< 1) mod_x
= 1;
61 if (mod_y
< 1) mod_y
= 1;
64 } else if (! strcmp("-gradient", argv
[i
])) {
65 if ((++i
) >= argc
) usage();
69 } else if (! strcmp("-display", argv
[i
])) {
70 // -display passed through tests ealier... we just skip it now
76 if ((mod
+ sol
+ grd
) != True
) {
81 bsetrootSet
, bsetrootMustSpecify
,
85 "%s: error: must specify one of: -solid, -mod, -gradient\n"),
86 getApplicationName());
91 if (sol
&& fore
) solid();
92 else if (mod
&& mod_x
&& mod_y
&& fore
&& back
) modula(mod_x
, mod_y
);
93 else if (grd
&& grad
&& fore
&& back
) gradient();
98 bsetroot::~bsetroot(void) {
99 XKillClient(getXDisplay(), AllTemporary
);
103 for (i
= 0; i
< getNumberOfScreens(); i
++)
104 if (pixmaps
[i
] != None
) {
105 XSetCloseDownMode(getXDisplay(), RetainTemporary
);
114 for (; i
< getNumberOfScreens(); i
++)
122 void bsetroot::solid(void) {
123 register int screen
= 0;
125 for (; screen
< getNumberOfScreens(); screen
++) {
128 img_ctrl
[screen
]->parseColor(&c
, fore
);
129 if (! c
.isAllocated()) c
.setPixel(BlackPixel(getXDisplay(), screen
));
131 XSetWindowBackground(getXDisplay(), getScreenInfo(screen
)->getRootWindow(),
133 XClearWindow(getXDisplay(), getScreenInfo(screen
)->getRootWindow());
138 void bsetroot::modula(int x
, int y
) {
142 register int screen
, i
;
144 pixmaps
= new Pixmap
[getNumberOfScreens()];
146 for (pattern
= 0, screen
= 0; screen
< getNumberOfScreens(); screen
++) {
147 for (i
= 0; i
< 16; i
++) {
153 for (i
= 0; i
< 16; i
++)
155 data
[(i
* 2)] = (char) 0xff;
156 data
[(i
* 2) + 1] = (char) 0xff;
158 data
[(i
* 2)] = pattern
& 0xff;
159 data
[(i
* 2) + 1] = (pattern
>> 8) & 0xff;
168 XCreateBitmapFromData(getXDisplay(),
169 getScreenInfo(screen
)->getRootWindow(), data
,
172 img_ctrl
[screen
]->parseColor(&f
, fore
);
173 img_ctrl
[screen
]->parseColor(&b
, back
);
175 if (! f
.isAllocated()) f
.setPixel(WhitePixel(getXDisplay(), screen
));
176 if (! b
.isAllocated()) b
.setPixel(BlackPixel(getXDisplay(), screen
));
178 gcv
.foreground
= f
.getPixel();
179 gcv
.background
= b
.getPixel();
181 gc
= XCreateGC(getXDisplay(), getScreenInfo(screen
)->getRootWindow(),
182 GCForeground
| GCBackground
, &gcv
);
185 XCreatePixmap(getXDisplay(), getScreenInfo(screen
)->getRootWindow(),
186 16, 16, getScreenInfo(screen
)->getDepth());
188 XCopyPlane(getXDisplay(), bitmap
, pixmaps
[screen
], gc
,
189 0, 0, 16, 16, 0, 0, 1l);
190 XSetWindowBackgroundPixmap(getXDisplay(),
191 getScreenInfo(screen
)->getRootWindow(),
193 XClearWindow(getXDisplay(), getScreenInfo(screen
)->getRootWindow());
195 XFreeGC(getXDisplay(), gc
);
196 XFreePixmap(getXDisplay(), bitmap
);
198 if (! (getScreenInfo(screen
)->getVisual()->c_class
& 1)) {
199 XFreePixmap(getXDisplay(), pixmaps
[screen
]);
200 pixmaps
[screen
] = None
;
206 void bsetroot::gradient(void) {
209 pixmaps
= new Pixmap
[getNumberOfScreens()];
211 for (screen
= 0; screen
< getNumberOfScreens(); screen
++) {
213 img_ctrl
[screen
]->parseTexture(&texture
, grad
);
214 img_ctrl
[screen
]->parseColor(texture
.getColor(), fore
);
215 img_ctrl
[screen
]->parseColor(texture
.getColorTo(), back
);
217 if (! texture
.getColor()->isAllocated())
218 texture
.getColor()->setPixel(WhitePixel(getXDisplay(), screen
));
219 if (! texture
.getColorTo()->isAllocated())
220 texture
.getColorTo()->setPixel(BlackPixel(getXDisplay(), screen
));
223 img_ctrl
[screen
]->renderImage(getScreenInfo(screen
)->size().w(),
224 getScreenInfo(screen
)->size().h(),
227 XSetWindowBackgroundPixmap(getXDisplay(),
228 getScreenInfo(screen
)->getRootWindow(),
230 XClearWindow(getXDisplay(), getScreenInfo(screen
)->getRootWindow());
232 if (! (getScreenInfo(screen
)->getVisual()->c_class
& 1)) {
233 img_ctrl
[screen
]->removeImage(pixmaps
[screen
]);
234 img_ctrl
[screen
]->timeout();
235 pixmaps
[screen
] = None
;
241 void bsetroot::usage(int exit_code
) {
246 bsetrootSet
, bsetrootUsage
,
250 "%s 2.0 : (c) 1997-1999 Brad Hughes\n\n"
251 " -display <string> display connection\n"
252 " -mod <x> <y> modula pattern\n"
253 " -foreground, -fg <color> modula foreground color\n"
254 " -background, -bg <color> modula background color\n\n"
255 " -gradient <texture> gradient texture\n"
256 " -from <color> gradient start color\n"
257 " -to <color> gradient end color\n\n"
258 " -solid <color> solid color\n\n"
259 " -help print this help text and exit\n"),
260 getApplicationName());
266 int main(int argc
, char **argv
) {
267 char *display_name
= (char *) 0;
270 NLSInit("openbox.cat");
272 for (; i
< argc
; i
++) {
273 if (! strcmp(argv
[i
], "-display")) {
274 // check for -display option
280 mainSet
, mainDISPLAYRequiresArg
,
284 "error: '-display' requires an argument\n"));
289 display_name
= argv
[i
];
293 bsetroot
app(argc
, argv
, display_name
);
This page took 0.045901 seconds and 4 git commands to generate.