5 * Copyright (C) 2001 pasp
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <sys/types.h>
36 #include <X11/extensions/shape.h>
43 void wmtunlo_read_prefs(void);
44 void wmtunlo_write_prefs(void);
46 void ButtonPressEvent(XButtonEvent
*);
47 int GotFirstClick1
, GotDoubleClick1
;
48 int GotFirstClick2
, GotDoubleClick2
;
49 int GotFirstClick3
, GotDoubleClick3
;
52 char ClickCommand1
[MAX_PATH
];
53 char ClickCommand2
[MAX_PATH
];
54 char ClickCommand3
[MAX_PATH
];
56 int tex_block_w
, tex_block_h
, shade_switch
, persp_switch
;
57 int t_color_1
, t_color_2
;
58 float t_persp
, t_shade_level
;
59 float t_mov_counter
, t_rot_counter
;
60 float t_mov_step
, t_rot_step
;
61 float t_col_add_R
, t_col_add_G
, t_col_add_B
;
62 float t_col_mul_R
, t_col_mul_G
, t_col_mul_B
;
64 int main(int argc
, char *argv
[])
83 XColor xColor
, xColors
[256];
85 int i
, j
, shade
, k
, l
, p
, q
, result
, col
;
87 unsigned char *Image
, *Texture
, *Tunnel_map
;
90 /* Read preferences */
94 openXwindow(argc
, argv
, dock_master
, dock_mask_bits
, dock_mask_width
, dock_mask_height
);
96 /* Get Display parameters */
97 Info
.display
= display
;
98 Info
.screen
= DefaultScreen(display
);
99 Info
.visual
= DefaultVisual(display
, Info
.screen
);
100 Info
.depth
= DefaultDepth(display
, Info
.screen
);
101 Info
.cmap
= DefaultColormap(display
, 0);
103 /* Initialize Color Table */
105 for (i
=0; i
<256; ++i
) {
106 col
= t_col_mul_R
* (float)i
+ t_col_add_R
;
108 if(col
>255) col
= 255;
111 col
= t_col_mul_G
* (float)i
+ t_col_add_G
;
113 if(col
>255) col
= 255;
116 col
= t_col_mul_B
* (float)i
+ t_col_add_B
;
118 if(col
>255) col
= 255;
122 /* Create an XImage with null data. Then allocate space for data. */
123 Info
.format
= ZPixmap
;
124 if (Info
.depth
== 8){
128 /* Set a private colormap */
129 Info
.cmap
= XCreateColormap(Info
.display
, RootWindow(Info
.display
, Info
.screen
), Info
.visual
, AllocAll
);
130 for (i
=0; i
<256; ++i
){
132 xColors
[i
].pixel
= i
;
133 xColors
[i
].red
= (unsigned short)Info
.R
[i
] << 8;
134 xColors
[i
].green
= (unsigned short)Info
.G
[i
] << 8;
135 xColors
[i
].blue
= (unsigned short)Info
.B
[i
] << 8;
136 xColors
[i
].flags
= DoRed
| DoGreen
| DoBlue
;
138 XStoreColors(Info
.display
, Info
.cmap
, xColors
, 256);
139 XSetWindowColormap(Info
.display
, win
, Info
.cmap
);
141 } else if (Info
.depth
> 8) {
143 /* Allocate Colors */
144 for (i
=0; i
<256; ++i
){
145 xColor
.red
= (unsigned short)Info
.R
[i
] << 8;
146 xColor
.green
= (unsigned short)Info
.G
[i
] << 8;
147 xColor
.blue
= (unsigned short)Info
.B
[i
] << 8;
148 xColor
.flags
= DoRed
| DoGreen
| DoBlue
;
149 XAllocColor(Info
.display
, Info
.cmap
, &xColor
);
150 Info
.Color
[i
] = xColor
.pixel
;
152 Info
.bitmap_pad
= 32;
155 fprintf(stderr
, "Need at least 8-bit display!\n");
159 xim
= XCreateImage(Info
.display
, Info
.visual
, Info
.depth
, Info
.format
, 0, (char *)0, 54, 54, Info
.bitmap_pad
, 0);
160 xim
->data
= (char *)malloc(xim
->bytes_per_line
* 54 );
162 /* Allocate memory for image data */
163 Image
= (unsigned char *)malloc(sizeof(unsigned char)*54*54);
165 /* Generate tunnel map */
166 Tunnel_map
= (unsigned char *)malloc(sizeof(unsigned char)*54*54*4);
168 for (k
=0, yz
=-54/2; yz
<54/2; yz
++)
169 for (xz
=-54/2; xz
<54/2; xz
++) {
171 py
= sqrt(xz
*xz
+ yz
*yz
);
172 shade
= py
* t_shade_level
;
173 if(shade
>255) shade
=255;
174 if(persp_switch
) py
= t_persp
/py
;
175 px
= atan2(yz
,xz
) * 128.0 / M_PI
;
176 result
= (int)py
* 256 + (int)px
;
178 Tunnel_map
[k
++]= result
&0xff;
179 Tunnel_map
[k
++]= result
>>8;
180 Tunnel_map
[k
++]= shade
&0xff;
183 /* Generate texture */
184 Texture
= (unsigned char *)malloc(sizeof(unsigned char)*256*256);
186 for(i
=0,q
=1;i
<256;i
+=tex_block_h
, q
*=-1)
187 for(j
=0,p
=q
;j
<256;j
+=tex_block_w
, p
*=-1)
188 for(l
=0;l
<tex_block_h
;l
++)
189 for(k
=0;k
<tex_block_w
;k
++)
190 if((j
+k
< 256) && (i
+l
< 256)) {
192 Texture
[(i
+l
)*256+j
+k
] = t_color_1
;
194 Texture
[(i
+l
)*256+j
+k
] = t_color_2
;
204 /* Process any pending X events. */
206 while(XPending(display
)){
207 XNextEvent(display
, &event
);
213 XSetInputFocus(display
, iconwin
, RevertToNone
, CurrentTime
);
214 if (Info
.depth
== 8) XInstallColormap(display
, Info
.cmap
);
217 XSetInputFocus(display
, None
, RevertToNone
, CurrentTime
);
218 if (Info
.depth
== 8) XUninstallColormap(display
, Info
.cmap
);
221 ButtonPressEvent(&event
.xbutton
);
234 *(Image
+ 54*i
+ j
) = (Tunnel_map
[(54*i
+j
)*3 + 2] * Texture
[ \
235 ((Tunnel_map
[(54*i
+j
)*3 + 1] + (int)t_mov_counter
) & 0xff)*256 + \
236 Tunnel_map
[(54*i
+j
)*3 + 0] - (int)t_rot_counter
]) >> 8;
238 *(Image
+ 54*i
+ j
) = Texture
[ \
239 ((Tunnel_map
[(54*i
+j
)*3 + 1] + (int)t_mov_counter
) & 0xff)*256 + \
240 Tunnel_map
[(54*i
+j
)*3 + 0] - (int)t_rot_counter
];
245 t_mov_counter
+= t_mov_step
;
246 if(t_mov_counter
> 256.0) t_mov_counter
= 0.0;
247 if(t_mov_counter
< 0.0) t_mov_counter
= 256.0;
248 t_rot_counter
+= t_rot_step
;
249 if(t_rot_counter
> 256.0) t_rot_counter
= 0.0;
250 if(t_rot_counter
< 0.0) t_rot_counter
= 256.0;
252 /* Paste up image. */
253 for ( i
=0; i
<54; ++i
)
254 for ( j
=0; j
<54; ++j
) {
255 XPutPixel(xim
, i
, j
, Info
.Color
[*(Image
+ j
*54 + i
)]);
259 XPutImage(display
, wmgen
.pixmap
, NormalGC
, xim
, 0, 0, 5, 5, 54, 54);
261 /* Make changes visible */
264 /* Wait for next update */
277 * This routine handles button presses.
280 * Mouse Button 1: Execute the command defined in the -e command-line option.
281 * Mouse Button 2: No action assigned.
282 * Mouse Button 3: No action assigned.
286 void ButtonPressEvent(XButtonEvent
*xev
){
289 if ((xev
->button
== Button1
) && (xev
->type
== ButtonPress
)){
290 if (GotFirstClick1
) GotDoubleClick1
= 1;
291 else GotFirstClick1
= 1;
292 } else if ((xev
->button
== Button2
) && (xev
->type
== ButtonPress
)){
293 if (GotFirstClick2
) GotDoubleClick2
= 1;
294 else GotFirstClick2
= 1;
295 } else if ((xev
->button
== Button3
) && (xev
->type
== ButtonPress
)){
296 if (GotFirstClick3
) GotDoubleClick3
= 1;
297 else GotFirstClick3
= 1;
301 * We got a double click on Mouse Button1 (i.e. the left one)
303 if (GotDoubleClick1
) {
306 system(ClickCommand1
);
310 * We got a double click on Mouse Button2 (i.e. the left one)
312 if (GotDoubleClick2
) {
315 system(ClickCommand2
);
319 * We got a double click on Mouse Button3 (i.e. the left one)
321 if (GotDoubleClick3
) {
324 system(ClickCommand3
);
331 /*----------------------------------------------------------------------*/
332 /* Write preferences */
334 void wmtunlo_write_prefs(void)
336 if (p_prefs_openfile (p_getfilename_config (".clay", "wmtunlorc"), P_WRITE
)) {
338 p_prefs_put_int("shade_switch", shade_switch
);
339 p_prefs_put_int("persp_switch", persp_switch
);
341 p_prefs_put_float("t_shade_level", t_shade_level
);
342 p_prefs_put_float("t_persp", t_persp
);
343 p_prefs_put_float("t_mov_step", t_mov_step
);
344 p_prefs_put_float("t_rot_step", t_rot_step
);
346 p_prefs_put_int("tex_block_w", tex_block_w
);
347 p_prefs_put_int("tex_block_h", tex_block_h
);
349 p_prefs_put_float("t_col_add_R", t_col_add_R
);
350 p_prefs_put_float("t_col_add_G", t_col_add_G
);
351 p_prefs_put_float("t_col_add_B", t_col_add_B
);
353 p_prefs_put_float("t_col_mul_R", t_col_mul_R
);
354 p_prefs_put_float("t_col_mul_G", t_col_mul_G
);
355 p_prefs_put_float("t_col_mul_B", t_col_mul_B
);
357 p_prefs_put_int("t_color_1", t_color_1
);
358 p_prefs_put_int("t_color_2", t_color_2
);
360 p_prefs_put_string("command1", ClickCommand1
);
361 p_prefs_put_string("command2", ClickCommand2
);
362 p_prefs_put_string("command3", ClickCommand3
);
366 p_prefs_closefile ();
369 /*----------------------------------------------------------------------*/
370 /* Read preferences */
372 void wmtunlo_read_prefs(void)
374 if (p_prefs_openfile (p_getfilename_config(".clay", "wmtunlorc"), P_READ
)) {
376 shade_switch
= p_prefs_get_int("shade_switch");
377 persp_switch
= p_prefs_get_int("persp_switch");
379 t_shade_level
= p_prefs_get_float("t_shade_level");
380 t_persp
= p_prefs_get_float("t_persp");
381 t_mov_step
= p_prefs_get_float("t_mov_step");
382 t_rot_step
= p_prefs_get_float("t_rot_step");
384 tex_block_w
= p_prefs_get_int("tex_block_w");
385 tex_block_h
= p_prefs_get_int("tex_block_h");
387 t_col_add_R
= p_prefs_get_float("t_col_add_R");
388 t_col_add_G
= p_prefs_get_float("t_col_add_G");
389 t_col_add_B
= p_prefs_get_float("t_col_add_B");
391 t_col_mul_R
= p_prefs_get_float("t_col_mul_R");
392 t_col_mul_G
= p_prefs_get_float("t_col_mul_G");
393 t_col_mul_B
= p_prefs_get_float("t_col_mul_B");
395 t_color_1
= p_prefs_get_int("t_color_1") % 255;
396 t_color_2
= p_prefs_get_int("t_color_2") % 255;
398 strcpy(ClickCommand1
, p_prefs_get_string ("command1"));
399 strcpy(ClickCommand2
, p_prefs_get_string ("command2"));
400 strcpy(ClickCommand3
, p_prefs_get_string ("command3"));
402 p_prefs_closefile ();
428 strcpy(ClickCommand1
, "xlock");
429 strcpy(ClickCommand2
, "xlock -mode thornbird");
430 strcpy(ClickCommand3
, "xlock -mode blank");
432 wmtunlo_write_prefs ();
437 /*----------------------------------------------------------------------*/