From 811f9334d1420baa7e1ac25fa6aa1d281e8bc21f Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 18 Sep 2021 02:19:09 -0400 Subject: [PATCH] A melange of fixen (#2179) * split up ncdirect_dump_{sprixel, cellplane}() * build ncdirect_dump_cellplane() out of fbuf #2167 * [macos] don't run pandoc in workflow * [gpm] account for margins in mouse reports * [in] drop mouse clicks from top/left margins * [ffmpeg] compile against avformat 59+ w/out warnings --- src/lib/gpm.c | 7 +++---- src/lib/in.c | 14 ++++++++++---- src/media/ffmpeg.c | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/lib/gpm.c b/src/lib/gpm.c index 40f3fafc3..e01e3b965 100644 --- a/src/lib/gpm.c +++ b/src/lib/gpm.c @@ -26,9 +26,9 @@ gpmwatcher(void* vti){ logwarn("negative input %hd %hd", gev.x, gev.y); continue; } - ++gev.x; - ++gev.y; - if(snprintf(cmdbuf + 3, space, "%hd;%hd;%hdM", 0, gev.x, gev.y) >= space){ + // gpm is 0-indexed, but we assume mice reports to be 1-indexed, as they + // are in the XTerm protocols. no need to account for margins here. + if(snprintf(cmdbuf + 3, space, "%hd;%hd;%hdM", 0, gev.x + 1, gev.y + 1) >= space){ logwarn("input overflowed %hd %hd\n", gev.x, gev.y); continue; } @@ -38,7 +38,6 @@ gpmwatcher(void* vti){ } int gpm_connect(tinfo* ti){ - (void)ti; gpm_zerobased = 1; // get all of _MOVE, _DRAG, _DOWN, and _UP gpmconn.eventMask = GPM_DRAG | GPM_DOWN | GPM_UP; diff --git a/src/lib/in.c b/src/lib/in.c index 91f8149a0..199cb49e7 100644 --- a/src/lib/in.c +++ b/src/lib/in.c @@ -806,10 +806,17 @@ set_sda_version(inputctx* ictx){ // ictx->numeric, ictx->p3, and ictx->p2 have the two parameters static void mouse_click(inputctx* ictx){ + // convert from 1- to 0-indexing, and account for margins + const int x = ictx->p3 - 1 - ictx->lmargin; + const int y = ictx->numeric - 1 - ictx->tmargin; + if(x < 0 || y < 0){ // click was in margins, drop it + logwarn("dropping click in margins\n"); + return; + } pthread_mutex_lock(&ictx->ilock); if(ictx->ivalid == ictx->isize){ pthread_mutex_unlock(&ictx->ilock); - logerror("dropping mouse click 0x%02x %d %d\n", ictx->p2, ictx->p3, ictx->numeric); + logerror("dropping mouse click 0x%02x %d %d\n", ictx->p2, y, x); return; } ncinput* ni = ictx->inputs + ictx->iwrite; @@ -827,9 +834,8 @@ mouse_click(inputctx* ictx){ ni->ctrl = ictx->p2 & 0x10; ni->alt = ictx->p2 & 0x08; ni->shift = ictx->p2 & 0x04; - // convert from 1- to 0-indexing and account for margins - ni->x = ictx->p3 - 1 - ictx->lmargin; - ni->y = ictx->numeric - 1 - ictx->tmargin; + ni->x = x; + ni->y = y; if(++ictx->iwrite == ictx->isize){ ictx->iwrite = 0; } diff --git a/src/media/ffmpeg.c b/src/media/ffmpeg.c index 60123646a..d3e0e2b7e 100644 --- a/src/media/ffmpeg.c +++ b/src/media/ffmpeg.c @@ -395,7 +395,12 @@ ncvisual* ffmpeg_from_file(const char* filename){ goto err; } //av_dump_format(ncv->details->fmtctx, 0, filename, false); - if((averr = av_find_best_stream(ncv->details->fmtctx, AVMEDIA_TYPE_SUBTITLE, -1, -1, &ncv->details->subtcodec, 0)) >= 0){ + if((averr = av_find_best_stream(ncv->details->fmtctx, AVMEDIA_TYPE_SUBTITLE, -1, -1, +#if LIBAVFORMAT_VERSION_MAJOR >= 59 + (const AVCodec**)&ncv->details->subtcodec, 0)) >= 0){ +#else + &ncv->details->subtcodec, 0)) >= 0){ +#endif ncv->details->sub_stream_index = averr; if((ncv->details->subtcodecctx = avcodec_alloc_context3(ncv->details->subtcodec)) == NULL){ //fprintf(stderr, "Couldn't allocate decoder for %s\n", filename); @@ -414,7 +419,12 @@ ncvisual* ffmpeg_from_file(const char* filename){ // fprintf(stderr, "Couldn't allocate packet for %s\n", filename); goto err; } - if((averr = av_find_best_stream(ncv->details->fmtctx, AVMEDIA_TYPE_VIDEO, -1, -1, &ncv->details->codec, 0)) < 0){ + if((averr = av_find_best_stream(ncv->details->fmtctx, AVMEDIA_TYPE_VIDEO, -1, -1, +#if LIBAVFORMAT_VERSION_MAJOR >= 59 + (const AVCodec**)&ncv->details->codec, 0)) < 0){ +#else + &ncv->details->codec, 0)) < 0){ +#endif // fprintf(stderr, "Couldn't find visuals in %s (%s)\n", filename, av_err2str(*averr)); goto err; }