X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Flib_mouse.c;h=43b0069a8a8b38ff90900ee69af6a69e5be91064;hp=60bf488c8c6464c619e10ac4244e6a89c1474e20;hb=e2e9c09c48b19b24979cafb2d4864f538b5ddd1c;hpb=a84fd46191c61f1151a7258e1539b89c395e61f9 diff --git a/ncurses/base/lib_mouse.c b/ncurses/base/lib_mouse.c index 60bf488c..43b0069a 100644 --- a/ncurses/base/lib_mouse.c +++ b/ncurses/base/lib_mouse.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc. * + * Copyright (c) 1998-2015,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -84,7 +84,7 @@ #define CUR SP_TERMTYPE #endif -MODULE_ID("$Id: lib_mouse.c,v 1.165 2014/11/01 12:27:59 tom Exp $") +MODULE_ID("$Id: lib_mouse.c,v 1.170 2016/09/10 18:36:08 tom Exp $") #include @@ -225,7 +225,7 @@ write_event(SCREEN *sp, int down, int button, int x, int y) char buf[6]; unsigned long ignore; - strcpy(buf, "\033[M"); /* should be the same as key_mouse */ + _nc_STRCPY(buf, "\033[M", sizeof(buf)); /* should be the same as key_mouse */ buf[3] = ' ' + (button - 1) + (down ? 0 : 0x40); buf[4] = ' ' + x - LEFT_COL + 1; buf[5] = ' ' + y - TOP_ROW + 1; @@ -641,13 +641,14 @@ initialize_mousetype(SCREEN *sp) #if USE_SYSMOUSE { + static char dev_tty[] = "/dev/tty"; struct mouse_info the_mouse; char *the_device = 0; if (NC_ISATTY(sp->_ifd)) the_device = ttyname(sp->_ifd); if (the_device == 0) - the_device = "/dev/tty"; + the_device = dev_tty; sp->_mouse_fd = open(the_device, O_RDWR); @@ -727,10 +728,11 @@ _nc_mouse_init(SCREEN *sp) /* initialize the mouse */ { bool result = FALSE; - int i; if (sp != 0) { if (!sp->_mouse_initialized) { + int i; + sp->_mouse_initialized = TRUE; TR(MY_TRACE, ("_nc_mouse_init() called")); @@ -888,7 +890,7 @@ _nc_mouse_event(SCREEN *sp) do { \ eventp->bstate = MASK_PRESS(n); \ sp->_mouse_bstate |= MASK_PRESS(n); \ - if (kbuf[0] & 0x40) { \ + if (button & 0x40) { \ eventp->bstate = MASK_RELEASE(n); \ sp->_mouse_bstate &= ~MASK_PRESS(n); \ } \ @@ -896,7 +898,7 @@ _nc_mouse_event(SCREEN *sp) #else #define PRESS_POSITION(n) \ do { \ - eventp->bstate = (mmask_t) (sp->_mouse_bstate & MASK_PRESS(n) \ + eventp->bstate = (mmask_t) ((sp->_mouse_bstate & MASK_PRESS(n)) \ ? REPORT_MOUSE_POSITION \ : MASK_PRESS(n)); \ sp->_mouse_bstate |= MASK_PRESS(n); \ @@ -946,11 +948,11 @@ static bool decode_X10_bstate(SCREEN *sp, MEVENT * eventp, unsigned intro) { bool result; - int b; eventp->bstate = 0; if (!handle_wheel(sp, eventp, (int) intro, (intro & 96) == 96)) { + /* * Release events aren't reported for individual buttons, just for * the button set as a whole. However, because there are normally @@ -959,6 +961,8 @@ decode_X10_bstate(SCREEN *sp, MEVENT * eventp, unsigned intro) * the previous event. */ if (sp->_mouse_bstate & BUTTON_PRESSED) { + int b; + eventp->bstate = BUTTON_RELEASED; for (b = 1; b <= MAX_BUTTONS; ++b) { if (!(sp->_mouse_bstate & MASK_PRESS(b))) @@ -1074,7 +1078,6 @@ decode_xterm_1005(SCREEN *sp, MEVENT * eventp) size_t grabbed; size_t limit = (sizeof(kbuf) - 1); unsigned coords[2]; - int res; bool result; coords[0] = 0; @@ -1087,6 +1090,7 @@ decode_xterm_1005(SCREEN *sp, MEVENT * eventp) _nc_globals.read_thread = pthread_self(); # endif for (grabbed = 0; grabbed < limit;) { + int res; res = (int) read( #if USE_EMX_MOUSE @@ -1101,8 +1105,10 @@ decode_xterm_1005(SCREEN *sp, MEVENT * eventp) if (grabbed > 1) { size_t check = 1; int n; - int rc; + for (n = 0; n < 2; ++n) { + int rc; + if (check >= grabbed) break; rc = _nc_conv_to_utf32(&coords[n], kbuf + check, (unsigned) @@ -1156,7 +1162,6 @@ read_SGR(SCREEN *sp, SGR_DATA * result) { char kbuf[80]; /* bigger than any possible mouse response */ int grabbed = 0; - int res; int ch = 0; int now = -1; int marker = 1; @@ -1168,7 +1173,10 @@ read_SGR(SCREEN *sp, SGR_DATA * result) # endif _nc_globals.read_thread = pthread_self(); # endif + do { + int res; + res = (int) read( #if USE_EMX_MOUSE (M_FD(sp) >= 0) ? M_FD(sp) : sp->_ifd, @@ -1248,7 +1256,6 @@ decode_xterm_SGR1006(SCREEN *sp, MEVENT * eventp) int b = data.params[0]; int b3 = 1 + (b & 3); - result = TRUE; eventp->id = NORMAL_EVENT; if (data.final == 'M') { (void) handle_wheel(sp, eventp, b, (b & 64) == 64); @@ -1824,7 +1831,6 @@ NCURSES_SP_NAME(mousemask) (NCURSES_SP_DCLx mmask_t newmask, mmask_t * oldmask) /* set the mouse event mask */ { mmask_t result = 0; - int b; T((T_CALLED("mousemask(%p,%#lx,%p)"), (void *) SP_PARM, @@ -1837,7 +1843,10 @@ NCURSES_SP_NAME(mousemask) (NCURSES_SP_DCLx mmask_t newmask, mmask_t * oldmask) if (newmask || SP_PARM->_mouse_initialized) { _nc_mouse_init(SP_PARM); + if (SP_PARM->_mouse_type != M_NONE) { + int b; + result = newmask & (REPORT_MOUSE_POSITION | BUTTON_ALT