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
|
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
|
|
|
|
|
|
|
/* 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>
|
2001-09-17 08:43:58 +04:00
|
|
|
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
#include "global.h"
|
2001-09-17 08:43:58 +04:00
|
|
|
#include "tty.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "mouse.h"
|
|
|
|
#include "key.h" /* define sequence */
|
|
|
|
|
2001-09-17 08:43:58 +04:00
|
|
|
int mouse_enabled = 0;
|
2004-08-30 03:27:40 +04:00
|
|
|
const char *xmouse_seq;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBGPM
|
|
|
|
void show_mouse_pointer (int x, int y)
|
|
|
|
{
|
2001-09-17 08:43:58 +04:00
|
|
|
if (use_mouse_p == MOUSE_GPM) {
|
1998-02-27 07:54:42 +03:00
|
|
|
Gpm_DrawPointer (x, y, gpm_consolefd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LIBGPM */
|
2001-09-17 08:43:58 +04:00
|
|
|
|
|
|
|
void init_mouse (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2001-09-17 08:43:58 +04:00
|
|
|
switch (use_mouse_p) {
|
|
|
|
#ifdef HAVE_LIBGPM
|
|
|
|
case MOUSE_NONE:
|
|
|
|
use_mouse_p = MOUSE_GPM;
|
|
|
|
break;
|
|
|
|
#endif /* HAVE_LIBGPM */
|
2006-03-06 12:28:14 +03:00
|
|
|
case MOUSE_XTERM_NORMAL_TRACKING:
|
|
|
|
case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
|
2001-09-17 08:43:58 +04:00
|
|
|
define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
|
|
|
|
break;
|
2001-11-14 21:27:45 +03:00
|
|
|
default:
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2001-09-17 08:43:58 +04:00
|
|
|
enable_mouse ();
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2001-09-17 08:43:58 +04:00
|
|
|
void enable_mouse (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2001-09-17 08:43:58 +04:00
|
|
|
if (mouse_enabled) {
|
|
|
|
return;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2001-09-17 08:43:58 +04: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:
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2001-09-17 08:43:58 +04: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;
|
|
|
|
|
2001-09-17 08:43:58 +04:00
|
|
|
mouse_d = Gpm_Open (&conn, 0);
|
|
|
|
if (mouse_d == -1) {
|
|
|
|
use_mouse_p = MOUSE_NONE;
|
1998-02-27 07:54:42 +03:00
|
|
|
return;
|
2001-09-17 08:43:58 +04:00
|
|
|
}
|
|
|
|
mouse_enabled = 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif /* HAVE_LIBGPM */
|
2006-03-06 12:28:14 +03:00
|
|
|
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:
|
2001-09-17 08:43:58 +04:00
|
|
|
/* save old highlight mouse tracking */
|
|
|
|
printf(ESC_STR "[?1001s");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2001-09-17 08:43:58 +04:00
|
|
|
/* enable mouse tracking */
|
2005-09-28 21:21:53 +04:00
|
|
|
printf(ESC_STR "[?1002h");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2001-09-17 08:43:58 +04:00
|
|
|
fflush (stdout);
|
|
|
|
mouse_enabled = 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
2001-11-14 21:27:45 +03:00
|
|
|
default:
|
|
|
|
break;
|
2001-09-17 08:43:58 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2001-09-17 08:43:58 +04:00
|
|
|
void disable_mouse (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2001-09-17 08:43:58 +04:00
|
|
|
if (!mouse_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mouse_enabled = 0;
|
|
|
|
|
|
|
|
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:
|
1998-02-27 07:54:42 +03:00
|
|
|
Gpm_Close ();
|
|
|
|
break;
|
|
|
|
#endif
|
2006-03-06 12:28:14 +03:00
|
|
|
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:
|
2001-09-17 08:43:58 +04:00
|
|
|
/* disable mouse tracking */
|
2005-09-28 21:21:53 +04:00
|
|
|
printf(ESC_STR "[?1002l");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2001-09-17 08:43:58 +04:00
|
|
|
/* restore old highlight mouse tracking */
|
|
|
|
printf(ESC_STR "[?1001r");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2001-09-17 08:43:58 +04:00
|
|
|
fflush (stdout);
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
2001-11-14 21:27:45 +03:00
|
|
|
default:
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|