reverse-branch
Martin Duquesnoy 17 years ago
parent 74ca67139b
commit 45f1a9df22
  1. 51
      ttyclock.c
  2. 11
      ttyclock.h

@ -66,8 +66,14 @@ init(void)
/* Init global struct */
ttyclock->running = True;
ttyclock->geo.x = 0;
ttyclock->geo.y = 0;
if(!ttyclock->geo.x)
ttyclock->geo.x = 0;
if(!ttyclock->geo.y)
ttyclock->geo.y = 0;
if(!ttyclock->geo.a)
ttyclock->geo.a = 1;
if(!ttyclock->geo.b)
ttyclock->geo.b = 1;
ttyclock->geo.w = (ttyclock->option.second) ? SECFRAMEW : NORMFRAMEW;
ttyclock->geo.h = 7;
ttyclock->tm = localtime(&(ttyclock->lt));
@ -103,12 +109,8 @@ signal_handler(int signal)
switch(signal)
{
case SIGWINCH:
/* If the terminal is resizing */
if(ttyclock->option.center)
{
endwin();
init();
}
endwin();
init();
break;
/* Interruption signal */
case SIGINT:
@ -137,7 +139,7 @@ update_hour(void)
ihour = ttyclock->tm->tm_hour;
if(ttyclock->option.twelve)
ttyclock->meridiem = (ihour > 12) ? " [PM]" : " [AM]";
ttyclock->meridiem = ((ihour > 12) ? PMSIGN : AMSIGN);
else
ttyclock->meridiem = "";
@ -266,6 +268,29 @@ clock_move(int x, int y, int w, int h)
return;
}
/* Useless but fun :) */
void
clock_rebound(void)
{
if(!ttyclock->option.rebound)
return;
if(ttyclock->geo.x < 1)
ttyclock->geo.a = 1;
if(ttyclock->geo.x > (LINES - ttyclock->geo.h - DATEWINH))
ttyclock->geo.a = -1;
if(ttyclock->geo.y < 1)
ttyclock->geo.b = 1;
if(ttyclock->geo.y > (COLS - ttyclock->geo.w - 1))
ttyclock->geo.b = -1;
clock_move(ttyclock->geo.x + ttyclock->geo.a,
ttyclock->geo.y + ttyclock->geo.b,
ttyclock->geo.w,
ttyclock->geo.h);
return;
}
void
set_second(void)
{
@ -356,6 +381,11 @@ key_event(void)
case 'C':
set_center(!ttyclock->option.center);
break;
case 'r':
case 'R':
ttyclock->option.rebound = !ttyclock->option.rebound;
break;
}
return;
@ -419,10 +449,13 @@ main(int argc, char **argv)
init();
while(ttyclock->running)
{
clock_rebound();
update_hour();
draw_clock();
key_event();
usleep(UPDATETIME);
}

@ -46,6 +46,8 @@
#define SECFRAMEW 54
#define UPDATETIME 10000
#define DATEWINH 3
#define AMSIGN " [AM]"
#define PMSIGN " [PM]"
/* Help string */
#define HELPSTR "tty-clock usage : tty-clock [-option] <arg> \n\
@ -72,12 +74,15 @@ typedef struct
Bool twelve;
Bool keylock;
Bool center;
Bool rebound;
} option;
/* Clock geometry */
struct
{
int x, y, w, h;
/* For rebound use (see clock_rebound())*/
int a, b;
} geo;
/* Date content ([2] = number by number) */
@ -86,7 +91,7 @@ typedef struct
unsigned int hour[2];
unsigned int minute[2];
unsigned int second[2];
char datestr[56];
char datestr[16];
} date;
/* time.h utils */
@ -95,8 +100,8 @@ typedef struct
/* Clock member */
char *meridiem;
WINDOW* framewin;
WINDOW* datewin;
WINDOW *framewin;
WINDOW *datewin;
} ttyclock_t;

Loading…
Cancel
Save