[comp.windows.x] simple xlib display

tiefel@kodak.UUCP (Lenny Tiefel) (02/21/90)

The simple program below should display a hard-wired
bitmap, but it doesn't -- only the window frame.

Could anyone help?

(This is my first xlib program.)

Len Tiefel
Physics Research
Eastman Kodak Company
(716) 722-2250
(email tiefel@kodak.com)





----------------------------CUT HERE---------------------------------------

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>

#include <stdio.h>

/* SMALL BITMAP TO BE PLACED INTO PIXMAP */
/* ------------------------------------- */
#define spicture_width 32
#define spicture_height 32
static char spicture[] = {
   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f,
   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
   0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0,
   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
   0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
   0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0};


int main()
{

   Display 			*dpy;
   Screen 			*screen;
   Window 			root, win;
   unsigned long 		fg, bg;
   unsigned int 		depth, screen_number;
   XEvent 			event;


   /* CREATE DISPLAY ON ROOT WINDOW */
   /* ----------------------------- */

   dpy = XOpenDisplay(NULL);
   if (dpy == NULL) printf("Dpy is NULL!\n");
   screen_number = XDefaultScreen(dpy);
   screen = XDefaultScreenOfDisplay(dpy);
   root = XDefaultRootWindow(dpy);

i   fg = XBlackPixelOfScreen(screen);
   bg = XWhitePixelOfScreen(screen);
   depth = XDefaultDepth(dpy,screen_number);
   win = XCreateSimpleWindow(dpy, root, 200, 200, 400, 400, 1, fg, bg);

   XCreatePixmapFromBitmapData(dpy, 
                        win, spicture, spicture_width, 
                        spicture_height, fg, bg, depth);

   XMapWindow(dpy, win);
   for (;;) 
      XNextEvent(dpy, &event);
}

   

garfinke@hpfcda.HP.COM (Dan Garfinkel) (02/23/90)

You need to do an XCopyArea() when you get an exposure event.

HELPFUL HINT:

Another way to do this is to create a subwindow and make the background of
the subwindow the pixmap you created.  This avoids a round-trip to redraw
the pixmap.

-Dan