mc/src/mouse.c

151 lines
3.1 KiB
C
Raw Normal View History

1998-02-27 07:54:42 +03:00
/* Mouse managing
Copyright (C) 1994 Miguel de Icaza.
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.
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
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
1998-02-27 07:54:42 +03:00
/* Events received by clients of this library have their coordinates 0 */
/* based */
#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>
#include "global.h"
#include "tty.h"
1998-02-27 07:54:42 +03:00
#include "mouse.h"
#include "key.h" /* define sequence */
int mouse_enabled = 0;
const char *xmouse_seq;
1998-02-27 07:54:42 +03:00
#ifdef HAVE_LIBGPM
void show_mouse_pointer (int x, int y)
{
if (use_mouse_p == MOUSE_GPM) {
1998-02-27 07:54:42 +03:00
Gpm_DrawPointer (x, y, gpm_consolefd);
}
}
#endif /* HAVE_LIBGPM */
void init_mouse (void)
1998-02-27 07:54:42 +03:00
{
switch (use_mouse_p) {
#ifdef HAVE_LIBGPM
case MOUSE_NONE:
use_mouse_p = MOUSE_GPM;
break;
#endif /* HAVE_LIBGPM */
case MOUSE_XTERM_NORMAL_TRACKING:
case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
break;
default:
break;
1998-02-27 07:54:42 +03:00
}
enable_mouse ();
1998-02-27 07:54:42 +03:00
}
void enable_mouse (void)
1998-02-27 07:54:42 +03:00
{
if (mouse_enabled) {
return;
1998-02-27 07:54:42 +03:00
}
switch (use_mouse_p) {
1998-02-27 07:54:42 +03:00
#ifdef HAVE_LIBGPM
case MOUSE_GPM:
1998-02-27 07:54:42 +03:00
{
int mouse_d;
1998-02-27 07:54:42 +03:00
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;
1998-02-27 07:54:42 +03:00
return;
}
mouse_enabled = 1;
1998-02-27 07:54:42 +03:00
}
break;
#endif /* HAVE_LIBGPM */
case MOUSE_XTERM_NORMAL_TRACKING:
/* save old highlight mouse tracking */
printf(ESC_STR "[?1001s");
/* enable mouse tracking */
printf(ESC_STR "[?1000h");
fflush (stdout);
mouse_enabled = 1;
break;
case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
/* save old highlight mouse tracking */
printf(ESC_STR "[?1001s");
1998-02-27 07:54:42 +03:00
/* enable mouse tracking */
printf(ESC_STR "[?1002h");
1998-02-27 07:54:42 +03:00
fflush (stdout);
mouse_enabled = 1;
1998-02-27 07:54:42 +03:00
break;
default:
break;
}
1998-02-27 07:54:42 +03:00
}
void disable_mouse (void)
1998-02-27 07:54:42 +03:00
{
if (!mouse_enabled) {
return;
}
mouse_enabled = 0;
switch (use_mouse_p) {
1998-02-27 07:54:42 +03:00
#ifdef HAVE_LIBGPM
case MOUSE_GPM:
1998-02-27 07:54:42 +03:00
Gpm_Close ();
break;
#endif
case MOUSE_XTERM_NORMAL_TRACKING:
/* disable mouse tracking */
printf(ESC_STR "[?1000l");
/* restore old highlight mouse tracking */
printf(ESC_STR "[?1001r");
fflush (stdout);
break;
case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
/* disable mouse tracking */
printf(ESC_STR "[?1002l");
1998-02-27 07:54:42 +03:00
/* restore old highlight mouse tracking */
printf(ESC_STR "[?1001r");
1998-02-27 07:54:42 +03:00
fflush (stdout);
1998-02-27 07:54:42 +03:00
break;
default:
break;
1998-02-27 07:54:42 +03:00
}
}