From xemacs-m  Sat May 10 15:10:52 1997
Received: from newman.aventail.com (root@newman.aventail.com [199.238.236.1])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id PAA20798
	for <xemacs-beta@xemacs.org>; Sat, 10 May 1997 15:10:51 -0500 (CDT)
Received: from kramer.in.aventail.com.aventail.com (wmperry@[192.168.1.12])
	by newman.aventail.com (8.8.5/8.8.5) with SMTP id NAA08982;
	Sat, 10 May 1997 13:10:48 -0700 (PDT)
To: "Karl M. Hegbloom" <karlheg@inetarena.com>
Cc: <xemacs-beta@xemacs.org>
Subject: Re: GPM patch: Crash report, semi success
References: <199705100125.SAA25045@bittersweet.inetarena.com>
Errors-to: wmperry@aventail.com
Reply-to: wmperry@aventail.com
X-Face: O~Rn;(l][/-o1sALg4A@xpE:9-"'IR[%;,,!m7</SYF`{vYQ(&RI1&EiH[FvT;J}@f!4kfz
 x_!Y#=y{Uuj9GvUi=cPuajQ(Z42R[wE@{G,sn$qGr5g/wnb*"*ktI+,CD}1Z'wxrM2ag-r0p5I6\nA
 [WJopW_J.WY;
From: wmperry@aventail.com (William M. Perry)
Date: 10 May 1997 13:10:48 -0700
In-Reply-To: "Karl M. Hegbloom"'s message of Fri, 9 May 1997 18:25:51 -0700
Message-ID: <86n2q3yto7.fsf@kramer.in.aventail.com>
Lines: 636
X-Mailer: Gnus v5.4.49/Emacs 19.34

"Karl M. Hegbloom" <karlheg@inetarena.com> writes:

>  `make` worked, and the resulting xemacs has mouse mostly working on a
> Linux console tty.  XTerm doesn't work yet... but you know that
> already.
> 
>  You probably know about this too:
> 
>  `make all-elc` fails with a segmentation fault.  Here's some debugger
> output that I am mostly clueless about.  I think that the #2 frame's
> 0xbfffe1f8 is meaningful, but I don't know what it means.  Is it?
> 
>  I need to get back to the bind and sendmail books; I've killed enough 
> time today with this. :-)

  Any non-interactive use would crash.  mousefd was uninitialized if you
were on a stream console (ie: noninteractive).  Try this new set of
patches.

-Bill P.

*** src/Makefile.in.in.orig	Fri May  2 17:26:39 1997
--- src/Makefile.in.in	Fri May  9 11:23:53 1997
***************
*** 418,423 ****
--- 418,430 ----
  JPEG_LIBS = -ljpeg
  #endif
  
+ #ifdef HAVE_GPM
+ GPM_LIBS = -lgpm
+ #define GPM_OBJS gpmevent.o
+ #else /* not HAVE_GPM */
+ #define GPM_OBJS
+ #endif /* not HAVE_GPM */
+ 
  #define NO_GNU_LINKER
  
  #ifdef DYNODUMP
***************
*** 895,900 ****
--- 902,908 ----
  	TOOLBAR_OBJS TOOLTALK_OBJS TTY_OBJS \
  	undo.o UNEXEC \
  	XOBJS XMU_OBJS BALLOONOBJS \
+ 	GPM_OBJS \
  	window.o
  
  #ifdef HAVE_TTY
***************
*** 1250,1256 ****
  	LIB_TOOLTALK $(LIBX) \
  	LIBS_SYSTEM LIBS_MACHINE LIBS_TERMCAP \
  	LIB_CANNA LIB_WNN LIB_INTL QUANTIFY_LIBS $(LIB_KSTAT) \
! 	DATABASE_LIBS LIBS_DEBUG $(GNULIB_VAR) LIB_MATH LIB_STANDARD \
  	$(GNULIB_VAR)
  
  /* Enable recompilation of certain other files depending on system type.  */
--- 1258,1265 ----
  	LIB_TOOLTALK $(LIBX) \
  	LIBS_SYSTEM LIBS_MACHINE LIBS_TERMCAP \
  	LIB_CANNA LIB_WNN LIB_INTL QUANTIFY_LIBS $(LIB_KSTAT) \
! 	DATABASE_LIBS $(GPM_LIBS) LIBS_DEBUG $(GNULIB_VAR) \
! 	LIB_MATH LIB_STANDARD \
  	$(GNULIB_VAR)
  
  /* Enable recompilation of certain other files depending on system type.  */
*** src/config.h.in.orig	Wed Apr  9 22:56:31 1997
--- src/config.h.in	Fri May  9 11:23:53 1997
***************
*** 218,223 ****
--- 218,226 ----
  #undef UNEXEC_SRC
  #undef AIX_SMT_EXP
  
+ /* Define HAVE_GPM if you have the 'gpm' library and want XEmacs to use it */
+ #undef HAVE_GPM
+ 
  /* Do you have the `socks' library and want XEmacs to use it? */
  #undef HAVE_SOCKS
  
*** src/console-tty.c.orig	Sat Mar  8 15:27:42 1997
--- src/console-tty.c	Fri May  9 11:23:53 1997
***************
*** 127,132 ****
--- 127,135 ----
  #endif /* MULE */
    CONSOLE_TTY_DATA (con)->terminal_type = terminal_type;
    CONSOLE_TTY_DATA (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);
    {
*** src/console-tty.h.orig	Thu Apr 10 19:10:31 1997
--- src/console-tty.h	Fri May  9 11:23:53 1997
***************
*** 41,46 ****
--- 41,49 ----
  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;
***************
*** 195,200 ****
--- 198,206 ----
  };
  
  #define CONSOLE_TTY_DATA(c) CONSOLE_TYPE_DATA (c, tty)
+ #ifdef HAVE_GPM
+ #define CONSOLE_TTY_MOUSE_FD(c) (CONSOLE_TTY_DATA (c)->mouse_fd)
+ #endif
  #define CONSOLE_TTY_CURSOR_X(c) (CONSOLE_TTY_DATA (c)->cursor_x)
  #define CONSOLE_TTY_CURSOR_Y(c) (CONSOLE_TTY_DATA (c)->cursor_y)
  #define CONSOLE_TTY_REAL_CURSOR_X(c) (CONSOLE_TTY_DATA (c)->real_cursor_x)
*** src/event-Xt.c.orig	Sun Apr 27 12:30:58 1997
--- src/event-Xt.c	Sat May 10 13:08:21 1997
***************
*** 1728,1734 ****
  emacs_Xt_select_console (struct console *con)
  {
    Lisp_Object console = Qnil;
!   int infd;
  
    if (CONSOLE_X_P (con))
      return; /* X consoles are automatically selected for when we
--- 1728,1734 ----
  emacs_Xt_select_console (struct console *con)
  {
    Lisp_Object console = Qnil;
!   int infd,mousefd;
  
    if (CONSOLE_X_P (con))
      return; /* X consoles are automatically selected for when we
***************
*** 1736,1748 ****
    infd = event_stream_unixoid_select_console (con);
    XSETCONSOLE (console, con);
    select_filedesc (infd, console);
  }
  
  static void
  emacs_Xt_unselect_console (struct console *con)
  {
    Lisp_Object console = Qnil;
!   int infd;
  
    if (CONSOLE_X_P (con))
      return; /* X consoles are automatically selected for when we
--- 1736,1757 ----
    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);
+     if (mousefd >= 0) {
+       select_filedesc (mousefd, console);
+     }
+   }
+ #endif
  }
  
  static void
  emacs_Xt_unselect_console (struct console *con)
  {
    Lisp_Object console = Qnil;
!   int infd,mousefd;
  
    if (CONSOLE_X_P (con))
      return; /* X consoles are automatically selected for when we
***************
*** 1750,1755 ****
--- 1759,1773 ----
    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
*** src/event-unixoid.c.orig	Wed Dec 18 14:44:10 1996
--- src/event-unixoid.c	Fri May  9 11:23:53 1997
***************
*** 39,44 ****
--- 39,49 ----
  #include "sysproc.h"		/* select stuff */
  #include "systime.h"
  
+ #ifdef HAVE_GPM
+ #include "gpmevent.h"
+ #include <gpm.h>
+ #endif
+ 
  /* Mask of bits indicating the descriptors that we wait for input on.
     These work as follows:
  
***************
*** 77,82 ****
--- 82,93 ----
    Lisp_Object console = Qnil;
  
    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)
*** src/frame-tty.c.orig	Sat Mar  8 15:27:47 1997
--- src/frame-tty.c	Fri May  9 11:23:53 1997
***************
*** 33,38 ****
--- 33,42 ----
  #include "console-tty.h"
  #include "frame.h"
  
+ #ifdef HAVE_GPM
+ #include <gpm.h>
+ #endif
+ 
  Lisp_Object Vdefault_tty_frame_plist;
  
  static void
***************
*** 62,67 ****
--- 66,97 ----
        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)
***************
*** 97,102 ****
--- 127,136 ----
  {
    CONSOLE_HAS_METHOD (tty, init_frame_1);
    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);
*** src/gpmevent.c.orig	Fri May  9 11:23:53 1997
--- src/gpmevent.c	Sat May 10 13:08:50 1997
***************
*** 0 ****
--- 1,113 ----
+ /* William Perry 1997 */
+ 
+ #include <config.h>
+ #include "lisp.h"
+ #include "console-tty.h"
+ #include "device.h"
+ #include "events.h"
+ #include "events-mod.h"
+ #include "process.h"
+ #include "sysdep.h"
+ #include "sysproc.h"		/* select stuff */
+ #include "systime.h"
+ 
+ #ifdef HAVE_GPM
+ #include "gpmevent.h"
+ #include <gpm.h>
+ 
+ #if (!defined(__linux__))	/* possible under xterm */
+ #define KG_SHIFT	0
+ #define KG_CTRL		2
+ #define KG_ALT		3
+ #else
+ #include <linux/keyboard.h> 
+ #endif
+ 
+ extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
+ extern SELECT_TYPE process_only_mask, device_only_mask;
+ void select_filedesc (int fd, Lisp_Object what);
+ 
+ int handle_gpm_read(struct Lisp_Event *event, struct console *con, int fd)
+ {
+   Gpm_Event ev;
+   int modifiers,type,button;
+ 
+   type = -1;
+   button = 1;
+ 
+   if (!Gpm_GetEvent(&ev))
+     return(0);
+   
+   event->timestamp       = 0;
+   event->channel         = CONSOLE_SELECTED_FRAME (con);
+   
+   /* Whow, wouldn't named defines be NICE!?!?! */
+   modifiers = 0;
+ 
+   if (ev.modifiers & 1)   modifiers |= MOD_SHIFT;
+   if (ev.modifiers & 2)   modifiers |= MOD_META;
+   if (ev.modifiers & 4)   modifiers |= MOD_CONTROL;
+   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) {
+     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:
+   case GPM_UP:
+     if (type == GPM_DOWN)
+       event->event_type           = button_press_event;
+     else event->event_type        = button_release_event;
+     event->event.button.x         = ev.x;
+     event->event.button.y         = ev.y;
+     event->event.button.button    = button;
+     event->event.button.modifiers = modifiers;
+     break;
+   case GPM_MOVE:
+     event->event_type             = pointer_motion_event;
+     event->event.motion.x         = ev.x;
+     event->event.motion.y         = ev.y;
+     event->event.motion.modifiers = modifiers;
+   default:
+     return (0);
+   }
+   return (1);
+ }
+ 
+ int connect_to_gpm(struct console *con)
+ {
+   /* 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 */
+     if (EQ (CONSOLE_TYPE (con), Qtty)) {
+       Gpm_Connect conn;
+ 
+       conn.eventMask = GPM_DOWN|GPM_UP|GPM_MOVE;
+       conn.defaultMask = GPM_MOVE;
+       conn.minMod = 0;
+       conn.maxMod = ((1<<KG_SHIFT)|(1<<KG_ALT)|(1<<KG_CTRL));
+ 
+       if (Gpm_Open (&conn, 0) == -1) {
+ 	CONSOLE_TTY_MOUSE_FD (con) = -1;
+ 	return(0);
+       }
+       set_descriptor_non_blocking (gpm_fd);
+       CONSOLE_TTY_MOUSE_FD (con) = gpm_fd;
+     }
+   }
+ }
+ 
+ #endif
*** src/gpmevent.h.orig	Fri May  9 11:23:53 1997
--- src/gpmevent.h	Fri May  9 11:23:53 1997
***************
*** 0 ****
--- 1,7 ----
+ #ifndef _HAVE_GPM
+ #define _HAVE_GPM
+ 
+ int handle_gpm_read(struct Lisp_Event *event, struct console *con, int fd);
+ int connect_to_gpm(struct console *con);
+ 
+ #endif
rcsdiff: lisp/x11/RCS/x-mouse.el,v: No such file or directory
===================================================================
RCS file: lisp/prim/mouse.el,v
retrieving revision 1.1
diff -c -r1.1 lisp/prim/mouse.el
*** lisp/prim/mouse.el	1997/05/09 19:36:08	1.1
--- lisp/prim/mouse.el	1997/05/09 19:44:05
***************
*** 47,56 ****
    :type 'boolean
    :group 'mouse)
  
! (defvar mouse-yank-function 'yank	; x11/x-mouse changes this...
    "Function that is called upon by `mouse-yank' to actually insert text.")
  
  
  (defun mouse-select ()
    "Select Emacs window the mouse is on."
    (interactive "@"))
--- 47,63 ----
    :type 'boolean
    :group 'mouse)
  
! (defvar mouse-yank-function 'mouse-uber-yank
    "Function that is called upon by `mouse-yank' to actually insert text.")
  
  
+ (defun mouse-uber-yank ()
+   "Insert the current clipboard selection."
+   (interactive "@e")
+   (case (device-type)
+     (x (x-yank-function event))
+     (tty (yank))))
+   
  (defun mouse-select ()
    "Select Emacs window the mouse is on."
    (interactive "@"))
*** configure.in.orig	Fri May  2 17:25:55 1997
--- configure.in	Fri May  9 11:23:53 1997
***************
*** 226,231 ****
--- 226,232 ----
  			 found.)
  --with-cde (*)		Compile in support for CDE drag and drop.
  --with-offix (*)	Compile in support for OffiX drag and drop.
+ --with-gpm (*)		Compile in support for General Purpose Mouse
  --with-xpm (*)		Compile with support for XPM files.
  			It is highly recommended that you obtain XPM
  			(version 3.4g or better) if you don't already
***************
*** 516,521 ****
--- 517,538 ----
            eval "${opt}=\"${val}\""
          ;;
  
+         ## Has the user requested GPM support?
+ 	"with_gpm" )
+ 	  ## Make sure the value given was either "yes" or "no".
+ 	  case "${val}" in
+ 	    y | ye | yes )	val=yes ;;
+ 	    n | no )		val=no  ;;
+ 	    * )
+ 	      (echo "${progname}: the \`--${optname}' option is supposed to have a boolean value.
+ Set it to either \`yes' or \`no'."
+ 	       echo "${short_usage}") >&2
+ 	      exit 1
+ 	    ;;
+ 	  esac
+           eval "${opt}=\"${val}\""
+         ;;
+ 
          ## Has the user requested database support?
          "with_database" )
  	  with_database_berkdb=no
***************
*** 2530,2535 ****
--- 2547,2570 ----
  dnl ### autodetect TIFF (not yet implemented)
  IF_YES_AC_DEFINE(with_tiff, HAVE_TIFF)
  
+ #
+ # autodetect GPM
+ #
+ if test "${with_tty}" != "no" ; then
+   if test "${with_gpm}" != "no" ; then
+     if test "${with_gpm}" != "yes" ; then
+       AC_HAVE_LIBRARY(-lgpm, with_gpm="yes")
+     fi
+   fi
+ else
+   echo "GPM support cannot be specified without TTY support."
+   exit 1
+ fi
+ 
+ if test "${with_gpm}" = "yes" ; then
+   AC_DEFINE(HAVE_GPM)
+ fi
+ 
  # We use Lucid toolkit defaults for the menubars and scrollbars, but
  # if Motif is available we use it for the dialog boxes.
  if test "${window_system}" != "none" ; then
***************
*** 3210,3215 ****
--- 3245,3251 ----
    echo "  Additional libraries:                                   ${site_runtime_libraries}"
  fi
  test "$with_dnet"  = yes && echo "  Compiling in support for DNET."
+ test "$with_gpm"   = yes && echo "  Compiling in support for GPM."
  test "$with_socks" = yes && echo "  Compiling in support for SOCKS."
  test "$with_term"  = yes && echo "  Compiling in support for TERM."
  test "$with_xauth" = yes && echo "  Compiling in support for XAUTH."
*** configure.orig	Fri May  2 17:25:54 1997
--- configure	Fri May  9 11:23:53 1997
***************
*** 210,215 ****
--- 210,216 ----
  			 found.)
  --with-cde (*)		Compile in support for CDE drag and drop.
  --with-offix (*)	Compile in support for OffiX drag and drop.
+ --with-gpm (*)		Compile in support for General Purpose Mouse
  --with-xpm (*)		Compile with support for XPM files.
  			It is highly recommended that you obtain XPM
  			(version 3.4g or better) if you don't already
***************
*** 503,508 ****
--- 504,525 ----
            eval "${opt}=\"${val}\""
          ;;
  
+         ## Has the user requested GPM support?
+ 	"with_gpm" )
+ 	  ## Make sure the value given was either "yes" or "no".
+ 	  case "${val}" in
+ 	    y | ye | yes )	val=yes ;;
+ 	    n | no )		val=no  ;;
+ 	    * )
+ 	      (echo "${progname}: the \`--${optname}' option is supposed to have a boolean value.
+ Set it to either \`yes' or \`no'."
+ 	       echo "${short_usage}") >&2
+ 	      exit 1
+ 	    ;;
+ 	  esac
+           eval "${opt}=\"${val}\""
+         ;;
+ 
          ## Has the user requested database support?
          "with_database" )
  	  with_database_berkdb=no
***************
*** 4224,4229 ****
--- 4241,4295 ----
  "
  }
  
+ #
+ # autodetect GPM
+ #
+ if test "${with_tty}" != "no" ; then
+   if test "${with_gpm}" != "no" ; then
+     if test "${with_gpm}" != "yes" ; then
+       #AC_HAVE_LIBRARY(-lgpm, with_gpm="yes")
+       ac_save_LIBS="${LIBS}"
+ LIBS="${LIBS} -lgpm"
+ ac_have_lib=""
+ test -n "$silent" || echo "checking for -lgpm"
+ cat > conftest.${ac_ext} <<EOF
+ #include "confdefs.h"
+ 
+ int main() { return 0; }
+ int t() { main();; return 0; }
+ EOF
+ if eval $ac_compile; then
+   rm -rf conftest*
+   ac_have_lib="1"
+ 
+ fi
+ rm -f conftest*
+ LIBS="${ac_save_LIBS}"
+ if test -n "${ac_have_lib}"; then
+    :; with_gpm="yes"
+ else
+    :; 
+ fi
+     fi
+   fi
+ else
+   echo "GPM support cannot be specified without TTY support."
+   exit 1
+ fi
+ 
+ if test "${with_gpm}" = "yes" ; then
+   #AC_DEFINE(HAVE_GPM)
+   {
+ test -n "$verbose" && \
+ echo "	defining HAVE_GPM"
+ echo "#define" HAVE_GPM "1" >> confdefs.h
+ DEFS="$DEFS -DHAVE_GPM=1"
+ ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_GPM\${ac_dB}HAVE_GPM\${ac_dC}1\${ac_dD}
+ \${ac_uA}HAVE_GPM\${ac_uB}HAVE_GPM\${ac_uC}1\${ac_uD}
+ \${ac_eA}HAVE_GPM\${ac_eB}HAVE_GPM\${ac_eC}1\${ac_eD}
+ "
+ }
+ fi
  
  # We use Lucid toolkit defaults for the menubars and scrollbars, but
  # if Motif is available we use it for the dialog boxes.
***************
*** 7154,7159 ****
--- 7220,7226 ----
    echo "  Additional libraries:                                   ${site_runtime_libraries}"
  fi
  test "$with_dnet"  = yes && echo "  Compiling in support for DNET."
+ test "$with_gpm"   = yes && echo "  Compiling in support for GPM."
  test "$with_socks" = yes && echo "  Compiling in support for SOCKS."
  test "$with_term"  = yes && echo "  Compiling in support for TERM."
  test "$with_xauth" = yes && echo "  Compiling in support for XAUTH."

