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)
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
29 * Version 0.2 - released Aug 16, 1999.
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....
52 #include "wmMatrix_master.xpm"
53 #include "wmMatrix_mask.xbm"
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
*);
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
;
73 /*char* ExecuteCommand = "xmatrixsmall";*/
74 char *progname
= "wmMatrix";
75 char *progclass
= "WMMatrix";
77 char *DoubleClickCmd
= NULL
;
78 char *RDoubleClickCmd
= NULL
;
79 char *TimeColor
= "#ffff00";
80 char *BackgroundColor
= "#181818";
85 int main(int argc
, char *argv
[])
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
);
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) {
126 * Process any pending X events.
128 while (XPending(display
)) {
129 XNextEvent(display
, &event
);
130 switch (event
.type
) {
135 ButtonPressEvent(&event
.xbutton
);
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
);
156 void ParseCMDLine(int argc
, char *argv
[])
160 for (i
= 1; i
< argc
; i
++) {
161 if (!strcmp(argv
[i
], "-display")) {
163 } else if (!strcmp(argv
[i
], "-c")) {
164 if ((i
+ 1 >= argc
) || (argv
[i
+ 1][0] == '-')) {
165 fprintf(stderr
, "wmMatrix: No command given\n");
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");
178 if (RDoubleClickCmd
!= NULL
)
179 free(RDoubleClickCmd
);
180 RDoubleClickCmd
= strdup(argv
[++i
]);
181 } else if (!strcmp(argv
[i
], "-sml")) {
183 } else if (!strcmp(argv
[i
], "-med")) {
185 } else if (!strcmp(argv
[i
], "-lrg")) {
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.
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
)
218 if ((xev
->button
== Button1
) && (xev
->type
== ButtonPress
)) {
223 } else if ((xev
->button
== Button2
) && (xev
->type
== ButtonPress
)) {
228 } else if ((xev
->button
== Button3
) && (xev
->type
== ButtonPress
)) {
236 * We got a double click on Mouse Button1 (i.e. the left one)
238 if (GotDoubleClick1
) {
241 system(DoubleClickCmd
);
245 * We got a double click on Mouse Button2 (i.e. the middle one)
247 if (GotDoubleClick2
) {
253 * We got a double click on Mouse Button3 (i.e. the right one)
255 if (GotDoubleClick3
) {
258 system(RDoubleClickCmd
);