/**************************************************************************** * * Creates an Icon Window * Loads an icon file and combines icon shape masks after a resize * special thanks to Rich Neitzel <*****@*****.**> * for his patch to handle icon windows * ****************************************************************************/ void CreateIconWindow(struct icon_info *item) { unsigned long valuemask; /* mask for create windows */ XSetWindowAttributes attributes; /* attributes for create windows */ attributes.background_pixel = icon_back_pix; attributes.border_pixel = 0; attributes.colormap = Pcmap; attributes.event_mask = ExposureMask; valuemask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; /* ccreate the icon label */ item->IconWin = XCreateWindow(dpy, icon_win, 0, 0, max_icon_width, max_icon_height + 10, 0, CopyFromParent, CopyFromParent, CopyFromParent, valuemask, &attributes); XSelectInput(dpy, item->IconWin, ICON_EVENTS); XSelectInput(dpy, item->id, PropertyChangeMask); item->wmhints = XGetWMHints(dpy, item->id); if (max_icon_height == 0) return; /* config specified icons have priority */ if ((item->icon_file != NULL) && !(item->extra_flags & DEFAULTICON)) { /* monochrome bitmap */ GetBitmapFile(item); /* color pixmap */ if((item->icon_w == 0) && (item->icon_h == 0)) GetXPMFile(item); } /* next come program specified icon windows and pixmaps*/ if((item->icon_h == 0) && (item->icon_w == 0) && item->wmhints) { if (item->wmhints->flags & IconWindowHint) GetIconWindow(item); else if (item->wmhints->flags & IconPixmapHint) GetIconBitmap(item); } /* if that all fails get the default */ if ((item->icon_file != NULL) && (item->icon_h == 0) && (item->icon_w == 0)) { /* monochrome bitmap */ GetBitmapFile(item); /* color pixmap */ if((item->icon_w == 0) && (item->icon_h == 0)) GetXPMFile(item); } /* create the window to hold the pixmap */ /* if using a non default visual client pixmaps must have a default visual window to be drawn into */ if (IS_ICON_OURS(item)) { if (Pdefault | (item->icon_depth == 1) | IS_PIXMAP_OURS(item)){ item->icon_pixmap_w = XCreateWindow(dpy, icon_win, 0, 0, max(max_icon_width, item->icon_w), max(max_icon_height, item->icon_h), 0, CopyFromParent, CopyFromParent, CopyFromParent, valuemask, &attributes); } else { attributes.background_pixel = 0; attributes.colormap = DefaultColormap(dpy, screen); item->icon_pixmap_w = XCreateWindow(dpy, icon_win, 0, 0, max(max_icon_width,item->icon_w), max(max_icon_height,item->icon_h), 0, DefaultDepth(dpy, screen), InputOutput, DefaultVisual(dpy, screen), valuemask, &attributes); } XSelectInput(dpy, item->icon_pixmap_w, ICON_EVENTS); } #ifdef XPM if (FShapesSupported && item->icon_maskPixmap != None) { int hr; hr = (Pdefault | (item->icon_depth == 1) | IS_PIXMAP_OURS(item)) ? icon_relief/2 : 0; FShapeCombineMask( dpy, item->icon_pixmap_w, FShapeBounding, hr, hr, item->icon_maskPixmap, FShapeSet); } #endif if(item->icon_depth == -1 ) { Pixmap temp = item->iconPixmap; item->iconPixmap = XCreatePixmap(dpy, Root, item->icon_w, item->icon_h, Pdepth); XCopyPlane(dpy, temp, item->iconPixmap, NormalGC, 0, 0, item->icon_w, item->icon_h, 0, 0, 1); } }
/**************************************************************************** * * Creates an icon window as needed * ****************************************************************************/ int main(int argc, char **argv) { char *display_name = NULL, *string = NULL; int retval = 0; XEvent Event; fd_set in_fdset; int fd_width ; struct timeval value; int fd[2]; fd_width = GetFdWidth(); /* Save our program name - for error messages */ string = strrchr (argv[0], '/'); if (string != (char *) 0) string++; myName = safemalloc (strlen (string) + 1); strcpy (myName, string); if(argc>=3) { /* sever our connection with fvwm, if we have one. */ fd[0] = atoi(argv[1]); fd[1] = atoi(argv[2]); #if 0 if(fd[0]>0)close(fd[0]); if(fd[1]>0)close(fd[1]); #endif /* 0 */ } else { fprintf (stderr, "%s version %s should only be executed by fvwm!\n", myName, VERSION); exit(1); } if (argc > 6) { pixmapName = safemalloc (strlen (argv[6]) + 1); strcpy (pixmapName, argv[6]); } /* Open the display */ if (!(dpy = XOpenDisplay(display_name))) { fprintf(stderr,"FvwmBanner: can't open display %s", XDisplayName(display_name)); exit (1); } screen= DefaultScreen(dpy); Root = RootWindow(dpy, screen); colormap = XDefaultColormap(dpy,screen); d_depth = DefaultDepth(dpy, screen); x_fd = XConnectionNumber(dpy); ScreenHeight = DisplayHeight(dpy,screen); ScreenWidth = DisplayWidth(dpy,screen); parseOptions(fd); /* Get the xpm banner */ if (pixmapName) GetXPMFile(pixmapName,pixmapPath); else #if 0 if(d_depth > 4) GetXPMData(k2_xpm); else #endif /* 0 */ GetXPMData(fvwm2_big_xpm); /* Create a window to hold the banner */ mysizehints.flags= USSize|USPosition|PWinGravity|PResizeInc|PBaseSize|PMinSize|PMaxSize; /* subtract one for the right/bottom border */ mysizehints.width = view.attributes.width; mysizehints.height=view.attributes.height; mysizehints.width_inc = 1; mysizehints.height_inc = 1; mysizehints.base_height = mysizehints.height; mysizehints.base_width = mysizehints.width; mysizehints.min_height = mysizehints.height; mysizehints.min_width = mysizehints.width; mysizehints.max_height = mysizehints.height; mysizehints.max_width = mysizehints.width; mysizehints.win_gravity = NorthWestGravity; mysizehints.x = (ScreenWidth - view.attributes.width)/2; mysizehints.y = (ScreenHeight - view.attributes.height)/2; win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y, mysizehints.width,mysizehints.height, 0,fore_pix ,None); /* Set assorted info for the window */ XSetTransientForHint(dpy,win,Root); wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False); XSetWMProtocols(dpy,win,&wm_del_win,1); XSetWMNormalHints(dpy,win,&mysizehints); change_window_name("FvwmBanner"); XSetWindowBackgroundPixmap(dpy,win,view.pixmap); #ifdef SHAPE if(view.mask != None) XShapeCombineMask(dpy, win, ShapeBounding,0,0,view.mask, ShapeSet); #endif XMapWindow(dpy,win); XSync(dpy,0); #if 0 usleep(timeout); #else XSelectInput(dpy,win,ButtonReleaseMask); /* Display the window */ value.tv_usec = timeout % 1000000; value.tv_sec = timeout / 1000000; while(1) { FD_ZERO(&in_fdset); FD_SET(x_fd,&in_fdset); if(!XPending(dpy)) retval=select(fd_width,SELECT_TYPE_ARG234 &in_fdset, 0, 0, &value); if (retval==0) { XDestroyWindow(dpy,win); XSync(dpy,0); exit(0); } if(FD_ISSET(x_fd, &in_fdset)) { /* read a packet */ XNextEvent(dpy,&Event); switch(Event.type) { case ButtonRelease: XDestroyWindow(dpy,win); XSync(dpy,0); exit(0); case ClientMessage: if (Event.xclient.format==32 && Event.xclient.data.l[0]==wm_del_win) { XDestroyWindow(dpy,win); XSync(dpy,0); exit(0); } default: break; } } } #endif /* 0 */ return 0; }