⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icons.c

📁 安装DDD之前
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $Id: icons.c,v 1.1 2004/08/28 19:25:46 dannybackx Exp $ *//**************************************************************************** * This module is mostly all new * by Rob Nation * A little of it is borrowed from ctwm. * Copyright 1993 Robert Nation. No restrictions are placed on this code, * as long as the copyright notice is preserved ****************************************************************************//*********************************************************************** * * mwm icon code * ***********************************************************************/#include <LTconfig.h>#include <stdio.h>#include <string.h>#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#ifdef HAVE_FCNTL_H#include <fcntl.h>#endif#include <X11/Intrinsic.h>#include <X11/extensions/shape.h>#include <Xm/Xm.h>#include <Xm/MwmUtil.h>#if XmVERSION >= 2#include <Xm/XpmP.h>#else#include <XmI/XmXpm.h>#endif#include "mwm.h"#define def_bitmap_width 50#define def_bitmap_height 50static unsigned char def_bitmap_bits[] ={    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,    0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x80,    0x00, 0x00, 0x20, 0x02, 0x01, 0x00, 0xc0, 0x00, 0x00, 0x30, 0x02, 0xe1,    0xff, 0xdf, 0xf0, 0xff, 0x37, 0x02, 0xe1, 0xff, 0xdf, 0xb0, 0xaa, 0x36,    0x02, 0xe1, 0xff, 0xdf, 0x50, 0x55, 0x35, 0x02, 0xe1, 0xff, 0xdf, 0xb0,    0xaa, 0x36, 0x02, 0xe1, 0xff, 0xdf, 0x50, 0x55, 0x35, 0x02, 0xe1, 0xff,    0xdf, 0xb0, 0xaa, 0x36, 0x02, 0xe1, 0xff, 0xdf, 0x50, 0x55, 0x35, 0x02,    0xe1, 0xff, 0xdf, 0xb0, 0xaa, 0x36, 0x02, 0xe1, 0xff, 0xdf, 0x50, 0x55,    0x35, 0x02, 0xe1, 0xff, 0xdf, 0xb0, 0xaa, 0x36, 0x02, 0xe1, 0xff, 0xdf,    0x50, 0x55, 0x35, 0x02, 0xe1, 0xff, 0xdf, 0xb0, 0xaa, 0x36, 0x02, 0xe1,    0xff, 0xdf, 0x50, 0x55, 0x35, 0x02, 0xe1, 0xff, 0xdf, 0xf0, 0xff, 0x37,    0x02, 0x01, 0x00, 0x80, 0x00, 0x00, 0x20, 0x02, 0xf1, 0xff, 0x3f, 0xf8,    0xff, 0x0f, 0x02, 0xf9, 0xff, 0x7f, 0xfc, 0xff, 0x1f, 0x02, 0x01, 0x00,    0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,    0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00,    0x00, 0x02, 0x01, 0x00, 0x80, 0x00, 0x00, 0x20, 0x02, 0x01, 0x00, 0xc0,    0x00, 0x00, 0x30, 0x02, 0xe1, 0xff, 0xdf, 0xf0, 0xff, 0x37, 0x02, 0x61,    0x55, 0xd5, 0xf0, 0xff, 0x37, 0x02, 0xa1, 0xaa, 0xda, 0xf0, 0xff, 0x37,    0x02, 0x61, 0x55, 0xd5, 0xf0, 0xff, 0x37, 0x02, 0xa1, 0xaa, 0xda, 0xf0,    0xff, 0x37, 0x02, 0x61, 0x55, 0xd5, 0xf0, 0xff, 0x37, 0x02, 0xa1, 0xaa,    0xda, 0xf0, 0xff, 0x37, 0x02, 0x61, 0x55, 0xd5, 0xf0, 0xff, 0x37, 0x02,    0xa1, 0xaa, 0xda, 0xf0, 0xff, 0x37, 0x02, 0x61, 0x55, 0xd5, 0xf0, 0xff,    0x37, 0x02, 0xa1, 0xaa, 0xda, 0xf0, 0xff, 0x37, 0x02, 0x61, 0x55, 0xd5,    0xf0, 0xff, 0x37, 0x02, 0xa1, 0xaa, 0xda, 0xf0, 0xff, 0x37, 0x02, 0x61,    0x55, 0xd5, 0xf0, 0xff, 0x37, 0x02, 0xe1, 0xff, 0xdf, 0xf0, 0xff, 0x37,    0x02, 0x01, 0x00, 0x80, 0x00, 0x00, 0x20, 0x02, 0xf1, 0xff, 0x3f, 0xf8,    0xff, 0x0f, 0x02, 0xf9, 0xff, 0x7f, 0xfc, 0xff, 0x1f, 0x02, 0x01, 0x00,    0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,    0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff,    0xff, 0x03};#ifdef __EMX__ /* dos-like */#define cPATHELEMENTSEP ';'#else  /* un*x-like */#define cPATHELEMENTSEP ':'#endif/* * Find the specified icon file somewhere along the given path. * * There is a possible race condition here:  We check the file and later * do something with it.  By then, the file might not be accessible. * Oh well. */static char *find_icon_file(const char *icon, const char *pathlist, int type){    char *path;    char *dir_end;    int l1, l2;    if (icon != NULL)	l1 = strlen(icon);    else	l1 = 0;    if (pathlist != NULL)	l2 = strlen(pathlist);    else	l2 = 0;    path = XtMalloc(l1 + l2 + 10);    *path = '\0';    if (*icon == '/')    {	/* No search if icon begins with a slash */	strcpy(path, icon);	return path;    }    if ((pathlist == NULL) || (*pathlist == '\0'))    {	/* No search if pathlist is empty */	strcpy(path, icon);	return path;    }    /* Search each element of the pathlist for the icon file */    while ((pathlist) && (*pathlist))    {	dir_end = strchr(pathlist, cPATHELEMENTSEP);	if (dir_end != NULL)	{	    strncpy(path, pathlist, dir_end - pathlist);	    path[dir_end - pathlist] = 0;	}	else	    strcpy(path, pathlist);	strcat(path, "/");	strcat(path, icon);	if (access(path, type) == 0)	    return path;	strcat(path, ".gz");	if (access(path, type) == 0)	    return path;	/* Point to next element of the path */	if (dir_end == NULL)	    pathlist = NULL;	else	    pathlist = dir_end + 1;    }    /* Hmm, couldn't find the file.  Return NULL */    XtFree(path);    return NULL;}/* * grab needed buttons for the icon window */static voidgrab_icon_buttons(ScreenInfo *scr, MwmWindow *tmp_win, Window w){    MouseButton *MouseEntry;    MouseEntry = scr->buttons;    while (MouseEntry != (MouseButton *)0)    {	if ((MouseEntry->func != (int)0) && (MouseEntry->context & C_ICON))	{	    if (MouseEntry->button > 0)		XGrabButton(dpy, MouseEntry->button, MouseEntry->modifier, w,			    True, ButtonPressMask | ButtonReleaseMask,			    GrabModeAsync, GrabModeAsync, None,			    scr->cursors[DEFAULT_CURS]);	    else	    {		XGrabButton(dpy, 1, MouseEntry->modifier, w,			    True, ButtonPressMask | ButtonReleaseMask,			    GrabModeAsync, GrabModeAsync, None,			    scr->cursors[DEFAULT_CURS]);		XGrabButton(dpy, 2, MouseEntry->modifier, w,			    True, ButtonPressMask | ButtonReleaseMask,			    GrabModeAsync, GrabModeAsync, None,			    scr->cursors[DEFAULT_CURS]);		XGrabButton(dpy, 3, MouseEntry->modifier, w,			    True, ButtonPressMask | ButtonReleaseMask,			    GrabModeAsync, GrabModeAsync, None,			    scr->cursors[DEFAULT_CURS]);	    }	}	MouseEntry = MouseEntry->next;    }}/* * grab needed keys for the icon window */static voidgrab_icon_keys(ScreenInfo *scr, MwmWindow *tmp_win, Window w){    FuncKey *tmp;    for (tmp = scr->keys; tmp != NULL; tmp = tmp->next)    {	if (tmp->cont & C_ICON)	    XGrabKey(dpy, tmp->keycode, tmp->mods, w, True,		     GrabModeAsync, GrabModeAsync);    }}/* * Looks for a monochrome icon bitmap file */static voidget_bitmap_file(ScreenInfo *scr, MwmWindow *tmp_win){    char *path = NULL;    int HotX, HotY;    path = find_icon_file(tmp_win->icon_image, scr->IconPath, R_OK);    if (path == NULL)	return;    if (XReadBitmapFile(dpy, scr->root_win, path,			(unsigned int *)&tmp_win->icon_p_width,			(unsigned int *)&tmp_win->icon_p_height,			&tmp_win->icon_pixmap,			&HotX, &HotY) != BitmapSuccess)    {	tmp_win->icon_p_width = 0;	tmp_win->icon_p_height = 0;    }    XtFree(path);}/* * Looks for a color XPM icon file */static voidget_xpm_file(ScreenInfo *scr, MwmWindow *tmp_win){    XWindowAttributes root_attr;#if XmVERSION >= 2    XpmAttributes xpm_attributes;#else    _LtXpmAttributes xpm_attributes;#endif    XImage *im, *imshape;    GC gc;    char *path = NULL;    path = find_icon_file(tmp_win->icon_image, scr->PixmapPath, R_OK);    if (path == NULL)	return;    XGetWindowAttributes(dpy, scr->root_win, &root_attr);    xpm_attributes.colormap = root_attr.colormap;    xpm_attributes.closeness = 40000;	/* Allow for "similar" colors */#if XmVERSION >= 2    xpm_attributes.valuemask = XpmSize | XpmReturnPixels | XpmColormap |	XpmCloseness;#else    xpm_attributes.valuemask = _LtXpmSize | _LtXpmReturnPixels | _LtXpmColormap |	_LtXpmCloseness;#endif#ifdef NONSTANDARD_CONVERTERS#if XmVERSION >= 2    if (XpmReadFileToImage(dpy, path, &im, &imshape, &xpm_attributes) == XpmSuccess)#else    if (_LtXpmReadFileToImage(dpy, path, &im, &imshape, &xpm_attributes) == _LtXpmSuccess)#endif    {	tmp_win->icon_pixmap = XCreatePixmap(dpy, scr->root_win,					     im->width, im->height,					     scr->d_depth);	if (imshape)	    tmp_win->icon_mask_pixmap = XCreatePixmap(dpy, scr->root_win,						  imshape->width,						  imshape->height,						  1);	gc = XCreateGC(dpy, tmp_win->icon_pixmap, 0, NULL);	XPutImage(dpy, tmp_win->icon_pixmap, gc, im, 0, 0, 0, 0,		  im->width, im->height);	XFreeGC(dpy, gc);	gc = XCreateGC(dpy, tmp_win->icon_mask_pixmap, 0, NULL);	if (imshape)	    XPutImage(dpy, tmp_win->icon_mask_pixmap, gc, imshape, 0, 0, 0, 0,		  imshape->width, imshape->height);	XFreeGC(dpy, gc);	if (tmp_win->icon_mask_pixmap)	    tmp_win->flags |= SHAPED_ICON;	tmp_win->icon_p_width = xpm_attributes.width;	tmp_win->icon_p_height = xpm_attributes.height;	tmp_win->flags |= XPM_FLAG;	tmp_win->flags |= PIXMAP_OURS;	tmp_win->icon_depth = scr->d_depth;    }#endif    XtFree(path);}/* * Looks for an application supplied icon window */static voidget_icon_window(ScreenInfo *scr, MwmWindow *tmp_win){    /* We are guaranteed that wmhints is non-null when calling this     * routine */    if (XGetGeometry(dpy, tmp_win->wmhints->icon_window, &JunkRoot,		     &JunkX, &JunkY, (unsigned int *)&tmp_win->icon_p_width,		     (unsigned int *)&tmp_win->icon_p_height,		     &JunkBW, &JunkDepth) == 0)    {	fprintf(stderr, "Help! Bad Icon Window!\n");    }    tmp_win->icon_p_width += JunkBW << 1;    tmp_win->icon_p_height += JunkBW << 1;    /*     * Now make the new window the icon window for this window,     * and set it up to work as such (select for key presses     * and button presses/releases, set up the contexts for it,     * and define the cursor for it).     */    tmp_win->icon_pixmap_w = tmp_win->wmhints->icon_window;    if (tmp_win->wmhints->flags & IconMaskHint)    {	tmp_win->flags |= SHAPED_ICON;	tmp_win->icon_mask_pixmap = tmp_win->wmhints->icon_mask;    }    tmp_win->flags &= ~ICON_OURS;}/* * Looks for an application supplied bitmap or pixmap */static voidget_icon_bitmap(MwmWindow *tmp_win){    /* We are guaranteed that wmhints is non-null when calling this     * routine */    XGetGeometry(dpy, tmp_win->wmhints->icon_pixmap, &JunkRoot, &JunkX, &JunkY,		 (unsigned int *)&tmp_win->icon_p_width,		 (unsigned int *)&tmp_win->icon_p_height, &JunkBW, &JunkDepth);    tmp_win->icon_pixmap = tmp_win->wmhints->icon_pixmap;    tmp_win->icon_depth = JunkDepth;    if (tmp_win->wmhints->flags & IconMaskHint)    {	tmp_win->flags |= SHAPED_ICON;	tmp_win->icon_mask_pixmap = tmp_win->wmhints->icon_mask;    }}#if 0/* * draw icon border windows */static voiddraw_icon_border(MwmWindow *t, Window win, int x, int y, int w, int h,		 GC ReliefGC, GC ShadowGC){    XSegment seg[4];    int i;    /* top */    if (win == t->icon_borders[0])    {	i = 0;	seg[i].x1 = x;	seg[i].y1 = y;	seg[i].x2 = w + x - 1;	seg[i++].y2 = y;	seg[i].x1 = x;	seg[i].y1 = y;	seg[i].x2 = x;	seg[i++].y2 = h + y - 1;	XDrawSegments(dpy, win, ReliefGC, seg, i);	i = 0;	seg[i].x1 = x + t->icon_border_width;	seg[i].y1 = y + h - 1;	seg[i].x2 = w + x - 1 - t->icon_border_width;	seg[i++].y2 = y + h - 1;	seg[i].x1 = x + w - 1;	seg[i].y1 = y;	seg[i].x2 = x + w - 1;	seg[i++].y2 = y + h - 1;	XDrawSegments(dpy, win, ShadowGC, seg, i);    }    /* right */    else if (win == t->icon_borders[1])    {	i = 0;	seg[i].x1 = x;	seg[i].y1 = y;	seg[i].x2 = w + x - 1;	seg[i++].y2 = y;	seg[i].x1 = x;	seg[i].y1 = y + t->icon_border_width - 1;	seg[i].x2 = x;	seg[i++].y2 = h + y - 1 - t->icon_border_width;	XDrawSegments(dpy, win, ReliefGC, seg, i);	i = 0;	seg[i].x1 = x;	seg[i].y1 = y + h - 1;	seg[i].x2 = w + x - 1;	seg[i++].y2 = y + h - 1;	seg[i].x1 = x + w - 1;	seg[i].y1 = y;	seg[i].x2 = x + w - 1;	seg[i++].y2 = y + h - 1;	XDrawSegments(dpy, win, ShadowGC, seg, i);    }    /* bottom */    else if (win == t->icon_borders[2])    {	i = 0;	seg[i].x1 = x + t->icon_border_width;	seg[i].y1 = y;	seg[i].x2 = w + x - t->icon_border_width;	seg[i++].y2 = y;	seg[i].x1 = x;	seg[i].y1 = y;	seg[i].x2 = x;	seg[i++].y2 = h + y - 1;	XDrawSegments(dpy, win, ReliefGC, seg, i);	i = 0;	seg[i].x1 = x;	seg[i].y1 = y + h - 1;	seg[i].x2 = w + x - 1;	seg[i++].y2 = y + h - 1;	seg[i].x1 = x + w - 1;	seg[i].y1 = y;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -