|
|
1.1 root 1: /* $Header: Icons.c,v 1.4 87/09/09 12:00:29 swick Exp $ */
2: #include <X11/copyright.h>
3:
4: /*
5: * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
6: *
7: * All Rights Reserved
8: *
9: * Permission to use, copy, modify, and distribute this software and its
10: * documentation for any purpose and without fee is hereby granted,
11: * provided that the above copyright notice appear in all copies and that
12: * both that copyright notice and this permission notice appear in
13: * supporting documentation, and that the name of Digital Equipment
14: * Corporation not be used in advertising or publicity pertaining to
15: * distribution of the software without specific, written prior permission.
16: *
17: *
18: * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
19: * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
20: * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
21: * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22: * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
23: * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24: * SOFTWARE.
25: */
26:
27:
28:
29: /*
30: * MODIFICATION HISTORY
31: *
32: * 000 -- L. Guarino Reid, DEC Ultrix Engineering Group
33: */
34:
35: #ifndef lint
36: static char *sccsid = "%W% %G%";
37: #endif
38:
39: #include "uwm.h"
40: #include <X11/Xutil.h>
41: #include <X11/Xatom.h>
42:
43: typedef struct _windowList {
44: struct _windowList *next;
45: Window window;
46: Window icon;
47: Bool own;
48: Pixmap pixmap;
49: } WindowListRec, *WindowList;
50:
51: WindowList Icons = NULL;
52:
53:
54: /* the client should pass us a bitmap (single-plane pixmap with background=0
55: * and foreground = 1). It is our responsibility to convert it to a pixmap
56: * of the appropriate depth for a window tile and also color it with the
57: * appropriate background and foreground pixels.
58: *
59: * we'll use the (global) IconGC for the fore/background pixels.
60: */
61:
62: static Pixmap MakePixmapFromBitmap( bitmap, width_return, height_return )
63: Pixmap bitmap;
64: unsigned int *width_return, *height_return;
65: {
66: Pixmap tile;
67: Window junkW;
68: int junk, width, height;
69:
70: if (!XGetGeometry( dpy, bitmap, &junkW, &junk, &junk,
71: &width, &height, &junk, &junk )) {
72: Warning( "client passed invalid pixmap for icon." );
73: return( NULL );
74: }
75:
76: tile = XCreatePixmap( dpy, RootWindow(dpy, scr), width, height,
77: DefaultDepth(dpy, scr) );
78:
79: /* use the IconGC's foreground & background, so we don't have to
80: * create another (and add yet another user configuration option.
81: * someday this may need to be split out.
82: */
83: XCopyPlane( dpy, bitmap, tile, IconGC, 0, 0, width, height, 0, 0, 1 );
84:
85: if (*width_return) *width_return = width;
86: if (*height_return) *height_return = height;
87:
88: return( tile );
89: }
90:
91:
92: char *
93: GetIconName(window)
94: Window window;
95: {
96: char *name;
97:
98: if (XGetIconName( dpy, window, &name )) return( name );
99:
100: if (XFetchName( dpy, window, &name )) return( name );
101:
102: return( NULL );
103: }
104:
105: Bool IsIcon(icon, x, y, mousePositioned, assoc)
106: Window icon;
107: Window *assoc;
108: {
109: WindowList ptr;
110: Window MakeIcon();
111:
112: for (ptr = Icons; ptr; ptr = ptr->next) {
113: if (ptr->icon == icon) {
114: if (assoc) *assoc = ptr->window;
115: return(TRUE);
116: }
117: if (ptr->window == icon) {
118: if (assoc) *assoc = ptr->icon;
119: return(FALSE);
120: }
121: }
122: if (assoc) *assoc = MakeIcon(icon, x, y, mousePositioned);
123: return(FALSE);
124: }
125:
126:
127: RemoveIcon(window)
128: Window window;
129: {
130: WindowList ptr, ptr1;
131:
132: for (ptr = Icons; ptr; ptr = ptr->next)
133: if (ptr->window == window) {
134: if (ptr->own) {
135: XDestroyWindow(dpy, ptr->icon);
136: if (ptr->pixmap != IBackground) XFreePixmap(dpy, ptr->pixmap);
137: }
138: break;
139: }
140: if (ptr) {
141: if (ptr==Icons) Icons = Icons->next;
142: else
143: for (ptr1 = Icons; ptr1->next; ptr1 = ptr1->next)
144: if (ptr1->next == ptr) {
145: ptr1->next = ptr->next;
146: break;
147: };
148: free(ptr);
149: }
150: }
151:
152: GetDefaultSize(window, icon_w, icon_h)
153: Window window;
154: int *icon_w, *icon_h;
155: {
156: char *name; /* Event window name. */
157:
158: /*
159: * Determine the size of the icon window.
160: */
161: name = GetIconName(window);
162: *icon_h = IFontInfo->ascent + IFontInfo->descent;
163: if (name) {
164: *icon_w = XTextWidth(IFontInfo, name, strlen(name));
165: if (*icon_w == 0)
166: *icon_w = *icon_h;
167: } else
168: *icon_w = *icon_h;
169: }
170:
171: Window MakeIcon(window, x, y, mousePositioned)
172: Window window; /* associated window. */
173: int x, y; /* Event mouse position. */
174: Bool mousePositioned;
175: {
176: Window icon; /* icon window. */
177: int icon_x, icon_y; /* Icon U. L. X and Y coordinates. */
178: int icon_w, icon_h; /* Icon width and height. */
179: int icon_bdr; /* Icon border width. */
180: int mask; /* Icon event mask */
181: int depth; /* for XGetGeometry */
182: XSetWindowAttributes iconValues; /* for icon window creation */
183: XWMHints *wmhints; /* see if icon position provided */
184: XWMHints *XGetWMHints();
185: Window AddIcon();
186:
187: iconValues.background_pixmap = IBackground;
188: mask = (KeyPressMask|ExposureMask|StructureNotifyMask);
189: /*
190: * Process window manager hints.
191: */
192: if (wmhints = XGetWMHints(dpy, window)) {
193: if (wmhints->flags&IconWindowHint)
194: return(
195: AddIcon(window, wmhints->icon_window, FALSE,
196: (StructureNotifyMask), (Pixmap)NULL));
197: else if (wmhints->flags&IconPixmapHint) {
198: iconValues.background_pixmap =
199: MakePixmapFromBitmap( wmhints->icon_pixmap, &icon_w, &icon_h );
200: if (iconValues.background_pixmap)
201: mask = (StructureNotifyMask);
202: else {
203: iconValues.background_pixmap = IBackground;
204: wmhints->flags &= ~IconPixmapHint;
205: GetDefaultSize(window, &icon_w, &icon_h);
206: }
207: }
208: else GetDefaultSize(window, &icon_w, &icon_h);
209: }
210: else GetDefaultSize(window, &icon_w, &icon_h);
211:
212: /*
213: * Fix up sizes by padding.
214: */
215: if (!wmhints || !(wmhints->flags&(IconPixmapHint|IconWindowHint))) {
216: icon_w += (HIconPad << 1);
217: icon_h += (VIconPad << 1);
218: }
219:
220: /*
221: * Set the icon border attributes.
222: */
223: if (!wmhints || !(wmhints->flags&IconWindowHint)) {
224: icon_bdr = IBorderWidth;
225: iconValues.border_pixel = IBorder;
226: }
227:
228: if (wmhints && (wmhints->flags&IconPositionHint)) {
229: icon_x = wmhints->icon_x;
230: icon_y = wmhints->icon_y;
231: } else {
232: if (mousePositioned) {
233: /*
234: * Determine the coordinates of the icon window;
235: * normalize so that we don't lose the icon off the
236: * edge of the screen.
237: */
238: icon_x = x - (icon_w >> 1) + 1;
239: if (icon_x < 0) icon_x = 0;
240: icon_y = y - (icon_h >> 1) + 1;
241: if (icon_y < 0) icon_y = 0;
242: if ((icon_x - 1 + icon_w + (icon_bdr << 1)) > ScreenWidth) {
243: icon_x = ScreenWidth - icon_w - (icon_bdr << 1) + 1;
244: }
245: if ((icon_y - 1 + icon_h + (icon_bdr << 1)) > ScreenHeight) {
246: icon_y = ScreenHeight - icon_h - (icon_bdr << 1) + 1;
247: }
248: }
249: else {
250: icon_x = x + (icon_w >> 1);
251: icon_y = y + (icon_y >> 1);
252: }
253:
254: }
255:
256: /*
257: * Create the icon window.
258: */
259: return(AddIcon(window,
260: XCreateWindow(
261: dpy, RootWindow(dpy, scr),
262: icon_x, icon_y,
263: icon_w, icon_h,
264: icon_bdr, 0, CopyFromParent, CopyFromParent,
265: CWBorderPixel+CWBackPixmap, &iconValues),
266: TRUE, mask, iconValues.background_pixmap));
267:
268: }
269:
270: Window AddIcon(window, icon, own, mask, background)
271: Window window, icon;
272: Bool own;
273: int mask;
274: Pixmap background;
275: {
276: WindowList ptr;
277:
278: if (icon == NULL) return(NULL);
279: /*
280: * Use the text cursor whenever the mouse is in the icon window.
281: */
282: XDefineCursor(dpy, icon, TextCursor);
283:
284: /*
285: * Select "key pressed", "window exposure" and "unmap window"
286: * events for the icon window.
287: */
288: XSelectInput(dpy, icon, mask);
289:
290: /*
291: * Set the event window's icon window to be the new icon window.
292: */
293: ptr = (WindowList) malloc(sizeof(WindowListRec));
294: ptr->window = window;
295: ptr->icon = icon;
296: ptr->own = own;
297: ptr->pixmap = background;
298: ptr->next = Icons;
299: Icons = ptr;
300:
301: return(icon);
302: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.