1 /* XDigger Copyright (C) 1988-99 Alexander Lang.
2
3 XDigger is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 XDigger is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
16
17 #include <stdio.h>
18
19 #include <X11/Xlib.h>
20 #include <X11/Xutil.h>
21
22 #include "defines.h"
23 #include "drawpixmaps.h"
24 #include "runlevels.h"
25 #include "xdigger.h"
26
27 Window iconwindow;
28 Bool in_handle_icon = False;
29 Bool icon_indiggeridlesequence = False;
30 int icon_fdiggersequenceidx, icon_fdiggeridleidx;
31 int last_icon_pixmap = PXID_ICON_DIGGER;
32
MakeIconWindow()33 void MakeIconWindow()
34 {
35 XWMHints wmhints;
36 /*XIconSize **size_list_return;
37 int count_return;*/
38
39 /*if (XGetIconSizes(display, mainwindow, size_list_return, &count_return))
40 {
41 fprintf(stderr, "count: %d", count_return);
42 fflush(stderr);
43 }*/
44
45 iconwindow = XCreateSimpleWindow(display, rootwindow,
46 0, 0, 16*iconmag, 16*iconmag, 1,
47 WhitePixel(display, screen),
48 BlackPixel(display, screen));
49 XSelectInput(display, iconwindow, ExposureMask);
50 wmhints.icon_window = iconwindow;
51 wmhints.flags = IconWindowHint;
52 XSetWMHints(display, mainwindow, &wmhints);
53 }
54
id2iconpixmap_id(int id,int flags)55 unsigned char id2iconpixmap_id(int id, int flags)
56 {
57 switch (id)
58 {
59 case ID_DIGGER :
60 {
61 switch (flags & F_DIGGER_MOVEMASK)
62 {
63 case F_DIGGER_DOWN0: return(PXID_ICON_DIGGER);
64 case F_DIGGER_FOOT: return(PXID_ICON_DIGGER_FOOT);
65 case F_DIGGER_EYE1: return(PXID_ICON_DIGGER_EYE1);
66 case F_DIGGER_EYE2: return(PXID_ICON_DIGGER_EYE2);
67 }
68 }
69 }
70 return(PXID_ICON_NOTHING);
71 } /* unsigned char id2pixmap_id(int id, int flags) */
72
Handle_Icon()73 void Handle_Icon()
74 {
75 FieldEntry icon_field;
76 /*XWMHints wmhints;*/
77
78 if (!in_xdigger_idle)
79 return;
80
81 in_handle_icon = True;
82 if ((!icon_indiggeridlesequence) && (MyRand(10) == 1))
83 {
84 icon_fdiggeridleidx = MyRand(2);
85 icon_fdiggersequenceidx = 0;
86 icon_indiggeridlesequence = True;
87 }
88 if (icon_indiggeridlesequence)
89 {
90 if (++icon_fdiggersequenceidx >
91 fdiggeridlesequence[icon_fdiggeridleidx][0])
92 icon_indiggeridlesequence = False;
93 }
94
95 icon_field.id = ID_DIGGER;
96
97 if (icon_indiggeridlesequence)
98 icon_field.flags =
99 (icon_field.flags & !F_DIGGER_MOVEMASK) |
100 fdiggeridlesequence[icon_fdiggeridleidx][icon_fdiggersequenceidx];
101 else
102 icon_field.flags =
103 (icon_field.flags & !F_DIGGER_MOVEMASK) | F_DIGGER_DOWN0;
104
105 icon_field.pixmap_id =
106 id2iconpixmap_id(icon_field.id, icon_field.flags);
107
108 if (icon_field.pixmap_id != last_icon_pixmap)
109 {
110 /*wmhints.icon_pixmap = pixmaps[icon_field.pixmap_id];
111 wmhints.flags = IconPixmapHint;
112 XSetWMHints(display, mainwindow, &wmhints);*/
113 /*CopyOnePixmap_Window(iconwindow, icon_field.pixmap_id, 0, 0);*/
114 XCopyArea(display, iconpixmaps[icon_field.pixmap_id], iconwindow, gc,
115 0, 0, 16*iconmag, 16*iconmag, 0, 0);
116 XFlush(display);
117 last_icon_pixmap = icon_field.pixmap_id;
118 }
119 in_handle_icon = False;
120 } /* void Handle_Icon() */
121
Handle_IconWindow_Event(XEvent * event)122 void Handle_IconWindow_Event(XEvent *event)
123 {
124 switch(event->type)
125 {
126 case Expose:
127 if (event->xexpose.count == 0)
128 {
129 XCopyArea(display, iconpixmaps[last_icon_pixmap], iconwindow, gc,
130 0, 0, 16*iconmag, 16*iconmag, 0, 0);
131 }
132 break;
133 }
134 }
135