Correctly copy in shrink + SIGWINCH (#80) (#93)

* notcurses_resize(): properly set new lenx/leny #80
* ppoll() for SIGWINCH #80
* widecolor-demo: keystroke-driven
pull/96/head
Nick Black 5 years ago committed by GitHub
parent 0b967ae528
commit 8b0634527d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -256,7 +256,13 @@ int widecolor_demo(struct notcurses* nc){
// ncplane_erase(n);
const int start = starts[i];
const int step = steps[i];
//do{
ncspecial_key special;
cell c;
do{
int dimy, dimx;
notcurses_resize(nc, &dimy, &dimx);
cell_init(&c);
special = NCKEY_INVALID;
int y, x, maxy, maxx;
ncplane_dim_yx(n, &maxy, &maxx);
int rgb = start;
@ -309,12 +315,13 @@ int widecolor_demo(struct notcurses* nc){
/*if(i){ FIXME
fadein(w, count, palette, FADE_MILLISECONDS);
}
do{
key = wgetch(w);
}while(key == ERR);
*/
nanosleep(&demodelay, NULL);
//}while(key == KEY_RESIZE);
int key;
do{
key = notcurses_getc_blocking(nc, &c, &special);
}while(key < 0);
// nanosleep(&demodelay, NULL);
}while(c.gcluster == 0 && special == NCKEY_RESIZE);
}
return 0;
}

@ -353,9 +353,11 @@ int notcurses_resize(notcurses* n, int* rows, int* cols){
}
int y, idx;
idx = 0;
p->lenx = *cols;
p->leny = *rows;
for(y = 0 ; y < p->leny ; ++y){
idx = y * p->lenx;
if(y > oldrows){
if(y >= oldrows){
memset(&p->fb[idx], 0, sizeof(*p->fb) * p->lenx);
continue;
}
@ -366,7 +368,7 @@ int notcurses_resize(notcurses* n, int* rows, int* cols){
}
memcpy(&p->fb[idx], &preserved[y * oldcols], oldcopy * sizeof(*p->fb));
}
if(p->lenx - oldcopy){
if(p->lenx > oldcopy){
memset(&p->fb[idx + oldcopy], 0, sizeof(*p->fb) * (p->lenx - oldcopy));
}
}
@ -1470,6 +1472,10 @@ void ncplane_erase(ncplane* n){
static int
handle_getc(const notcurses* nc __attribute__ ((unused)), cell* c, int kpress,
ncspecial_key* special){
fprintf(stderr, "KEYPRESS: %d\n", kpress);
if(kpress < 0){
return -1;
}
*special = 0;
if(kpress == 0x04){ // ctrl-d
return -1;
@ -1505,22 +1511,26 @@ int notcurses_getc_blocking(const notcurses* nc, cell* c, ncspecial_key* special
.events = POLLIN | POLLRDHUP,
.revents = 0,
};
int pret;
while((pret = poll(&pfd, 1, -1)) >= 0){
int pret, r;
sigset_t smask;
sigfillset(&smask);
sigdelset(&smask, SIGWINCH);
while((pret = ppoll(&pfd, 1, NULL, &smask)) >= 0){
if(pret == 0){
continue;
}
int r = getc(nc->ttyinfp);
r = getc(nc->ttyinfp);
if(r < 0){
if(errno == EINTR){
if(resize_seen){
resize_seen = 0;
c->gcluster = 0;
*special = NCKEY_RESIZE;
return 1;
}
}
return handle_getc(nc, c, r, special);
break; // want EINTR handling below
}
return handle_getc(nc, c, r, special);
}
if(errno == EINTR){
if(resize_seen){
resize_seen = 0;
c->gcluster = 0;
*special = NCKEY_RESIZE;
return 1;
}
}
return -1;

Loading…
Cancel
Save