demo: hook up Ctrl+L to refresh #379

This commit is contained in:
nick black 2020-02-23 23:55:44 -05:00 committed by Nick Black
parent 9db4bdd599
commit 0e3be34d2c
4 changed files with 26 additions and 9 deletions

View File

@ -5,6 +5,7 @@
#include <assert.h>
#include <unistd.h>
#include <limits.h>
#include <pthread.h>
#include <stdatomic.h>
#include <version.h>
#include <notcurses/notcurses.h>
@ -146,6 +147,9 @@ int demo_render(struct notcurses* nc);
#define DEMO_RENDER(nc) { int demo_render_err = demo_render(nc); if(demo_render_err){ return demo_render_err; }}
// locked by callers to notcurses_render() and notcurses_refresh(), all internal
extern pthread_mutex_t demo_render_lock;
// if you won't be doing things, and it's a long sleep, consider using
// demo_nanosleep(). it updates the HUD, which looks better to the user.
int demo_nanosleep(struct notcurses* nc, const struct timespec *ts);

View File

@ -5,6 +5,8 @@
// their mouse. it should always be on the top of the z-stack.
struct ncplane* hud = NULL;
pthread_mutex_t demo_render_lock = PTHREAD_MUTEX_INITIALIZER;
// while the HUD is grabbed by the mouse, these are set to the position where
// the grab started. they are reset once the HUD is released.
static int hud_grab_x = -1;
@ -438,5 +440,9 @@ int demo_render(struct notcurses* nc){
return -1;
}
}
return notcurses_render(nc);
// lock against a possible notcurses_refresh() on Ctrl+L
pthread_mutex_lock(&demo_render_lock);
int ret = notcurses_render(nc);
pthread_mutex_unlock(&demo_render_lock);
return ret;
}

View File

@ -92,16 +92,23 @@ ultramegaok_demo(void* vnc){
continue;
}
if(nckey_mouse_p(ni.id)){
handle_mouse(&ni);
}else{
// if this was about the menu or HUD, pass to them, and continue
if(menu_or_hud_key(nc, &ni)){
if(handle_mouse(&ni)){
continue;
}
// go ahead and pass keyboard through to demo, even if it was a 'q'
// (this might cause the demo to exit immediately, as is desired)
pass_along(&ni);
}
if(id == 'L' && ni.ctrl){
pthread_mutex_lock(&demo_render_lock);
notcurses_refresh(nc);
pthread_mutex_unlock(&demo_render_lock);
continue;
}
// if this was about the menu or HUD, pass to them, and continue
if(menu_or_hud_key(nc, &ni)){
continue;
}
// go ahead and pass keyboard through to demo, even if it was a 'q'
// (this might cause the demo to exit immediately, as is desired)
pass_along(&ni);
}
return NULL;
}

View File

@ -179,7 +179,7 @@ typedef struct ncselector {
uint64_t titlechannels; // title channels
uint64_t footchannels; // secondary and footer channels
uint64_t boxchannels; // border channels
int uarrowy, darrowy, arrowx;// location of scrollarrows, -1 if not present
int uarrowy, darrowy, arrowx;// location of scrollarrows, even if not present
} ncselector;
typedef struct ncdirect {