diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index dc86b7d6c..69eda20bc 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -171,13 +171,15 @@ int ncplane_at_cursor(ncplane* n, cell* c){ } int ncplane_at_yx(ncplane* n, int y, int x, cell* c){ - if(y >= n->leny || x >= n->lenx){ - return true; + int ret = -1; + pthread_mutex_lock(&n->nc->lock); + if(y < n->leny && x < n->lenx){ + if(y >= 0 && x >= 0){ + ret = cell_duplicate(n, c, &n->fb[fbcellidx(n, y, x)]); + } } - if(y < 0 || x < 0){ - return true; - } - return cell_duplicate(n, c, &n->fb[fbcellidx(n, y, x)]); + pthread_mutex_unlock(&n->nc->lock); + return ret; } cell* ncplane_cell_ref_yx(ncplane* n, int y, int x){ @@ -1515,22 +1517,6 @@ void ncplane_yx(const ncplane* n, int* y, int* x){ pthread_mutex_unlock(&n->nc->lock); } -// copy the UTF8-encoded EGC out of the cell, whether simple or complex. the -// result is not tied to the ncplane, and persists across erases / destruction. -static inline char* -cell_egc_copy(const ncplane* n, const cell* c){ - char* ret; - if(cell_simple_p(c)){ - if( (ret = malloc(2)) ){ - ret[0] = c->gcluster; - ret[1] = '\0'; - } - }else{ - ret = strdup(cell_extended_gcluster(n, c)); - } - return ret; -} - void ncplane_erase(ncplane* n){ ncplane_lock(n); // we must preserve the background, but a pure cell_duplicate() would be diff --git a/src/lib/render.c b/src/lib/render.c index 06d8a4f70..101edabfa 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -619,3 +619,18 @@ int notcurses_render(notcurses* nc){ return ret; } +char* notcurses_at_yx(notcurses* nc, int y, int x, cell* c){ + char* egc = NULL; + pthread_mutex_lock(&nc->lock); + if(nc->lastframe){ + if(y >= 0 && y < nc->lfdimy){ + if(x >= 0 || x < nc->lfdimx){ + const cell* srccell = &nc->lastframe[y * nc->lfdimx + x]; + memcpy(c, srccell, sizeof(*c)); // unsafe copy of gcluster + egc = cell_egc_copy(nc->stdscr, srccell); + } + } + } + pthread_mutex_unlock(&nc->lock); + return egc; +}