1 /* 2 * TTY-CLOCK headers file. 3 * Copyright © 2008 Martin Duquesnoy <xorg62@gmail.com> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * * Redistributions in binary form must reproduce the above 13 * copyright notice, this list of conditions and the following disclaimer 14 * in the documentation and/or other materials provided with the 15 * distribution. 16 * * Neither the name of the nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #ifndef TTYCLOCK_H_INCLUDED 34 #define TTYCLOCK_H_INCLUDED 35 36 #include <sys/types.h> 37 #include <sys/stat.h> 38 #include <assert.h> 39 #include <stdlib.h> 40 #include <string.h> 41 #include <errno.h> 42 #include <time.h> 43 #include <signal.h> 44 #include <ncurses.h> 45 #include <unistd.h> 46 #include <getopt.h> 47 48 /* Macro */ 49 #define NORMFRAMEW 35 50 #define SECFRAMEW 54 51 #define DATEWINH 3 52 #define AMSIGN " [AM]" 53 #define PMSIGN " [PM]" 54 55 typedef enum { False, True } Bool; 56 57 /* Global ttyclock struct */ 58 typedef struct 59 { 60 /* while() boolean */ 61 Bool running; 62 63 /* terminal variables */ 64 SCREEN *ttyscr; 65 char *tty; 66 int bg; 67 68 /* Running option */ 69 struct 70 { 71 Bool second; 72 Bool screensaver; 73 Bool twelve; 74 Bool center; 75 Bool rebound; 76 Bool date; 77 Bool utc; 78 Bool box; 79 Bool noquit; 80 char *format; 81 int color; 82 Bool bold; 83 long delay; 84 Bool blink; 85 long nsdelay; 86 } option; 87 88 /* Clock geometry */ 89 struct 90 { 91 int x, y, w, h; 92 /* For rebound use (see clock_rebound())*/ 93 int a, b; 94 } geo; 95 96 /* Date content ([2] = number by number) */ 97 struct 98 { 99 unsigned int hour[2]; 100 unsigned int minute[2]; 101 unsigned int second[2]; 102 char datestr[256]; 103 } date; 104 105 /* time.h utils */ 106 struct tm *tm; 107 time_t lt; 108 109 /* Clock member */ 110 char *meridiem; 111 WINDOW *framewin; 112 WINDOW *datewin; 113 114 } ttyclock_t; 115 116 /* Prototypes */ 117 void init(void); 118 void signal_handler(int signal); 119 void update_hour(void); 120 void draw_number(int n, int x, int y); 121 void draw_clock(void); 122 void clock_move(int x, int y, int w, int h); 123 void set_second(void); 124 void set_center(Bool b); 125 void set_box(Bool b); 126 void key_event(void); 127 128 /* Global variable */ 129 ttyclock_t *ttyclock; 130 131 /* Number matrix */ 132 const Bool number[][15] = 133 { 134 {1,1,1,1,0,1,1,0,1,1,0,1,1,1,1}, /* 0 */ 135 {0,0,1,0,0,1,0,0,1,0,0,1,0,0,1}, /* 1 */ 136 {1,1,1,0,0,1,1,1,1,1,0,0,1,1,1}, /* 2 */ 137 {1,1,1,0,0,1,1,1,1,0,0,1,1,1,1}, /* 3 */ 138 {1,0,1,1,0,1,1,1,1,0,0,1,0,0,1}, /* 4 */ 139 {1,1,1,1,0,0,1,1,1,0,0,1,1,1,1}, /* 5 */ 140 {1,1,1,1,0,0,1,1,1,1,0,1,1,1,1}, /* 6 */ 141 {1,1,1,0,0,1,0,0,1,0,0,1,0,0,1}, /* 7 */ 142 {1,1,1,1,0,1,1,1,1,1,0,1,1,1,1}, /* 8 */ 143 {1,1,1,1,0,1,1,1,1,0,0,1,1,1,1}, /* 9 */ 144 }; 145 146 #endif /* TTYCLOCK_H_INCLUDED */ 147