/****************************************************************************
- * Copyright (c) 1998-2010,2011 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2013,2014 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.133 2011/10/22 23:01:26 tom Exp $")
+MODULE_ID("$Id: lib_mouse.c,v 1.143 2014/04/26 18:47:20 juergen Exp $")
#include <tic.h>
#undef buttons /* symbol conflict in consio.h */
#undef mouse_info /* symbol conflict in consio.h */
#include <osreldate.h>
-#if (__FreeBSD_version >= 400017)
+#if defined(__DragonFly_version) || (defined(__FreeBSD__) && (__FreeBSD_version >= 400017))
#include <sys/consio.h>
#include <sys/fbio.h>
#else
#endif
#endif /* use_SYSMOUSE */
+#if USE_KLIBC_MOUSE
+#include <sys/socket.h>
+#define pipe(handles) socketpair(AF_LOCAL, SOCK_STREAM, 0, handles)
+#define DosWrite(hfile, pbuffer, cbwrite, pcbactual) \
+ write(hfile, pbuffer, cbwrite)
+#define DosExit(action, result ) /* do nothing */
+#define DosCreateThread(ptid, pfn, param, flag, cbStack) \
+ (*(ptid) = _beginthread(pfn, NULL, cbStack, \
+ (void *)param), (*(ptid) == -1))
+#endif
+
#define MY_TRACE TRACE_ICALLS|TRACE_IEVENT
#define MASK_RELEASE(x) (mmask_t) NCURSES_MOUSE_MASK(x, 001)
char buf[6];
unsigned long ignore;
- strncpy(buf, key_mouse, 3); /* should be "\033[M" */
+ strcpy(buf, "\033[M"); /* 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;
}
static void
+#if USE_KLIBC_MOUSE
+mouse_server(void *param)
+#else
mouse_server(unsigned long param)
+#endif
{
SCREEN *sp = (SCREEN *) param;
unsigned short fWait = MOU_WAIT;
/* sit and wait on the event queue */
rc = MouReadEventQue(&mouev, &fWait, hmou);
if (rc) {
- sprintf(err, "Error reading mouse queue, rc=%lu.\r\n", rc);
+ _nc_SPRINTF(err, _nc_SLIMIT(sizeof(err))
+ "Error reading mouse queue, rc=%lu.\r\n", rc);
break;
}
if (!sp->_emxmouse_activated)
finish:
oldstate = mouev.fs;
}
- } else
- sprintf(err, "Error setting event mask, buttons=%d, rc=%lu.\r\n",
- nbuttons, rc);
+ } else {
+ _nc_SPRINTF(err, _nc_SLIMIT(sizeof(err))
+ "Error setting event mask, buttons=%d, rc=%lu.\r\n",
+ nbuttons, rc);
+ }
DosWrite(2, err, strlen(err), &rc);
MouClose(hmou);
#if USE_EMX_MOUSE
sp->_emxmouse_activated = enable;
#else
- NCURSES_SP_NAME(_nc_putp) (NCURSES_SP_ARGx
- "xterm-mouse",
- TPARM_1(sp->_mouse_xtermcap, enable));
+ NCURSES_PUTP2("xterm-mouse", TPARM_1(sp->_mouse_xtermcap, enable));
#endif
sp->_mouse_active = enable;
}
#if USE_GPM_SUPPORT
static bool
-allow_gpm_mouse(void)
+allow_gpm_mouse(SCREEN *sp)
{
bool result = FALSE;
- /* GPM does printf's without checking if stdout is a terminal */
- if (isatty(fileno(stdout))) {
+#if USE_WEAK_SYMBOLS
+ /* Danger Robinson: do not use dlopen for libgpm if already loaded */
+ if ((Gpm_Wgetch)) {
+ if (!sp->_mouse_gpm_loaded) {
+ T(("GPM library was already dlopen'd, not by us"));
+ }
+ } else
+#endif
+ /* GPM does printf's without checking if stdout is a terminal */
+ if (NC_ISATTY(fileno(stdout))) {
char *list = getenv("NCURSES_GPM_TERMS");
char *env = getenv("TERM");
if (list != 0) {
/* Try gpm first, because gpm may be configured to run in xterm */
#if USE_GPM_SUPPORT
- if (allow_gpm_mouse()) {
+ if (allow_gpm_mouse(sp)) {
if (!sp->_mouse_gpm_loaded) {
#ifdef HAVE_LIBDL
load_gpm_library(sp);
struct mouse_info the_mouse;
char *the_device = 0;
- if (isatty(sp->_ifd))
+ if (NC_ISATTY(sp->_ifd))
the_device = ttyname(sp->_ifd);
if (the_device == 0)
the_device = "/dev/tty";
#endif /* USE_SYSMOUSE */
#ifdef USE_TERM_DRIVER
- CallDriver(sp, initmouse);
+ CallDriver(sp, td_initmouse);
#else
/* we know how to recognize mouse events under "xterm" */
if (key_mouse != 0) {