/* An sample X Window application */ /* Songyan Feng (Tiger) */ /* August 2001 */ /* Argonne National Lab. */ /* USA */ /* Xlib include files */ #include #include #include #include /* Standard C include file */ #include /* Bitmap data for icon */ int icon_bitmap_width = 64; int icon_bitmap_height = 64; const char icon_bitmap_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x98, 0x01, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x63, 0x00, 0xe0, 0x00, 0x8e, 0x01, 0x00, 0x00, 0x63, 0xc0, 0xf1, 0x01, 0xc7, 0x01, 0x00, 0x00, 0xc3, 0xe0, 0xb3, 0x81, 0xc3, 0x00, 0x00, 0x00, 0xc7, 0x61, 0xb3, 0xc1, 0xe1, 0x00, 0x00, 0x00, 0x86, 0x63, 0xb3, 0xf3, 0x70, 0x00, 0x00, 0x00, 0x0e, 0x6f, 0x73, 0x3f, 0x3e, 0x00, 0x00, 0x00, 0x1c, 0x7e, 0x63, 0x8e, 0x1f, 0x00, 0x00, 0x00, 0x38, 0x38, 0x63, 0xe0, 0x03, 0x00, 0x00, 0x00, 0xf0, 0x00, 0xe7, 0xf8, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x0f, 0xc6, 0x78, 0x00, 0x00, 0x00, 0x00, 0x80, 0x1f, 0xc6, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0xc6, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0x00, 0xf7, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0xfb, 0x01, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0xcf, 0x03, 0x00, 0x00, 0x78, 0x00, 0x00, 0x80, 0x03, 0x07, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x80, 0x03, 0x06, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x80, 0x01, 0x06, 0x00, 0x00, 0x80, 0x03, 0x80, 0xbf, 0x0d, 0x06, 0x00, 0x00, 0x00, 0x07, 0xe0, 0xff, 0x0d, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x70, 0xe0, 0x0d, 0x06, 0x00, 0x00, 0x00, 0x1c, 0x38, 0x80, 0x01, 0x06, 0x00, 0x00, 0x00, 0x18, 0x18, 0x80, 0x03, 0x06, 0x00, 0x00, 0x00, 0x38, 0x18, 0x00, 0x0f, 0x07, 0x00, 0x00, 0x00, 0x30, 0x1c, 0x00, 0xfe, 0x03, 0x00, 0x00, 0x00, 0x30, 0x0c, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0xf0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x80, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf8, 0x00, 0x78, 0x00, 0xff, 0x01, 0x00, 0x00, 0xe0, 0x01, 0xfc, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x80, 0x07, 0xce, 0xc1, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x86, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x87, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; #define BITMAPDEPTH 1 #define DEBUG /* Values for window_size in main */ #define TOO_SMALL 0 #define BIG_ENOUGH 1 char *display_name =NULL; Display *display; int screen_num; Screen *screen_ptr; static char *progname; unsigned int display_width, display_height; int main(argc,argv) int argc; char **argv; { Window win; unsigned int width, height; int x=0,y=0; unsigned int border_width = 4; unsigned int display_width, display_height; char * window_name = "Basic Window Program by Tiger"; char * icon_name = "basicwin"; Pixmap icon_pixmap; XSizeHints *size_hints; XEvent report; GC gc; XFontStruct *font_into; char *display_name=NULL; XWMHints *wm_hints; XClassHint *class_hints; XTextProperty windowName, iconName; int window_size=0; XFontStruct *font_info; progname = argv[0]; /* Connect to X server */ if ( (display=XOpenDisplay(display_name)) == NULL) { (void) fprintf(stderr, "%s: cannot connect to X server %s\n", progname, XDisplayName(display_name)); exit(-1); } /* Open display */ screen_num=DefaultScreen(display); /* screen_ptr=DefaultScreenofDisplay(display); */ /* Display size */ display_width=DisplayWidth(display,screen_num); display_height=DisplayHeight(display,screen_num); /* Window size */ width=display_width/3, height=display_height/4; win=XCreateSimpleWindow(display,RootWindow(display,screen_num),x,y,width,height, border_width, BlackPixel(display, screen_num), WhitePixel(display, screen_num)); /* Create pixmap of depth 1 (bitmap) for icon */ icon_pixmap =XCreateBitmapFromData(display, win, icon_bitmap_bits, icon_bitmap_width, icon_bitmap_height); /* Communication with window manager */ if (!(size_hints=XAllocSizeHints())) { fprintf(stderr,"%s: failure allocating memory\n",progname); exit(0); } if (!(wm_hints=XAllocWMHints())){ fprintf(stderr,"%s: failure allocating memory\n",progname); exit(0); } if (!(class_hints=XAllocClassHint())){ fprintf(stderr,"%s: failure allocating memory\n",progname); exit(0); } size_hints->flags=PPosition | PSize |PMinSize; size_hints->min_width=300; size_hints->min_height=200; if (XStringListToTextProperty(&window_name, 1, &windowName)==0){ (void) fprintf(stderr, "%s: structure allocation for windowName failed.\n", progname); exit(-1); } if (XStringListToTextProperty(&icon_name,1,&iconName)==0){ (void) fprintf(stderr, "%s: structure allocation for iconName failed.\n", progname); exit(-1); } wm_hints->initial_state=NormalState; wm_hints->input=True; wm_hints->icon_pixmap=icon_pixmap; wm_hints->flags=StateHint | IconPixmapHint |InputHint; class_hints->res_name=progname; class_hints->res_class="Basicwin"; XSetWMProperties(display,win,&windowName,&iconName,argv,argc,size_hints,wm_hints,class_hints); /* Event */ XSelectInput(display,win,ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask); /* Display window */ XMapWindow(display,win); /* Event Loop */ while(1) { XNextEvent(display, &report); switch(report.type){ case Expose: if(report.xexpose.count != 0) break; /* if(window_size==TOO_SMALL) TooSmall(win,gc,font_into); else{ place_text(win,gc,font_info,width,height); place_graphics(win,gc,width,height); } */ break; case ConfigureNotify: width=report.xconfigure.width; height=report.xconfigure.height; if((widthmin_width) || (heightmin_height)) window_size=TOO_SMALL; else window_size=BIG_ENOUGH; break; case ButtonPress: break; case KeyPress: XUnloadFont(display,font_info->fid); XFreeGC(display,gc); XCloseDisplay(display); exit(1); default: break; } } #ifdef DEBUG printf("-----------Here we are in the DEBUG portion.-----------\n"); printf("Window is: %d\n", win); printf("Pixmap is: %d\n", icon_pixmap); printf("Screen_num is: %d\n", screen_num); printf("Display size (Width, Height) is : (%d, %d)\n", display_width, display_height); printf("Window size (Width, Height) is: (%d, %d)\n", width, height); printf("Icon size (Width, Height) is: (%d, %d)\n", icon_bitmap_width, icon_bitmap_height); printf("-----------Here is the end of the DEBUG portion.-----------\n"); #endif }