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.2"
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
);
385 switch (toupper(type
[0])) {
387 texture
->width
= iwidth
;
388 texture
->height
= iheight
;
389 if (!pixmap
&& !RConvertImage(rc
, image
, &pixmap
)) {
390 wwarning("could not convert texture:%s",
391 RMessageForError(RErrorCode
));
392 RDestroyImage(image
);
396 RDestroyImage(image
);
400 if (toupper(type
[0])=='S') {
404 if (iwidth
*scrHeight
> iheight
*scrWidth
) {
406 h
= (scrWidth
*iheight
)/iwidth
;
409 w
= (scrHeight
*iwidth
)/iheight
;
416 simage
= RSmoothScaleImage(image
, w
, h
);
418 simage
= RScaleImage(image
, w
, h
);
420 wwarning("could not scale image:%s",
421 RMessageForError(RErrorCode
));
422 RDestroyImage(image
);
425 RDestroyImage(image
);
427 iwidth
= image
->width
;
428 iheight
= image
->height
;
435 if (!pixmap
&& !RConvertImage(rc
, image
, &pixmap
)) {
436 wwarning("could not convert texture:%s",
437 RMessageForError(RErrorCode
));
438 RDestroyImage(image
);
442 if (iwidth
!= scrWidth
|| iheight
!= scrHeight
) {
443 int x
, y
, sx
, sy
, w
, h
;
445 cpixmap
= XCreatePixmap(dpy
, root
, scrWidth
, scrHeight
,
446 DefaultDepth(dpy
, scr
));
448 XSetForeground(dpy
, DefaultGC(dpy
, scr
), color
.pixel
);
449 XFillRectangle(dpy
, cpixmap
, DefaultGC(dpy
, scr
),
450 0, 0, scrWidth
, scrHeight
);
452 if (iheight
< scrHeight
) {
454 y
= (scrHeight
- h
)/2;
457 sy
= (iheight
- scrHeight
)/2;
461 if (iwidth
< scrWidth
) {
463 x
= (scrWidth
- w
)/2;
466 sx
= (iwidth
- scrWidth
)/2;
471 XCopyArea(dpy
, pixmap
, cpixmap
, DefaultGC(dpy
, scr
),
473 XFreePixmap(dpy
, pixmap
);
477 RDestroyImage(image
);
479 texture
->width
= scrWidth
;
480 texture
->height
= scrHeight
;
485 texture
->pixmap
= pixmap
;
486 texture
->color
= color
;
487 } else if (strcasecmp(type
, "thgradient")==0
488 || strcasecmp(type
, "tvgradient")==0
489 || strcasecmp(type
, "tdgradient")==0) {
491 RColor color1
, color2
;
501 GETSTRORGOTO(val
, file
, 1, error
);
503 GETSTRORGOTO(val
, tmp
, 2, error
);
507 GETSTRORGOTO(val
, tmp
, 3, error
);
509 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
510 wwarning("could not parse color %s in texture %s", tmp
, text
);
514 color1
.red
= color
.red
>> 8;
515 color1
.green
= color
.green
>> 8;
516 color1
.blue
= color
.blue
>> 8;
518 GETSTRORGOTO(val
, tmp
, 4, error
);
520 if (!XParseColor(dpy
, DefaultColormap(dpy
, scr
), tmp
, &color
)) {
521 wwarning("could not parse color %s in texture %s", tmp
, text
);
525 color2
.red
= color
.red
>> 8;
526 color2
.green
= color
.green
>> 8;
527 color2
.blue
= color
.blue
>> 8;
529 image
= loadImage(rc
, file
);
531 RDestroyImage(gradient
);
538 gtype
= RHorizontalGradient
;
540 theight
= image
->height
> scrHeight
? scrHeight
: image
->height
;
544 gtype
= RVerticalGradient
;
545 twidth
= image
->width
> scrWidth
? scrWidth
: image
->width
;
549 gtype
= RDiagonalGradient
;
554 gradient
= RRenderGradient(twidth
, theight
, &color1
, &color2
, gtype
);
557 wwarning("could not render texture:%s",
558 RMessageForError(RErrorCode
));
559 RDestroyImage(gradient
);
563 tiled
= RMakeTiledImage(image
, twidth
, theight
);
565 wwarning("could not render texture:%s",
566 RMessageForError(RErrorCode
));
567 RDestroyImage(gradient
);
568 RDestroyImage(image
);
571 RDestroyImage(image
);
573 RCombineImagesWithOpaqueness(tiled
, gradient
, opaq
);
574 RDestroyImage(gradient
);
576 if (!RConvertImage(rc
, tiled
, &pixmap
)) {
577 wwarning("could not convert texture:%s",
578 RMessageForError(RErrorCode
));
579 RDestroyImage(image
);
582 texture
->width
= tiled
->width
;
583 texture
->height
= tiled
->height
;
585 RDestroyImage(tiled
);
587 texture
->pixmap
= pixmap
;
588 } else if (strcasecmp(type
, "function")==0) {
590 void (*initFunc
) (Display
*, Colormap
);
591 RImage
* (*mainFunc
) (int, char**, int, int, int);
595 char *lib
, *func
, **argv
= 0;
600 goto function_cleanup
;
602 /* get the library name */
603 GETSTRORGOTO(val
, lib
, 1, function_cleanup
);
605 /* get the function name */
606 GETSTRORGOTO(val
, func
, 2, function_cleanup
);
609 argv
= (char**)wmalloc(argc
* sizeof(char*));
611 /* get the parameters */
613 for (i
=0; i
<argc
-1; i
++) {
614 GETSTRORGOTO(val
, tmp
, 3+i
, function_cleanup
);
615 argv
[i
+1] = wstrdup(tmp
);
618 handle
= dlopen(lib
, RTLD_LAZY
);
620 wwarning("could not find library %s", lib
);
621 goto function_cleanup
;
624 initFunc
= dlsym(handle
, "initWindowMaker");
626 wwarning("could not initialize library %s", lib
);
627 goto function_cleanup
;
629 initFunc(dpy
, DefaultColormap(dpy
, scr
));
631 mainFunc
= dlsym(handle
, func
);
633 wwarning("could not find function %s::%s", lib
, func
);
634 goto function_cleanup
;
636 image
= mainFunc(argc
, argv
, scrWidth
, scrHeight
, 0);
638 if (!RConvertImage(rc
, image
, &pixmap
)) {
639 wwarning("could not convert texture:%s",
640 RMessageForError(RErrorCode
));
641 goto function_cleanup
;
643 texture
->width
= scrWidth
;
644 texture
->height
= scrHeight
;
645 texture
->pixmap
= pixmap
;
651 for (i
=0; i
<argc
; i
++) {
659 RDestroyImage(image
);
665 wwarning("function textures not supported");
669 wwarning("invalid texture type %s", text
);
673 texture
->spec
= wstrdup(text
);
688 freeTexture(BackgroundTexture
*texture
)
690 if (texture
->solid
) {
693 pixel
[0] = texture
->color
.pixel
;
694 /* dont free black/white pixels */
695 if (pixel
[0]!=BlackPixelOfScreen(DefaultScreenOfDisplay(dpy
))
696 && pixel
[0]!=WhitePixelOfScreen(DefaultScreenOfDisplay(dpy
)))
697 XFreeColors(dpy
, DefaultColormap(dpy
, scr
), pixel
, 1, 0);
699 if (texture
->pixmap
) {
700 XFreePixmap(dpy
, texture
->pixmap
);
708 setupTexture(RContext
*rc
, BackgroundTexture
**textures
, int *maxTextures
,
709 int workspace
, char *texture
)
711 BackgroundTexture
*newTexture
= NULL
;
714 /* unset the texture */
716 if (textures
[workspace
]!=NULL
) {
717 textures
[workspace
]->refcount
--;
719 if (textures
[workspace
]->refcount
== 0)
720 freeTexture(textures
[workspace
]);
722 textures
[workspace
] = NULL
;
726 if (textures
[workspace
]
727 && strcasecmp(textures
[workspace
]->spec
, texture
)==0) {
728 /* texture did not change */
732 /* check if the same texture is already created */
733 for (i
= 0; i
< *maxTextures
; i
++) {
734 if (textures
[i
] && strcasecmp(textures
[i
]->spec
, texture
)==0) {
735 newTexture
= textures
[i
];
741 /* create the texture */
742 newTexture
= parseTexture(rc
, texture
);
747 if (textures
[workspace
]!=NULL
) {
749 textures
[workspace
]->refcount
--;
751 if (textures
[workspace
]->refcount
== 0)
752 freeTexture(textures
[workspace
]);
755 newTexture
->refcount
++;
756 textures
[workspace
] = newTexture
;
758 if (*maxTextures
< workspace
)
759 *maxTextures
= workspace
;
765 duplicatePixmap(Pixmap pixmap
, int width
, int height
)
770 /* must open a new display or the RetainPermanent will
771 * leave stuff allocated in RContext unallocated after exit */
772 tmpDpy
= XOpenDisplay(display
);
774 wwarning("could not open display to update background image information");
780 copyP
= XCreatePixmap(tmpDpy
, root
, width
, height
,
781 DefaultDepth(tmpDpy
, scr
));
782 XCopyArea(tmpDpy
, pixmap
, copyP
, DefaultGC(tmpDpy
, scr
),
783 0, 0, width
, height
, 0, 0);
784 XSync(tmpDpy
, False
);
786 XSetCloseDownMode(tmpDpy
, RetainPermanent
);
787 XCloseDisplay(tmpDpy
);
795 dummyErrorHandler(Display
*dpy
, XErrorEvent
*err
)
801 setPixmapProperty(Pixmap pixmap
)
803 static Atom prop
= 0;
806 unsigned long length
, after
;
811 prop
= XInternAtom(dpy
, "_XROOTPMAP_ID", False
);
816 /* Clear out the old pixmap */
817 XGetWindowProperty(dpy
, root
, prop
, 0L, 1L, False
, AnyPropertyType
,
818 &type
, &format
, &length
, &after
, &data
);
820 if ((type
== XA_PIXMAP
) && (format
== 32) && (length
== 1)) {
821 XSetErrorHandler(dummyErrorHandler
);
822 XKillClient(dpy
, *((Pixmap
*)data
));
824 XSetErrorHandler(NULL
);
825 mode
= PropModeReplace
;
827 mode
= PropModeAppend
;
830 XChangeProperty(dpy
, root
, prop
, XA_PIXMAP
, 32, mode
,
831 (unsigned char *) &pixmap
, 1);
833 XDeleteProperty(dpy
, root
, prop
);
843 changeTexture(BackgroundTexture
*texture
)
848 if (texture
->solid
) {
849 XSetWindowBackground(dpy
, root
, texture
->color
.pixel
);
851 XSetWindowBackgroundPixmap(dpy
, root
, texture
->pixmap
);
853 XClearWindow(dpy
, root
);
860 pixmap
= duplicatePixmap(texture
->pixmap
, texture
->width
,
863 setPixmapProperty(pixmap
);
869 readmsg(int fd
, unsigned char *buffer
, int size
)
875 count
= read(fd
, buffer
, size
);
889 * sizeSntexture_spec - sets the texture for workspace n
890 * sizeCn - change background texture to the one for workspace n
891 * sizePpath - set the pixmap search path
894 * size = 4 bytes for length of the message data
897 helperLoop(RContext
*rc
)
899 BackgroundTexture
*textures
[WORKSPACE_COUNT
];
901 unsigned char buffer
[2048], buf
[8];
905 memset(textures
, 0, WORKSPACE_COUNT
*sizeof(BackgroundTexture
*));
911 /* get length of message */
912 if (readmsg(0, buffer
, 4) < 0) {
913 wsyserror("error reading message from Window Maker");
921 memcpy(buf
, buffer
, 4);
926 if (readmsg(0, buffer
, size
) < 0) {
927 wsyserror("error reading message from Window Maker");
936 printf("RECEIVED %s\n",buffer
);
938 if (buffer
[0]!='P' && buffer
[0]!='K') {
939 memcpy(buf
, &buffer
[1], 4);
941 workspace
= atoi(buf
);
942 if (workspace
< 0 || workspace
>= WORKSPACE_COUNT
) {
943 wwarning("received message with invalid workspace number %i\n",
952 printf("set texture %s\n", &buffer
[5]);
954 setupTexture(rc
, textures
, &maxTextures
, workspace
, &buffer
[5]);
959 printf("change texture %i\n", workspace
);
961 if (!textures
[workspace
])
962 changeTexture(textures
[0]);
964 changeTexture(textures
[workspace
]);
969 printf("change pixmappath %s\n", &buffer
[1]);
973 PixmapPath
= wstrdup(&buffer
[1]);
978 printf("unset workspace %i\n", workspace
);
980 setupTexture(rc
, textures
, &maxTextures
, workspace
, NULL
);
985 printf("exit command\n");
990 wwarning("unknown message received");
998 updateDomain(char *domain
, char *key
, char *texture
)
1000 char *program
= "wdwrite";
1002 execlp(program
, program
, domain
, key
, texture
, NULL
);
1003 wwarning("warning could not run \"%s\"", program
);
1009 globalDefaultsPathForDomain(char *domain
)
1013 sprintf(path
, "%s/%s", SYSCONFDIR
, domain
);
1015 return wstrdup(path
);
1020 getValueForKey(char *domain
, char *keyName
)
1027 key
= PLMakeString(keyName
);
1029 /* try to find PixmapPath in user defaults */
1030 path
= wdefaultspathfordomain(domain
);
1031 d
= PLGetProplistWithPath(path
);
1033 wwarning("could not open domain file %s", path
);
1037 if (d
&& !PLIsDictionary(d
)) {
1042 val
= PLGetDictionaryEntry(d
, key
);
1046 /* try to find PixmapPath in global defaults */
1048 path
= globalDefaultsPathForDomain(domain
);
1050 wwarning("could not locate file for domain %s", domain
);
1053 d
= PLGetProplistWithPath(path
);
1057 if (d
&& !PLIsDictionary(d
)) {
1062 val
= PLGetDictionaryEntry(d
, key
);
1082 getPixmapPath(char *domain
)
1088 val
= getValueForKey(domain
, "PixmapPath");
1090 if (!val
|| !PLIsArray(val
)) {
1096 count
= PLGetNumberOfElements(val
);
1098 for (i
=0; i
<count
; i
++) {
1101 v
= PLGetArrayElement(val
, i
);
1102 if (!v
|| !PLIsString(v
)) {
1105 len
+= strlen(PLGetString(v
))+1;
1108 ptr
= data
= wmalloc(len
+1);
1111 for (i
=0; i
<count
; i
++) {
1114 v
= PLGetArrayElement(val
, i
);
1115 if (!v
|| !PLIsString(v
)) {
1118 strcpy(ptr
, PLGetString(v
));
1120 ptr
+= strlen(PLGetString(v
));
1125 ptr
--; *(ptr
--) = 0;
1143 print_help(char *ProgName
)
1145 printf("Usage: %s [options] [image]\n", ProgName
);
1146 puts("Sets the workspace background to the specified image or a texture and optionally update Window Maker configuration");
1148 #define P(m) puts(m)
1149 P(" -display display to use");
1150 P(" -d, --dither dither image");
1151 P(" -m, --match match colors");
1152 P(" -S, --smooth smooth scaled image");
1153 P(" -b, --back-color <color> background color");
1154 P(" -t, --tile tile image");
1155 P(" -e, --center center image");
1156 P(" -s, --scale scale image (default)");
1157 P(" -a, --maxscale scale image and keep aspect ratio");
1158 P(" -u, --update-wmaker update WindowMaker domain database");
1159 P(" -D, --update-domain <domain> update <domain> database");
1160 P(" -c, --colors <cpc> colors per channel to use");
1161 P(" -p, --parse <texture> proplist style texture specification");
1162 P(" -w, --workspace <workspace> update background for the specified workspace");
1163 P(" --version show version of wmsetbg and exit");
1164 P(" --help show this help and exit");
1171 changeTextureForWorkspace(char *domain
, char *texture
, int workspace
)
1178 val
= PLGetProplistWithDescription(texture
);
1180 wwarning("could not parse texture %s", texture
);
1184 array
= getValueForKey("WindowMaker", "WorkspaceSpecificBack");
1187 array
= PLMakeArrayFromElements(NULL
, NULL
);
1190 j
= PLGetNumberOfElements(array
);
1191 if (workspace
>= j
) {
1194 empty
= PLMakeArrayFromElements(NULL
, NULL
);
1196 while (j
++ < workspace
-1) {
1197 PLAppendArrayElement(array
, empty
);
1199 PLAppendArrayElement(array
, val
);
1201 PLRemoveArrayElement(array
, workspace
);
1202 PLInsertArrayElement(array
, val
, workspace
);
1205 value
= PLGetDescription(array
);
1206 updateDomain(domain
, "WorkspaceSpecificBack", value
);
1211 main(int argc
, char **argv
)
1216 RContextAttributes rattr
;
1217 char *style
= "spixmap";
1218 char *back_color
= "gray20";
1219 char *image_name
= NULL
;
1220 char *domain
= "WindowMaker";
1221 int update
=0, cpc
=4, render_mode
=RM_DITHER
, obey_user
=0;
1222 char *texture
= NULL
;
1225 signal(SIGINT
, SIG_DFL
);
1226 signal(SIGTERM
, SIG_DFL
);
1227 signal(SIGQUIT
, SIG_DFL
);
1228 signal(SIGSEGV
, SIG_DFL
);
1229 signal(SIGBUS
, SIG_DFL
);
1230 signal(SIGFPE
, SIG_DFL
);
1231 signal(SIGABRT
, SIG_DFL
);
1232 signal(SIGHUP
, SIG_DFL
);
1233 signal(SIGPIPE
, SIG_DFL
);
1234 signal(SIGCHLD
, SIG_DFL
);
1236 WMInitializeApplication("wmsetbg", &argc
, argv
);
1238 for (i
=1; i
<argc
; i
++) {
1239 if (strcmp(argv
[i
], "-helper")==0) {
1241 } else if (strcmp(argv
[i
], "-display")==0) {
1244 wfatal("too few arguments for %s\n", argv
[i
-1]);
1248 } else if (strcmp(argv
[i
], "-s")==0
1249 || strcmp(argv
[i
], "--scale")==0) {
1251 } else if (strcmp(argv
[i
], "-t")==0
1252 || strcmp(argv
[i
], "--tile")==0) {
1254 } else if (strcmp(argv
[i
], "-e")==0
1255 || strcmp(argv
[i
], "--center")==0) {
1257 } else if (strcmp(argv
[i
], "-a")==0
1258 || strcmp(argv
[i
], "--maxscale")==0) {
1260 } else if (strcmp(argv
[i
], "-d")==0
1261 || strcmp(argv
[i
], "--dither")==0) {
1262 render_mode
= RM_DITHER
;
1264 } else if (strcmp(argv
[i
], "-m")==0
1265 || strcmp(argv
[i
], "--match")==0) {
1266 render_mode
= RM_MATCH
;
1268 } else if (strcmp(argv
[i
], "-S")==0
1269 || strcmp(argv
[i
], "--smooth")==0) {
1271 } else if (strcmp(argv
[i
], "-u")==0
1272 || strcmp(argv
[i
], "--update-wmaker")==0) {
1274 } else if (strcmp(argv
[i
], "-D")==0
1275 || strcmp(argv
[i
], "--update-domain")==0) {
1279 wfatal("too few arguments for %s\n", argv
[i
-1]);
1282 domain
= wstrdup(argv
[i
]);
1283 } else if (strcmp(argv
[i
], "-c")==0
1284 || strcmp(argv
[i
], "--colors")==0) {
1287 wfatal("too few arguments for %s\n", argv
[i
-1]);
1290 if (sscanf(argv
[i
], "%i", &cpc
)!=1) {
1291 wfatal("bad value for colors per channel: \"%s\"\n", argv
[i
]);
1294 } else if (strcmp(argv
[i
], "-b")==0
1295 || strcmp(argv
[i
], "--back-color")==0) {
1298 wfatal("too few arguments for %s\n", argv
[i
-1]);
1301 back_color
= argv
[i
];
1302 } else if (strcmp(argv
[i
], "-p")==0
1303 || strcmp(argv
[i
], "--parse")==0) {
1306 wfatal("too few arguments for %s\n", argv
[i
-1]);
1310 } else if (strcmp(argv
[i
], "-w")==0
1311 || strcmp(argv
[i
], "--workspace")==0) {
1314 wfatal("too few arguments for %s\n", argv
[i
-1]);
1317 if (sscanf(argv
[i
], "%i", &workspace
)!=1) {
1318 wfatal("bad value for workspace number: \"%s\"",
1322 } else if (strcmp(argv
[i
], "--version")==0) {
1324 printf(PROG_VERSION
);
1327 } else if (strcmp(argv
[i
], "--help")==0) {
1328 print_help(argv
[0]);
1330 } else if (argv
[i
][0] != '-') {
1331 image_name
= argv
[i
];
1333 printf("%s: invalid argument '%s'\n", argv
[0], argv
[i
]);
1334 printf("Try '%s --help' for more information\n", argv
[0]);
1338 if (!image_name
&& !texture
&& !helperMode
) {
1339 printf("%s: you must specify a image file name or a texture\n",
1341 printf("Try '%s --help' for more information\n", argv
[0]);
1346 PixmapPath
= getPixmapPath(domain
);
1348 dpy
= XOpenDisplay(display
);
1350 wfatal("could not open display");
1354 XSynchronize(dpy
, 1);
1357 root
= DefaultRootWindow(dpy
);
1359 scr
= DefaultScreen(dpy
);
1361 scrWidth
= WidthOfScreen(DefaultScreenOfDisplay(dpy
));
1362 scrHeight
= HeightOfScreen(DefaultScreenOfDisplay(dpy
));
1364 if (!obey_user
&& DefaultDepth(dpy
, scr
) <= 8)
1365 render_mode
= RM_DITHER
;
1367 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_DefaultVisual
;
1368 rattr
.render_mode
= render_mode
;
1369 rattr
.colors_per_channel
= cpc
;
1371 rc
= RCreateContext(dpy
, scr
, &rattr
);
1374 /* lower priority, so that it wont use all the CPU */
1379 BackgroundTexture
*tex
;
1383 sprintf(buffer
, "(%s, \"%s\", %s)", style
, image_name
, back_color
);
1384 texture
= (char*)buffer
;
1387 if (update
&& workspace
< 0) {
1388 updateDomain(domain
, "WorkspaceBack", texture
);
1391 tex
= parseTexture(rc
, texture
);
1398 /* always update domain */
1399 changeTextureForWorkspace(domain
, texture
, workspace
-1);