Here is a reworked version of the GPM support. This is equivalent
functionality-wise to the current implementation, but does not sink its
teeth into all the console and event loops like the old one.
You can also choose whether or not you want GPM to be on by the new
function:
-----------------
`gpm-mode' is a built-in function
(gpm-mode &optional ARG)
Documentation:
Start accepting GPM mouse events iff ARG is positive.
-----------------
This works a lot like the tooltalk support. When gpm-mode is turned on, it
calls Gpm_Open to get the file descriptor, sticks it into the
lisp-accessible variable 'gpm-fd', connects a process object to the fd, and
sets the process filter to read the GPM events, and sticks the button
events into the unread-command-events variable, and dispatches movement
events via Fdispatch_event.
This should make the GPM code much more stable/useful (I like being able to
turn it off temporarily if I want to cut/paste something between virtual
consoles, not just XEmacs frames).
No need to worry about selecting the same FD multiple times if you open
multiple TTY devices, etc.
The only drawback to doing it this way is that the GPM pointer cannot be
seen very well. If anybody has ideas on how to fix that, other than having
XEmacs draw it as part of redisplay, please let me know.
-Bill P.
Index: src/console-tty.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/console-tty.c,v
retrieving revision 1.18.2.5
diff -u -w -r1.18.2.5 console-tty.c
--- console-tty.c 1999/10/24 03:48:31 1.18.2.5
+++ console-tty.c 1999/11/04 16:32:06
@@ -38,9 +38,6 @@
#ifdef FILE_CODING
#include "file-coding.h"
#endif
-#ifdef HAVE_GPM
-#include "gpmevent.h"
-#endif
DEFINE_CONSOLE_TYPE (tty);
DECLARE_IMAGE_INSTANTIATOR_FORMAT (nothing);
@@ -129,10 +126,6 @@
#endif /* MULE */
tty_con->terminal_type = terminal_type;
tty_con->controlling_process = controlling_process;
-
-#ifdef HAVE_GPM
- connect_to_gpm (con);
-#endif
if (NILP (CONSOLE_NAME (con)))
CONSOLE_NAME (con) = Ffile_name_nondirectory (tty);
Index: src/console-tty.h
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/console-tty.h,v
retrieving revision 1.8.2.2
diff -u -w -r1.8.2.2 console-tty.h
--- console-tty.h 1999/02/17 20:03:57 1.8.2.2
+++ console-tty.h 1999/11/04 16:32:09
@@ -41,9 +41,6 @@
struct tty_console
{
int infd, outfd;
-#ifdef HAVE_GPM
- int mouse_fd;
-#endif
Lisp_Object instream, outstream;
Lisp_Object terminal_type;
Lisp_Object controlling_process;
@@ -203,9 +200,6 @@
unsigned int is_stdio :1;
};
-#ifdef HAVE_GPM
-#define CONSOLE_TTY_MOUSE_FD(c) (CONSOLE_TTY_DATA (c)->mouse_fd)
-#endif
#define CONSOLE_TTY_DATA(c) CONSOLE_TYPE_DATA (c, tty)
#define CONSOLE_TTY_CURSOR_X(c) (CONSOLE_TTY_DATA (c)->cursor_x)
#define CONSOLE_TTY_CURSOR_Y(c) (CONSOLE_TTY_DATA (c)->cursor_y)
Index: src/device-tty.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/device-tty.c,v
retrieving revision 1.9
diff -u -w -r1.9 device-tty.c
--- device-tty.c 1998/05/27 20:42:00 1.9
+++ device-tty.c 1999/11/04 16:32:38
@@ -38,10 +38,6 @@
#include "syssignal.h" /* for SIGWINCH */
-#ifdef HAVE_GPM
-#include <gpm.h>
-#endif
-
#include <errno.h>
Lisp_Object Qinit_pre_tty_win, Qinit_post_tty_win;
@@ -155,15 +151,6 @@
CONSOLE_TTY_DATA (con)->width = width;
CONSOLE_TTY_DATA (con)->height = height;
-#ifdef HAVE_GPM
- /* We need to tell GPM how big our screen is now
- ** I am pretty sure the GPM library will get incredibly confused
- ** if you try to connect to more than one mouse-capable device,
- ** so I don't think it will cause any more damage in that case.
- */
- gpm_mx = width;
- gpm_my = height;
-#endif
for (tail = DEVICE_FRAME_LIST (d);
!NILP (tail);
tail = XCDR (tail))
Index: src/emacs.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/emacs.c,v
retrieving revision 1.82.2.32
diff -u -w -r1.82.2.32 emacs.c
--- emacs.c 1999/11/02 02:41:45 1.82.2.32
+++ emacs.c 1999/11/04 16:32:57
@@ -1088,6 +1088,10 @@
syms_of_eldap ();
#endif
+#ifdef HAVE_GPM
+ syms_of_gpmevent ();
+#endif
+
/* Now create the subtypes for the types that have them.
We do this before the vars_*() because more symbols
may get initialized here. */
@@ -1481,6 +1485,10 @@
#ifdef HAVE_LDAP
vars_of_eldap ();
+#endif
+
+#ifdef HAVE_GPM
+ vars_of_gpmevent ();
#endif
/* Now initialize any specifier variables. We do this later
Index: src/event-Xt.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/event-Xt.c,v
retrieving revision 1.41.2.14
diff -u -w -r1.41.2.14 event-Xt.c
--- event-Xt.c 1999/10/10 11:45:15 1.41.2.14
+++ event-Xt.c 1999/11/04 16:33:05
@@ -2034,9 +2034,6 @@
{
Lisp_Object console;
int infd;
-#ifdef HAVE_GPM
- int mousefd;
-#endif
if (CONSOLE_X_P (con))
return; /* X consoles are automatically selected for when we
@@ -2044,32 +2041,13 @@
infd = event_stream_unixoid_select_console (con);
XSETCONSOLE (console, con);
select_filedesc (infd, console);
-#ifdef HAVE_GPM
- /* On a stream device (ie: noninteractive), bad things can happen. */
- if (EQ (CONSOLE_TYPE (con), Qtty)) {
- mousefd = CONSOLE_TTY_MOUSE_FD (con);
- /* We check filedesc_to_what_closure[fd] here because if you run
- ** XEmacs from a TTY, it will fire up GPM, select the mouse fd, then
- ** if you run gnuattach to connect to another TTY, it will fire up
- ** GPM again, and try to reselect the mouse fd. GPM uses the same
- ** fd for every connection apparently, and select_filedesc will
- ** fail its assertion if we try to select it twice.
- */
- if ((mousefd >= 0) && !filedesc_to_what_closure[mousefd]) {
- select_filedesc (mousefd, console);
}
- }
-#endif
-}
static void
emacs_Xt_unselect_console (struct console *con)
{
Lisp_Object console;
int infd;
-#ifdef HAVE_GPM
- int mousefd;
-#endif
if (CONSOLE_X_P (con))
return; /* X consoles are automatically selected for when we
@@ -2077,15 +2055,6 @@
infd = event_stream_unixoid_unselect_console (con);
XSETCONSOLE (console, con);
unselect_filedesc (infd);
-#ifdef HAVE_GPM
- /* On a stream device (ie: noninteractive), bad things can happen. */
- if (EQ (CONSOLE_TYPE (con), Qtty)) {
- mousefd = CONSOLE_TTY_MOUSE_FD (con);
- if (mousefd >= 0) {
- unselect_filedesc (mousefd);
- }
- }
-#endif
}
/* read an event from a tty, if one is available. Returns non-zero
Index: src/event-unixoid.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/event-unixoid.c,v
retrieving revision 1.9.2.1
diff -u -w -r1.9.2.1 event-unixoid.c
--- event-unixoid.c 1999/03/07 15:25:17 1.9.2.1
+++ event-unixoid.c 1999/11/04 16:33:05
@@ -41,10 +41,6 @@
#include "sysproc.h" /* select stuff */
#include "systime.h"
-#ifdef HAVE_GPM
-#include "gpmevent.h"
-#endif
-
/* Mask of bits indicating the descriptors that we wait for input on.
These work as follows:
@@ -83,12 +79,6 @@
Lisp_Object console;
XSETCONSOLE (console, con);
-
-#ifdef HAVE_GPM
- if (fd == CONSOLE_TTY_MOUSE_FD (con)) {
- return handle_gpm_read (event,con,fd);
- }
-#endif
nread = read (fd, &ch, 1);
if (nread <= 0)
Index: src/frame-tty.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/frame-tty.c,v
retrieving revision 1.8.2.1
diff -u -w -r1.8.2.1 frame-tty.c
--- frame-tty.c 1998/12/05 16:55:48 1.8.2.1
+++ frame-tty.c 1999/11/04 16:33:05
@@ -33,11 +33,7 @@
#include "events.h"
-#ifdef HAVE_GPM
-#include <gpm.h>
-#endif
-
/* Default properties to use when creating frames. */
Lisp_Object Vdefault_tty_frame_plist;
@@ -86,33 +82,6 @@
call1 (Qinit_post_tty_win, FRAME_CONSOLE (f));
}
-#ifdef HAVE_GPM
-static int
-tty_get_mouse_position (struct device *d, Lisp_Object *frame, int *x, int *y)
-{
- Gpm_Event ev;
- int num_buttons;
-
- num_buttons = Gpm_GetSnapshot(&ev);
- *x = ev.x;
- *y = ev.y;
- *frame = DEVICE_SELECTED_FRAME (d);
- return (1);
-}
-
-static void
-tty_set_mouse_position (struct window *w, int x, int y)
-{
- /* XXX
- I couldn't find any GPM functions that set the mouse position.
- Mr. Perry had left this function empty; that must be why.
- karlheg
- */
-}
-
-#endif
-
-
/* Change from withdrawn state to mapped state. */
static void
tty_make_frame_visible (struct frame *f)
@@ -223,10 +192,6 @@
CONSOLE_HAS_METHOD (tty, init_frame_1);
CONSOLE_HAS_METHOD (tty, init_frame_3);
CONSOLE_HAS_METHOD (tty, after_init_frame);
-#ifdef HAVE_GPM
- CONSOLE_HAS_METHOD (tty, get_mouse_position);
- CONSOLE_HAS_METHOD (tty, set_mouse_position);
-#endif
CONSOLE_HAS_METHOD (tty, make_frame_visible);
CONSOLE_HAS_METHOD (tty, make_frame_invisible);
CONSOLE_HAS_METHOD (tty, frame_visible_p);
Index: src/gpmevent.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/gpmevent.c,v
retrieving revision 1.5
diff -u -w -r1.5 gpmevent.c
--- gpmevent.c 1998/03/31 20:11:47 1.5
+++ gpmevent.c 1999/11/04 16:33:07
@@ -1,5 +1,28 @@
-/* William Perry 1997 */
+/* GPM functions
+ Copyright (C) 1997 William M. Perry <wmperry(a)gnu.org>
+ Copyright (C) 1999 Free Software Foundation, Inc.
+
+This file is part of XEmacs.
+
+XEmacs 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, or (at your option) any
+later version.
+
+XEmacs 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 XEmacs; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+/* Synched up with: Not in FSF. */
+
+/* Authors: William Perry */
+
#include <config.h>
#include "lisp.h"
#include "console.h"
@@ -8,11 +31,16 @@
#include "events.h"
#include "events-mod.h"
#include "sysdep.h"
+#include "commands.h"
#ifdef HAVE_GPM
#include "gpmevent.h"
#include <gpm.h>
+/* This is commented out in commands.h, I'm not sure why */
+extern Lisp_Object Vunread_command_events;
+extern Lisp_Object Vunread_command_event;
+
#if (!defined(__linux__)) /* possible under xterm */
#define KG_SHIFT 0
#define KG_CTRL 2
@@ -21,19 +49,38 @@
#include <linux/keyboard.h>
#endif
-int
-handle_gpm_read (struct Lisp_Event *event, struct console *con, int fd)
+Lisp_Object Vgpm_fd;
+
+DEFUN ("receive-gpm-event", Freceive_gpm_event, 0, 2, 0, /*
+Run GPM_GetEvent().
+This function is the process handler for the GPM connection.
+*/
+ (ignore1, ignore2))
{
Gpm_Event ev;
int modifiers = 0;
int type = -1;
int button = 1;
+ Lisp_Object fake_event;
+ struct Lisp_Event *event = NULL;
+ struct gcpro gcpro1;
+ static int num_events;
if (!Gpm_GetEvent(&ev))
- return 0;
+ {
+ warn_when_safe (Qnil, Qcritical, "Gpm_GetEvent failed");
+ return(Qzero);
+ }
+
+ GCPRO1(fake_event);
+
+ num_events++;
+ fake_event = Fmake_event (Qnil, Qnil);
+ event = XEVENT(fake_event);
+
event->timestamp = 0;
- event->channel = CONSOLE_SELECTED_FRAME (con);
+ event->channel = Fselected_frame (Qnil); /* CONSOLE_SELECTED_FRAME (co
n); */
/* Whow, wouldn't named defines be NICE!?!?! */
modifiers = 0;
@@ -44,20 +91,30 @@
if (ev.modifiers & 8) modifiers |= MOD_META;
if (ev.type & GPM_DOWN)
+ {
type = GPM_DOWN;
+ }
else if (ev.type & GPM_UP)
+ {
type = GPM_UP;
- else if (ev.type & GPM_MOVE) {
+ }
+ else if (ev.type & GPM_MOVE)
+ {
type = GPM_MOVE;
- GPM_DRAWPOINTER(&ev);
}
if (ev.buttons & GPM_B_LEFT)
+ {
button = 1;
+ }
else if (ev.buttons & GPM_B_MIDDLE)
+ {
button = 2;
+ }
else if (ev.buttons & GPM_B_RIGHT)
+ {
button = 3;
+ }
switch (type) {
case GPM_DOWN:
@@ -75,21 +132,130 @@
event->event.motion.y = ev.y;
event->event.motion.modifiers = modifiers;
default:
- return 0;
+ /* This will never happen */
+ break;
+ }
+
+ /* Handle the event */
+#if 0
+ /* dispatching it directly doesn't seem to work well */
+ Fdispatch_event (fake_event);
+#else
+ /* Let's try sticking it on the unread events queue */
+ if (!command_event_p (fake_event))
+ {
+ /* unread_command_events does not like motion events */
+ Fdispatch_event (fake_event);
+ }
+ else if (NILP (Vunread_command_events))
+ {
+ Vunread_command_events = Fcons (fake_event, Qnil);
+ }
+ else
+ {
+ Lisp_Object arg[2];
+ arg[0] = Vunread_command_events;
+ arg[1] = fake_event;
+
+ Vunread_command_events = Fappend (2,arg);
+ }
+#endif
+ GPM_DRAWPOINTER(&ev);
+
+ UNGCPRO;
+
+ return (Qzero);
+}
+
+static void turn_off_gpm (void)
+{
+ Fdelete_process (build_string ("gpm"));
+ Gpm_Close();
+ Vgpm_fd = Qnil;
+
+ /* Remove the TTY mouse methods */
+ /* This is breaking abstraction a bit, but... */
+ tty_console_methods->get_mouse_position_method = NULL;
+ tty_console_methods->set_mouse_position_method = NULL;
+}
+
+/* This function appears to work once in a blue moon. I'm not sure
+** exactly why either. *sigh*
+** wmperry Nov 4, 1999
+*/
+static int
+tty_get_mouse_position (struct device *d, Lisp_Object *frame, int *x, int *y)
+{
+ Gpm_Event ev;
+ int num_buttons;
+
+ memset(&ev,'\0',sizeof(ev));
+ num_buttons = Gpm_GetSnapshot(&ev);
+
+ if (!num_buttons)
+ {
+ /* This means there are events pending... */
+ return(-1);
}
- return 1;
+ *x = ev.x;
+ *y = ev.y;
+ *frame = DEVICE_SELECTED_FRAME (d);
+ return (1);
+}
+
+static void
+tty_set_mouse_position (struct window *w, int x, int y)
+{
+ /* XXX
+ I couldn't find any GPM functions that set the mouse position.
+ Mr. Perry had left this function empty; that must be why.
+ karlheg
+ */
}
-void
-connect_to_gpm (struct console *con)
+DEFUN ("gpm-mode", Fgpm_mode, 0, 1, 0, /*
+Start accepting GPM mouse events iff ARG is positive.
+*/
+ (arg))
{
- /* Only do this if we are running after dumping and really interactive */
- if (!noninteractive && initialized) {
- /* We really only want to do this on a TTY */
- CONSOLE_TTY_MOUSE_FD (con) = -1;
- if (EQ (CONSOLE_TYPE (con), Qtty)) {
Gpm_Connect conn;
int rval;
+ Lisp_Object gpm_process;
+ Lisp_Object gpm_filter;
+
+ if (NILP (arg))
+ {
+ /* Toggle current GPM mode */
+ if (!NILP (Vgpm_fd))
+ {
+ /* Need to turn it off */
+ turn_off_gpm ();
+ return (Qnil);
+ }
+ }
+ else
+ {
+ int i;
+
+ CHECK_INT (arg);
+
+ i = XINT (arg);
+
+ if (i < 0)
+ {
+ turn_off_gpm ();
+ return (Qnil);
+ }
+ }
+
+ if (!NILP (Vgpm_fd))
+ {
+ error ("Already connected to GPM");
+ }
+
+ /* Install the mouse position methods for the TTY console type */
+ CONSOLE_HAS_METHOD (tty, get_mouse_position);
+ CONSOLE_HAS_METHOD (tty, set_mouse_position);
conn.eventMask = GPM_DOWN|GPM_UP|GPM_MOVE;
conn.defaultMask = GPM_MOVE;
@@ -97,6 +263,7 @@
conn.maxMod = ((1<<KG_SHIFT)|(1<<KG_ALT)|(1<<KG_CTRL));
rval = Gpm_Open (&conn, 0);
+
switch (rval) {
case -1: /* General failure */
break;
@@ -105,10 +272,39 @@
break;
default:
set_descriptor_non_blocking (gpm_fd);
- CONSOLE_TTY_MOUSE_FD (con) = gpm_fd;
+ Vgpm_fd = make_int(gpm_fd);
+ gpm_process = connect_to_file_descriptor (build_string ("gpm"),
Qnil,
+
Vgpm_fd, Vgpm_fd);
+
+ if (!NILP (gpm_process))
+ {
+ Fprocess_kill_without_query (gpm_process, Qnil);
+ XSETSUBR (gpm_filter, &SFreceive_gpm_event);
+ set_process_filter (gpm_process, gpm_filter, 1);
}
+ else
+ {
+ Gpm_Close();
+ Vgpm_fd = Qnil;
}
}
+ return(Vgpm_fd);
}
-#endif
+void vars_of_gpmevent (void)
+{
+ Fprovide (intern ("gpm"));
+
+ DEFVAR_LISP ("gpm-fd", &Vgpm_fd /*
+File descriptor returned by Gpm_Open; nil if not connected to GPM.
+*/ );
+ Vgpm_fd = Qnil;
+}
+
+void syms_of_gpmevent (void)
+{
+ DEFSUBR (Freceive_gpm_event);
+ DEFSUBR (Fgpm_mode);
+}
+
+#endif /* HAVE_GPM */
Index: src/symsinit.h
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/src/symsinit.h,v
retrieving revision 1.31.2.13
diff -u -w -r1.31.2.13 symsinit.h
--- symsinit.h 1999/10/30 03:00:51 1.31.2.13
+++ symsinit.h 1999/11/04 16:33:08
@@ -148,6 +148,7 @@
void syms_of_window (void);
void syms_of_xselect (void);
void syms_of_eldap (void);
+void syms_of_gpmevent (void);
/* Initialize the console types (dump-time but for reinit_). */
@@ -368,6 +369,7 @@
void vars_of_xselect (void);
void reinit_vars_of_xselect (void);
void vars_of_eldap (void);
+void vars_of_gpmevent (void);
/* Initialize specifier variables (dump-time only). */