From xemacs-m  Mon Jun  2 02:02:12 1997
Received: from crystal.WonderWorks.COM (crystal.WonderWorks.com [192.203.206.1])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id CAA22155
	for <xemacs-beta@xemacs.org>; Mon, 2 Jun 1997 02:02:09 -0500 (CDT)
Received: by crystal.WonderWorks.COM 
	id QQcsdw04064; Mon, 2 Jun 1997 03:02:07 -0400 (EDT)
Date: Mon, 2 Jun 1997 03:02:07 -0400 (EDT)
Message-Id: <QQcsdw04064.199706020702@crystal.WonderWorks.COM>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
From: Kyle Jones <kyle_jones@wonderworks.com>
To: xemacs-beta@xemacs.org
Subject: [PATCH] 20.3-b3: more work on tty frames
X-Mailer: VM 6.32 under 20.3 XEmacs Lucid (beta3)
X-Face: /cA45WHG7jWq>(O3&Z57Y<"WsX5ddc,4c#w0F*zrV#=M
        0@~@,s;b,aMtR5Sqs"+nU.z^CSFQ9t`z2>W,S,]:[+2^
        Nbf6v4g>!&,7R4Ot4Wg{&tm=WX7P["9%a)_da48-^tGy
        ,qz]Z,Zz\{E.,]'EO+F)@$KtF&V

The bug I was bstensibly tryign to fix was the cursor lockstep
that occurs between tty frames on the same device displaying the
same buffer.  I ended up having to do quite a lot before this bug
went away.

Before applying this patch, you should apply the src/frame-tty.c
patch I sent earlier.

Mon Jun  2 02:49:44 1997  Kyle Jones  <kyle_jones@wonderworks.com>

	* src/frame.c, src/frame-tty.c
	  Treat tty frames like a cross between stacked window
	  system frames and frames on virtual displays.  All
	  frames but the top frame are visible but hidden by
	  default.  next-frame and previous-frame now skip
	  invisible tty frames by default.  raise-frame and
	  lower-frame now control whether a frame is hidden
	  instead of whether it is visible.  Frames are no
	  longer automatically raised when they are selected.
	  After a raise/lower operation selection of the new
	  topmost frame is deferred until a selection magic
	  event is read.


--- 1.1	1997/05/31 03:41:45
+++ src/frame.c	1997/06/02 06:00:15
@@ -639,25 +639,6 @@
 select_frame_1 (Lisp_Object frame)
 {
   struct frame *f = XFRAME (frame);
-
-  /* If on a TTY, selecting a frame must raise it.  */
-#ifdef HAVE_TTY
-  if (FRAME_TTY_P (f))
-    FRAMEMETH(f, raise_frame, (f));  /* tty_raise_frame will call
-					select_frame_2, so we can skip
-					it. */
-  else
-    select_frame_2 (frame);
-#else
-  select_frame_2 (frame);
-#endif
-}
-
-/* Called from tty_raise_frame. */
-void
-select_frame_2 (Lisp_Object frame)
-{
-  struct frame *f = XFRAME (frame);
   Lisp_Object old_selected_frame = Fselected_frame (Qnil);
 
   if (EQ (frame, old_selected_frame))
@@ -985,7 +966,6 @@
 {
   int passed = 0;
   int started_over = 0;
-  Lisp_Object tmp_frametype;
 
   /* If this frame is dead, it won't be in frame_list, and we'll loop
      forever.  Forestall that.  */
@@ -1033,18 +1013,7 @@
 		  if (EQ (f, frame))
 		    return f;
 
-		  tmp_frametype = frametype;
-		  if (FRAME_TTY_P (XFRAME (f)))
-		    {
-		      /* Only one TTY frame is visible at a time, but
-                         next-frame and similar should still find
-                         them.  */
-		      if (EQ (frametype, Qvisible)
-			  || EQ (frametype, Qvisible_nomini)
-			  || EQ (frametype, Qvisible_iconic_nomini))
-			tmp_frametype = Qnil;
-		    }
-		  if (frame_matches_frametype (f, tmp_frametype))
+		  if (frame_matches_frametype (f, frametype))
 		    return f;
 		}
 	      
@@ -1074,7 +1043,6 @@
 {
   Lisp_Object devcons, concons;
   Lisp_Object prev;
-  Lisp_Object tmp_frametype;
 
   /* If this frame is dead, it won't be in frame_list, and we'll loop
      forever.  Forestall that.  */
@@ -1099,17 +1067,7 @@
 	  /* Decide whether this frame is eligible to be returned,
 	     according to frametype.  */
 
-	  tmp_frametype = frametype;
-	  if (FRAME_TTY_P (XFRAME (f)))
-	    {
-	      /* Only one TTY frame is visible at a time, but
-		 next-frame and similar should still find them.  */
-	      if (EQ (frametype, Qvisible)
-		  || EQ (frametype, Qvisible_nomini)
-		  || EQ (frametype, Qvisible_iconic_nomini))
-		tmp_frametype = Qnil;
-	    }
-	  if (frame_matches_frametype (f, tmp_frametype))
+	  if (frame_matches_frametype (f, frametype))
 	    prev = f;
 
 	}
--- 1.2	1997/06/01 00:09:12
+++ src/frame-tty.c	1997/06/02 06:40:01
@@ -44,9 +44,7 @@
 /* The count of frame number. */
 static int tty_frame_count;
 
-static void tty_make_frame_visible (struct frame *);
-static void tty_make_frame_invisible (struct frame *);
-static void tty_schedule_frame_focus (struct frame *);
+static void tty_raise_frame (struct frame *);
 
 
 static void
@@ -68,16 +66,23 @@
 static void
 tty_init_frame_3 (struct frame *f)
 {
-  tty_schedule_frame_focus (f);
+  tty_raise_frame (f);
 }
 
 static void
-tty_schedule_frame_focus (struct frame *f)
+tty_select_frame_if_unhidden (Lisp_Object frame)
+{
+    if (FRAME_REPAINT_P (XFRAME (frame)))
+      select_frame_1 (frame);
+}
+
+static void
+tty_schedule_frame_select (struct frame *f)
 {
   Lisp_Object frame;
 
   XSETFRAME (frame, f);
-  enqueue_magic_eval_event (select_frame_1, frame);
+  enqueue_magic_eval_event (tty_select_frame_if_unhidden, frame);
 }
 
 static void
@@ -121,8 +126,7 @@
 {
   if (!FRAME_VISIBLE_P(f))
     {
-      SET_FRAME_CLEAR(f);
-      f->visible = 1;
+      f->visible = -1;
     }
 }
 
@@ -133,65 +137,101 @@
   f->visible = 0;
 }
 
+static void
+tty_make_frame_hidden (struct frame *f)
+{
+  f->visible = -1;
+}
+
+static void
+tty_make_frame_unhidden (struct frame *f)
+{
+  if (!FRAME_REPAINT_P(f))
+    {
+      SET_FRAME_CLEAR(f);
+      f->visible = 1;
+    }
+}
+
 static int
 tty_frame_visible_p (struct frame *f)
 {
   return FRAME_VISIBLE_P (f);
 }
 
-/* Raise the frame.  This means that it becomes visible, and all the
-   others become invisible.  */
 static void
-tty_raise_frame (struct frame *f)
+tty_raise_frame_no_select (struct frame *f)
 {
+  struct frame *o;
   struct device *d = XDEVICE (FRAME_DEVICE (f));
   Lisp_Object frame_list = DEVICE_FRAME_LIST (d);
   Lisp_Object tail = frame_list;
 
   while (CONSP (tail))
     {
-      if (decode_frame (XCAR (tail)) != f)
-	tty_make_frame_invisible (XFRAME (XCAR (tail)));
+      o = XFRAME (XCAR (tail));
+      if (o != f && FRAME_REPAINT_P(o))
+	{
+	   tty_make_frame_hidden (o);
+	   break;
+	}
       tail = XCDR (tail);
     }
-  select_frame_2 (make_frame (f));
-  tty_make_frame_visible (f);
+  tty_make_frame_unhidden (f);
+}
+
+static void
+tty_raise_frame (struct frame *f)
+{
+  struct device *d = XDEVICE (FRAME_DEVICE (f));
+
+  tty_raise_frame_no_select (f);
+  tty_schedule_frame_select (f);
 }
 
-/* Lower the frame.  This means that it becomes invisible, while the
-   one after it in the frame list becomes visible.  */
 static void
 tty_lower_frame (struct frame *f)
 {
+  struct frame *o;
   struct device *d = XDEVICE (FRAME_DEVICE (f));
   Lisp_Object frame_list = DEVICE_FRAME_LIST (d);
   Lisp_Object tail;
   Lisp_Object new;
 
-  if (!FRAME_VISIBLE_P (f))
+  if (!FRAME_REPAINT_P (f))
     return;
 
   tail = frame_list;
   while (CONSP (tail))
     {
-      if (decode_frame (XCAR (tail)) == f)
+      o = XFRAME (XCAR (tail));
+      if (o == f)
 	break;
       tail = XCDR (tail);
     }
-  if (!CONSP (tail))
-    {
-      error ("Cannot find frame to lower");
-    }
 
-  tty_make_frame_invisible (f);
+  /* to lower this frame another frame has to be raised.
+     return if there is no other frame. */
+  if (!CONSP (tail) && EQ(frame_list, tail))
+    return;
+
+  tty_make_frame_hidden (f);
   if (CONSP (XCDR (tail)))
     new = XCAR (XCDR (tail));
   else
     new = XCAR (frame_list);
-  tty_make_frame_visible (XFRAME (new));
-  select_frame_2 (new);
+  tty_make_frame_unhidden (XFRAME (new));
+  tty_schedule_frame_select (XFRAME (new));
 }
 
+static void
+tty_delete_frame (struct frame *f)
+{
+    struct device *d = XDEVICE (FRAME_DEVICE (f));
+
+    if (!NILP (DEVICE_SELECTED_FRAME (d)))
+      tty_raise_frame (XFRAME (DEVICE_SELECTED_FRAME (d)));
+}
 
 /************************************************************************/
 /*                            initialization                            */
@@ -212,6 +252,7 @@
   CONSOLE_HAS_METHOD (tty, frame_visible_p);
   CONSOLE_HAS_METHOD (tty, raise_frame);
   CONSOLE_HAS_METHOD (tty, lower_frame);
+  CONSOLE_HAS_METHOD (tty, delete_frame);
 }
 
 void

