1998-02-27 07:54:42 +03:00
|
|
|
/* Mouse managing
|
2007-09-26 14:22:25 +04:00
|
|
|
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006,
|
2009-06-12 14:55:06 +04:00
|
|
|
2007, 2009 Free Software Foundation, Inc.
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2009-06-12 14:55:06 +04:00
|
|
|
Written by:
|
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2009.
|
2010-11-08 13:21:45 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2010-11-08 13:21:45 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file mouse.c
|
|
|
|
* \brief Source: mouse managing
|
|
|
|
*
|
|
|
|
* Events received by clients of this library have their coordinates 0 based
|
|
|
|
*/
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdio.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2009-05-08 14:01:05 +04:00
|
|
|
|
2010-01-07 02:57:27 +03:00
|
|
|
#include "tty.h"
|
2010-11-08 13:21:45 +03:00
|
|
|
#include "tty-internal.h" /* mouse_enabled */
|
2010-01-07 02:57:27 +03:00
|
|
|
#include "mouse.h"
|
2010-11-08 13:21:45 +03:00
|
|
|
#include "key.h" /* define sequence */
|
|
|
|
|
|
|
|
/*** global variables ****************************************************************************/
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2011-02-02 13:43:37 +03:00
|
|
|
Mouse_Type use_mouse_p = MOUSE_NONE;
|
2009-07-13 22:13:19 +04:00
|
|
|
gboolean mouse_enabled = FALSE;
|
2004-08-30 03:27:40 +04:00
|
|
|
const char *xmouse_seq;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-07-13 22:13:19 +04:00
|
|
|
void
|
|
|
|
show_mouse_pointer (int x, int y)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-07-13 22:13:19 +04:00
|
|
|
#ifdef HAVE_LIBGPM
|
|
|
|
if (use_mouse_p == MOUSE_GPM)
|
2009-09-17 02:07:04 +04:00
|
|
|
Gpm_DrawPointer (x, y, gpm_consolefd);
|
2010-02-02 14:44:33 +03:00
|
|
|
#else
|
|
|
|
(void) x;
|
|
|
|
(void) y;
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif /* HAVE_LIBGPM */
|
2009-07-13 22:13:19 +04:00
|
|
|
}
|
2001-09-17 08:43:58 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-07-13 22:13:19 +04:00
|
|
|
void
|
|
|
|
init_mouse (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
switch (use_mouse_p)
|
|
|
|
{
|
2001-09-17 08:43:58 +04:00
|
|
|
#ifdef HAVE_LIBGPM
|
|
|
|
case MOUSE_NONE:
|
2009-09-17 02:07:04 +04:00
|
|
|
use_mouse_p = MOUSE_GPM;
|
|
|
|
break;
|
2001-09-17 08:43:58 +04:00
|
|
|
#endif /* HAVE_LIBGPM */
|
2009-07-13 22:13:19 +04:00
|
|
|
|
2006-03-06 12:28:14 +03:00
|
|
|
case MOUSE_XTERM_NORMAL_TRACKING:
|
|
|
|
case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
|
2009-09-17 02:07:04 +04:00
|
|
|
define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
|
|
|
|
break;
|
2009-07-13 22:13:19 +04:00
|
|
|
|
2001-11-14 21:27:45 +03:00
|
|
|
default:
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2009-07-13 22:13:19 +04:00
|
|
|
|
2001-09-17 08:43:58 +04:00
|
|
|
enable_mouse ();
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-07-13 22:13:19 +04:00
|
|
|
void
|
|
|
|
enable_mouse (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-07-13 22:13:19 +04:00
|
|
|
if (mouse_enabled)
|
2009-09-17 02:07:04 +04:00
|
|
|
return;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
switch (use_mouse_p)
|
|
|
|
{
|
1998-02-27 07:54:42 +03:00
|
|
|
#ifdef HAVE_LIBGPM
|
2001-09-17 08:43:58 +04:00
|
|
|
case MOUSE_GPM:
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
|
|
|
int mouse_d;
|
|
|
|
Gpm_Connect conn;
|
|
|
|
|
|
|
|
conn.eventMask = ~GPM_MOVE;
|
|
|
|
conn.defaultMask = GPM_MOVE;
|
|
|
|
conn.minMod = 0;
|
|
|
|
conn.maxMod = 0;
|
|
|
|
|
|
|
|
mouse_d = Gpm_Open (&conn, 0);
|
|
|
|
if (mouse_d == -1)
|
|
|
|
{
|
|
|
|
use_mouse_p = MOUSE_NONE;
|
|
|
|
return;
|
|
|
|
}
|
2011-08-25 14:15:46 +04:00
|
|
|
mouse_enabled = TRUE;
|
2009-09-17 02:07:04 +04:00
|
|
|
}
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif /* HAVE_LIBGPM */
|
2009-07-13 22:13:19 +04:00
|
|
|
|
2006-03-06 12:28:14 +03:00
|
|
|
case MOUSE_XTERM_NORMAL_TRACKING:
|
2009-09-17 02:07:04 +04:00
|
|
|
/* save old highlight mouse tracking */
|
|
|
|
printf (ESC_STR "[?1001s");
|
2006-03-06 12:28:14 +03:00
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
/* enable mouse tracking */
|
|
|
|
printf (ESC_STR "[?1000h");
|
2006-03-06 12:28:14 +03:00
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
fflush (stdout);
|
|
|
|
mouse_enabled = TRUE;
|
|
|
|
break;
|
2009-07-13 22:13:19 +04:00
|
|
|
|
2006-03-06 12:28:14 +03:00
|
|
|
case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
|
2009-09-17 02:07:04 +04:00
|
|
|
/* save old highlight mouse tracking */
|
|
|
|
printf (ESC_STR "[?1001s");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
/* enable mouse tracking */
|
|
|
|
printf (ESC_STR "[?1002h");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
fflush (stdout);
|
|
|
|
mouse_enabled = TRUE;
|
|
|
|
break;
|
2009-07-13 22:13:19 +04:00
|
|
|
|
2001-11-14 21:27:45 +03:00
|
|
|
default:
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
2001-09-17 08:43:58 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-07-13 22:13:19 +04:00
|
|
|
void
|
|
|
|
disable_mouse (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-07-13 22:13:19 +04:00
|
|
|
if (!mouse_enabled)
|
2009-09-17 02:07:04 +04:00
|
|
|
return;
|
2001-09-17 08:43:58 +04:00
|
|
|
|
2009-07-13 22:13:19 +04:00
|
|
|
mouse_enabled = FALSE;
|
2001-09-17 08:43:58 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
switch (use_mouse_p)
|
|
|
|
{
|
1998-02-27 07:54:42 +03:00
|
|
|
#ifdef HAVE_LIBGPM
|
2001-09-17 08:43:58 +04:00
|
|
|
case MOUSE_GPM:
|
2009-09-17 02:07:04 +04:00
|
|
|
Gpm_Close ();
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif
|
2006-03-06 12:28:14 +03:00
|
|
|
case MOUSE_XTERM_NORMAL_TRACKING:
|
2009-09-17 02:07:04 +04:00
|
|
|
/* disable mouse tracking */
|
|
|
|
printf (ESC_STR "[?1000l");
|
2006-03-06 12:28:14 +03:00
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
/* restore old highlight mouse tracking */
|
|
|
|
printf (ESC_STR "[?1001r");
|
2006-03-06 12:28:14 +03:00
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
fflush (stdout);
|
|
|
|
break;
|
2006-03-06 12:28:14 +03:00
|
|
|
case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
|
2009-09-17 02:07:04 +04:00
|
|
|
/* disable mouse tracking */
|
|
|
|
printf (ESC_STR "[?1002l");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
/* restore old highlight mouse tracking */
|
|
|
|
printf (ESC_STR "[?1001r");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
fflush (stdout);
|
|
|
|
break;
|
2001-11-14 21:27:45 +03:00
|
|
|
default:
|
2009-09-17 02:07:04 +04:00
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|