v02i034: set the root background, Patch1
Mike Wexler
mikew at wyse.wyse.com
Wed Dec 7 09:24:28 AEST 1988
Submitted-by: Bob Sutterfield <bob at cis.ohio-state.edu>
Posting-number: Volume 2, Issue 34
Archive-name: xsetroot/patch1
Long ago, Mark Baushke (mdb at silvlis.com) posted changes for the X11R2
xsetroot so that it could use Sun rasterfile format bitmaps as its
input. I simply merged those changes back into the X11R3 xsetroot. --Bob
diff -rc2 X.V11R3/clients/xsetroot/xsetroot.c.dist X.V11R3/clients/xsetroot/xsetroot.c
*** X.V11R3/clients/xsetroot/xsetroot.c.dist Tue Nov 29 23:29:55 1988
--- X.V11R3/clients/xsetroot/xsetroot.c Wed Nov 30 00:22:17 1988
***************
*** 7,10 ****
--- 7,14 ----
#include "X11/bitmaps/gray"
+ #ifdef sun
+ #include <pixrect/pixrect_hs.h>
+ #endif /* sun */
+
/*
* xsetroot.c MIT Project Athena, X Window system root window
***************
*** 14,17 ****
--- 18,26 ----
* Author: Mark Lillibridge, MIT Project Athena
* 11-Jun-87
+ * Modified: Mark Baushke <mdb at silvlis.com>, to add -rast option
+ * 2-Jun-88
+ * Bob Sutterfield <bob at cis.ohio-state.edu>, re-merged
+ * mdb's -rast changes into X11R3.
+ * 30-Nov-88
*/
***************
*** 46,49 ****
--- 55,59 ----
fprintf(stderr, " -gray or -grey\n");
fprintf(stderr, " -bitmap <filename>\n");
+ fprintf(stderr, " -rast <filename>\n");
fprintf(stderr, " -mod <x> <y>\n");
exit(1);
***************
*** 52,55 ****
--- 62,68 ----
Pixmap MakeModulaBitmap(), ReadBitmapFile();
+ #ifdef sun
+ Pixmap ReadSunRasterFile(), XCreateBitmapFromSunPixrectData();
+ #endif /* sun */
XColor NameToXColor();
unsigned long NameToPixel();
***************
*** 70,73 ****
--- 83,89 ----
int gray = 0;
char *bitmap_file = NULL;
+ #ifdef sun
+ char *rast_file = NULL;
+ #endif /* sun */
int mod_x = 0;
int mod_y = 0;
***************
*** 132,135 ****
--- 148,164 ----
continue;
}
+ if (!strcmp("-rast", argv[i])) {
+ #ifdef sun
+ if (++i>=argc) usage();
+ rast_file = argv[i];
+ excl++;
+ continue;
+ #else /* sun */
+ fprintf(stderr, "%s: "-rast" option not implemented.\n",
+ program_name);
+ if (++i>=argc) usage();
+ continue;
+ #endif /* sun */
+ }
if (!strcmp("-mod", argv[i])) {
if (++i>=argc) usage();
***************
*** 151,157 ****
/* Check for multiple use of exclusive options */
if (excl > 1) {
! fprintf(stderr, "%s: choose only one of {solid, gray, bitmap, mod}\n",
! program_name);
! usage();
}
--- 180,192 ----
/* Check for multiple use of exclusive options */
if (excl > 1) {
! #ifdef sun
! fprintf(stderr,
! "%s: choose only one of {solid, gray, bitmap, rast, mod}\n",
! program_name);
! #else /* sun */
! fprintf(stderr, "%s: choose only one of {solid, gray, bitmap, mod}\n",
! program_name);
! #endif /* sun */
! usage();
}
***************
*** 196,200 ****
SetBackgroundToBitmap(bitmap, ww, hh);
}
!
/* Handle set background to a modula pattern */
if (mod_x) {
--- 231,243 ----
SetBackgroundToBitmap(bitmap, ww, hh);
}
!
! #ifdef sun
! /* Handle -rast option */
! if (rast_file) {
! bitmap = ReadSunRasterFile(rast_file, &ww, &hh);
! SetBackgroundToBitmap(bitmap, ww, hh);
! }
! #endif /* sun */
!
/* Handle set background to a modula pattern */
if (mod_x) {
***************
*** 441,442 ****
--- 484,618 ----
/*NOTREACHED*/
}
+
+ #ifdef sun
+ char *malloc();
+
+ Pixmap ReadSunRasterFile(filename, width, height)
+ char *filename;
+ unsigned int *width, *height;
+ {
+ Pixmap bitmap;
+ int status;
+ int rows, cols, linebytes;
+ short *data;
+ FILE *file;
+ struct rasterfile header;
+ struct pixrect *pr, *pr_load_image();
+ int firsttime, value, i, data_length;
+
+ file = fopen(filename, "r");
+ if (file == NULL) {
+ fprintf(stderr, "%s: can't open file: %s\n", program_name,
+ filename);
+ exit(1);
+ }
+
+ cols = rows = -1;
+
+ /* Get the raster file's header. */
+ if (pr_load_header(file, &header) != 0) {
+ fprintf(stderr, "%s: Unable to read in raster file header.\n",
+ filename);
+ exit(1);
+ }
+
+ /* can only handle monochrome bitmaps. */
+ if (header.ras_depth != 1) {
+ fprintf(stderr, "%s: Invalid depth.\n", filename);
+ exit(1);
+ }
+
+ cols = header.ras_width;
+ rows = header.ras_height;
+ if (cols <= 0) {
+ fprintf(stderr, "%s: Invalid width: %d.\n", filename, cols);
+ exit(1);
+ }
+
+ if (rows <= 0) {
+ fprintf(stderr, "%s: Invalid height: %d.\n", filename, rows);
+ exit(1);
+ }
+
+ /* If there is a color map, skip over it. */
+ if (header.ras_maptype != RMT_NONE && header.ras_maplength != 0) {
+ if (pr_load_colormap(file, &header, NULL) != 0) {
+ fprintf(stderr, "%s: Unable to skip colormap data.\n", filename);
+ exit(1);
+ }
+ }
+
+ /* Now load the data. The pixrect returned is a memory pixrect. */
+ if ((pr = pr_load_image(file, &header, NULL)) == NULL) {
+ fprintf(stderr,
+ "Unable to read in the image from the raster file: %s.\n",
+ filename);
+ exit(1);
+ }
+ fclose(file);
+
+ linebytes = ((struct mpr_data *)pr->pr_data)->md_linebytes;
+ data = ((struct mpr_data *)pr->pr_data)->md_image;
+
+ *width = cols;
+ *height = rows;
+ bitmap = XCreateBitmapFromSunPixrectData(dpy, root, (char *) data,
+ *width, *height, linebytes);
+ if (!bitmap) {
+ fprintf(stderr, "%s: insufficient memory for bitmap: %s",
+ program_name, filename);
+ exit(1);
+ }
+ return(bitmap);
+ }
+
+
+ /*
+ * XCreateBitmapFromSunPixrectData: Routine to make a pixmap of depth 1 from user supplied data.
+ * D is any drawable on the same screen that the pixmap will be used in.
+ * Data is a pointer to the bit data, and
+ * width & height give the size in bits of the pixmap.
+ *
+ * The following format is assumed for data:
+ *
+ * format=XYPixmap
+ * bit_order=MSBFirst
+ * byte_order=MSBFirst
+ * padding=8
+ * bitmap_unit=8
+ * xoffset=0
+ * rows are rounded up to 16-bit boundaries
+ */
+ Pixmap XCreateBitmapFromSunPixrectData(display, d, data, width,
+ height, linebytes)
+ Display *display;
+ Drawable d;
+ char *data;
+ unsigned int width, height;
+ int linebytes;
+ {
+ XImage ximage;
+ GC gc;
+ Pixmap pix;
+
+ pix = XCreatePixmap(display, d, width, height, 1);
+ if (!pix)
+ return(0);
+ gc = XCreateGC(display, pix, (unsigned long)0, (XGCValues *)0);
+ ximage.height = height;
+ ximage.width = width;
+ ximage.depth = 1;
+ ximage.xoffset = 0;
+ ximage.format = XYPixmap;
+ ximage.data = data;
+ ximage.byte_order = MSBFirst;
+ ximage.bitmap_unit = 8;
+ ximage.bitmap_bit_order = MSBFirst;
+ ximage.bitmap_pad = 8;
+ ximage.bytes_per_line = (linebytes == 0) ? (((width+15)>>3) & ~1) : linebytes;
+
+ XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height);
+ XFreeGC(display, gc);
+ return(pix);
+ }
+ #endif /* sun */
diff -rc2 X.V11R3/clients/xsetroot/xsetroot.man.dist X.V11R3/clients/xsetroot/xsetroot.man
*** X.V11R3/clients/xsetroot/xsetroot.man.dist Tue Nov 29 23:30:08 1988
--- X.V11R3/clients/xsetroot/xsetroot.man Wed Nov 30 00:04:43 1988
***************
*** 6,9 ****
--- 6,10 ----
[-help] [-def] [-display \fIdisplay\fP]
[-cursor \fIcursorfile maskfile\fP] [-bitmap \fIfilename\fP]
+ [-rast \fIfilename\fP]
[-mod \fIx y\fP] [-gray] [-grey] [-fg \fIcolor\fP] [-bg \fIcolor\fP] [-rv]
[-solid \fIcolor\fP] [-name \fIstring\fP]
***************
*** 26,30 ****
.PP
Only one of the background color/tiling changing options
! (-solid, -gray, -grey, -bitmap, and -mod) may be specified at a time.
.SH OPTIONS
.PP
--- 27,31 ----
.PP
Only one of the background color/tiling changing options
! (-solid, -gray, -grey, -bitmap, -rast, and -mod) may be specified at a time.
.SH OPTIONS
.PP
***************
*** 48,51 ****
--- 49,58 ----
program. The entire background will be made up of repeated "tiles" of
the bitmap.
+ .IP "\fB-rast\fP \fIfilename\fP"
+ Use the sun raster file specified in the file to set the window
+ pattern. You can make your own sun raster files (little pictures) using the
+ .I screendump(1)
+ program. The entire background will be made up of repeated "tiles" of
+ the raster file.
.IP "\fB-mod\fP \fIx\fP \fIy\fP"
This is used if you want a plaid-like grid pattern on your screen.
***************
*** 74,78 ****
Specifies the server to connect to; see \fIX(1)\fP.
.SH "SEE ALSO"
! X(1), xset(1), xrdb(1)
.SH COPYRIGHT
Copyright 1988, Massachusetts Institute of Technology.
--- 81,85 ----
Specifies the server to connect to; see \fIX(1)\fP.
.SH "SEE ALSO"
! X(1), xset(1), xrdb(1), screendump(1), screenload(1)
.SH COPYRIGHT
Copyright 1988, Massachusetts Institute of Technology.
diff -rc2 X.V11R3/clients/xsetroot/Imakefile.dist X.V11R3/clients/xsetroot/Imakefile
*** X.V11R3/clients/xsetroot/Imakefile.dist Tue Nov 29 23:46:29 1988
--- X.V11R3/clients/xsetroot/Imakefile Tue Nov 29 23:47:15 1988
***************
*** 1,3 ****
! LOCAL_LIBRARIES = $(XLIB)
SRCS = xsetroot.c
OBJS = xsetroot.o
--- 1,3 ----
! LOCAL_LIBRARIES = $(XLIB) /usr/lib/libpixrect.a
SRCS = xsetroot.c
OBJS = xsetroot.o
--
Mike Wexler(wyse!mikew) Phone: (408)433-1000 x1330
Moderator of comp.sources.x
More information about the Comp.sources.x
mailing list