demo: don't allow HUD to drive rendering

pull/327/head
nick black 5 years ago
parent 14f03f781a
commit 0bff959eed
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -66,7 +66,7 @@ pass_along(const ncinput* ni){
} }
static int static int
handle_mouse(struct notcurses* nc, const ncinput* ni){ handle_mouse(const ncinput* ni){
if(ni->id != NCKEY_BUTTON1 && ni->id != NCKEY_RELEASE){ if(ni->id != NCKEY_BUTTON1 && ni->id != NCKEY_RELEASE){
return 0; return 0;
} }
@ -76,9 +76,9 @@ handle_mouse(struct notcurses* nc, const ncinput* ni){
}else{ }else{
ret = hud_grab(ni->y, ni->x); ret = hud_grab(ni->y, ni->x);
} }
if(ret == 0){ // do not render here. the demos, if coded properly, will be regularly
ret = demo_render(nc); // rendering (if via demo_nanosleep() if nothing else). rendering based off
} // HUD movements can cause disruptions due to the main thread being unready.
return ret; return ret;
} }
@ -92,7 +92,7 @@ ultramegaok_demo(void* vnc){
continue; continue;
} }
if(nckey_mouse_p(ni.id)){ if(nckey_mouse_p(ni.id)){
handle_mouse(nc, &ni); handle_mouse(&ni);
}else{ }else{
if(ni.id == 'q'){ if(ni.id == 'q'){
interrupt_demo(); interrupt_demo();

@ -289,14 +289,12 @@ ncplane_create(notcurses* nc, int rows, int cols, int yoff, int xoff){
p->channels = 0; p->channels = 0;
egcpool_init(&p->pool); egcpool_init(&p->pool);
cell_init(&p->basecell); cell_init(&p->basecell);
// FIXME we ought lock the notcurses struct here, but that breaks inside of pthread_mutex_lock(&nc->lock);
// e.g. ncplane_dup(). the latter ought be purely ncplane-based locking!
//pthread_mutex_lock(&nc->lock);
p->z = nc->top; p->z = nc->top;
nc->top = p; nc->top = p;
p->nc = nc; p->nc = nc;
nc->stats.fbbytes += fbsize; nc->stats.fbbytes += fbsize;
//pthread_mutex_unlock(&nc->lock); pthread_mutex_unlock(&nc->lock);
return p; return p;
} }
@ -357,7 +355,8 @@ ncplane_cursor_move_yx_locked(ncplane* n, int y, int x){
} }
ncplane* ncplane_dup(ncplane* n, void* opaque){ ncplane* ncplane_dup(ncplane* n, void* opaque){
ncplane_lock(n); // FIXME need ncplane-level locking around n; notcurses-level locking breaks
// on calls to ncplane_destroy()/ncplane_new()
int dimy = n->leny; int dimy = n->leny;
int dimx = n->lenx; int dimx = n->lenx;
int aty = n->absy; int aty = n->absy;
@ -378,7 +377,6 @@ ncplane* ncplane_dup(ncplane* n, void* opaque){
memcpy(newn->fb, n->fb, sizeof(*n->fb) * dimy * dimy); memcpy(newn->fb, n->fb, sizeof(*n->fb) * dimy * dimy);
} }
} }
ncplane_unlock(n);
return newn; return newn;
} }
@ -1197,52 +1195,66 @@ advance_cursor(ncplane* n, int cols){
// 'n' ends up above 'above' // 'n' ends up above 'above'
int ncplane_move_above_unsafe(ncplane* restrict n, ncplane* restrict above){ int ncplane_move_above_unsafe(ncplane* restrict n, ncplane* restrict above){
ncplane_lock(n);
if(n->z == above){ if(n->z == above){
ncplane_unlock(n);
return 0; return 0;
} }
ncplane** an = find_above_ncplane(n); ncplane** an = find_above_ncplane(n);
if(an == NULL){ if(an == NULL){
ncplane_unlock(n);
return -1; return -1;
} }
ncplane** aa = find_above_ncplane(above); ncplane** aa = find_above_ncplane(above);
if(aa == NULL){ if(aa == NULL){
ncplane_unlock(n);
return -1; return -1;
} }
*an = n->z; // splice n out *an = n->z; // splice n out
n->z = above; // attach above below n n->z = above; // attach above below n
*aa = n; // spline n in above *aa = n; // spline n in above
ncplane_unlock(n);
return 0; return 0;
} }
// 'n' ends up below 'below' // 'n' ends up below 'below'
int ncplane_move_below_unsafe(ncplane* restrict n, ncplane* restrict below){ int ncplane_move_below_unsafe(ncplane* restrict n, ncplane* restrict below){
ncplane_lock(n);
if(below->z == n){ if(below->z == n){
ncplane_unlock(n);
return 0; return 0;
} }
ncplane** an = find_above_ncplane(n); ncplane** an = find_above_ncplane(n);
if(an == NULL){ if(an == NULL){
ncplane_unlock(n);
return -1; return -1;
} }
*an = n->z; // splice n out *an = n->z; // splice n out
n->z = below->z; // reattach subbelow list to n n->z = below->z; // reattach subbelow list to n
below->z = n; // splice n in below below->z = n; // splice n in below
ncplane_unlock(n);
return 0; return 0;
} }
int ncplane_move_top(ncplane* n){ int ncplane_move_top(ncplane* n){
ncplane_lock(n);
ncplane** an = find_above_ncplane(n); ncplane** an = find_above_ncplane(n);
if(an == NULL){ if(an == NULL){
ncplane_unlock(n);
return -1; return -1;
} }
*an = n->z; // splice n out *an = n->z; // splice n out
n->z = n->nc->top; n->z = n->nc->top;
n->nc->top = n; n->nc->top = n;
ncplane_unlock(n);
return 0; return 0;
} }
int ncplane_move_bottom(ncplane* n){ int ncplane_move_bottom(ncplane* n){
ncplane_lock(n);
ncplane** an = find_above_ncplane(n); ncplane** an = find_above_ncplane(n);
if(an == NULL){ if(an == NULL){
ncplane_unlock(n);
return -1; return -1;
} }
*an = n->z; // splice n out *an = n->z; // splice n out
@ -1252,6 +1264,7 @@ int ncplane_move_bottom(ncplane* n){
} }
*an = n; *an = n;
n->z = NULL; n->z = NULL;
ncplane_unlock(n);
return 0; return 0;
} }

Loading…
Cancel
Save