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

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

Loading…
Cancel
Save