I'm experimenting with implementing a different approach to
alt-screen, similar to the effect of termcapinfo ti@:te@, except when
using an app which actually requests alt mode.

The specific goal I have is to have a working mouse-wheel in both
shells and pagers in terminals which change mouse-wheel behavior
depending on the terminal mode.  Currently, scrolling in a shell pages
through the history list or similar, while scrolling in a pager or
editor generally works properly.  Setting ti@:te@ gets usable behavior
out of shells, but loses the ability to scroll in less, vim, and so
forth.

The idea is to restore somewhat sane mouse-wheel scrolling by setting
screen to not use alternate mode until a running app actually requests
it.

Attached is the (not working) patch I've come up with so far.

AddCStr(...) appears to be modifying a global, which then gets flushed
out to the tty on Flush(), but repeating the calls (D_TI/TE) in
Enter/LeaveAltScreen doesn't seem to do anything (after removing the
D_TI/TE's in the initialization);  I'm not certain if that's because
it's the wrong call, or just the wrong place for the call.  It's
possible that Enter/LeaveAltScreen isn't the right place to put those
calls, although that seems unlikely, as they're called almost directly
from where an app's ti/te would be handled.

--Carey Underwood
--- screen-4.0.3.orig/display.c
+++ screen-4.0.3/display.c
@@ -722,6 +722,6 @@ int adapt;
   ASSERT(display);
   ASSERT(D_tcinited);
   D_top = D_bot = -1;
-  AddCStr(D_TI);
   AddCStr(D_IS);
   /* Check for toggle */
   if (D_IM && strcmp(D_IM, D_EI))
@@ -788,6 +788,6 @@ FinitTerm()
       GotoPos(0, D_height - 1);
       AddChar('\r');
       AddChar('\n');
-      AddCStr(D_TE);
     }
   Flush();
 }
@@ -3302,6 +3302,6 @@ NukePending()
   D_obufp = D_obuf;
   D_obuffree += len;
   D_top = D_bot = -1;
-  AddCStr(D_TI);
   AddCStr(D_IS);
   /* Turn off all attributes. (Tim MacKenzie) */
   if (D_ME)
diff --git a/resize.c b/resize.c
index 6b5cef4..a0e39ab 100644
--- a/resize.c
+++ b/resize.c
@@ -1084,6 +1084,9 @@ void
 EnterAltScreen(p)
 struct win *p;
 {
+  AddCStr(D_TI);
+  Flush();
+
   int ox = p->w_x, oy = p->w_y;
   FreeAltScreen(p);
   SwapAltScreen(p);
@@ -1096,6 +1099,9 @@ void
 LeaveAltScreen(p)
 struct win *p;
 {
+  AddCStr(D_TE);
+  Flush();
+
   if (!p->w_alt_mlines)
     return;
   SwapAltScreen(p);

Reply via email to