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

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

Loading…
Cancel
Save