wmclockmon: update change-log
[dockapps.git] / fookb / images.c
blobf5348d9c53ea731021eeaced4aaabd59b4607c05
1 /*
2 * images.c
4 * (c) 1998-2004 Alexey Vyskubov <alexey@mawhrin.net>
5 */
7 #include <stdio.h> /* puts() */
8 #include <stdlib.h>
9 #include <string.h>
11 /* Xpm fun */
12 #include <X11/xpm.h>
14 //#include "fookb.h"
15 #include "params.h"
16 #include "images.h"
18 /* Let us make lint happy! */
19 #define lputs(x) (void)(puts(x))
21 static int w = 0;
22 static int h = 0;
24 static XImage *stupid_picture[5]; /* Icons for fookb */
26 int get_width() {
27 return w;
30 int get_height() {
31 return h;
34 static int get_one_image(char *name, int index, Display *dpy)
36 int foo;
38 foo = XpmReadFileToImage(dpy, name, &stupid_picture[index],
39 NULL, NULL);
41 if (foo < 0)
42 return foo;
44 if (0 == w) {
45 w = stupid_picture[index]->width;
46 if (0 == w) {
47 lputs("FATAL: Icon1 has zero width!");
48 exit(EXIT_FAILURE);
50 if (w > 64) {
51 lputs("Warning: Icon width is more than 64. Strange things may happen if using Window Maker.");
55 if (0 == h) {
56 h = stupid_picture[index]->height;
57 if (0 == h) {
58 lputs("FATAL: Icon1 had zero height!");
59 exit(EXIT_FAILURE);
61 if (h > 64) {
62 lputs("Warning: Icon height is more than 64. Strange things may happen if using Window Maker.");
66 if (w != stupid_picture[index]->width) {
67 lputs("FATAL: Not all icons are of the same width!");
68 exit(EXIT_FAILURE);
71 if (h != stupid_picture[index]->height) {
72 lputs("FATAL: Not all iconse are of the same height!");
73 exit(EXIT_FAILURE);
75 return (foo);
78 void read_images(Display *dpy)
80 int i;
81 int res;
82 int status = 0;
84 for (i = 0; i < 5; i++) {
86 switch (i) {
87 case 0:
88 res = get_one_image(read_param("Icon1"), 0, dpy);
89 break;
90 case 1:
91 res = get_one_image(read_param("Icon2"), 1, dpy);
92 break;
93 case 2:
94 res = get_one_image(read_param("Icon3"), 2, dpy);
95 break;
96 case 3:
97 res = get_one_image(read_param("Icon4"), 3, dpy);
98 break;
99 default:
100 res = get_one_image(read_param("IconBoom"), 4, dpy);
101 break;
104 switch (res) {
105 case XpmOpenFailed:
106 lputs("Xpm file open failed:");
107 status = 1 << 5;
108 break;
109 case XpmFileInvalid:
110 lputs("Xpm file is invalid:");
111 status = 1 << 6;
112 break;
113 case XpmNoMemory:
114 lputs("No memory for open xpm file:");
115 status = 1 << 7;
116 break;
117 default:
118 break;
121 if (!(status == 0)) {
122 status += 1 << i;
123 switch (i) {
124 case 0:
125 lputs(read_param("Icon1"));
126 break;
127 case 1:
128 lputs(read_param("Icon2"));
129 break;
130 case 2:
131 lputs(read_param("Icon3"));
132 break;
133 case 3:
134 lputs(read_param("Icon4"));
135 break;
136 case 4:
137 lputs(read_param("IconBoom"));
138 break;
139 default:
140 lputs("UNKNOWN ERROR! PLEASE REPORT!!!");
141 exit(-2);
143 exit(status);
149 void update_window(Drawable win, GC gc, unsigned int whattodo, Display *dpy)
151 int err;
153 err = XPutImage(dpy, win, gc, stupid_picture[whattodo],
154 0, 0, 0, 0, w, h);
156 if (0 == err) return;
158 switch (err) {
159 case BadDrawable:
160 lputs("Fatal error, XPutImage returns BadDrawable. "
161 "Please report!");
162 break;
163 case BadGC:
164 lputs("Fatal error, XPutImage returns BadGC. "
165 "Please report!");
166 break;
167 case BadMatch:
168 lputs("Fatal error, XPutImage returns BadMatch. "
169 "Please report!");
170 break;
171 case BadValue:
172 lputs("Fatal error, XPutImage returns BadValue. "
173 "Please report!");
174 break;
175 default:
176 lputs("Fatal error, XPutImage returns unknown error. "
177 "Please report, but probably "
178 "it is a bug in X.");
179 break;