Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
mice.c
Go to the documentation of this file.
1#include "internal.h"
2
3int mouse_setup(tinfo* ti, unsigned eventmask){
4 if(ti->qterm == TERMINAL_LINUX){
5 if(eventmask == 0){
6 if(ti->gpmfd < 0){
7 return 0;
8 }
9 ti->gpmfd = -1;
10 return gpm_close(ti);
11 }
12 if(ti->gpmfd < 0){
13 // FIXME pass in eventmask
14 if((ti->gpmfd = gpm_connect(ti)) < 0){
15 return -1;
16 }
17 }
18 return 0;
19 }
20 if(ti->ttyfd < 0){
21 logerror("no tty, not emitting mouse control\n");
22 return -1;
23 }
24 // we'll need to fill in 'h' vs 'l' for both, and the event mode
25 char command = 'h';
26 // we have to choose one event mode, where all > drag > button > none.
27 // if user wants *only* move and not button, we'll need filter those FIXME.
28 if(eventmask & NCMICE_MOVE_EVENT){
29 ti->mouseproto = '3'; // SET_ALL_EVENT_MOUSE
30 }else if(eventmask & NCMICE_DRAG_EVENT){
31 ti->mouseproto = '2'; // SET_BTN_EVENT_MOUSE
32 }else if(eventmask & NCMICE_BUTTON_EVENT){
33 ti->mouseproto = '0'; // SET_X11_MOUSE_PROT
34 }else if(eventmask == 0){
35 if(ti->mouseproto == 0){
36 return 0;
37 }
38 command = 'l';
39 }
40// Sets the shift-escape option, allowing shift+mouse to override the standard
41// mouse protocol (mainly so copy-and-paste can still be performed).
42#define XTSHIFTESCAPE "\x1b[>1s"
43 char* mousecmd;
44 if(ti->pixelmice){
45 static char m[] = XTSHIFTESCAPE "\x1b[?100x;" SET_PIXEL_MOUSE_PROT "x";
46 mousecmd = m;
47 }else{
48 static char m[] = XTSHIFTESCAPE "\x1b[?100x;" SET_SGR_MOUSE_PROT "x";
49 mousecmd = m;
50 }
51 mousecmd[11] = ti->mouseproto;
52 mousecmd[17] = command;
53 if(command == 'l'){
54 ti->mouseproto = 0;
55 }
56 return tty_emit(mousecmd, ti->ttyfd);
57#undef XTSHIFTESCAPE
58}
int gpm_connect(tinfo *ti)
Definition gpm.c:79
int gpm_close(tinfo *ti)
Definition gpm.c:90
@ TERMINAL_LINUX
Definition in.h:35
#define SET_PIXEL_MOUSE_PROT
Definition internal.h:1188
#define SET_SGR_MOUSE_PROT
Definition internal.h:1183
#define logerror(fmt,...)
Definition logging.h:32
int mouse_setup(tinfo *ti, unsigned eventmask)
Definition mice.c:3
#define XTSHIFTESCAPE
#define NCMICE_BUTTON_EVENT
Definition notcurses.h:1342
#define NCMICE_DRAG_EVENT
Definition notcurses.h:1343
#define NCMICE_MOVE_EVENT
Definition notcurses.h:1341
queried_terminals_e qterm
Definition termdesc.h:178
char mouseproto
Definition termdesc.h:196
bool pixelmice
Definition termdesc.h:197
int gpmfd
Definition termdesc.h:195
int ttyfd
Definition termdesc.h:109