fookb: Add version 3.1 to repository.
[dockapps.git] / fookb / images.c
blob54b4e694f0798f599a1adcc5c3a3cabf9e7a5e93
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 (0 == w) {
42 w = stupid_picture[index]->width;
43 if (0 == w) {
44 lputs("FATAL: Icon1 has zero width!");
45 exit(EXIT_FAILURE);
47 #ifdef WMAKER
48 if (w > 64) {
49 lputs("Warning: Icon width is more than 64. Strange things may happen.");
51 #endif
54 if (0 == h) {
55 h = stupid_picture[index]->height;
56 if (0 == h) {
57 lputs("FATAL: Icon1 had zero height!");
58 exit(EXIT_FAILURE);
60 #ifdef WMAKER
61 if (h > 64) {
62 lputs("Warning: Icon height is more than 64. Strange things may happen.");
64 #endif
67 if (w != stupid_picture[index]->width) {
68 lputs("FATAL: Not all icons are of the same width!");
69 exit(EXIT_FAILURE);
72 if (h != stupid_picture[index]->height) {
73 lputs("FATAL: Not all iconse are of the same height!");
74 exit(EXIT_FAILURE);
76 return (foo);
79 void read_images(Display *dpy)
81 int i;
82 int res;
83 int status = 0;
85 for (i = 0; i < 5; i++) {
87 switch (i) {
88 case 0:
89 res = get_one_image(read_param("Icon1"), 0, dpy);
90 break;
91 case 1:
92 res = get_one_image(read_param("Icon2"), 1, dpy);
93 break;
94 case 2:
95 res = get_one_image(read_param("Icon3"), 2, dpy);
96 break;
97 case 3:
98 res = get_one_image(read_param("Icon4"), 3, dpy);
99 break;
100 default:
101 res = get_one_image(read_param("IconBoom"), 4, dpy);
102 break;
105 switch (res) {
106 case XpmOpenFailed:
107 lputs("Xpm file open failed:");
108 status = 1 << 5;
109 break;
110 case XpmFileInvalid:
111 lputs("Xpm file is invalid:");
112 status = 1 << 6;
113 break;
114 case XpmNoMemory:
115 lputs("No memory for open xpm file:");
116 status = 1 << 7;
117 break;
118 default:
119 break;
122 if (!(status == 0)) {
123 status += 1 << i;
124 switch (i) {
125 case 0:
126 lputs(read_param("Icon1"));
127 break;
128 case 1:
129 lputs(read_param("Icon2"));
130 break;
131 case 2:
132 lputs(read_param("Icon3"));
133 break;
134 case 3:
135 lputs(read_param("Icon4"));
136 break;
137 case 4:
138 lputs(read_param("IconBoom"));
139 break;
140 default:
141 lputs("UNKNOWN ERROR! PLEASE REPORT!!!");
142 exit(-2);
144 exit(status);
150 void update_window(Window win, GC gc, unsigned int whattodo, Display *dpy)
152 int err;
154 err = XPutImage(dpy, win, gc, stupid_picture[whattodo],
155 0, 0, 0, 0, w, h);
157 if (0 == err) return;
159 switch (err) {
160 case BadDrawable:
161 lputs("Fatal error, XPutImage returns BadDrawable. "
162 "Please report!");
163 break;
164 case BadGC:
165 lputs("Fatal error, XPutImage returns BadGC. "
166 "Please report!");
167 break;
168 case BadMatch:
169 lputs("Fatal error, XPutImage returns BadMatch. "
170 "Please report!");
171 break;
172 case BadValue:
173 lputs("Fatal error, XPutImage returns BadValue. "
174 "Please report!");
175 break;
176 default:
177 lputs("Fatal error, XPutImage returns unknown error. "
178 "Please report, but probably "
179 "it is a bug in X.");
180 break;