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"
49 #include "../WINGs/WINGs.h"
50 #include "../WINGs/WUtil.h"
51 #include "../wrlib/wraster.h"
55 #define PROG_VERSION "wmsetbg (Window Maker) 2.3"
58 #define WORKSPACE_COUNT (MAX_WORKSPACES+1)
72 Pixmap CurrentPixmap
= None
;
73 char *PixmapPath
= NULL
;
76 extern Pixmap
LoadJPEG(RContext
*rc
, char *file_name
, int *width
, int *height
);
79 typedef struct BackgroundTexture
{
87 Pixmap pixmap
; /* for all textures, including solid */
88 int width
; /* size of the pixmap */
95 loadImage(RContext
*rc
, char *file
)
100 if (access(file
, F_OK
)!=0) {
101 path
= wfindfile(PixmapPath
, file
);
103 wwarning("%s:could not find image file used in texture", file
);
107 path
= wstrdup(file
);
110 image
= RLoadImage(rc
, path
, 0);
112 wwarning("%s:could not load image file used in texture:%s", path
,
113 RMessageForError(RErrorCode
));
122 parseTexture(RContext
*rc
, char *text
)
124 BackgroundTexture
*texture
= NULL
;
131 #define GETSTRORGOTO(val, str, i, label) \
132 val = PLGetArrayElement(texarray, i);\
133 if (!PLIsString(val)) {\
134 wwarning("could not parse texture %s", text);\
137 str = PLGetString(val)
139 texarray
= PLGetProplistWithDescription(text
);
140 if (!texarray
|| !PLIsArray(texarray
)
141 || (count
= PLGetNumberOfElements(texarray
)) < 2) {
143 wwarning("could not parse texture %s", text
);
149 texture
= wmalloc(sizeof(BackgroundTexture
));
150 memset(texture
, 0, sizeof(BackgroundTexture
));
152 GETSTRORGOTO(val
, type
, 0, error
);
154 if (strcasecmp(type
, "solid")==0) {
160 GETSTRORGOTO(val
, tmp
, 1, error
);
162 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
163 wwarning("could not parse color %s in texture %s", tmp
, text
);
166 XAllocColor(dpy
, DefaultColormap(dpy
, scr
), &color
);
168 pixmap
= XCreatePixmap(dpy
, root
, 8, 8, DefaultDepth(dpy
, scr
));
169 XSetForeground(dpy
, DefaultGC(dpy
, scr
), color
.pixel
);
170 XFillRectangle(dpy
, pixmap
, DefaultGC(dpy
, scr
), 0, 0, 8, 8);
172 texture
->pixmap
= pixmap
;
173 texture
->color
= color
;
176 } else if (strcasecmp(type
, "vgradient")==0
177 || strcasecmp(type
, "dgradient")==0
178 || strcasecmp(type
, "hgradient")==0) {
180 RColor color1
, color2
;
186 GETSTRORGOTO(val
, tmp
, 1, error
);
188 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
189 wwarning("could not parse color %s in texture %s", tmp
, text
);
193 color1
.red
= color
.red
>> 8;
194 color1
.green
= color
.green
>> 8;
195 color1
.blue
= color
.blue
>> 8;
197 GETSTRORGOTO(val
, tmp
, 2, error
);
199 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
200 wwarning("could not parse color %s in texture %s", tmp
, text
);
204 color2
.red
= color
.red
>> 8;
205 color2
.green
= color
.green
>> 8;
206 color2
.blue
= color
.blue
>> 8;
211 gtype
= RHorizontalGradient
;
217 gtype
= RVerticalGradient
;
222 gtype
= RDiagonalGradient
;
228 image
= RRenderGradient(iwidth
, iheight
, &color1
, &color2
, gtype
);
231 wwarning("could not render gradient texture:%s",
232 RMessageForError(RErrorCode
));
236 if (!RConvertImage(rc
, image
, &pixmap
)) {
237 wwarning("could not convert texture:%s",
238 RMessageForError(RErrorCode
));
239 RDestroyImage(image
);
243 texture
->width
= image
->width
;
244 texture
->height
= image
->height
;
245 RDestroyImage(image
);
247 texture
->pixmap
= pixmap
;
248 } else if (strcasecmp(type
, "mvgradient")==0
249 || strcasecmp(type
, "mdgradient")==0
250 || strcasecmp(type
, "mhgradient")==0) {
259 colors
= malloc(sizeof(RColor
*)*(count
-1));
261 wwarning("out of memory while parsing texture");
264 memset(colors
, 0, sizeof(RColor
*)*(count
-1));
266 for (i
= 2; i
< count
; i
++) {
267 val
= PLGetArrayElement(texarray
, i
);
268 if (!PLIsString(val
)) {
269 wwarning("could not parse texture %s", text
);
271 for (j
= 0; colors
[j
]!=NULL
; j
++)
276 tmp
= PLGetString(val
);
278 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
279 wwarning("could not parse color %s in texture %s",
282 for (j
= 0; colors
[j
]!=NULL
; j
++)
287 if (!(colors
[i
-2] = malloc(sizeof(RColor
)))) {
288 wwarning("out of memory while parsing texture");
290 for (j
= 0; colors
[j
]!=NULL
; j
++)
296 colors
[i
-2]->red
= color
.red
>> 8;
297 colors
[i
-2]->green
= color
.green
>> 8;
298 colors
[i
-2]->blue
= color
.blue
>> 8;
304 gtype
= RHorizontalGradient
;
310 gtype
= RVerticalGradient
;
315 gtype
= RDiagonalGradient
;
321 image
= RRenderMultiGradient(iwidth
, iheight
, colors
, gtype
);
323 for (j
= 0; colors
[j
]!=NULL
; j
++)
328 wwarning("could not render gradient texture:%s",
329 RMessageForError(RErrorCode
));
333 if (!RConvertImage(rc
, image
, &pixmap
)) {
334 wwarning("could not convert texture:%s",
335 RMessageForError(RErrorCode
));
336 RDestroyImage(image
);
340 texture
->width
= image
->width
;
341 texture
->height
= image
->height
;
342 RDestroyImage(image
);
344 texture
->pixmap
= pixmap
;
345 } else if (strcasecmp(type
, "cpixmap")==0
346 || strcasecmp(type
, "spixmap")==0
347 || strcasecmp(type
, "mpixmap")==0
348 || strcasecmp(type
, "tpixmap")==0) {
350 Pixmap pixmap
= None
;
351 RImage
*image
= NULL
;
355 GETSTRORGOTO(val
, tmp
, 1, error
);
357 if (toupper(type[0]) == 'T' || toupper(type[0]) == 'C')
358 pixmap = LoadJPEG(rc, tmp, &iwidth, &iheight);
362 image
= loadImage(rc
, tmp
);
366 iwidth
= image
->width
;
367 iheight
= image
->height
;
370 GETSTRORGOTO(val
, tmp
, 2, error
);
372 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
373 wwarning("could not parse color %s in texture %s\n", tmp
, text
);
374 RDestroyImage(image
);
377 if (!XAllocColor(dpy
, DefaultColormap(dpy
, scr
), &color
)) {
380 rcolor
.red
= color
.red
>> 8;
381 rcolor
.green
= color
.green
>> 8;
382 rcolor
.blue
= color
.blue
>> 8;
383 RGetClosestXColor(rc
, &rcolor
, &color
);
386 switch (toupper(type
[0])) {
388 texture
->width
= iwidth
;
389 texture
->height
= iheight
;
390 if (!pixmap
&& !RConvertImage(rc
, image
, &pixmap
)) {
391 wwarning("could not convert texture:%s",
392 RMessageForError(RErrorCode
));
393 RDestroyImage(image
);
397 RDestroyImage(image
);
401 if (toupper(type
[0])=='S') {
405 if (iwidth
*scrHeight
> iheight
*scrWidth
) {
407 h
= (scrWidth
*iheight
)/iwidth
;
410 w
= (scrHeight
*iwidth
)/iheight
;
417 simage
= RSmoothScaleImage(image
, w
, h
);
419 simage
= RScaleImage(image
, w
, h
);
421 wwarning("could not scale image:%s",
422 RMessageForError(RErrorCode
));
423 RDestroyImage(image
);
426 RDestroyImage(image
);
428 iwidth
= image
->width
;
429 iheight
= image
->height
;
436 if (!pixmap
&& !RConvertImage(rc
, image
, &pixmap
)) {
437 wwarning("could not convert texture:%s",
438 RMessageForError(RErrorCode
));
439 RDestroyImage(image
);
443 if (iwidth
!= scrWidth
|| iheight
!= scrHeight
) {
444 int x
, y
, sx
, sy
, w
, h
;
446 cpixmap
= XCreatePixmap(dpy
, root
, scrWidth
, scrHeight
,
447 DefaultDepth(dpy
, scr
));
449 XSetForeground(dpy
, DefaultGC(dpy
, scr
), color
.pixel
);
450 XFillRectangle(dpy
, cpixmap
, DefaultGC(dpy
, scr
),
451 0, 0, scrWidth
, scrHeight
);
453 if (iheight
< scrHeight
) {
455 y
= (scrHeight
- h
)/2;
458 sy
= (iheight
- scrHeight
)/2;
462 if (iwidth
< scrWidth
) {
464 x
= (scrWidth
- w
)/2;
467 sx
= (iwidth
- scrWidth
)/2;
472 XCopyArea(dpy
, pixmap
, cpixmap
, DefaultGC(dpy
, scr
),
474 XFreePixmap(dpy
, pixmap
);
478 RDestroyImage(image
);
480 texture
->width
= scrWidth
;
481 texture
->height
= scrHeight
;
486 texture
->pixmap
= pixmap
;
487 texture
->color
= color
;
488 } else if (strcasecmp(type
, "thgradient")==0
489 || strcasecmp(type
, "tvgradient")==0
490 || strcasecmp(type
, "tdgradient")==0) {
492 RColor color1
, color2
;
502 GETSTRORGOTO(val
, file
, 1, error
);
504 GETSTRORGOTO(val
, tmp
, 2, error
);
508 GETSTRORGOTO(val
, tmp
, 3, error
);
510 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
511 wwarning("could not parse color %s in texture %s", tmp
, text
);
515 color1
.red
= color
.red
>> 8;
516 color1
.green
= color
.green
>> 8;
517 color1
.blue
= color
.blue
>> 8;
519 GETSTRORGOTO(val
, tmp
, 4, error
);
521 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
522 wwarning("could not parse color %s in texture %s", tmp
, text
);
526 color2
.red
= color
.red
>> 8;
527 color2
.green
= color
.green
>> 8;
528 color2
.blue
= color
.blue
>> 8;
530 image
= loadImage(rc
, file
);
532 RDestroyImage(gradient
);
539 gtype
= RHorizontalGradient
;
541 theight
= image
->height
> scrHeight
? scrHeight
: image
->height
;
545 gtype
= RVerticalGradient
;
546 twidth
= image
->width
> scrWidth
? scrWidth
: image
->width
;
550 gtype
= RDiagonalGradient
;
555 gradient
= RRenderGradient(twidth
, theight
, &color1
, &color2
, gtype
);
558 wwarning("could not render texture:%s",
559 RMessageForError(RErrorCode
));
560 RDestroyImage(gradient
);
564 tiled
= RMakeTiledImage(image
, twidth
, theight
);
566 wwarning("could not render texture:%s",
567 RMessageForError(RErrorCode
));
568 RDestroyImage(gradient
);
569 RDestroyImage(image
);
572 RDestroyImage(image
);
574 RCombineImagesWithOpaqueness(tiled
, gradient
, opaq
);
575 RDestroyImage(gradient
);
577 if (!RConvertImage(rc
, tiled
, &pixmap
)) {
578 wwarning("could not convert texture:%s",
579 RMessageForError(RErrorCode
));
580 RDestroyImage(image
);
583 texture
->width
= tiled
->width
;
584 texture
->height
= tiled
->height
;
586 RDestroyImage(tiled
);
588 texture
->pixmap
= pixmap
;
589 } else if (strcasecmp(type
, "function")==0) {
591 void (*initFunc
) (Display
*, Colormap
);
592 RImage
* (*mainFunc
) (int, char**, int, int, int);
596 char *lib
, *func
, **argv
= 0;
601 goto function_cleanup
;
603 /* get the library name */
604 GETSTRORGOTO(val
, lib
, 1, function_cleanup
);
606 /* get the function name */
607 GETSTRORGOTO(val
, func
, 2, function_cleanup
);
610 argv
= (char**)wmalloc(argc
* sizeof(char*));
612 /* get the parameters */
614 for (i
=0; i
<argc
-1; i
++) {
615 GETSTRORGOTO(val
, tmp
, 3+i
, function_cleanup
);
616 argv
[i
+1] = wstrdup(tmp
);
619 handle
= dlopen(lib
, RTLD_LAZY
);
621 wwarning("could not find library %s", lib
);
622 goto function_cleanup
;
625 initFunc
= dlsym(handle
, "initWindowMaker");
627 wwarning("could not initialize library %s", lib
);
628 goto function_cleanup
;
630 initFunc(dpy
, DefaultColormap(dpy
, scr
));
632 mainFunc
= dlsym(handle
, func
);
634 wwarning("could not find function %s::%s", lib
, func
);
635 goto function_cleanup
;
637 image
= mainFunc(argc
, argv
, scrWidth
, scrHeight
, 0);
639 if (!RConvertImage(rc
, image
, &pixmap
)) {
640 wwarning("could not convert texture:%s",
641 RMessageForError(RErrorCode
));
642 goto function_cleanup
;
644 texture
->width
= scrWidth
;
645 texture
->height
= scrHeight
;
646 texture
->pixmap
= pixmap
;
652 for (i
=0; i
<argc
; i
++) {
660 RDestroyImage(image
);
666 wwarning("function textures not supported");
670 wwarning("invalid texture type %s", text
);
674 texture
->spec
= wstrdup(text
);
689 freeTexture(BackgroundTexture
*texture
)
691 if (texture
->solid
) {
694 pixel
[0] = texture
->color
.pixel
;
695 /* dont free black/white pixels */
696 if (pixel
[0]!=BlackPixelOfScreen(DefaultScreenOfDisplay(dpy
))
697 && pixel
[0]!=WhitePixelOfScreen(DefaultScreenOfDisplay(dpy
)))
698 XFreeColors(dpy
, DefaultColormap(dpy
, scr
), pixel
, 1, 0);
700 if (texture
->pixmap
) {
701 XFreePixmap(dpy
, texture
->pixmap
);
709 setupTexture(RContext
*rc
, BackgroundTexture
**textures
, int *maxTextures
,
710 int workspace
, char *texture
)
712 BackgroundTexture
*newTexture
= NULL
;
715 /* unset the texture */
717 if (textures
[workspace
]!=NULL
) {
718 textures
[workspace
]->refcount
--;
720 if (textures
[workspace
]->refcount
== 0)
721 freeTexture(textures
[workspace
]);
723 textures
[workspace
] = NULL
;
727 if (textures
[workspace
]
728 && strcasecmp(textures
[workspace
]->spec
, texture
)==0) {
729 /* texture did not change */
733 /* check if the same texture is already created */
734 for (i
= 0; i
< *maxTextures
; i
++) {
735 if (textures
[i
] && strcasecmp(textures
[i
]->spec
, texture
)==0) {
736 newTexture
= textures
[i
];
742 /* create the texture */
743 newTexture
= parseTexture(rc
, texture
);
748 if (textures
[workspace
]!=NULL
) {
750 textures
[workspace
]->refcount
--;
752 if (textures
[workspace
]->refcount
== 0)
753 freeTexture(textures
[workspace
]);
756 newTexture
->refcount
++;
757 textures
[workspace
] = newTexture
;
759 if (*maxTextures
< workspace
)
760 *maxTextures
= workspace
;
766 duplicatePixmap(Pixmap pixmap
, int width
, int height
)
771 /* must open a new display or the RetainPermanent will
772 * leave stuff allocated in RContext unallocated after exit */
773 tmpDpy
= XOpenDisplay(display
);
775 wwarning("could not open display to update background image information");
781 copyP
= XCreatePixmap(tmpDpy
, root
, width
, height
,
782 DefaultDepth(tmpDpy
, scr
));
783 XCopyArea(tmpDpy
, pixmap
, copyP
, DefaultGC(tmpDpy
, scr
),
784 0, 0, width
, height
, 0, 0);
785 XSync(tmpDpy
, False
);
787 XSetCloseDownMode(tmpDpy
, RetainPermanent
);
788 XCloseDisplay(tmpDpy
);
796 dummyErrorHandler(Display
*dpy
, XErrorEvent
*err
)
802 setPixmapProperty(Pixmap pixmap
)
804 static Atom prop
= 0;
807 unsigned long length
, after
;
812 prop
= XInternAtom(dpy
, "_XROOTPMAP_ID", False
);
817 /* Clear out the old pixmap */
818 XGetWindowProperty(dpy
, root
, prop
, 0L, 1L, False
, AnyPropertyType
,
819 &type
, &format
, &length
, &after
, &data
);
821 if ((type
== XA_PIXMAP
) && (format
== 32) && (length
== 1)) {
822 XSetErrorHandler(dummyErrorHandler
);
823 XKillClient(dpy
, *((Pixmap
*)data
));
825 XSetErrorHandler(NULL
);
826 mode
= PropModeReplace
;
828 mode
= PropModeAppend
;
831 XChangeProperty(dpy
, root
, prop
, XA_PIXMAP
, 32, mode
,
832 (unsigned char *) &pixmap
, 1);
834 XDeleteProperty(dpy
, root
, prop
);
844 changeTexture(BackgroundTexture
*texture
)
849 if (texture
->solid
) {
850 XSetWindowBackground(dpy
, root
, texture
->color
.pixel
);
852 XSetWindowBackgroundPixmap(dpy
, root
, texture
->pixmap
);
854 XClearWindow(dpy
, root
);
861 pixmap
= duplicatePixmap(texture
->pixmap
, texture
->width
,
864 setPixmapProperty(pixmap
);
870 readmsg(int fd
, unsigned char *buffer
, int size
)
876 count
= read(fd
, buffer
, size
);
890 * sizeSntexture_spec - sets the texture for workspace n
891 * sizeCn - change background texture to the one for workspace n
892 * sizePpath - set the pixmap search path
895 * size = 4 bytes for length of the message data
898 helperLoop(RContext
*rc
)
900 BackgroundTexture
*textures
[WORKSPACE_COUNT
];
902 unsigned char buffer
[2048], buf
[8];
906 memset(textures
, 0, WORKSPACE_COUNT
*sizeof(BackgroundTexture
*));
912 /* get length of message */
913 if (readmsg(0, buffer
, 4) < 0) {
914 wsyserror("error reading message from Window Maker");
922 memcpy(buf
, buffer
, 4);
927 if (readmsg(0, buffer
, size
) < 0) {
928 wsyserror("error reading message from Window Maker");
937 printf("RECEIVED %s\n",buffer
);
939 if (buffer
[0]!='P' && buffer
[0]!='K') {
940 memcpy(buf
, &buffer
[1], 4);
942 workspace
= atoi(buf
);
943 if (workspace
< 0 || workspace
>= WORKSPACE_COUNT
) {
944 wwarning("received message with invalid workspace number %i\n",
953 printf("set texture %s\n", &buffer
[5]);
955 setupTexture(rc
, textures
, &maxTextures
, workspace
, &buffer
[5]);
960 printf("change texture %i\n", workspace
);
962 if (!textures
[workspace
])
963 changeTexture(textures
[0]);
965 changeTexture(textures
[workspace
]);
970 printf("change pixmappath %s\n", &buffer
[1]);
974 PixmapPath
= wstrdup(&buffer
[1]);
979 printf("unset workspace %i\n", workspace
);
981 setupTexture(rc
, textures
, &maxTextures
, workspace
, NULL
);
986 printf("exit command\n");
991 wwarning("unknown message received");
999 updateDomain(char *domain
, char *key
, char *texture
)
1001 char *program
= "wdwrite";
1003 system(wstrappend("wdwrite ",
1004 wstrappend(domain
, smooth
? " SmoothWorkspaceBack YES"
1005 : " SmoothWorkspaceBack NO")));
1007 execlp(program
, program
, domain
, key
, texture
, NULL
);
1008 wwarning("warning could not run \"%s\"", program
);
1014 globalDefaultsPathForDomain(char *domain
)
1018 sprintf(path
, "%s/%s", SYSCONFDIR
, domain
);
1020 return wstrdup(path
);
1025 getValueForKey(char *domain
, char *keyName
)
1032 key
= PLMakeString(keyName
);
1034 /* try to find PixmapPath in user defaults */
1035 path
= wdefaultspathfordomain(domain
);
1036 d
= PLGetProplistWithPath(path
);
1038 wwarning("could not open domain file %s", path
);
1042 if (d
&& !PLIsDictionary(d
)) {
1047 val
= PLGetDictionaryEntry(d
, key
);
1051 /* try to find PixmapPath in global defaults */
1053 path
= globalDefaultsPathForDomain(domain
);
1055 wwarning("could not locate file for domain %s", domain
);
1058 d
= PLGetProplistWithPath(path
);
1062 if (d
&& !PLIsDictionary(d
)) {
1067 val
= PLGetDictionaryEntry(d
, key
);
1087 getPixmapPath(char *domain
)
1093 val
= getValueForKey(domain
, "PixmapPath");
1095 if (!val
|| !PLIsArray(val
)) {
1101 count
= PLGetNumberOfElements(val
);
1103 for (i
=0; i
<count
; i
++) {
1106 v
= PLGetArrayElement(val
, i
);
1107 if (!v
|| !PLIsString(v
)) {
1110 len
+= strlen(PLGetString(v
))+1;
1113 ptr
= data
= wmalloc(len
+1);
1116 for (i
=0; i
<count
; i
++) {
1119 v
= PLGetArrayElement(val
, i
);
1120 if (!v
|| !PLIsString(v
)) {
1123 strcpy(ptr
, PLGetString(v
));
1125 ptr
+= strlen(PLGetString(v
));
1130 ptr
--; *(ptr
--) = 0;
1148 print_help(char *ProgName
)
1150 printf("Usage: %s [options] [image]\n", ProgName
);
1151 puts("Sets the workspace background to the specified image or a texture and optionally update Window Maker configuration");
1153 #define P(m) puts(m)
1154 P(" -display display to use");
1155 P(" -d, --dither dither image");
1156 P(" -m, --match match colors");
1157 P(" -S, --smooth smooth scaled image");
1158 P(" -b, --back-color <color> background color");
1159 P(" -t, --tile tile image");
1160 P(" -e, --center center image");
1161 P(" -s, --scale scale image (default)");
1162 P(" -a, --maxscale scale image and keep aspect ratio");
1163 P(" -u, --update-wmaker update WindowMaker domain database");
1164 P(" -D, --update-domain <domain> update <domain> database");
1165 P(" -c, --colors <cpc> colors per channel to use");
1166 P(" -p, --parse <texture> proplist style texture specification");
1167 P(" -w, --workspace <workspace> update background for the specified workspace");
1168 P(" --version show version of wmsetbg and exit");
1169 P(" --help show this help and exit");
1176 changeTextureForWorkspace(char *domain
, char *texture
, int workspace
)
1183 val
= PLGetProplistWithDescription(texture
);
1185 wwarning("could not parse texture %s", texture
);
1189 array
= getValueForKey("WindowMaker", "WorkspaceSpecificBack");
1192 array
= PLMakeArrayFromElements(NULL
, NULL
);
1195 j
= PLGetNumberOfElements(array
);
1196 if (workspace
>= j
) {
1199 empty
= PLMakeArrayFromElements(NULL
, NULL
);
1201 while (j
++ < workspace
-1) {
1202 PLAppendArrayElement(array
, empty
);
1204 PLAppendArrayElement(array
, val
);
1206 PLRemoveArrayElement(array
, workspace
);
1207 PLInsertArrayElement(array
, val
, workspace
);
1210 value
= PLGetDescription(array
);
1211 updateDomain(domain
, "WorkspaceSpecificBack", value
);
1216 main(int argc
, char **argv
)
1221 RContextAttributes rattr
;
1222 char *style
= "spixmap";
1223 char *back_color
= "gray20";
1224 char *image_name
= NULL
;
1225 char *domain
= "WindowMaker";
1226 int update
=0, cpc
=4, render_mode
=RDitheredRendering
, obey_user
=0;
1227 char *texture
= NULL
;
1230 signal(SIGINT
, SIG_DFL
);
1231 signal(SIGTERM
, SIG_DFL
);
1232 signal(SIGQUIT
, SIG_DFL
);
1233 signal(SIGSEGV
, SIG_DFL
);
1234 signal(SIGBUS
, SIG_DFL
);
1235 signal(SIGFPE
, SIG_DFL
);
1236 signal(SIGABRT
, SIG_DFL
);
1237 signal(SIGHUP
, SIG_DFL
);
1238 signal(SIGPIPE
, SIG_DFL
);
1239 signal(SIGCHLD
, SIG_DFL
);
1241 WMInitializeApplication("wmsetbg", &argc
, argv
);
1243 for (i
=1; i
<argc
; i
++) {
1244 if (strcmp(argv
[i
], "-helper")==0) {
1246 } else if (strcmp(argv
[i
], "-display")==0) {
1249 wfatal("too few arguments for %s\n", argv
[i
-1]);
1253 } else if (strcmp(argv
[i
], "-s")==0
1254 || strcmp(argv
[i
], "--scale")==0) {
1256 } else if (strcmp(argv
[i
], "-t")==0
1257 || strcmp(argv
[i
], "--tile")==0) {
1259 } else if (strcmp(argv
[i
], "-e")==0
1260 || strcmp(argv
[i
], "--center")==0) {
1262 } else if (strcmp(argv
[i
], "-a")==0
1263 || strcmp(argv
[i
], "--maxscale")==0) {
1265 } else if (strcmp(argv
[i
], "-d")==0
1266 || strcmp(argv
[i
], "--dither")==0) {
1267 render_mode
= RDitheredRendering
;
1269 } else if (strcmp(argv
[i
], "-m")==0
1270 || strcmp(argv
[i
], "--match")==0) {
1271 render_mode
= RBestMatchRendering
;
1273 } else if (strcmp(argv
[i
], "-S")==0
1274 || strcmp(argv
[i
], "--smooth")==0) {
1276 } else if (strcmp(argv
[i
], "-u")==0
1277 || strcmp(argv
[i
], "--update-wmaker")==0) {
1279 } else if (strcmp(argv
[i
], "-D")==0
1280 || strcmp(argv
[i
], "--update-domain")==0) {
1284 wfatal("too few arguments for %s\n", argv
[i
-1]);
1287 domain
= wstrdup(argv
[i
]);
1288 } else if (strcmp(argv
[i
], "-c")==0
1289 || strcmp(argv
[i
], "--colors")==0) {
1292 wfatal("too few arguments for %s\n", argv
[i
-1]);
1295 if (sscanf(argv
[i
], "%i", &cpc
)!=1) {
1296 wfatal("bad value for colors per channel: \"%s\"\n", argv
[i
]);
1299 } else if (strcmp(argv
[i
], "-b")==0
1300 || strcmp(argv
[i
], "--back-color")==0) {
1303 wfatal("too few arguments for %s\n", argv
[i
-1]);
1306 back_color
= argv
[i
];
1307 } else if (strcmp(argv
[i
], "-p")==0
1308 || strcmp(argv
[i
], "--parse")==0) {
1311 wfatal("too few arguments for %s\n", argv
[i
-1]);
1315 } else if (strcmp(argv
[i
], "-w")==0
1316 || strcmp(argv
[i
], "--workspace")==0) {
1319 wfatal("too few arguments for %s\n", argv
[i
-1]);
1322 if (sscanf(argv
[i
], "%i", &workspace
)!=1) {
1323 wfatal("bad value for workspace number: \"%s\"",
1327 } else if (strcmp(argv
[i
], "--version")==0) {
1329 printf(PROG_VERSION
);
1332 } else if (strcmp(argv
[i
], "--help")==0) {
1333 print_help(argv
[0]);
1335 } else if (argv
[i
][0] != '-') {
1336 image_name
= argv
[i
];
1338 printf("%s: invalid argument '%s'\n", argv
[0], argv
[i
]);
1339 printf("Try '%s --help' for more information\n", argv
[0]);
1343 if (!image_name
&& !texture
&& !helperMode
) {
1344 printf("%s: you must specify a image file name or a texture\n",
1346 printf("Try '%s --help' for more information\n", argv
[0]);
1351 PixmapPath
= getPixmapPath(domain
);
1355 val
= PLGetDictionaryEntry(domain
,
1356 PLMakeString("SmoothWorkspaceBack"));
1357 if (val
&& PLIsString(val
) && strcasecmp(PLGetString(val
), "YES")==0)
1361 dpy
= XOpenDisplay(display
);
1363 wfatal("could not open display");
1367 XSynchronize(dpy
, 1);
1370 root
= DefaultRootWindow(dpy
);
1372 scr
= DefaultScreen(dpy
);
1374 scrWidth
= WidthOfScreen(DefaultScreenOfDisplay(dpy
));
1375 scrHeight
= HeightOfScreen(DefaultScreenOfDisplay(dpy
));
1377 if (!obey_user
&& DefaultDepth(dpy
, scr
) <= 8)
1378 render_mode
= RDitheredRendering
;
1380 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_DefaultVisual
;
1381 rattr
.render_mode
= render_mode
;
1382 rattr
.colors_per_channel
= cpc
;
1384 rc
= RCreateContext(dpy
, scr
, &rattr
);
1387 /* lower priority, so that it wont use all the CPU */
1392 BackgroundTexture
*tex
;
1396 sprintf(buffer
, "(%s, \"%s\", %s)", style
, image_name
, back_color
);
1397 texture
= (char*)buffer
;
1400 if (update
&& workspace
< 0) {
1401 updateDomain(domain
, "WorkspaceBack", texture
);
1404 tex
= parseTexture(rc
, texture
);
1411 /* always update domain */
1412 changeTextureForWorkspace(domain
, texture
, workspace
-1);