changeset 84968:85eb2660cbe3

(mouse_face_window): Rename from Qmouse_face_window. Update all users. (handle_one_term_event): Use Gpm_DrawPointer. (Fgpm_mouse_start): Rename from Fterm_open_connection. Signal errors instead of returning nil. Always return nil. (Fgpm_mouse_stop): Rename from Fterm_close_connection. Make it a noop if gpm-mouse was not activated. (syms_of_term): Update names.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 28 Sep 2007 19:47:02 +0000
parents 90cae4d53a9c
children 6e58c1c8c0fc
files src/ChangeLog src/term.c
diffstat 2 files changed, 39 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Sep 28 16:55:00 2007 +0000
+++ b/src/ChangeLog	Fri Sep 28 19:47:02 2007 +0000
@@ -1,3 +1,14 @@
+2007-09-28  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* term.c (mouse_face_window): Rename from Qmouse_face_window.
+	Update all users.
+	(handle_one_term_event): Use Gpm_DrawPointer.
+	(Fgpm_mouse_start): Rename from Fterm_open_connection.
+	Signal errors instead of returning nil.  Always return nil.
+	(Fgpm_mouse_stop): Rename from Fterm_close_connection.
+	Make it a noop if gpm-mouse was not activated.
+	(syms_of_term): Update names.
+
 2007-09-27  Stefan Monnier  <monnier@iro.umontreal.ca>
 
 	* sysdep.c (narrow_foreground_group, widen_foreground_group): Static.
--- a/src/term.c	Fri Sep 28 16:55:00 2007 +0000
+++ b/src/term.c	Fri Sep 28 19:47:02 2007 +0000
@@ -202,7 +202,7 @@
 static int mouse_face_beg_row, mouse_face_beg_col;
 static int mouse_face_end_row, mouse_face_end_col;
 static int mouse_face_past_end;
-static Lisp_Object Qmouse_face_window;
+static Lisp_Object mouse_face_window;
 static int mouse_face_face_id;
 
 static int pos_x, pos_y;
@@ -2360,7 +2360,7 @@
 static void
 term_show_mouse_face (enum draw_glyphs_face draw)
 {
-  struct window *w = XWINDOW (Qmouse_face_window);
+  struct window *w = XWINDOW (mouse_face_window);
   int save_x, save_y;
   int i;
 
@@ -2439,12 +2439,12 @@
 static void
 term_clear_mouse_face ()
 {
-  if (!NILP (Qmouse_face_window))
+  if (!NILP (mouse_face_window))
     term_show_mouse_face (DRAW_NORMAL_TEXT);
 
   mouse_face_beg_row = mouse_face_beg_col = -1;
   mouse_face_end_row = mouse_face_end_col = -1;
-  Qmouse_face_window = Qnil;
+  mouse_face_window = Qnil;
 }
 
 /* Find the glyph matrix position of buffer position POS in window W.
@@ -2541,7 +2541,7 @@
   if (!WINDOWP (window))
     return;
 
-  if (!EQ (window, Qmouse_face_window))
+  if (!EQ (window, mouse_face_window))
     term_clear_mouse_face ();
 
   w = XWINDOW (window);
@@ -2624,7 +2624,7 @@
 	noverlays = sort_overlays (overlay_vec, noverlays, w);
 
 	/* Check mouse-face highlighting.  */
-	if (!(EQ (window, Qmouse_face_window)
+	if (!(EQ (window, mouse_face_window)
 	      && y >= mouse_face_beg_row
 	      && y <= mouse_face_end_row
 	      && (y > mouse_face_beg_row
@@ -2674,7 +2674,7 @@
 		  = !fast_find_position (w, XFASTINT (after),
 					 &mouse_face_end_col,
 					 &mouse_face_end_row);
-		Qmouse_face_window = window;
+		mouse_face_window = window;
 
 		mouse_face_face_id
 		  = face_at_buffer_position (w, pos, 0, 0,
@@ -2709,7 +2709,7 @@
 		  = !fast_find_position (w, XFASTINT (after),
 					 &mouse_face_end_col,
 					 &mouse_face_end_row);
-		Qmouse_face_window = window;
+		mouse_face_window = window;
 
 		mouse_face_face_id
 		  = face_at_buffer_position (w, pos, 0, 0,
@@ -2885,7 +2885,6 @@
 handle_one_term_event (struct tty_display_info *tty, Gpm_Event *event, struct input_event* hold_quit)
 {
   struct frame *f = XFRAME (tty->top_frame);
-  int fd;
   struct input_event ie;
   int do_help = 0;
   int count = 0;
@@ -2895,24 +2894,10 @@
   ie.arg = Qnil;
 
   if (event->type & (GPM_MOVE | GPM_DRAG)) {
-    unsigned char buf[6 * sizeof (short)];
-    unsigned short *arg = (unsigned short *) buf + 1;
-    const char *name;
-
     previous_help_echo_string = help_echo_string;
     help_echo_string = Qnil;
 
-    /* Display mouse pointer */
-    buf[sizeof(short) - 1] = 2;  /* set selection */
-
-    arg[0] = arg[2] = (unsigned short) event->x + gpm_zerobased;
-    arg[1] = arg[3] = (unsigned short) event->y + gpm_zerobased;
-    arg[4] = (unsigned short) 3;
-    
-    name = ttyname (0);
-    fd = open (name, O_WRONLY);
-    ioctl (fd, TIOCLINUX, buf + sizeof (short) - 1);
-    close (fd);
+    Gpm_DrawPointer (event->x, event->y, fileno (tty->output));
 
     if (!term_mouse_movement (f, event))
       help_echo_string = previous_help_echo_string;
@@ -2955,10 +2940,10 @@
   return count;
 }
 
-DEFUN ("term-open-connection", Fterm_open_connection, Sterm_open_connection,
+DEFUN ("gpm-mouse-start", Fgpm_mouse_start, Sgpm_mouse_start,
        0, 0, 0,
        doc: /* Open a connection to Gpm.
-We only support Gpm on one tty at a time.  */)
+Gpm-mouse can only be activated for one tty at a time.  */)
      ()
 {
   struct frame *f = SELECTED_FRAME ();
@@ -2967,8 +2952,10 @@
        ? (f)->terminal->display_info.tty : NULL);
   Gpm_Connect connection;
 
-  if (gpm_tty || !tty)		/* Already running, or not applicable.  */
-    return Qnil;
+  if (gpm_tty)
+    error ("Gpm-mouse can only be activated for one tty at a time");
+  if (!tty)
+    error ("Gpm-mouse only works in the GNU/Linux console");
 
   connection.eventMask = ~0;
   connection.defaultMask = ~GPM_HARD;
@@ -2977,7 +2964,7 @@
   gpm_zerobased = 1;
 
   if (Gpm_Open (&connection, 0) < 0)
-    return Qnil;
+    error ("Gpm-mouse failed to connect to the gpm daemon");
   else
     {
       gpm_tty = tty;
@@ -2987,19 +2974,20 @@
       reset_sys_modes (tty);
       init_sys_modes (tty);
       add_gpm_wait_descriptor (gpm_fd);
-      return Qt;
+      return Qnil;
     }
 }
 
-DEFUN ("term-close-connection", Fterm_close_connection, Sterm_close_connection,
+DEFUN ("gpm-mouse-stop", Fgpm_mouse_stop, Sgpm_mouse_stop,
        0, 0, 0,
        doc: /* Close a connection to Gpm.  */)
      ()
 {
-   delete_gpm_wait_descriptor (gpm_fd);
-   while (Gpm_Close()); /* close all the stack */
-   gpm_tty = NULL;
-   return Qnil;
+  if (gpm_fd >= 0)
+    delete_gpm_wait_descriptor (gpm_fd);
+  while (Gpm_Close()); /* close all the stack */
+  gpm_tty = NULL;
+  return Qnil;
 }
 #endif /* HAVE_GPM */
 
@@ -3272,7 +3260,7 @@
 
 #ifdef HAVE_GPM
   terminal->mouse_position_hook = term_mouse_position;
-  Qmouse_face_window = Qnil;
+  mouse_face_window = Qnil;
 #endif
 
 #ifdef WINDOWSNT
@@ -3904,10 +3892,10 @@
   defsubr (&Ssuspend_tty);
   defsubr (&Sresume_tty);
 #ifdef HAVE_GPM
-  defsubr (&Sterm_open_connection);
-  defsubr (&Sterm_close_connection);
-
-  staticpro (&Qmouse_face_window);
+  defsubr (&Sgpm_mouse_start);
+  defsubr (&Sgpm_mouse_stop);
+
+  staticpro (&mouse_face_window);
 #endif /* HAVE_GPM */
 }