1 /* wmsetbg.c- sets root window background image and also works as
2 * workspace background setting helper for wmaker
4 * WindowMaker window manager
6 * Copyright (c) 1998, 1999 Alfredo K. Kojima
7 * Copyright (c) 1998 Dan Pascu
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 * TODO: rewrite, too dirty
33 #include <X11/Xutil.h>
34 #include <X11/Xatom.h>
38 #include <sys/types.h>
41 #include "../src/config.h"
47 #include "../src/wconfig.h"
54 #define PROG_VERSION "wmsetbg (Window Maker) 2.5"
57 #define WORKSPACE_COUNT (MAX_WORKSPACES+1)
71 Pixmap CurrentPixmap
= None
;
72 char *PixmapPath
= NULL
;
75 extern Pixmap
LoadJPEG(RContext
*rc
, char *file_name
, int *width
, int *height
);
78 typedef struct BackgroundTexture
{
86 Pixmap pixmap
; /* for all textures, including solid */
87 int width
; /* size of the pixmap */
94 loadImage(RContext
*rc
, char *file
)
99 if (access(file
, F_OK
)!=0) {
100 path
= wfindfile(PixmapPath
, file
);
102 wwarning("%s:could not find image file used in texture", file
);
106 path
= wstrdup(file
);
109 image
= RLoadImage(rc
, path
, 0);
111 wwarning("%s:could not load image file used in texture:%s", path
,
112 RMessageForError(RErrorCode
));
121 parseTexture(RContext
*rc
, char *text
)
123 BackgroundTexture
*texture
= NULL
;
130 #define GETSTRORGOTO(val, str, i, label) \
131 val = PLGetArrayElement(texarray, i);\
132 if (!PLIsString(val)) {\
133 wwarning("could not parse texture %s", text);\
136 str = PLGetString(val)
138 texarray
= PLGetProplistWithDescription(text
);
139 if (!texarray
|| !PLIsArray(texarray
)
140 || (count
= PLGetNumberOfElements(texarray
)) < 2) {
142 wwarning("could not parse texture %s", text
);
148 texture
= wmalloc(sizeof(BackgroundTexture
));
149 memset(texture
, 0, sizeof(BackgroundTexture
));
151 GETSTRORGOTO(val
, type
, 0, error
);
153 if (strcasecmp(type
, "solid")==0) {
159 GETSTRORGOTO(val
, tmp
, 1, error
);
161 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
162 wwarning("could not parse color %s in texture %s", tmp
, text
);
165 XAllocColor(dpy
, DefaultColormap(dpy
, scr
), &color
);
167 pixmap
= XCreatePixmap(dpy
, root
, 8, 8, DefaultDepth(dpy
, scr
));
168 XSetForeground(dpy
, DefaultGC(dpy
, scr
), color
.pixel
);
169 XFillRectangle(dpy
, pixmap
, DefaultGC(dpy
, scr
), 0, 0, 8, 8);
171 texture
->pixmap
= pixmap
;
172 texture
->color
= color
;
175 } else if (strcasecmp(type
, "vgradient")==0
176 || strcasecmp(type
, "dgradient")==0
177 || strcasecmp(type
, "hgradient")==0) {
179 RColor color1
, color2
;
185 GETSTRORGOTO(val
, tmp
, 1, error
);
187 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
188 wwarning("could not parse color %s in texture %s", tmp
, text
);
192 color1
.red
= color
.red
>> 8;
193 color1
.green
= color
.green
>> 8;
194 color1
.blue
= color
.blue
>> 8;
196 GETSTRORGOTO(val
, tmp
, 2, error
);
198 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
199 wwarning("could not parse color %s in texture %s", tmp
, text
);
203 color2
.red
= color
.red
>> 8;
204 color2
.green
= color
.green
>> 8;
205 color2
.blue
= color
.blue
>> 8;
210 gtype
= RHorizontalGradient
;
216 gtype
= RVerticalGradient
;
221 gtype
= RDiagonalGradient
;
227 image
= RRenderGradient(iwidth
, iheight
, &color1
, &color2
, gtype
);
230 wwarning("could not render gradient texture:%s",
231 RMessageForError(RErrorCode
));
235 if (!RConvertImage(rc
, image
, &pixmap
)) {
236 wwarning("could not convert texture:%s",
237 RMessageForError(RErrorCode
));
238 RDestroyImage(image
);
242 texture
->width
= image
->width
;
243 texture
->height
= image
->height
;
244 RDestroyImage(image
);
246 texture
->pixmap
= pixmap
;
247 } else if (strcasecmp(type
, "mvgradient")==0
248 || strcasecmp(type
, "mdgradient")==0
249 || strcasecmp(type
, "mhgradient")==0) {
258 colors
= malloc(sizeof(RColor
*)*(count
-1));
260 wwarning("out of memory while parsing texture");
263 memset(colors
, 0, sizeof(RColor
*)*(count
-1));
265 for (i
= 2; i
< count
; i
++) {
266 val
= PLGetArrayElement(texarray
, i
);
267 if (!PLIsString(val
)) {
268 wwarning("could not parse texture %s", text
);
270 for (j
= 0; colors
[j
]!=NULL
; j
++)
275 tmp
= PLGetString(val
);
277 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
278 wwarning("could not parse color %s in texture %s",
281 for (j
= 0; colors
[j
]!=NULL
; j
++)
286 if (!(colors
[i
-2] = malloc(sizeof(RColor
)))) {
287 wwarning("out of memory while parsing texture");
289 for (j
= 0; colors
[j
]!=NULL
; j
++)
295 colors
[i
-2]->red
= color
.red
>> 8;
296 colors
[i
-2]->green
= color
.green
>> 8;
297 colors
[i
-2]->blue
= color
.blue
>> 8;
303 gtype
= RHorizontalGradient
;
309 gtype
= RVerticalGradient
;
314 gtype
= RDiagonalGradient
;
320 image
= RRenderMultiGradient(iwidth
, iheight
, colors
, gtype
);
322 for (j
= 0; colors
[j
]!=NULL
; j
++)
327 wwarning("could not render gradient texture:%s",
328 RMessageForError(RErrorCode
));
332 if (!RConvertImage(rc
, image
, &pixmap
)) {
333 wwarning("could not convert texture:%s",
334 RMessageForError(RErrorCode
));
335 RDestroyImage(image
);
339 texture
->width
= image
->width
;
340 texture
->height
= image
->height
;
341 RDestroyImage(image
);
343 texture
->pixmap
= pixmap
;
344 } else if (strcasecmp(type
, "cpixmap")==0
345 || strcasecmp(type
, "spixmap")==0
346 || strcasecmp(type
, "mpixmap")==0
347 || strcasecmp(type
, "tpixmap")==0) {
349 Pixmap pixmap
= None
;
350 RImage
*image
= NULL
;
356 GETSTRORGOTO(val
, tmp
, 1, error
);
358 if (toupper(type[0]) == 'T' || toupper(type[0]) == 'C')
359 pixmap = LoadJPEG(rc, tmp, &iwidth, &iheight);
363 image
= loadImage(rc
, tmp
);
367 iwidth
= image
->width
;
368 iheight
= image
->height
;
371 GETSTRORGOTO(val
, tmp
, 2, error
);
373 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
374 wwarning("could not parse color %s in texture %s\n", tmp
, text
);
375 RDestroyImage(image
);
378 if (!XAllocColor(dpy
, DefaultColormap(dpy
, scr
), &color
)) {
379 rcolor
.red
= color
.red
>> 8;
380 rcolor
.green
= color
.green
>> 8;
381 rcolor
.blue
= color
.blue
>> 8;
382 RGetClosestXColor(rc
, &rcolor
, &color
);
388 /* for images with a transparent color */
389 if (image
->data
[3]) {
390 RCombineImageWithColor(image
, &rcolor
);
393 switch (toupper(type
[0])) {
395 texture
->width
= iwidth
;
396 texture
->height
= iheight
;
397 if (!pixmap
&& !RConvertImage(rc
, image
, &pixmap
)) {
398 wwarning("could not convert texture:%s",
399 RMessageForError(RErrorCode
));
400 RDestroyImage(image
);
404 RDestroyImage(image
);
408 if (toupper(type
[0])=='S') {
412 if (iwidth
*scrHeight
> iheight
*scrWidth
) {
414 h
= (scrWidth
*iheight
)/iwidth
;
417 w
= (scrHeight
*iwidth
)/iheight
;
420 if (w
!= image
->width
|| h
!= image
->height
) {
424 simage
= RSmoothScaleImage(image
, w
, h
);
426 simage
= RScaleImage(image
, w
, h
);
428 wwarning("could not scale image:%s",
429 RMessageForError(RErrorCode
));
430 RDestroyImage(image
);
433 RDestroyImage(image
);
436 iwidth
= image
->width
;
437 iheight
= image
->height
;
444 if (!pixmap
&& !RConvertImage(rc
, image
, &pixmap
)) {
445 wwarning("could not convert texture:%s",
446 RMessageForError(RErrorCode
));
447 RDestroyImage(image
);
451 if (iwidth
!= scrWidth
|| iheight
!= scrHeight
) {
452 int x
, y
, sx
, sy
, w
, h
;
454 cpixmap
= XCreatePixmap(dpy
, root
, scrWidth
, scrHeight
,
455 DefaultDepth(dpy
, scr
));
457 XSetForeground(dpy
, DefaultGC(dpy
, scr
), color
.pixel
);
458 XFillRectangle(dpy
, cpixmap
, DefaultGC(dpy
, scr
),
459 0, 0, scrWidth
, scrHeight
);
461 if (iheight
< scrHeight
) {
463 y
= (scrHeight
- h
)/2;
466 sy
= (iheight
- scrHeight
)/2;
470 if (iwidth
< scrWidth
) {
472 x
= (scrWidth
- w
)/2;
475 sx
= (iwidth
- scrWidth
)/2;
480 XCopyArea(dpy
, pixmap
, cpixmap
, DefaultGC(dpy
, scr
),
482 XFreePixmap(dpy
, pixmap
);
486 RDestroyImage(image
);
488 texture
->width
= scrWidth
;
489 texture
->height
= scrHeight
;
494 texture
->pixmap
= pixmap
;
495 texture
->color
= color
;
496 } else if (strcasecmp(type
, "thgradient")==0
497 || strcasecmp(type
, "tvgradient")==0
498 || strcasecmp(type
, "tdgradient")==0) {
500 RColor color1
, color2
;
510 GETSTRORGOTO(val
, file
, 1, error
);
512 GETSTRORGOTO(val
, tmp
, 2, error
);
516 GETSTRORGOTO(val
, tmp
, 3, error
);
518 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
519 wwarning("could not parse color %s in texture %s", tmp
, text
);
523 color1
.red
= color
.red
>> 8;
524 color1
.green
= color
.green
>> 8;
525 color1
.blue
= color
.blue
>> 8;
527 GETSTRORGOTO(val
, tmp
, 4, error
);
529 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
530 wwarning("could not parse color %s in texture %s", tmp
, text
);
534 color2
.red
= color
.red
>> 8;
535 color2
.green
= color
.green
>> 8;
536 color2
.blue
= color
.blue
>> 8;
538 image
= loadImage(rc
, file
);
546 gtype
= RHorizontalGradient
;
548 theight
= image
->height
> scrHeight
? scrHeight
: image
->height
;
552 gtype
= RVerticalGradient
;
553 twidth
= image
->width
> scrWidth
? scrWidth
: image
->width
;
557 gtype
= RDiagonalGradient
;
562 gradient
= RRenderGradient(twidth
, theight
, &color1
, &color2
, gtype
);
565 wwarning("could not render texture:%s",
566 RMessageForError(RErrorCode
));
567 RDestroyImage(gradient
);
568 RDestroyImage(image
);
572 tiled
= RMakeTiledImage(image
, twidth
, theight
);
574 wwarning("could not render texture:%s",
575 RMessageForError(RErrorCode
));
576 RDestroyImage(gradient
);
577 RDestroyImage(image
);
580 RDestroyImage(image
);
582 RCombineImagesWithOpaqueness(tiled
, gradient
, opaq
);
583 RDestroyImage(gradient
);
585 if (!RConvertImage(rc
, tiled
, &pixmap
)) {
586 wwarning("could not convert texture:%s",
587 RMessageForError(RErrorCode
));
588 RDestroyImage(tiled
);
591 texture
->width
= tiled
->width
;
592 texture
->height
= tiled
->height
;
594 RDestroyImage(tiled
);
596 texture
->pixmap
= pixmap
;
597 } else if (strcasecmp(type
, "function")==0) {
599 void (*initFunc
) (Display
*, Colormap
);
600 RImage
* (*mainFunc
) (int, char**, int, int, int);
604 char *lib
, *func
, **argv
= 0;
609 goto function_cleanup
;
611 /* get the library name */
612 GETSTRORGOTO(val
, lib
, 1, function_cleanup
);
614 /* get the function name */
615 GETSTRORGOTO(val
, func
, 2, function_cleanup
);
618 argv
= (char**)wmalloc(argc
* sizeof(char*));
620 /* get the parameters */
622 for (i
=0; i
<argc
-1; i
++) {
623 GETSTRORGOTO(val
, tmp
, 3+i
, function_cleanup
);
624 argv
[i
+1] = wstrdup(tmp
);
627 handle
= dlopen(lib
, RTLD_LAZY
);
629 wwarning("could not find library %s", lib
);
630 goto function_cleanup
;
633 initFunc
= dlsym(handle
, "initWindowMaker");
635 wwarning("could not initialize library %s", lib
);
636 goto function_cleanup
;
638 initFunc(dpy
, DefaultColormap(dpy
, scr
));
640 mainFunc
= dlsym(handle
, func
);
642 wwarning("could not find function %s::%s", lib
, func
);
643 goto function_cleanup
;
645 image
= mainFunc(argc
, argv
, scrWidth
, scrHeight
, 0);
647 if (!RConvertImage(rc
, image
, &pixmap
)) {
648 wwarning("could not convert texture:%s",
649 RMessageForError(RErrorCode
));
650 goto function_cleanup
;
652 texture
->width
= scrWidth
;
653 texture
->height
= scrHeight
;
654 texture
->pixmap
= pixmap
;
660 for (i
=0; i
<argc
; i
++) {
668 RDestroyImage(image
);
674 wwarning("function textures not supported");
678 wwarning("invalid texture type %s", text
);
682 texture
->spec
= wstrdup(text
);
697 freeTexture(BackgroundTexture
*texture
)
699 if (texture
->solid
) {
702 pixel
[0] = texture
->color
.pixel
;
703 /* dont free black/white pixels */
704 if (pixel
[0]!=BlackPixelOfScreen(DefaultScreenOfDisplay(dpy
))
705 && pixel
[0]!=WhitePixelOfScreen(DefaultScreenOfDisplay(dpy
)))
706 XFreeColors(dpy
, DefaultColormap(dpy
, scr
), pixel
, 1, 0);
708 if (texture
->pixmap
) {
709 XFreePixmap(dpy
, texture
->pixmap
);
717 setupTexture(RContext
*rc
, BackgroundTexture
**textures
, int *maxTextures
,
718 int workspace
, char *texture
)
720 BackgroundTexture
*newTexture
= NULL
;
723 /* unset the texture */
725 if (textures
[workspace
]!=NULL
) {
726 textures
[workspace
]->refcount
--;
728 if (textures
[workspace
]->refcount
== 0)
729 freeTexture(textures
[workspace
]);
731 textures
[workspace
] = NULL
;
735 if (textures
[workspace
]
736 && strcasecmp(textures
[workspace
]->spec
, texture
)==0) {
737 /* texture did not change */
741 /* check if the same texture is already created */
742 for (i
= 0; i
< *maxTextures
; i
++) {
743 if (textures
[i
] && strcasecmp(textures
[i
]->spec
, texture
)==0) {
744 newTexture
= textures
[i
];
750 /* create the texture */
751 newTexture
= parseTexture(rc
, texture
);
756 if (textures
[workspace
]!=NULL
) {
758 textures
[workspace
]->refcount
--;
760 if (textures
[workspace
]->refcount
== 0)
761 freeTexture(textures
[workspace
]);
764 newTexture
->refcount
++;
765 textures
[workspace
] = newTexture
;
767 if (*maxTextures
< workspace
)
768 *maxTextures
= workspace
;
774 duplicatePixmap(Pixmap pixmap
, int width
, int height
)
779 /* must open a new display or the RetainPermanent will
780 * leave stuff allocated in RContext unallocated after exit */
781 tmpDpy
= XOpenDisplay(display
);
783 wwarning("could not open display to update background image information");
789 copyP
= XCreatePixmap(tmpDpy
, root
, width
, height
,
790 DefaultDepth(tmpDpy
, scr
));
791 XCopyArea(tmpDpy
, pixmap
, copyP
, DefaultGC(tmpDpy
, scr
),
792 0, 0, width
, height
, 0, 0);
793 XSync(tmpDpy
, False
);
795 XSetCloseDownMode(tmpDpy
, RetainPermanent
);
796 XCloseDisplay(tmpDpy
);
804 dummyErrorHandler(Display
*dpy
, XErrorEvent
*err
)
810 setPixmapProperty(Pixmap pixmap
)
812 static Atom prop
= 0;
815 unsigned long length
, after
;
820 prop
= XInternAtom(dpy
, "_XROOTPMAP_ID", False
);
825 /* Clear out the old pixmap */
826 XGetWindowProperty(dpy
, root
, prop
, 0L, 1L, False
, AnyPropertyType
,
827 &type
, &format
, &length
, &after
, &data
);
829 if ((type
== XA_PIXMAP
) && (format
== 32) && (length
== 1)) {
830 XSetErrorHandler(dummyErrorHandler
);
831 XKillClient(dpy
, *((Pixmap
*)data
));
833 XSetErrorHandler(NULL
);
834 mode
= PropModeReplace
;
836 mode
= PropModeAppend
;
839 XChangeProperty(dpy
, root
, prop
, XA_PIXMAP
, 32, mode
,
840 (unsigned char *) &pixmap
, 1);
842 XDeleteProperty(dpy
, root
, prop
);
852 changeTexture(BackgroundTexture
*texture
)
858 if (texture
->solid
) {
859 XSetWindowBackground(dpy
, root
, texture
->color
.pixel
);
861 XSetWindowBackgroundPixmap(dpy
, root
, texture
->pixmap
);
863 XClearWindow(dpy
, root
);
870 pixmap
= duplicatePixmap(texture
->pixmap
, texture
->width
,
873 setPixmapProperty(pixmap
);
879 readmsg(int fd
, unsigned char *buffer
, int size
)
885 count
= read(fd
, buffer
, size
);
899 * sizeSntexture_spec - sets the texture for workspace n
900 * sizeCn - change background texture to the one for workspace n
901 * sizePpath - set the pixmap search path
904 * size = 4 bytes for length of the message data
907 helperLoop(RContext
*rc
)
909 BackgroundTexture
*textures
[WORKSPACE_COUNT
];
911 unsigned char buffer
[2048], buf
[8];
915 memset(textures
, 0, WORKSPACE_COUNT
*sizeof(BackgroundTexture
*));
921 /* get length of message */
922 if (readmsg(0, buffer
, 4) < 0) {
923 wsyserror("error reading message from Window Maker");
931 memcpy(buf
, buffer
, 4);
936 if (readmsg(0, buffer
, size
) < 0) {
937 wsyserror("error reading message from Window Maker");
946 printf("RECEIVED %s\n",buffer
);
948 if (buffer
[0]!='P' && buffer
[0]!='K') {
949 memcpy(buf
, &buffer
[1], 4);
951 workspace
= atoi(buf
);
952 if (workspace
< 0 || workspace
>= WORKSPACE_COUNT
) {
953 wwarning("received message with invalid workspace number %i\n",
962 printf("set texture %s\n", &buffer
[5]);
964 setupTexture(rc
, textures
, &maxTextures
, workspace
, &buffer
[5]);
969 printf("change texture %i\n", workspace
);
971 if (!textures
[workspace
]) {
972 changeTexture(textures
[0]);
974 changeTexture(textures
[workspace
]);
980 printf("change pixmappath %s\n", &buffer
[1]);
984 PixmapPath
= wstrdup(&buffer
[1]);
989 printf("unset workspace %i\n", workspace
);
991 setupTexture(rc
, textures
, &maxTextures
, workspace
, NULL
);
996 printf("exit command\n");
1001 wwarning("unknown message received");
1009 updateDomain(char *domain
, char *key
, char *texture
)
1011 char *program
= "wdwrite";
1013 system(wstrappend("wdwrite ",
1014 wstrappend(domain
, smooth
? " SmoothWorkspaceBack YES"
1015 : " SmoothWorkspaceBack NO")));
1017 execlp(program
, program
, domain
, key
, texture
, NULL
);
1018 wwarning("warning could not run \"%s\"", program
);
1024 globalDefaultsPathForDomain(char *domain
)
1028 sprintf(path
, "%s/WindowMaker/%s", SYSCONFDIR
, domain
);
1030 return wstrdup(path
);
1035 getValueForKey(char *domain
, char *keyName
)
1042 key
= PLMakeString(keyName
);
1044 /* try to find PixmapPath in user defaults */
1045 path
= wdefaultspathfordomain(domain
);
1046 d
= PLGetProplistWithPath(path
);
1048 wwarning("could not open domain file %s", path
);
1052 if (d
&& !PLIsDictionary(d
)) {
1057 val
= PLGetDictionaryEntry(d
, key
);
1061 /* try to find PixmapPath in global defaults */
1063 path
= globalDefaultsPathForDomain(domain
);
1065 wwarning("could not locate file for domain %s", domain
);
1068 d
= PLGetProplistWithPath(path
);
1072 if (d
&& !PLIsDictionary(d
)) {
1077 val
= PLGetDictionaryEntry(d
, key
);
1097 getPixmapPath(char *domain
)
1103 val
= getValueForKey(domain
, "PixmapPath");
1105 if (!val
|| !PLIsArray(val
)) {
1111 count
= PLGetNumberOfElements(val
);
1113 for (i
=0; i
<count
; i
++) {
1116 v
= PLGetArrayElement(val
, i
);
1117 if (!v
|| !PLIsString(v
)) {
1120 len
+= strlen(PLGetString(v
))+1;
1123 ptr
= data
= wmalloc(len
+1);
1126 for (i
=0; i
<count
; i
++) {
1129 v
= PLGetArrayElement(val
, i
);
1130 if (!v
|| !PLIsString(v
)) {
1133 strcpy(ptr
, PLGetString(v
));
1135 ptr
+= strlen(PLGetString(v
));
1140 ptr
--; *(ptr
--) = 0;
1158 print_help(char *ProgName
)
1160 printf("Usage: %s [options] [image]\n", ProgName
);
1161 puts("Sets the workspace background to the specified image or a texture and optionally update Window Maker configuration");
1163 #define P(m) puts(m)
1164 P(" -display display to use");
1165 P(" -d, --dither dither image");
1166 P(" -m, --match match colors");
1167 P(" -S, --smooth smooth scaled image");
1168 P(" -b, --back-color <color> background color");
1169 P(" -t, --tile tile image");
1170 P(" -e, --center center image");
1171 P(" -s, --scale scale image (default)");
1172 P(" -a, --maxscale scale image and keep aspect ratio");
1173 P(" -u, --update-wmaker update WindowMaker domain database");
1174 P(" -D, --update-domain <domain> update <domain> database");
1175 P(" -c, --colors <cpc> colors per channel to use");
1176 P(" -p, --parse <texture> proplist style texture specification");
1177 P(" -w, --workspace <workspace> update background for the specified workspace");
1178 P(" --version show version of wmsetbg and exit");
1179 P(" --help show this help and exit");
1186 changeTextureForWorkspace(char *domain
, char *texture
, int workspace
)
1193 val
= PLGetProplistWithDescription(texture
);
1195 wwarning("could not parse texture %s", texture
);
1199 array
= getValueForKey("WindowMaker", "WorkspaceSpecificBack");
1202 array
= PLMakeArrayFromElements(NULL
, NULL
);
1205 j
= PLGetNumberOfElements(array
);
1206 if (workspace
>= j
) {
1209 empty
= PLMakeArrayFromElements(NULL
, NULL
);
1211 while (j
++ < workspace
-1) {
1212 PLAppendArrayElement(array
, empty
);
1214 PLAppendArrayElement(array
, val
);
1216 PLRemoveArrayElement(array
, workspace
);
1217 PLInsertArrayElement(array
, val
, workspace
);
1220 value
= PLGetDescription(array
);
1221 updateDomain(domain
, "WorkspaceSpecificBack", value
);
1226 main(int argc
, char **argv
)
1231 RContextAttributes rattr
;
1232 char *style
= "spixmap";
1233 char *back_color
= "gray20";
1234 char *image_name
= NULL
;
1235 char *domain
= "WindowMaker";
1236 int update
=0, cpc
=4, render_mode
=RDitheredRendering
, obey_user
=0;
1237 char *texture
= NULL
;
1240 signal(SIGINT
, SIG_DFL
);
1241 signal(SIGTERM
, SIG_DFL
);
1242 signal(SIGQUIT
, SIG_DFL
);
1243 signal(SIGSEGV
, SIG_DFL
);
1244 signal(SIGBUS
, SIG_DFL
);
1245 signal(SIGFPE
, SIG_DFL
);
1246 signal(SIGABRT
, SIG_DFL
);
1247 signal(SIGHUP
, SIG_DFL
);
1248 signal(SIGPIPE
, SIG_DFL
);
1249 signal(SIGCHLD
, SIG_DFL
);
1251 WMInitializeApplication("wmsetbg", &argc
, argv
);
1253 for (i
=1; i
<argc
; i
++) {
1254 if (strcmp(argv
[i
], "-helper")==0) {
1256 } else if (strcmp(argv
[i
], "-display")==0) {
1259 wfatal("too few arguments for %s\n", argv
[i
-1]);
1263 } else if (strcmp(argv
[i
], "-s")==0
1264 || strcmp(argv
[i
], "--scale")==0) {
1266 } else if (strcmp(argv
[i
], "-t")==0
1267 || strcmp(argv
[i
], "--tile")==0) {
1269 } else if (strcmp(argv
[i
], "-e")==0
1270 || strcmp(argv
[i
], "--center")==0) {
1272 } else if (strcmp(argv
[i
], "-a")==0
1273 || strcmp(argv
[i
], "--maxscale")==0) {
1275 } else if (strcmp(argv
[i
], "-d")==0
1276 || strcmp(argv
[i
], "--dither")==0) {
1277 render_mode
= RDitheredRendering
;
1279 } else if (strcmp(argv
[i
], "-m")==0
1280 || strcmp(argv
[i
], "--match")==0) {
1281 render_mode
= RBestMatchRendering
;
1283 } else if (strcmp(argv
[i
], "-S")==0
1284 || strcmp(argv
[i
], "--smooth")==0) {
1286 } else if (strcmp(argv
[i
], "-u")==0
1287 || strcmp(argv
[i
], "--update-wmaker")==0) {
1289 } else if (strcmp(argv
[i
], "-D")==0
1290 || strcmp(argv
[i
], "--update-domain")==0) {
1294 wfatal("too few arguments for %s\n", argv
[i
-1]);
1297 domain
= wstrdup(argv
[i
]);
1298 } else if (strcmp(argv
[i
], "-c")==0
1299 || strcmp(argv
[i
], "--colors")==0) {
1302 wfatal("too few arguments for %s\n", argv
[i
-1]);
1305 if (sscanf(argv
[i
], "%i", &cpc
)!=1) {
1306 wfatal("bad value for colors per channel: \"%s\"\n", argv
[i
]);
1309 } else if (strcmp(argv
[i
], "-b")==0
1310 || strcmp(argv
[i
], "--back-color")==0) {
1313 wfatal("too few arguments for %s\n", argv
[i
-1]);
1316 back_color
= argv
[i
];
1317 } else if (strcmp(argv
[i
], "-p")==0
1318 || strcmp(argv
[i
], "--parse")==0) {
1321 wfatal("too few arguments for %s\n", argv
[i
-1]);
1325 } else if (strcmp(argv
[i
], "-w")==0
1326 || strcmp(argv
[i
], "--workspace")==0) {
1329 wfatal("too few arguments for %s\n", argv
[i
-1]);
1332 if (sscanf(argv
[i
], "%i", &workspace
)!=1) {
1333 wfatal("bad value for workspace number: \"%s\"",
1337 } else if (strcmp(argv
[i
], "--version")==0) {
1339 printf(PROG_VERSION
);
1342 } else if (strcmp(argv
[i
], "--help")==0) {
1343 print_help(argv
[0]);
1345 } else if (argv
[i
][0] != '-') {
1346 image_name
= argv
[i
];
1348 printf("%s: invalid argument '%s'\n", argv
[0], argv
[i
]);
1349 printf("Try '%s --help' for more information\n", argv
[0]);
1353 if (!image_name
&& !texture
&& !helperMode
) {
1354 printf("%s: you must specify a image file name or a texture\n",
1356 printf("Try '%s --help' for more information\n", argv
[0]);
1361 PixmapPath
= getPixmapPath(domain
);
1364 #if 0 /* some problem with Alpha... TODO: check if its right */
1365 val
= PLGetDictionaryEntry(domain
,
1366 PLMakeString("SmoothWorkspaceBack"));
1368 val
= getValueForKey(domain
, "SmoothWorkspaceBack");
1371 if (val
&& PLIsString(val
) && strcasecmp(PLGetString(val
), "YES")==0)
1375 dpy
= XOpenDisplay(display
);
1377 wfatal("could not open display");
1381 XSynchronize(dpy
, 1);
1384 root
= DefaultRootWindow(dpy
);
1386 scr
= DefaultScreen(dpy
);
1388 scrWidth
= WidthOfScreen(DefaultScreenOfDisplay(dpy
));
1389 scrHeight
= HeightOfScreen(DefaultScreenOfDisplay(dpy
));
1391 if (!obey_user
&& DefaultDepth(dpy
, scr
) <= 8)
1392 render_mode
= RDitheredRendering
;
1394 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
1395 | RC_StandardColormap
;
1396 rattr
.render_mode
= render_mode
;
1397 rattr
.colors_per_channel
= cpc
;
1398 rattr
.standard_colormap_mode
= RCreateStdColormap
;
1400 rc
= RCreateContext(dpy
, scr
, &rattr
);
1402 wfatal("could not initialize wrlib:",
1403 RMessageForError(RErrorCode
));
1408 /* lower priority, so that it wont use all the CPU */
1413 BackgroundTexture
*tex
;
1417 sprintf(buffer
, "(%s, \"%s\", %s)", style
, image_name
, back_color
);
1418 texture
= (char*)buffer
;
1421 if (update
&& workspace
< 0) {
1422 updateDomain(domain
, "WorkspaceBack", texture
);
1425 tex
= parseTexture(rc
, texture
);
1432 /* always update domain */
1433 changeTextureForWorkspace(domain
, texture
, workspace
);