16 #include "wmgeneral.h"
24 #define RELEASED "October 2006"
28 void display_time(int number
,int time_unit
);
29 void display_lines(time_t seconds
);
30 void display_date(int day_of_week
, int day_of_month
, int month
, int year
,int mode
,time_t seconds
);
31 void setColor(char *color
);
32 void setMode(char *mode
);
33 void display_help(void);
34 void display_version(void);
35 bool errorColor(char *color
);
36 bool errorMode(char *mode
);
41 char color_line
[12]="+\tc #";
44 bool errorMode(char *mode
)
46 if (strncmp(mode
,"0",1)!=0 && strncmp(mode
,"1",1)!=0)
52 bool errorColor(char *color
)
62 if ((color
[i
]<48 || color
[i
]>57) && (color
[i
]<65 || color
[i
]>70) && (color
[i
]<97 || color
[i
]>102))
71 puts("\033[1mwmHexaClock\033[0m");
72 printf("Version: \t%s\n",VERSION
);
73 printf("Released: \t%s\n",RELEASED
);
74 puts("Info: \t\thttp://www.bjoernw.de/");
80 puts("Usage: wmHexaClock [OPTIONS]");
81 puts("Possible Options are:\n");
82 puts(" -v or --version:\t\tGives information about version and release date");
83 puts(" -h or --help:\t\t\tPrints this dialog");
84 puts(" -c [COLOR] or --color [COLOR]:\tSpecifies the foreground color; for [COLOR] you use the hexadecimal notation RRGGBB (R=red, G=green, B=blue)");
85 puts(" \t\t\t\tExample: \"wmHexaClock -c FF0000\" for red");
86 puts(" -m [i] or --mode [i]:\t\tThere are two different display modes; for [i] you type 0 or 1 to chose between them (0 is default)");
90 void setColor(char *color
)
92 if (!errorColor(color
))
93 xpm_numbers
[3]=strncat(color_line
,color
,6); //Edit the Color-Line in xpm_numbers (-> pixmaps.h)
96 fprintf (stderr
,"The Color Code is nor correct! Example: \"-c 00FF00\" for green!\n");
101 void setMode(char *mode
)
103 if (!errorMode(mode
))
104 g_mode
=((int)*(mode
))-48;
107 fprintf (stderr
,"Please choose between mode 0 and 1. Example: \"-mode 0\"!\n");
112 int main(int argc
, char *argv
[])
117 static struct option long_options
[] =
119 /* These options set a flag. */
120 {"version", no_argument
, 0, 'v'},
121 {"help", no_argument
, 0, 'h'},
122 {"color", required_argument
, 0, 'c'},
123 {"mode", required_argument
, 0, 'm'},
131 int option_index
= 0;
133 c
= getopt_long (argc
, argv
, "vhc:m:", long_options
, &option_index
);
135 /* Detect the end of the options. */
154 puts("Type wmHexaClock -h for information");
162 openXwindow(argc
, argv
, xpm_numbers
, xpm_master
, xpm_mask_bits
, xpm_mask_width
, xpm_mask_height
);
168 if (actualtime
!=time(0))
170 /* Process any pending X events. */
171 while (XPending(display
))
173 XNextEvent(display
, &event
);
174 if (event
.type
==Expose
)
180 /* we should never get here */
187 struct tm
*time_struct
;
189 time_struct
=localtime(&actualtime
);
193 display_time(time_struct
->tm_hour
,HOUR
);
194 display_time(time_struct
->tm_min
,MINUTE
);
195 display_time(time_struct
->tm_sec
,SECOND
);
196 copyXPMArea(177,0,8,12,27,3); /*Display the two dots*/
198 display_lines(time_struct
->tm_sec
);
200 display_date(time_struct
->tm_wday
,time_struct
->tm_mday
,time_struct
->tm_mon
,time_struct
->tm_year
+1900,g_mode
,time_struct
->tm_sec
);
205 void display_time(int number
,int time_unit
){
207 int first_pos
=number
/16;
208 int second_pos
=number
%16;
212 copyXPMArea(first_pos
*11,0,11,12,5,5);
213 copyXPMArea(second_pos
*11,0,11,12,16,5);
215 else if (time_unit
==MINUTE
)
217 copyXPMArea(first_pos
*11,0,11,12,35,5);
218 copyXPMArea(second_pos
*11,0,11,12,46,5);
220 else if (time_unit
==SECOND
)
222 copyXPMArea(first_pos
*7,12,7,8,40,20);
223 copyXPMArea(second_pos
*7,12,7,8,48,20);
230 void display_lines(time_t seconds
)
234 for (i
=0;i
<(seconds
/8);i
++)
235 copyXPMArea(0,29,8,4,i
*8+4,32);
240 void display_date(int day_of_week
, int day_of_month
, int month
, int year
,int mode
,time_t seconds
)
242 int first_pos_day
=day_of_month
/16;
243 int second_pos_day
=day_of_month
%16;
244 int first_pos_month
=(month
+1)/16;
245 int second_pos_month
=(month
+1)%16;
246 int first_pos_year
=year
/256;
247 int second_pos_year
=(year
-first_pos_year
*256)/16;
248 int third_pos_year
=year
-first_pos_year
*256-second_pos_year
*16;
250 static bool rec_mode
;
254 copyXPMArea((day_of_week
-1)*22,20,22,9,5,39);
255 copyXPMArea(first_pos_day
*7,12,7,9,30,39);
256 copyXPMArea(second_pos_day
*7,12,7,9,37,39);
257 copyXPMArea(8,30,2,2,45,46);
258 copyXPMArea(first_pos_month
*7,12,7,9,47,39);
259 copyXPMArea(second_pos_month
*7,12,7,9,54,39);
260 copyXPMArea(first_pos_year
*7,12,7,8,34,50);
261 copyXPMArea(second_pos_year
*7,12,7,8,44,50);
262 copyXPMArea(third_pos_year
*7,12,7,8,53,50);
271 copyXPMArea((day_of_week
-1)*31,32,31,12,16,39);
274 copyXPMArea(first_pos_day
*11,0,11,12,3,36);
275 copyXPMArea(second_pos_day
*11,0,11,12,14,36);
276 copyXPMArea(180,9,4,3,26,46);
277 copyXPMArea(first_pos_month
*11,0,11,12,32,36);
278 copyXPMArea(second_pos_month
*11,0,11,12,43,36);
279 copyXPMArea(180,9,4,3,55,46);
280 copyXPMArea(first_pos_year
*7,12,7,8,18,51);
281 copyXPMArea(second_pos_year
*7,12,7,8,28,51);
282 copyXPMArea(third_pos_year
*7,12,7,8,37,51);