wmusic: Bump to version 2.1.0
[dockapps.git] / wmMatrix / wmMatrix.c
blobe4b387ef8f54a82382e5f56b28b2209f703c4864
1 /*
3 * wmMatrix-0.2 (C) 1999 Mike Henderson (mghenderson@lanl.gov)
5 * - A DockApp version of Jamie Zawinski's xmatrix screensaver hack.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
27 * Changes:
29 * Version 0.2 - released Aug 16, 1999.
32 * ToDo:
33 * Tie speed to cpu load or some such thing. (Idea from Ken Steen.) Still need to work
34 * on how best to accomplish this....
42 * Includes
44 #include <stdio.h>
45 #include <unistd.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <time.h>
49 #include <X11/X.h>
50 #include <X11/xpm.h>
51 #include "xutils.h"
52 #include "wmMatrix_master.xpm"
53 #include "wmMatrix_mask.xbm"
54 #include "matrix.h"
57 * Delay between refreshes (in microseconds)
59 #define DELAY 20000UL /* 0.020000 sec */
60 #define WMMATRIX_VERSION "0.2"
62 void ParseCMDLine(int argc, char *argv[]);
63 void ButtonPressEvent(XButtonEvent *);
64 void print_usage();
65 m_state *init_matrix(Display *, Window);
66 void draw_matrix(m_state *, int);
68 int GotFirstClick1, GotDoubleClick1;
69 int GotFirstClick2, GotDoubleClick2;
70 int GotFirstClick3, GotDoubleClick3;
71 int DblClkDelay;
72 /*int HasExecute;*/
73 /*char* ExecuteCommand = "xmatrixsmall";*/
74 char *progname = "wmMatrix";
75 char *progclass = "WMMatrix";
76 int PixmapSize;
77 char *DoubleClickCmd = NULL;
78 char *RDoubleClickCmd = NULL;
79 char *TimeColor = "#ffff00";
80 char *BackgroundColor = "#181818";
83 * main
85 int main(int argc, char *argv[])
87 XEvent event;
88 m_state *state;
91 * Parse any command line arguments.
93 ParseCMDLine(argc, argv);
94 if (DoubleClickCmd == NULL)
95 DoubleClickCmd = strdup("xscreensaver-demo");
96 if (RDoubleClickCmd == NULL)
97 RDoubleClickCmd = strdup("xscreensaver-command -activate");
98 initXwindow(argc, argv);
99 openXwindow(argc, argv, wmMatrix_master, wmMatrix_mask_bits, wmMatrix_mask_width, wmMatrix_mask_height);
100 state = init_matrix(display, iconwin);
103 * Loop until we die
105 while (1) {
106 draw_matrix(state, 40);
109 * Double Click Delays
110 * Keep track of click events. If Delay too long, set GotFirstClick's to False.
112 /* 25 * 0.02 = .5 sec */
113 if (DblClkDelay > 25) {
114 DblClkDelay = 0;
115 GotFirstClick1 = 0;
116 GotDoubleClick1 = 0;
117 GotFirstClick2 = 0;
118 GotDoubleClick2 = 0;
119 GotFirstClick3 = 0;
120 GotDoubleClick3 = 0;
121 } else {
122 ++DblClkDelay;
126 * Process any pending X events.
128 while (XPending(display)) {
129 XNextEvent(display, &event);
130 switch (event.type) {
131 case Expose:
132 RedrawWindow();
133 break;
134 case ButtonPress:
135 ButtonPressEvent(&event.xbutton);
136 break;
137 case ButtonRelease:
138 break;
143 * sleep till next update. I cant seem to get usleep or select to work properly
144 * with args smaller than 10000. A kernel tick problem? If I comment out the next line,
145 * the app screams (chews up cpu too). Or if I use DELAY of 0 it also screams.
146 * But a delay of 1 or higher is slow.....
149 short_uusleep(DELAY);
154 * ParseCMDLine()
156 void ParseCMDLine(int argc, char *argv[])
158 int i;
159 PixmapSize = 2;
160 for (i = 1; i < argc; i++) {
161 if (!strcmp(argv[i], "-display")) {
162 ++i;
163 } else if (!strcmp(argv[i], "-c")) {
164 if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) {
165 fprintf(stderr, "wmMatrix: No command given\n");
166 print_usage();
167 exit(-1);
169 if (DoubleClickCmd != NULL)
170 free(DoubleClickCmd);
171 DoubleClickCmd = strdup(argv[++i]);
172 } else if (!strcmp(argv[i], "-cr")) {
173 if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) {
174 fprintf(stderr, "wmMatrix: No command given\n");
175 print_usage();
176 exit(-1);
178 if (RDoubleClickCmd != NULL)
179 free(RDoubleClickCmd);
180 RDoubleClickCmd = strdup(argv[++i]);
181 } else if (!strcmp(argv[i], "-sml")) {
182 PixmapSize = 1;
183 } else if (!strcmp(argv[i], "-med")) {
184 PixmapSize = 2;
185 } else if (!strcmp(argv[i], "-lrg")) {
186 PixmapSize = 3;
187 } else {
188 print_usage();
189 exit(1);
194 void print_usage()
196 printf("\nwmMatrix version: %s\n", WMMATRIX_VERSION);
197 printf("\t-h\t\tDisplay help screen.\n");
198 printf("\t-c cmd\t\tCommand executed on doubleclick.\n");
199 printf("\t-cr cmd\t\tCommand executed on right doubleclick\n");
200 printf("\t-sml\t\tUse small size pixmap.\n");
201 printf("\t-med\t\tUse medium size pixmap.\n");
202 printf("\t-lrg\t\tUse large size pixmap.\n");
206 * This routine handles button presses.
208 * Double click on
209 * Mouse Button 1: Execute the command defined in the -c command-line option.
210 * Mouse Button 2: No action assigned.
211 * Mouse Button 3: Execute the command defined in the -cr command-line option.
215 void ButtonPressEvent(XButtonEvent * xev)
217 DblClkDelay = 0;
218 if ((xev->button == Button1) && (xev->type == ButtonPress)) {
219 if (GotFirstClick1)
220 GotDoubleClick1 = 1;
221 else
222 GotFirstClick1 = 1;
223 } else if ((xev->button == Button2) && (xev->type == ButtonPress)) {
224 if (GotFirstClick2)
225 GotDoubleClick2 = 1;
226 else
227 GotFirstClick2 = 1;
228 } else if ((xev->button == Button3) && (xev->type == ButtonPress)) {
229 if (GotFirstClick3)
230 GotDoubleClick3 = 1;
231 else
232 GotFirstClick3 = 1;
236 * We got a double click on Mouse Button1 (i.e. the left one)
238 if (GotDoubleClick1) {
239 GotFirstClick1 = 0;
240 GotDoubleClick1 = 0;
241 system(DoubleClickCmd);
245 * We got a double click on Mouse Button2 (i.e. the middle one)
247 if (GotDoubleClick2) {
248 GotFirstClick2 = 0;
249 GotDoubleClick2 = 0;
253 * We got a double click on Mouse Button3 (i.e. the right one)
255 if (GotDoubleClick3) {
256 GotFirstClick3 = 0;
257 GotDoubleClick3 = 0;
258 system(RDoubleClickCmd);
260 return;