wmcalc: Bump to version 0.7.
[dockapps.git] / wmxss / Src / wmxss.c
blobf51c4a5d4490cb59fb039486abd80444f8311c45
1 /*
3 * wmxss-0.10 (C) 1999 Mike Henderson (mghenderson@lanl.gov)
5 * - Its a DockApp front end for xscreensaver
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program (see the file COPYING); if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA
26 * Changes:
28 * Version 0.10 - released Aug 11, 1999.
29 * just playing around right now....
39 * Includes
41 #include <stdio.h>
42 #include <unistd.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <time.h>
46 #include <X11/X.h>
47 #include <X11/xpm.h>
48 #include "xutils.h"
49 #include "wmxss_master.xpm"
50 #include "wmxss_mask.xbm"
55 * Delay between refreshes (in microseconds)
57 #define DELAY 10000L
58 #define WMXSS_VERSION "0.10"
64 void ParseCMDLine(int argc, char *argv[]);
65 void ButtonPressEvent(XButtonEvent *);
66 void print_usage();
69 int GotFirstClick1, GotDoubleClick1;
70 int GotFirstClick2, GotDoubleClick2;
71 int GotFirstClick3, GotDoubleClick3;
72 int DblClkDelay;
73 int HasExecute;
74 char ExecuteCommand[1024];
80 char TimeColor[30] = "#ffff00";
81 char BackgroundColor[30] = "#181818";
89 * main
91 int main(int argc, char *argv[]) {
94 XEvent event;
95 int n;
96 char Command[512];
100 * Parse any command line arguments.
102 ParseCMDLine(argc, argv);
110 initXwindow(argc, argv);
111 openXwindow(argc, argv, wmxss_master, wmxss_mask_bits, wmxss_mask_width, wmxss_mask_height);
115 if (HasExecute){
116 sprintf(Command, "%s -window-id 0x%x &", ExecuteCommand, (int)iconwin);
117 system(Command);
123 * Loop until we die
125 n = 32000;
126 while(1) {
129 if ( n>10){
131 n = 0;
133 } else {
136 * Update the counter.
138 ++n;
147 * Double Click Delays
148 * Keep track of click events. If Delay too long, set GotFirstClick's to False.
150 if (DblClkDelay > 150) {
152 DblClkDelay = 0;
153 GotFirstClick1 = 0; GotDoubleClick1 = 0;
154 GotFirstClick2 = 0; GotDoubleClick2 = 0;
155 GotFirstClick3 = 0; GotDoubleClick3 = 0;
157 } else {
159 ++DblClkDelay;
167 * Process any pending X events.
169 while(XPending(display)){
170 XNextEvent(display, &event);
171 switch(event.type){
172 case Expose:
173 RedrawWindow();
174 break;
175 case ButtonPress:
176 ButtonPressEvent(&event.xbutton);
177 break;
178 case ButtonRelease:
179 break;
189 * Redraw and wait for next update
192 RedrawWindow();
194 usleep(DELAY);
211 * ParseCMDLine()
213 void ParseCMDLine(int argc, char *argv[]) {
215 int i;
217 for (i = 1; i < argc; i++) {
219 if (!strcmp(argv[i], "-display")){
221 ++i;
223 } else if (!strcmp(argv[i], "-tc")){
225 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
226 fprintf(stderr, "wmxss: No color found\n");
227 print_usage();
228 exit(-1);
230 strcpy(TimeColor, argv[++i]);
232 } else if (!strcmp(argv[i], "-bc")){
234 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
235 fprintf(stderr, "wmxss: No color found\n");
236 print_usage();
237 exit(-1);
239 strcpy(BackgroundColor, argv[++i]);
241 } else if (!strcmp(argv[i], "-e")){
243 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
244 fprintf(stderr, "wmxss: No command given\n");
245 print_usage();
246 exit(-1);
248 strcpy(ExecuteCommand, argv[++i]);
249 HasExecute = 1;
251 } else {
253 print_usage();
254 exit(1);
263 void print_usage(){
265 printf("\nwmxss version: %s\n", WMXSS_VERSION);
266 printf("\nusage: wmxss [-e \"Command\"] \n\n");
267 printf("\t-e \"Command\"\tCommand to execute via double click of mouse button 1.\n");
268 printf("\t-h\t\tDisplay help screen.\n");
269 printf("\nExample: wmxss -e xflame\n\n");
280 * This routine handles button presses.
282 * Double click on
283 * Mouse Button 1: Execute the command defined in the -e command-line option.
284 * Mouse Button 2: No action assigned.
285 * Mouse Button 3: No action assigned.
289 void ButtonPressEvent(XButtonEvent *xev){
293 DblClkDelay = 0;
294 if ((xev->button == Button1) && (xev->type == ButtonPress)){
295 if (GotFirstClick1) GotDoubleClick1 = 1;
296 else GotFirstClick1 = 1;
297 } else if ((xev->button == Button2) && (xev->type == ButtonPress)){
298 if (GotFirstClick2) GotDoubleClick2 = 1;
299 else GotFirstClick2 = 1;
300 } else if ((xev->button == Button3) && (xev->type == ButtonPress)){
301 if (GotFirstClick3) GotDoubleClick3 = 1;
302 else GotFirstClick3 = 1;
307 * We got a double click on Mouse Button1 (i.e. the left one)
309 if (GotDoubleClick1) {
310 GotFirstClick1 = 0;
311 GotDoubleClick1 = 0;
312 system("xscreensaver-demo");
317 * We got a double click on Mouse Button2 (i.e. the left one)
319 if (GotDoubleClick2) {
320 GotFirstClick2 = 0;
321 GotDoubleClick2 = 0;
326 * We got a double click on Mouse Button3 (i.e. the left one)
328 if (GotDoubleClick3) {
329 GotFirstClick3 = 0;
330 GotDoubleClick3 = 0;
335 return;