diff --git a/src/lib/internal.h b/src/lib/internal.h index 5d19227ff..013d30964 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -1145,7 +1145,12 @@ coerce_styles(fbuf* f, const tinfo* ti, uint16_t* curstyle, static inline int mouse_enable(tinfo* ti, FILE* out){ if(ti->qterm == TERMINAL_LINUX){ - return gpm_connect(ti); + if(ti->gpmfd >= 0){ + return 0; + } + if((ti->gpmfd = gpm_connect(ti)) >= 0){ + return 0; + } } // Sets the shift-escape option, allowing shift+mouse to override the standard // mouse protocol (mainly so copy-and-paste can still be performed). @@ -1159,6 +1164,10 @@ mouse_enable(tinfo* ti, FILE* out){ static inline int mouse_disable(tinfo* ti, fbuf* f){ if(ti->qterm == TERMINAL_LINUX){ + if(ti->gpmfd < 0){ + return 0; + } + ti->gpmfd = -1; return gpm_close(ti); } return fbuf_emit(f, "\x1b[?" SET_BTN_EVENT_MOUSE ";" diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index dc316301f..06f2c7645 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -673,10 +673,11 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut cursor_y = &foolcursor_y; } *cursor_x = *cursor_y = -1; - ti->qterm = TERMINAL_UNKNOWN; memset(ti, 0, sizeof(*ti)); + ti->qterm = TERMINAL_UNKNOWN; // we don't need a controlling tty for everything we do; allow a failure here ti->ttyfd = get_tty_fd(out); + ti->gpmfd = -1; size_t tablelen = 0; size_t tableused = 0; const char* tname = NULL; diff --git a/src/lib/termdesc.h b/src/lib/termdesc.h index cfd28384d..2f5de2cac 100644 --- a/src/lib/termdesc.h +++ b/src/lib/termdesc.h @@ -195,6 +195,7 @@ typedef struct tinfo { int default_rows; // LINES environment var / lines terminfo / 24 int default_cols; // COLUMNS environment var / cols terminfo / 80 + int gpmfd; // connection to GPM daemon #ifdef __linux__ int linux_fb_fd; // linux framebuffer device fd char* linux_fb_dev; // device corresponding to linux_fb_dev