3 * This is an all new program to set the root window to an Xpm pixmap.
4 * Copyright 1993, Rob Nation
5 * You may use this file for anything you want, as long as the copyright
6 * is kept intact. No guarantees of any sort are made in any way regarding
7 * this program or anything related to it.
15 #include <X11/Xatom.h>
16 #include "libs/fvwmlib.h"
17 #include "libs/Picture.h"
18 #include "libs/Graphics.h"
19 #include "libs/Fsvg.h"
25 char *display_name
= NULL
;
26 Pixmap rootImage
= None
;
27 Bool NoDither
= False
;
29 Bool NoColorLimit
= False
;
30 int opt_color_limit
= -1;
31 Bool use_our_color_limit
= False
;
33 void usage(int verbose
)
35 FILE *output
= verbose
? stdout
: stderr
;
37 output
, "fvwm-root version %s with support for: XBM"
49 "\nUsage: fvwm-root [ options ] file\n");
57 "\t--no-retain-pixmap\n"
59 "\t--no-color-limit\n"
67 int SetRootWindow(char *tline
)
69 Pixmap shapeMask
= None
, temp_pix
= None
, alpha
= None
;
72 int nalloc_pixels
= 0;
73 Pixel
*alloc_pixels
= NULL
;
75 FvwmPictureAttributes fpa
;
77 if (use_our_color_limit
)
79 PictureColorLimitOption colorLimitop
= {-1, -1, -1, -1, -1};
80 colorLimitop
.color_limit
= opt_color_limit
;
82 dpy
, !NoColorLimit
, &colorLimitop
, True
, True
);
86 /* this use the default visual (not the fvwm one) as
87 * getenv("FVWM_VISUALID") is NULL in any case. But this use
88 * the same color limit than fvwm.
89 * This is "broken" when fvwm use depth <= 8 and a private
90 * color map (i.e., fvwm is started with the -visual{ID}
91 * option), because when fvwm use a private color map the
92 * default color limit is 244. There is no way to know here if
93 * getenv("FVWM_VISUALID") !=NULL.
94 * So, in this unfortunate case the user should use the
95 * --color-limit option */
99 /* try built-in image path first, but not before pwd */
100 PictureSetImagePath(".:+");
101 file_path
= PictureFindImageFile(tline
, NULL
, R_OK
);
103 if (file_path
== NULL
)
107 fpa
.mask
= FPAM_NO_ALLOC_PIXELS
| FPAM_NO_ALPHA
;
108 if (Pdepth
<= 8 && !NoDither
)
110 fpa
.mask
|= FPAM_DITHER
;
112 else if (Pdepth
<= 16 && Dither
)
114 fpa
.mask
|= FPAM_DITHER
;
118 fpa
.mask
|= FPAM_NO_COLOR_LIMIT
;
120 if (!PImageLoadPixmapFromFile(
121 dpy
, root
, file_path
, &temp_pix
, &shapeMask
, &alpha
,
122 &w
, &h
, &depth
, &nalloc_pixels
, &alloc_pixels
, 0, fpa
))
125 stderr
, "[fvwm-root] failed to load image file '%s'\n",
131 rootImage
= temp_pix
;
138 gcv
.background
= WhitePixel(dpy
, screen
);
139 gcv
.foreground
= BlackPixel(dpy
, screen
);
140 gc
= fvwmlib_XCreateGC(
141 dpy
, root
, GCForeground
| GCBackground
, &gcv
);
142 rootImage
= XCreatePixmap(dpy
, root
, w
, h
, Pdepth
);
143 XCopyPlane(dpy
, temp_pix
, rootImage
, gc
, 0, 0, w
, h
, 0, 0, 1);
144 XFreePixmap(dpy
, temp_pix
);
147 XSetWindowBackgroundPixmap(dpy
, root
, rootImage
);
149 XClearWindow(dpy
, root
);
154 int main(int argc
, char **argv
)
161 unsigned long length
, after
;
164 Bool e_killed
= False
;
166 Bool RetainPixmap
= False
;
171 fprintf(stderr
, "Nothing to do, try again.\n");
174 dpy
= XOpenDisplay(display_name
);
178 stderr
, "fvwm-root: unable to open display '%s'\n",
179 XDisplayName (display_name
));
182 screen
= DefaultScreen(dpy
);
183 root
= RootWindow(dpy
, screen
);
185 for (i
= 1; i
< argc
- 1; i
++)
188 strcasecmp(argv
[i
], "-r") == 0 ||
189 strcasecmp(argv
[i
], "--retain-pixmap") == 0)
194 strcasecmp(argv
[i
], "--no-retain-pixmap") == 0)
196 RetainPixmap
= False
;
199 strcasecmp(argv
[i
], "-d") == 0 ||
200 strcasecmp(argv
[i
], "--dummy") == 0)
205 strcasecmp(argv
[i
], "--no-dummy") == 0)
210 strcasecmp(argv
[i
], "--dither") == 0)
215 strcasecmp(argv
[i
], "--no-dither") == 0)
220 strcasecmp(argv
[i
], "--color-limit") == 0)
222 use_our_color_limit
= True
;
226 opt_color_limit
= atoi(argv
[i
]);
230 strcasecmp(argv
[i
], "--no-color-limit") == 0)
235 strcasecmp(argv
[i
], "-h") == 0 ||
236 strcasecmp(argv
[i
], "-?") == 0 ||
237 strcasecmp(argv
[i
], "--help") == 0)
243 strcasecmp(argv
[i
], "-V") == 0 ||
244 strcasecmp(argv
[i
], "--version") == 0)
246 fprintf(stdout
, "%s\n", VERSION
);
252 stderr
, "fvwm-root: unknown option '%s'\n",
255 stderr
, "Run '%s --help' to get the usage.\n",
263 strcasecmp(argv
[argc
-1], "-d") == 0 ||
264 strcasecmp(argv
[argc
-1], "--dummy") == 0)
269 strcasecmp(argv
[argc
-1], "-h") == 0 ||
270 strcasecmp(argv
[argc
-1], "-?") == 0 ||
271 strcasecmp(argv
[argc
-1], "--help") == 0)
277 strcasecmp(argv
[argc
-1], "-V") == 0 ||
278 strcasecmp(argv
[argc
-1], "--version") == 0)
280 fprintf(stdout
, "%s\n", VERSION
);
287 rc
= SetRootWindow(argv
[argc
-1]);
294 prop
= XInternAtom(dpy
, "_XSETROOT_ID", False
);
295 (void)XGetWindowProperty(
296 dpy
, root
, prop
, 0L, 1L, True
, AnyPropertyType
,
297 &type
, &format
, &length
, &after
, &data
);
298 if (type
== XA_PIXMAP
&& format
== 32 && length
== 1 && after
== 0 &&
299 data
!= NULL
&& (Pixmap
)(*(long *)data
) != None
)
301 XKillClient(dpy
, *((Pixmap
*)data
));
306 e_prop
= XInternAtom(dpy
, "ESETROOT_PMAP_ID", False
);
307 (void)XGetWindowProperty(
308 dpy
, root
, e_prop
, 0L, 1L, True
, AnyPropertyType
,
309 &type
, &format
, &length
, &after
, &data
);
310 if (type
== XA_PIXMAP
&& format
== 32 && length
== 1 && after
== 0 &&
311 data
!= NULL
&& (Pixmap
)(*(long *)data
) != None
)
314 XKillClient(dpy
, *((Pixmap
*)data
));
316 if (e_killed
&& !Dummy
)
318 m_prop
= XInternAtom(dpy
, "_XROOTPMAP_ID", False
);
319 XDeleteProperty(dpy
, root
, m_prop
);
322 if (RetainPixmap
&& !Dummy
)
329 XSetCloseDownMode(dpy
, RetainPermanent
);
331 e_prop
= XInternAtom(dpy
, "ESETROOT_PMAP_ID", False
);
333 m_prop
= XInternAtom(dpy
, "_XROOTPMAP_ID", False
);
335 dpy
, root
, e_prop
, XA_PIXMAP
, 32, PropModeReplace
,
336 (unsigned char *) &prop
, 1);
338 dpy
, root
, m_prop
, XA_PIXMAP
, 32, PropModeReplace
,
339 (unsigned char *) &prop
, 1);
343 long dp
= (long)None
;
346 prop
= XInternAtom(dpy
, "_XSETROOT_ID", False
);
348 dpy
, root
, prop
, XA_PIXMAP
, 32, PropModeReplace
,
349 (unsigned char *) &dp
, 1);