Added window winch signal

This commit is contained in:
2017-11-27 18:06:32 +00:00
parent 4add211375
commit b78d59dd85
2 changed files with 14 additions and 0 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
*~ *~
*.o *.o
nclock nclock
/nclock

View File

@@ -6,6 +6,13 @@
#include "numbers.h" #include "numbers.h"
#include <time.h> #include <time.h>
#include <unistd.h> //sleep #include <unistd.h> //sleep
#include <signal.h>
void handle_winch(int sig) {
endwin();
clear();
refresh();
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
/* enable ncurses standard screen */ /* enable ncurses standard screen */
@@ -16,6 +23,11 @@ int main(int argc, char **argv) {
keypad(stdscr, FALSE); //Disable the F1-12 keypad keypad(stdscr, FALSE); //Disable the F1-12 keypad
curs_set(0); //Disable the cursor curs_set(0); //Disable the cursor
//Windows resize handler
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = handle_winch;
sigaction(SIGWINCH, &sa, NULL);
state s = {0}; state s = {0};
@@ -81,6 +93,7 @@ void draw(state *s) {
while (1) { while (1) {
time(&timer); time(&timer);
curTime = localtime(&timer); curTime = localtime(&timer);
initState(s);
drawTime(s, curTime->tm_hour, curTime->tm_min, curTime->tm_sec); drawTime(s, curTime->tm_hour, curTime->tm_min, curTime->tm_sec);
refresh(); refresh();
sleep(1); sleep(1);