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