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.1"
58 #define WORKSPACE_COUNT (MAX_WORKSPACES+1)
68 Pixmap CurrentPixmap
= None
;
69 char *PixmapPath
= NULL
;
72 extern Pixmap
LoadJPEG(RContext
*rc
, char *file_name
, int *width
, int *height
);
75 typedef struct BackgroundTexture
{
83 Pixmap pixmap
; /* for all textures, including solid */
84 int width
; /* size of the pixmap */
91 loadImage(RContext
*rc
, char *file
)
96 if (access(file
, F_OK
)!=0) {
97 path
= wfindfile(PixmapPath
, file
);
99 wwarning("%s:could not find image file used in texture", file
);
103 path
= wstrdup(file
);
106 image
= RLoadImage(rc
, path
, 0);
108 wwarning("%s:could not load image file used in texture:%s", path
,
109 RMessageForError(RErrorCode
));
118 parseTexture(RContext
*rc
, char *text
)
120 BackgroundTexture
*texture
= NULL
;
127 #define GETSTRORGOTO(val, str, i, label) \
128 val = PLGetArrayElement(texarray, i);\
129 if (!PLIsString(val)) {\
130 wwarning("could not parse texture %s", text);\
133 str = PLGetString(val)
135 texarray
= PLGetProplistWithDescription(text
);
136 if (!texarray
|| !PLIsArray(texarray
)
137 || (count
= PLGetNumberOfElements(texarray
)) < 2) {
139 wwarning("could not parse texture %s", text
);
145 texture
= wmalloc(sizeof(BackgroundTexture
));
146 memset(texture
, 0, sizeof(BackgroundTexture
));
148 GETSTRORGOTO(val
, type
, 0, error
);
150 if (strcasecmp(type
, "solid")==0) {
156 GETSTRORGOTO(val
, tmp
, 1, error
);
158 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
159 wwarning("could not parse color %s in texture %s", tmp
, text
);
162 XAllocColor(dpy
, DefaultColormap(dpy
, scr
), &color
);
164 pixmap
= XCreatePixmap(dpy
, root
, 8, 8, DefaultDepth(dpy
, scr
));
165 XSetForeground(dpy
, DefaultGC(dpy
, scr
), color
.pixel
);
166 XFillRectangle(dpy
, pixmap
, DefaultGC(dpy
, scr
), 0, 0, 8, 8);
168 texture
->pixmap
= pixmap
;
169 texture
->color
= color
;
172 } else if (strcasecmp(type
, "vgradient")==0
173 || strcasecmp(type
, "dgradient")==0
174 || strcasecmp(type
, "hgradient")==0) {
176 RColor color1
, color2
;
182 GETSTRORGOTO(val
, tmp
, 1, error
);
184 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
185 wwarning("could not parse color %s in texture %s", tmp
, text
);
189 color1
.red
= color
.red
>> 8;
190 color1
.green
= color
.green
>> 8;
191 color1
.blue
= color
.blue
>> 8;
193 GETSTRORGOTO(val
, tmp
, 2, error
);
195 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
196 wwarning("could not parse color %s in texture %s", tmp
, text
);
200 color2
.red
= color
.red
>> 8;
201 color2
.green
= color
.green
>> 8;
202 color2
.blue
= color
.blue
>> 8;
207 gtype
= RHorizontalGradient
;
213 gtype
= RVerticalGradient
;
218 gtype
= RDiagonalGradient
;
224 image
= RRenderGradient(iwidth
, iheight
, &color1
, &color2
, gtype
);
227 wwarning("could not render gradient texture:%s",
228 RMessageForError(RErrorCode
));
232 if (!RConvertImage(rc
, image
, &pixmap
)) {
233 wwarning("could not convert texture:%s",
234 RMessageForError(RErrorCode
));
235 RDestroyImage(image
);
239 texture
->width
= image
->width
;
240 texture
->height
= image
->height
;
241 RDestroyImage(image
);
243 texture
->pixmap
= pixmap
;
244 } else if (strcasecmp(type
, "mvgradient")==0
245 || strcasecmp(type
, "mdgradient")==0
246 || strcasecmp(type
, "mhgradient")==0) {
255 colors
= malloc(sizeof(RColor
*)*(count
-1));
257 wwarning("out of memory while parsing texture");
260 memset(colors
, 0, sizeof(RColor
*)*(count
-1));
262 for (i
= 2; i
< count
; i
++) {
263 val
= PLGetArrayElement(texarray
, i
);
264 if (!PLIsString(val
)) {
265 wwarning("could not parse texture %s", text
);
267 for (j
= 0; colors
[j
]!=NULL
; j
++)
272 tmp
= PLGetString(val
);
274 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
275 wwarning("could not parse color %s in texture %s",
278 for (j
= 0; colors
[j
]!=NULL
; j
++)
283 if (!(colors
[i
-2] = malloc(sizeof(RColor
)))) {
284 wwarning("out of memory while parsing texture");
286 for (j
= 0; colors
[j
]!=NULL
; j
++)
292 colors
[i
-2]->red
= color
.red
>> 8;
293 colors
[i
-2]->green
= color
.green
>> 8;
294 colors
[i
-2]->blue
= color
.blue
>> 8;
300 gtype
= RHorizontalGradient
;
306 gtype
= RVerticalGradient
;
311 gtype
= RDiagonalGradient
;
317 image
= RRenderMultiGradient(iwidth
, iheight
, colors
, gtype
);
319 for (j
= 0; colors
[j
]!=NULL
; j
++)
324 wwarning("could not render gradient texture:%s",
325 RMessageForError(RErrorCode
));
329 if (!RConvertImage(rc
, image
, &pixmap
)) {
330 wwarning("could not convert texture:%s",
331 RMessageForError(RErrorCode
));
332 RDestroyImage(image
);
336 texture
->width
= image
->width
;
337 texture
->height
= image
->height
;
338 RDestroyImage(image
);
340 texture
->pixmap
= pixmap
;
341 } else if (strcasecmp(type
, "cpixmap")==0
342 || strcasecmp(type
, "spixmap")==0
343 || strcasecmp(type
, "mpixmap")==0
344 || strcasecmp(type
, "tpixmap")==0) {
346 Pixmap pixmap
= None
;
347 RImage
*image
= NULL
;
351 GETSTRORGOTO(val
, tmp
, 1, error
);
353 if (toupper(type[0]) == 'T' || toupper(type[0]) == 'C')
354 pixmap = LoadJPEG(rc, tmp, &iwidth, &iheight);
358 image
= loadImage(rc
, tmp
);
362 iwidth
= image
->width
;
363 iheight
= image
->height
;
366 GETSTRORGOTO(val
, tmp
, 2, error
);
368 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
369 wwarning("could not parse color %s in texture %s\n", tmp
, text
);
370 RDestroyImage(image
);
373 if (!XAllocColor(dpy
, DefaultColormap(dpy
, scr
), &color
)) {
376 rcolor
.red
= color
.red
>> 8;
377 rcolor
.green
= color
.green
>> 8;
378 rcolor
.blue
= color
.blue
>> 8;
379 RGetClosestXColor(rc
, &rcolor
, &color
);
381 switch (toupper(type
[0])) {
383 texture
->width
= iwidth
;
384 texture
->height
= iheight
;
385 if (!pixmap
&& !RConvertImage(rc
, image
, &pixmap
)) {
386 wwarning("could not convert texture:%s",
387 RMessageForError(RErrorCode
));
388 RDestroyImage(image
);
392 RDestroyImage(image
);
396 if (toupper(type
[0])=='S') {
400 if (iwidth
*scrHeight
> iheight
*scrWidth
) {
402 h
= (scrWidth
*iheight
)/iwidth
;
405 w
= (scrHeight
*iwidth
)/iheight
;
411 simage
= RScaleImage(image
, w
, h
);
413 wwarning("could not scale image:%s",
414 RMessageForError(RErrorCode
));
415 RDestroyImage(image
);
418 RDestroyImage(image
);
420 iwidth
= image
->width
;
421 iheight
= image
->height
;
428 if (!pixmap
&& !RConvertImage(rc
, image
, &pixmap
)) {
429 wwarning("could not convert texture:%s",
430 RMessageForError(RErrorCode
));
431 RDestroyImage(image
);
435 if (iwidth
!= scrWidth
|| iheight
!= scrHeight
) {
436 int x
, y
, sx
, sy
, w
, h
;
438 cpixmap
= XCreatePixmap(dpy
, root
, scrWidth
, scrHeight
,
439 DefaultDepth(dpy
, scr
));
441 XSetForeground(dpy
, DefaultGC(dpy
, scr
), color
.pixel
);
442 XFillRectangle(dpy
, cpixmap
, DefaultGC(dpy
, scr
),
443 0, 0, scrWidth
, scrHeight
);
445 if (iheight
< scrHeight
) {
447 y
= (scrHeight
- h
)/2;
450 sy
= (iheight
- scrHeight
)/2;
454 if (iwidth
< scrWidth
) {
456 x
= (scrWidth
- w
)/2;
459 sx
= (iwidth
- scrWidth
)/2;
464 XCopyArea(dpy
, pixmap
, cpixmap
, DefaultGC(dpy
, scr
),
466 XFreePixmap(dpy
, pixmap
);
470 RDestroyImage(image
);
472 texture
->width
= scrWidth
;
473 texture
->height
= scrHeight
;
478 texture
->pixmap
= pixmap
;
479 texture
->color
= color
;
480 } else if (strcasecmp(type
, "thgradient")==0
481 || strcasecmp(type
, "tvgradient")==0
482 || strcasecmp(type
, "tdgradient")==0) {
484 RColor color1
, color2
;
494 GETSTRORGOTO(val
, file
, 1, error
);
496 GETSTRORGOTO(val
, tmp
, 2, error
);
500 GETSTRORGOTO(val
, tmp
, 3, error
);
502 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
503 wwarning("could not parse color %s in texture %s", tmp
, text
);
507 color1
.red
= color
.red
>> 8;
508 color1
.green
= color
.green
>> 8;
509 color1
.blue
= color
.blue
>> 8;
511 GETSTRORGOTO(val
, tmp
, 4, error
);
513 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
514 wwarning("could not parse color %s in texture %s", tmp
, text
);
518 color2
.red
= color
.red
>> 8;
519 color2
.green
= color
.green
>> 8;
520 color2
.blue
= color
.blue
>> 8;
522 image
= loadImage(rc
, file
);
524 RDestroyImage(gradient
);
531 gtype
= RHorizontalGradient
;
533 theight
= image
->height
> scrHeight
? scrHeight
: image
->height
;
537 gtype
= RVerticalGradient
;
538 twidth
= image
->width
> scrWidth
? scrWidth
: image
->width
;
542 gtype
= RDiagonalGradient
;
547 gradient
= RRenderGradient(twidth
, theight
, &color1
, &color2
, gtype
);
550 wwarning("could not render texture:%s",
551 RMessageForError(RErrorCode
));
552 RDestroyImage(gradient
);
556 tiled
= RMakeTiledImage(image
, twidth
, theight
);
558 wwarning("could not render texture:%s",
559 RMessageForError(RErrorCode
));
560 RDestroyImage(gradient
);
561 RDestroyImage(image
);
564 RDestroyImage(image
);
566 RCombineImagesWithOpaqueness(tiled
, gradient
, opaq
);
567 RDestroyImage(gradient
);
569 if (!RConvertImage(rc
, tiled
, &pixmap
)) {
570 wwarning("could not convert texture:%s",
571 RMessageForError(RErrorCode
));
572 RDestroyImage(image
);
575 texture
->width
= tiled
->width
;
576 texture
->height
= tiled
->height
;
578 RDestroyImage(tiled
);
580 texture
->pixmap
= pixmap
;
581 } else if (strcasecmp(type
, "function")==0) {
583 void (*initFunc
) (Display
*, Colormap
);
584 RImage
* (*mainFunc
) (int, char**, int, int, int);
588 char *lib
, *func
, **argv
= 0;
593 goto function_cleanup
;
595 /* get the library name */
596 GETSTRORGOTO(val
, lib
, 1, function_cleanup
);
598 /* get the function name */
599 GETSTRORGOTO(val
, func
, 2, function_cleanup
);
602 argv
= (char**)wmalloc(argc
* sizeof(char*));
604 /* get the parameters */
606 for (i
=0; i
<argc
-1; i
++) {
607 GETSTRORGOTO(val
, tmp
, 3+i
, function_cleanup
);
608 argv
[i
+1] = wstrdup(tmp
);
611 handle
= dlopen(lib
, RTLD_LAZY
);
613 wwarning("could not find library %s", lib
);
614 goto function_cleanup
;
617 initFunc
= dlsym(handle
, "initWindowMaker");
619 wwarning("could not initialize library %s", lib
);
620 goto function_cleanup
;
622 initFunc(dpy
, DefaultColormap(dpy
, scr
));
624 mainFunc
= dlsym(handle
, func
);
626 wwarning("could not find function %s::%s", lib
, func
);
627 goto function_cleanup
;
629 image
= mainFunc(argc
, argv
, scrWidth
, scrHeight
, 0);
631 if (!RConvertImage(rc
, image
, &pixmap
)) {
632 wwarning("could not convert texture:%s",
633 RMessageForError(RErrorCode
));
634 goto function_cleanup
;
636 texture
->width
= scrWidth
;
637 texture
->height
= scrHeight
;
638 texture
->pixmap
= pixmap
;
644 for (i
=0; i
<argc
; i
++) {
652 RDestroyImage(image
);
658 wwarning("function textures not supported");
662 wwarning("invalid texture type %s", text
);
666 texture
->spec
= wstrdup(text
);
681 freeTexture(BackgroundTexture
*texture
)
683 if (texture
->solid
) {
686 pixel
[0] = texture
->color
.pixel
;
687 /* dont free black/white pixels */
688 if (pixel
[0]!=BlackPixelOfScreen(DefaultScreenOfDisplay(dpy
))
689 && pixel
[0]!=WhitePixelOfScreen(DefaultScreenOfDisplay(dpy
)))
690 XFreeColors(dpy
, DefaultColormap(dpy
, scr
), pixel
, 1, 0);
692 if (texture
->pixmap
) {
693 XFreePixmap(dpy
, texture
->pixmap
);
701 setupTexture(RContext
*rc
, BackgroundTexture
**textures
, int *maxTextures
,
702 int workspace
, char *texture
)
704 BackgroundTexture
*newTexture
= NULL
;
707 /* unset the texture */
709 if (textures
[workspace
]!=NULL
) {
710 textures
[workspace
]->refcount
--;
712 if (textures
[workspace
]->refcount
== 0)
713 freeTexture(textures
[workspace
]);
715 textures
[workspace
] = NULL
;
719 if (textures
[workspace
]
720 && strcasecmp(textures
[workspace
]->spec
, texture
)==0) {
721 /* texture did not change */
725 /* check if the same texture is already created */
726 for (i
= 0; i
< *maxTextures
; i
++) {
727 if (textures
[i
] && strcasecmp(textures
[i
]->spec
, texture
)==0) {
728 newTexture
= textures
[i
];
734 /* create the texture */
735 newTexture
= parseTexture(rc
, texture
);
740 if (textures
[workspace
]!=NULL
) {
742 textures
[workspace
]->refcount
--;
744 if (textures
[workspace
]->refcount
== 0)
745 freeTexture(textures
[workspace
]);
748 newTexture
->refcount
++;
749 textures
[workspace
] = newTexture
;
751 if (*maxTextures
< workspace
)
752 *maxTextures
= workspace
;
758 duplicatePixmap(Pixmap pixmap
, int width
, int height
)
763 /* must open a new display or the RetainPermanent will
764 * leave stuff allocated in RContext unallocated after exit */
765 tmpDpy
= XOpenDisplay(display
);
767 wwarning("could not open display to update background image information");
773 copyP
= XCreatePixmap(tmpDpy
, root
, width
, height
,
774 DefaultDepth(tmpDpy
, scr
));
775 XCopyArea(tmpDpy
, pixmap
, copyP
, DefaultGC(tmpDpy
, scr
),
776 0, 0, width
, height
, 0, 0);
777 XSync(tmpDpy
, False
);
779 XSetCloseDownMode(tmpDpy
, RetainPermanent
);
780 XCloseDisplay(tmpDpy
);
788 dummyErrorHandler(Display
*dpy
, XErrorEvent
*err
)
794 setPixmapProperty(Pixmap pixmap
)
796 static Atom prop
= 0;
799 unsigned long length
, after
;
804 prop
= XInternAtom(dpy
, "_XROOTPMAP_ID", False
);
809 /* Clear out the old pixmap */
810 XGetWindowProperty(dpy
, root
, prop
, 0L, 1L, False
, AnyPropertyType
,
811 &type
, &format
, &length
, &after
, &data
);
813 if ((type
== XA_PIXMAP
) && (format
== 32) && (length
== 1)) {
814 XSetErrorHandler(dummyErrorHandler
);
815 XKillClient(dpy
, *((Pixmap
*)data
));
817 XSetErrorHandler(NULL
);
818 mode
= PropModeReplace
;
820 mode
= PropModeAppend
;
823 XChangeProperty(dpy
, root
, prop
, XA_PIXMAP
, 32, mode
,
824 (unsigned char *) &pixmap
, 1);
826 XDeleteProperty(dpy
, root
, prop
);
836 changeTexture(BackgroundTexture
*texture
)
841 if (texture
->solid
) {
842 XSetWindowBackground(dpy
, root
, texture
->color
.pixel
);
844 XSetWindowBackgroundPixmap(dpy
, root
, texture
->pixmap
);
846 XClearWindow(dpy
, root
);
853 pixmap
= duplicatePixmap(texture
->pixmap
, texture
->width
,
856 setPixmapProperty(pixmap
);
862 readmsg(int fd
, unsigned char *buffer
, int size
)
868 count
= read(fd
, buffer
, size
);
882 * sizeSntexture_spec - sets the texture for workspace n
883 * sizeCn - change background texture to the one for workspace n
884 * sizePpath - set the pixmap search path
887 * size = 4 bytes for length of the message data
890 helperLoop(RContext
*rc
)
892 BackgroundTexture
*textures
[WORKSPACE_COUNT
];
894 unsigned char buffer
[2048], buf
[8];
898 memset(textures
, 0, WORKSPACE_COUNT
*sizeof(BackgroundTexture
*));
904 /* get length of message */
905 if (readmsg(0, buffer
, 4) < 0) {
906 wsyserror("error reading message from Window Maker");
914 memcpy(buf
, buffer
, 4);
919 if (readmsg(0, buffer
, size
) < 0) {
920 wsyserror("error reading message from Window Maker");
929 printf("RECEIVED %s\n",buffer
);
931 if (buffer
[0]!='P' && buffer
[0]!='K') {
932 memcpy(buf
, &buffer
[1], 4);
934 workspace
= atoi(buf
);
935 if (workspace
< 0 || workspace
>= WORKSPACE_COUNT
) {
936 wwarning("received message with invalid workspace number %i\n",
945 printf("set texture %s\n", &buffer
[5]);
947 setupTexture(rc
, textures
, &maxTextures
, workspace
, &buffer
[5]);
952 printf("change texture %i\n", workspace
);
954 if (!textures
[workspace
])
955 changeTexture(textures
[0]);
957 changeTexture(textures
[workspace
]);
962 printf("change pixmappath %s\n", &buffer
[1]);
966 PixmapPath
= wstrdup(&buffer
[1]);
971 printf("unset workspace %i\n", workspace
);
973 setupTexture(rc
, textures
, &maxTextures
, workspace
, NULL
);
978 printf("exit command\n");
983 wwarning("unknown message received");
991 updateDomain(char *domain
, char *key
, char *texture
)
993 char *program
= "wdwrite";
995 execlp(program
, program
, domain
, key
, texture
, NULL
);
996 wwarning("warning could not run \"%s\"", program
);
1002 globalDefaultsPathForDomain(char *domain
)
1006 sprintf(path
, "%s/%s", SYSCONFDIR
, domain
);
1008 return wstrdup(path
);
1013 getValueForKey(char *domain
, char *keyName
)
1020 key
= PLMakeString(keyName
);
1022 /* try to find PixmapPath in user defaults */
1023 path
= wdefaultspathfordomain(domain
);
1024 d
= PLGetProplistWithPath(path
);
1026 wwarning("could not open domain file %s", path
);
1030 if (d
&& !PLIsDictionary(d
)) {
1035 val
= PLGetDictionaryEntry(d
, key
);
1039 /* try to find PixmapPath in global defaults */
1041 path
= globalDefaultsPathForDomain(domain
);
1043 wwarning("could not locate file for domain %s", domain
);
1046 d
= PLGetProplistWithPath(path
);
1050 if (d
&& !PLIsDictionary(d
)) {
1055 val
= PLGetDictionaryEntry(d
, key
);
1075 getPixmapPath(char *domain
)
1081 val
= getValueForKey(domain
, "PixmapPath");
1083 if (!val
|| !PLIsArray(val
)) {
1089 count
= PLGetNumberOfElements(val
);
1091 for (i
=0; i
<count
; i
++) {
1094 v
= PLGetArrayElement(val
, i
);
1095 if (!v
|| !PLIsString(v
)) {
1098 len
+= strlen(PLGetString(v
))+1;
1101 ptr
= data
= wmalloc(len
+1);
1104 for (i
=0; i
<count
; i
++) {
1107 v
= PLGetArrayElement(val
, i
);
1108 if (!v
|| !PLIsString(v
)) {
1111 strcpy(ptr
, PLGetString(v
));
1113 ptr
+= strlen(PLGetString(v
));
1118 ptr
--; *(ptr
--) = 0;
1136 print_help(char *ProgName
)
1138 printf("Usage: %s [options] [image]\n", ProgName
);
1139 puts("Sets the workspace background to the specified image or a texture and optionally update Window Maker configuration");
1141 #define P(m) puts(m)
1142 P(" -display display to use");
1143 P(" -d, --dither dither image");
1144 P(" -m, --match match colors");
1145 P(" -b, --back-color <color> background color");
1146 P(" -t, --tile tile image");
1147 P(" -e, --center center image");
1148 P(" -s, --scale scale image (default)");
1149 P(" -a, --maxscale scale image and keep aspect ratio");
1150 P(" -u, --update-wmaker update WindowMaker domain database");
1151 P(" -D, --update-domain <domain> update <domain> database");
1152 P(" -c, --colors <cpc> colors per channel to use");
1153 P(" -p, --parse <texture> proplist style texture specification");
1154 P(" -w, --workspace <workspace> update background for the specified workspace");
1155 P(" --version show version of wmsetbg and exit");
1156 P(" --help show this help and exit");
1163 changeTextureForWorkspace(char *domain
, char *texture
, int workspace
)
1170 val
= PLGetProplistWithDescription(texture
);
1172 wwarning("could not parse texture %s", texture
);
1176 array
= getValueForKey("WindowMaker", "WorkspaceSpecificBack");
1179 array
= PLMakeArrayFromElements(NULL
, NULL
);
1182 j
= PLGetNumberOfElements(array
);
1183 if (workspace
>= j
) {
1186 empty
= PLMakeArrayFromElements(NULL
, NULL
);
1188 while (j
++ < workspace
-1) {
1189 PLAppendArrayElement(array
, empty
);
1191 PLAppendArrayElement(array
, val
);
1193 PLRemoveArrayElement(array
, workspace
);
1194 PLInsertArrayElement(array
, val
, workspace
);
1197 value
= PLGetDescription(array
);
1198 updateDomain(domain
, "WorkspaceSpecificBack", value
);
1203 main(int argc
, char **argv
)
1208 RContextAttributes rattr
;
1209 char *style
= "spixmap";
1210 char *back_color
= "gray20";
1211 char *image_name
= NULL
;
1212 char *domain
= "WindowMaker";
1213 int update
=0, cpc
=4, render_mode
=RM_DITHER
, obey_user
=0;
1214 char *texture
= NULL
;
1217 signal(SIGINT
, SIG_DFL
);
1218 signal(SIGTERM
, SIG_DFL
);
1219 signal(SIGQUIT
, SIG_DFL
);
1220 signal(SIGSEGV
, SIG_DFL
);
1221 signal(SIGBUS
, SIG_DFL
);
1222 signal(SIGFPE
, SIG_DFL
);
1223 signal(SIGABRT
, SIG_DFL
);
1224 signal(SIGHUP
, SIG_DFL
);
1225 signal(SIGPIPE
, SIG_DFL
);
1226 signal(SIGCHLD
, SIG_DFL
);
1228 WMInitializeApplication("wmsetbg", &argc
, argv
);
1230 for (i
=1; i
<argc
; i
++) {
1231 if (strcmp(argv
[i
], "-helper")==0) {
1233 } else if (strcmp(argv
[i
], "-display")==0) {
1236 wfatal("too few arguments for %s\n", argv
[i
-1]);
1240 } else if (strcmp(argv
[i
], "-s")==0
1241 || strcmp(argv
[i
], "--scale")==0) {
1243 } else if (strcmp(argv
[i
], "-t")==0
1244 || strcmp(argv
[i
], "--tile")==0) {
1246 } else if (strcmp(argv
[i
], "-e")==0
1247 || strcmp(argv
[i
], "--center")==0) {
1249 } else if (strcmp(argv
[i
], "-a")==0
1250 || strcmp(argv
[i
], "--maxscale")==0) {
1252 } else if (strcmp(argv
[i
], "-d")==0
1253 || strcmp(argv
[i
], "--dither")==0) {
1254 render_mode
= RM_DITHER
;
1256 } else if (strcmp(argv
[i
], "-m")==0
1257 || strcmp(argv
[i
], "--match")==0) {
1258 render_mode
= RM_MATCH
;
1260 } else if (strcmp(argv
[i
], "-u")==0
1261 || strcmp(argv
[i
], "--update-wmaker")==0) {
1263 } else if (strcmp(argv
[i
], "-D")==0
1264 || strcmp(argv
[i
], "--update-domain")==0) {
1268 wfatal("too few arguments for %s\n", argv
[i
-1]);
1271 domain
= wstrdup(argv
[i
]);
1272 } else if (strcmp(argv
[i
], "-c")==0
1273 || strcmp(argv
[i
], "--colors")==0) {
1276 wfatal("too few arguments for %s\n", argv
[i
-1]);
1279 if (sscanf(argv
[i
], "%i", &cpc
)!=1) {
1280 wfatal("bad value for colors per channel: \"%s\"\n", argv
[i
]);
1283 } else if (strcmp(argv
[i
], "-b")==0
1284 || strcmp(argv
[i
], "--back-color")==0) {
1287 wfatal("too few arguments for %s\n", argv
[i
-1]);
1290 back_color
= argv
[i
];
1291 } else if (strcmp(argv
[i
], "-p")==0
1292 || strcmp(argv
[i
], "--parse")==0) {
1295 wfatal("too few arguments for %s\n", argv
[i
-1]);
1299 } else if (strcmp(argv
[i
], "-w")==0
1300 || strcmp(argv
[i
], "--workspace")==0) {
1303 wfatal("too few arguments for %s\n", argv
[i
-1]);
1306 if (sscanf(argv
[i
], "%i", &workspace
)!=1) {
1307 wfatal("bad value for workspace number: \"%s\"",
1311 } else if (strcmp(argv
[i
], "--version")==0) {
1313 printf(PROG_VERSION
);
1316 } else if (strcmp(argv
[i
], "--help")==0) {
1317 print_help(argv
[0]);
1319 } else if (argv
[i
][0] != '-') {
1320 image_name
= argv
[i
];
1322 printf("%s: invalid argument '%s'\n", argv
[0], argv
[i
]);
1323 printf("Try '%s --help' for more information\n", argv
[0]);
1327 if (!image_name
&& !texture
&& !helperMode
) {
1328 printf("%s: you must specify a image file name or a texture\n",
1330 printf("Try '%s --help' for more information\n", argv
[0]);
1335 PixmapPath
= getPixmapPath(domain
);
1337 dpy
= XOpenDisplay(display
);
1339 wfatal("could not open display");
1343 XSynchronize(dpy
, 1);
1346 root
= DefaultRootWindow(dpy
);
1348 scr
= DefaultScreen(dpy
);
1350 scrWidth
= WidthOfScreen(DefaultScreenOfDisplay(dpy
));
1351 scrHeight
= HeightOfScreen(DefaultScreenOfDisplay(dpy
));
1353 if (!obey_user
&& DefaultDepth(dpy
, scr
) <= 8)
1354 render_mode
= RM_DITHER
;
1356 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_DefaultVisual
;
1357 rattr
.render_mode
= render_mode
;
1358 rattr
.colors_per_channel
= cpc
;
1360 rc
= RCreateContext(dpy
, scr
, &rattr
);
1363 /* lower priority, so that it wont use all the CPU */
1368 BackgroundTexture
*tex
;
1372 sprintf(buffer
, "(%s, \"%s\", %s)", style
, image_name
, back_color
);
1373 texture
= (char*)buffer
;
1376 if (update
&& workspace
< 0) {
1377 updateDomain(domain
, "WorkspaceBack", texture
);
1380 tex
= parseTexture(rc
, texture
);
1387 /* always update domain */
1388 changeTextureForWorkspace(domain
, texture
, workspace
-1);