complete initial libgpm support #1405

This commit is contained in:
nick black 2021-09-01 20:03:42 -04:00
parent 1463049d32
commit 582e7b24c5
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
5 changed files with 28 additions and 4 deletions

View File

@ -65,6 +65,9 @@ using `USE_MULTIMEDIA`. Valid values are `ffmpeg`, `oiio` (for OpenImageIO),
or `none`. Without a multimedia engine, Notcurses will be unable to decode or `none`. Without a multimedia engine, Notcurses will be unable to decode
images and videos. images and videos.
To get mouse events in the Linux console, you'll need the GPM daemon running,
and you'll need run `cmake` with `-DUSE_GPM=on`.
Run unit tests with `make test` following a successful build. If you have unit Run unit tests with `make test` following a successful build. If you have unit
test failures, *please* file a bug including the output of test failures, *please* file a bug including the output of

View File

@ -1,6 +1,10 @@
This document attempts to list user-visible changes and any major internal This document attempts to list user-visible changes and any major internal
rearrangements of Notcurses. rearrangements of Notcurses.
* 2.3.19 (not yet released)
* Mouse events in the Linux console are now reported from GPM when built
with `-DUSE_GPM=on`.
* 2.3.18 (2021-08-31) * 2.3.18 (2021-08-31)
* No user-visible changes. * No user-visible changes.

View File

@ -8,9 +8,13 @@ static Gpm_Connect gpmconn; // gpm server handle
static void* static void*
gpmwatcher(void* vti){ gpmwatcher(void* vti){
static char cmdbuf[20]; // max is '\x1b[<int;int;intM'
cmdbuf[0] = '\x1b';
cmdbuf[1] = '[';
cmdbuf[2] = '<';
tinfo* ti = vti; tinfo* ti = vti;
(void)ti; // FIXME
Gpm_Event gev; Gpm_Event gev;
const int space = sizeof(cmdbuf) - 3;
while(true){ while(true){
if(!Gpm_GetEvent(&gev)){ if(!Gpm_GetEvent(&gev)){
logerror("error reading from gpm daemon\n"); logerror("error reading from gpm daemon\n");
@ -18,7 +22,17 @@ gpmwatcher(void* vti){
} }
loginfo("got gpm event y=%hd x=%hd mod=%u butt=%u\n", gev.y, gev.x, loginfo("got gpm event y=%hd x=%hd mod=%u butt=%u\n", gev.y, gev.x,
(unsigned)gev.modifiers, (unsigned)gev.buttons); (unsigned)gev.modifiers, (unsigned)gev.buttons);
// FIXME decode event and enqueue to input layer if(gev.y < 0 || gev.x < 0){
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){
logwarn("input overflowed %hd %hd\n", gev.x, gev.y);
continue;
}
ncinput_shovel(&ti->input, cmdbuf, strlen(cmdbuf));
} }
return NULL; return NULL;
} }

View File

@ -535,12 +535,15 @@ handle_queued_input(ncinputlayer* nc, ncinput* ni,
return ret; return ret;
} }
int ncinput_shovel(ncinputlayer* ni, const unsigned char* buf, size_t len){ int ncinput_shovel(ncinputlayer* ni, const char* buf, size_t len){
int ret = -1; int ret = -1;
pthread_mutex_lock(&ni->lock); pthread_mutex_lock(&ni->lock);
size_t space = input_queue_space(ni); size_t space = input_queue_space(ni);
if(len < space){ if(len < space){
size_t spaceback = sizeof(ni->inputbuf) / sizeof(*ni->inputbuf) - ni->inputbuf_write_at; size_t spaceback = sizeof(ni->inputbuf) / sizeof(*ni->inputbuf) - ni->inputbuf_write_at;
if(spaceback > len){
spaceback = len;
}
memcpy(ni->inputbuf + ni->inputbuf_write_at, buf, spaceback); memcpy(ni->inputbuf + ni->inputbuf_write_at, buf, spaceback);
len -= spaceback; len -= spaceback;
ni->inputbuf_write_at += spaceback; ni->inputbuf_write_at += spaceback;

View File

@ -60,7 +60,7 @@ int cbreak_mode(struct tinfo* ti);
// appropriate. we can be interrupted by a new user context. // appropriate. we can be interrupted by a new user context.
void ncinput_extract_clrs(struct tinfo* ti); void ncinput_extract_clrs(struct tinfo* ti);
int ncinput_shovel(struct ncinputlayer* ni, const unsigned char* buf, size_t len); int ncinput_shovel(struct ncinputlayer* ni, const char* buf, size_t len);
#ifdef __cplusplus #ifdef __cplusplus
} }