/****************************************************************************
- * Copyright (c) 1998-2015,2016 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2018,2019 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 *
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_mouse.c,v 1.169 2016/05/28 23:11:26 tom Exp $")
+MODULE_ID("$Id: lib_mouse.c,v 1.183 2019/08/10 17:11:50 tom Exp $")
#include <tic.h>
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;
#if USE_WEAK_SYMBOLS
/* Danger Robinson: do not use dlopen for libgpm if already loaded */
- if ((Gpm_Wgetch)) {
+ if ((Gpm_Wgetch) != 0) {
if (!sp->_mouse_gpm_loaded) {
T(("GPM library was already dlopen'd, not by us"));
}
{
sp->_mouse_gpm_found = FALSE;
if ((sp->_dlopen_gpm = dlopen(LIBGPM_SONAME, my_RTLD)) != 0) {
+#if (defined(__GNUC__) && (__GNUC__ >= 5)) || defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpedantic"
+#endif
if (GET_DLSYM(gpm_fd) == 0 ||
GET_DLSYM(Gpm_Open) == 0 ||
GET_DLSYM(Gpm_Close) == 0 ||
GET_DLSYM(Gpm_GetEvent) == 0) {
+#if (defined(__GNUC__) && (__GNUC__ >= 5)) || defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
T(("GPM initialization failed: %s", dlerror()));
unload_gpm_library(sp);
} else {
/* OS/2 VIO */
#if USE_EMX_MOUSE
if (!sp->_emxmouse_thread
- && strstr(TerminalOf(sp)->type.term_names, "xterm") == 0
- && key_mouse) {
+ && strstr(SP_TERMTYPE term_names, "xterm") == 0
+ && NonEmpty(key_mouse)) {
int handles[2];
if (pipe(handles) < 0) {
CallDriver(sp, td_initmouse);
#else
/* we know how to recognize mouse events under "xterm" */
- if (key_mouse != 0) {
- if (!strcmp(key_mouse, xterm_kmous)
- || strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
- init_xterm_mouse(sp);
- }
- } else if (strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) {
+ if (NonEmpty(key_mouse)) {
+ init_xterm_mouse(sp);
+ } else if (strstr(SP_TERMTYPE term_names, "xterm") != 0) {
if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK)
init_xterm_mouse(sp);
}
static bool
decode_xterm_X10(SCREEN *sp, MEVENT * eventp)
{
- unsigned char kbuf[4];
+#define MAX_KBUF 3
+ unsigned char kbuf[MAX_KBUF + 1];
size_t grabbed;
int res;
bool result;
# endif
_nc_globals.read_thread = pthread_self();
# endif
- for (grabbed = 0; grabbed < 3; grabbed += (size_t) res) {
+ for (grabbed = 0; grabbed < MAX_KBUF; grabbed += (size_t) res) {
/* For VIO mouse we add extra bit 64 to disambiguate button-up. */
res = (int) read(
#else
sp->_ifd,
#endif
- kbuf + grabbed, 3 - grabbed);
+ kbuf + grabbed, (size_t) (MAX_KBUF - (int) grabbed));
if (res == -1)
break;
}
#if USE_PTHREADS_EINTR
_nc_globals.read_thread = 0;
#endif
- kbuf[3] = '\0';
+ kbuf[MAX_KBUF] = '\0';
TR(TRACE_IEVENT,
("_nc_mouse_inline sees the following xterm data: '%s'", kbuf));
#else
sp->_ifd,
#endif
- kbuf + grabbed, 1);
+ (kbuf + grabbed), (size_t) 1);
if (res == -1)
break;
grabbed += (size_t) res;
#else
sp->_ifd,
#endif
- kbuf + grabbed, 1);
+ (kbuf + grabbed), (size_t) 1);
if (res == -1)
break;
- if ((grabbed + 3) >= (int) sizeof(kbuf)) {
+ if ((grabbed + MAX_KBUF) >= (int) sizeof(kbuf)) {
result->nerror++;
break;
}
eventp->bstate = REPORT_MOUSE_POSITION;
}
}
+ if (b & 4) {
+ eventp->bstate |= BUTTON_SHIFT;
+ }
+ if (b & 8) {
+ eventp->bstate |= BUTTON_ALT;
+ }
+ if (b & 16) {
+ eventp->bstate |= BUTTON_CTRL;
+ }
result = (eventp->bstate & REPORT_MOUSE_POSITION) ? TRUE : FALSE;
eventp->x = (data.params[1] ? (data.params[1] - 1) : 0);
eventp->y = (data.params[2] ? (data.params[2] - 1) : 0);
NCURSES_SP_NAME(getmouse) (NCURSES_SP_DCLx MEVENT * aevent)
{
int result = ERR;
+ MEVENT *eventp;
T((T_CALLED("getmouse(%p,%p)"), (void *) SP_PARM, (void *) aevent));
- if ((aevent != 0) && (SP_PARM != 0) && (SP_PARM->_mouse_type != M_NONE)) {
- MEVENT *eventp = SP_PARM->_mouse_eventp;
+ if ((aevent != 0) &&
+ (SP_PARM != 0) &&
+ (SP_PARM->_mouse_type != M_NONE) &&
+ (eventp = SP_PARM->_mouse_eventp) != 0) {
/* compute the current-event pointer */
MEVENT *prev = PREV(eventp);
NCURSES_SP_NAME(ungetmouse) (NCURSES_SP_DCLx MEVENT * aevent)
{
int result = ERR;
+ MEVENT *eventp;
T((T_CALLED("ungetmouse(%p,%p)"), (void *) SP_PARM, (void *) aevent));
- if (aevent != 0 && SP_PARM != 0) {
- MEVENT *eventp = SP_PARM->_mouse_eventp;
+ if (aevent != 0 &&
+ SP_PARM != 0 &&
+ (eventp = SP_PARM->_mouse_eventp) != 0) {
/* stick the given event in the next-free slot */
*eventp = *aevent;