diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/.gdbinit | 2 | ||||
-rw-r--r-- | src/Makefile.in | 25 | ||||
-rw-r--r-- | src/alloc.c | 2 | ||||
-rw-r--r-- | src/cm.c | 216 | ||||
-rw-r--r-- | src/cm.h | 118 | ||||
-rw-r--r-- | src/config.in | 6 | ||||
-rw-r--r-- | src/dispextern.h | 56 | ||||
-rw-r--r-- | src/dispnew.c | 270 | ||||
-rw-r--r-- | src/emacs.c | 35 | ||||
-rw-r--r-- | src/fontset.c | 3 | ||||
-rw-r--r-- | src/frame.c | 305 | ||||
-rw-r--r-- | src/frame.h | 95 | ||||
-rw-r--r-- | src/fringe.c | 13 | ||||
-rw-r--r-- | src/indent.c | 2 | ||||
-rw-r--r-- | src/keyboard.c | 495 | ||||
-rw-r--r-- | src/keyboard.h | 7 | ||||
-rw-r--r-- | src/keymap.c | 1 | ||||
-rw-r--r-- | src/lisp.h | 18 | ||||
-rw-r--r-- | src/lread.c | 1 | ||||
-rw-r--r-- | src/macterm.c | 13 | ||||
-rw-r--r-- | src/macterm.h | 3 | ||||
-rw-r--r-- | src/minibuf.c | 9 | ||||
-rw-r--r-- | src/msdos.c | 4 | ||||
-rw-r--r-- | src/process.c | 21 | ||||
-rw-r--r-- | src/scroll.c | 13 | ||||
-rw-r--r-- | src/sysdep.c | 709 | ||||
-rw-r--r-- | src/syssignal.h | 1 | ||||
-rw-r--r-- | src/term.c | 2450 | ||||
-rw-r--r-- | src/termchar.h | 209 | ||||
-rw-r--r-- | src/termhooks.h | 438 | ||||
-rw-r--r-- | src/termopts.h | 5 | ||||
-rw-r--r-- | src/w32term.c | 13 | ||||
-rw-r--r-- | src/w32term.h | 2 | ||||
-rw-r--r-- | src/window.c | 4 | ||||
-rw-r--r-- | src/window.h | 2 | ||||
-rw-r--r-- | src/xdisp.c | 182 | ||||
-rw-r--r-- | src/xfaces.c | 17 | ||||
-rw-r--r-- | src/xfns.c | 41 | ||||
-rw-r--r-- | src/xmenu.c | 2 | ||||
-rw-r--r-- | src/xselect.c | 52 | ||||
-rw-r--r-- | src/xsmfns.c | 1 | ||||
-rw-r--r-- | src/xterm.c | 269 | ||||
-rw-r--r-- | src/xterm.h | 3 |
43 files changed, 3867 insertions, 2266 deletions
diff --git a/src/.gdbinit b/src/.gdbinit index ccc36694da8..145f4f4df87 100644 --- a/src/.gdbinit +++ b/src/.gdbinit @@ -383,7 +383,7 @@ set print sevenbit-strings show environment DISPLAY show environment TERM -set args -geometry 80x40+0+0 +#set args -geometry 80x40+0+0 # Don't let abort actually run, as it will make # stdio stop working and therefore the `pr' command above as well. diff --git a/src/Makefile.in b/src/Makefile.in index ecf59f87b59..775c454e813 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -873,7 +873,9 @@ SOME_MACHINE_LISP = ${dotdot}/lisp/mouse.elc \ ${dotdot}/lisp/w32-fns.elc ${dotdot}/lisp/dos-w32.elc \ ${dotdot}/lisp/disp-table.elc ${dotdot}/lisp/dos-vars.elc \ ${dotdot}/lisp/international/ccl.elc \ - ${dotdot}/lisp/international/codepage.elc + ${dotdot}/lisp/international/codepage.elc \ + ${dotdot}/lisp/mouse.elc ${dotdot}/lisp/international/fontset.elc \ + ${dotdot}/lisp/x-dnd.elc ${dotdot}/lisp/term/x-win.elc /* Construct full set of libraries to be linked. Note that SunOS needs -lm to come before -lc; otherwise, you get @@ -1047,7 +1049,7 @@ ccl.o: ccl.c ccl.h charset.h coding.h $(config_h) charset.o: charset.c charset.h buffer.h coding.h composite.h disptab.h \ $(config_h) coding.o: coding.c coding.h ccl.h buffer.h charset.h intervals.h composite.h window.h $(config_h) -cm.o: cm.c cm.h termhooks.h $(config_h) +cm.o: cm.c frame.h cm.h termhooks.h termchar.h $(config_h) cmds.o: cmds.c syntax.h buffer.h charset.h commands.h window.h $(config_h) \ msdos.h dispextern.h pre-crt0.o: pre-crt0.c @@ -1055,7 +1057,7 @@ ecrt0.o: ecrt0.c $(config_h) CRT0_COMPILE ${srcdir}/ecrt0.c dired.o: dired.c commands.h buffer.h $(config_h) charset.h coding.h regex.h \ systime.h -dispnew.o: dispnew.c systty.h systime.h commands.h process.h frame.h \ +dispnew.o: dispnew.c systime.h commands.h process.h frame.h \ window.h buffer.h dispextern.h termchar.h termopts.h termhooks.h cm.h \ disptab.h \ xterm.h blockinput.h atimer.h charset.h msdos.h composite.h keyboard.h \ @@ -1077,7 +1079,7 @@ frame.o: frame.c xterm.h window.h frame.h termhooks.h commands.h keyboard.h \ msdos.h dosfns.h dispextern.h $(config_h) fringe.o: fringe.c dispextern.h frame.h window.h buffer.h $(config_h) fontset.o: dispextern.h fontset.h fontset.c ccl.h buffer.h charset.h frame.h \ - keyboard.h $(config_h) + keyboard.h termhooks.h $(config_h) getloadavg.o: getloadavg.c $(config_h) indent.o: indent.c frame.h window.h indent.h buffer.h $(config_h) termchar.h \ termopts.h disptab.h region-cache.h charset.h composite.h dispextern.h \ @@ -1086,7 +1088,7 @@ insdel.o: insdel.c window.h buffer.h $(INTERVAL_SRC) blockinput.h charset.h \ dispextern.h atimer.h systime.h $(config_h) keyboard.o: keyboard.c termchar.h termhooks.h termopts.h buffer.h charset.h \ commands.h frame.h window.h macros.h disptab.h keyboard.h syssignal.h \ - systty.h systime.h dispextern.h syntax.h $(INTERVAL_SRC) blockinput.h \ + systime.h dispextern.h syntax.h $(INTERVAL_SRC) blockinput.h \ atimer.h xterm.h puresize.h msdos.h $(config_h) keymap.o: keymap.c buffer.h commands.h keyboard.h termhooks.h blockinput.h \ atimer.h systime.h puresize.h charset.h intervals.h $(config_h) @@ -1100,7 +1102,7 @@ vm-limit.o: vm-limit.c mem-limits.h $(config_h) marker.o: marker.c buffer.h charset.h $(config_h) md5.o: md5.c md5.h $(config_h) minibuf.o: minibuf.c syntax.h dispextern.h frame.h window.h keyboard.h \ - buffer.h commands.h charset.h msdos.h $(config_h) + buffer.h commands.h charset.h msdos.h termhooks.h $(config_h) mktime.o: mktime.c $(config_h) msdos.o: msdos.c msdos.h dosfns.h systime.h termhooks.h dispextern.h frame.h \ termopts.h termchar.h charset.h coding.h ccl.h disptab.h window.h \ @@ -1112,7 +1114,7 @@ process.o: process.c process.h buffer.h window.h termhooks.h termopts.h \ regex.o: regex.c syntax.h buffer.h $(config_h) regex.h category.h charset.h region-cache.o: region-cache.c buffer.h region-cache.h scroll.o: scroll.c termchar.h dispextern.h frame.h msdos.h keyboard.h \ - $(config_h) + termhooks.h $(config_h) search.o: search.c regex.h commands.h buffer.h region-cache.h syntax.h \ blockinput.h atimer.h systime.h category.h charset.h composite.h $(config_h) strftime.o: strftime.c $(config_h) @@ -1120,7 +1122,7 @@ syntax.o: syntax.c syntax.h buffer.h commands.h category.h charset.h \ composite.h $(config_h) sysdep.o: sysdep.c syssignal.h systty.h systime.h syswait.h blockinput.h \ process.h dispextern.h termhooks.h termchar.h termopts.h \ - frame.h atimer.h window.h msdos.h dosfns.h keyboard.h $(config_h) + frame.h atimer.h window.h msdos.h dosfns.h keyboard.h cm.h $(config_h) term.o: term.c termchar.h termhooks.h termopts.h $(config_h) cm.h frame.h \ disptab.h dispextern.h keyboard.h charset.h coding.h ccl.h msdos.h termcap.o: termcap.c $(config_h) @@ -1142,10 +1144,11 @@ xdisp.o: xdisp.c macros.h commands.h process.h indent.h buffer.h dispextern.h co termchar.h frame.h window.h disptab.h termhooks.h charset.h $(config_h) \ msdos.h composite.h fontset.h blockinput.h atimer.h systime.h keymap.h xfaces.o: xfaces.c dispextern.h frame.h xterm.h buffer.h blockinput.h \ - window.h charset.h msdos.h dosfns.h composite.h atimer.h systime.h $(config_h) + window.h charset.h msdos.h dosfns.h composite.h atimer.h systime.h \ + termchar.h $(config_h) xfns.o: xfns.c buffer.h frame.h window.h keyboard.h xterm.h dispextern.h \ $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h epaths.h \ - charset.h gtkutil.h $(config_h) + charset.h gtkutil.h termchar.h $(config_h) xmenu.o: xmenu.c xterm.h termhooks.h window.h dispextern.h frame.h buffer.h \ keyboard.h $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h \ gtkutil.h msdos.h coding.h $(config_h) @@ -1177,7 +1180,7 @@ floatfns.o: floatfns.c $(config_h) fns.o: fns.c commands.h $(config_h) frame.h buffer.h charset.h keyboard.h \ frame.h window.h dispextern.h $(INTERVAL_SRC) coding.h md5.h print.o: print.c process.h frame.h window.h buffer.h keyboard.h charset.h \ - $(config_h) dispextern.h msdos.h composite.h + $(config_h) dispextern.h msdos.h composite.h termchar.h intervals.h lread.o: lread.c commands.h keyboard.h buffer.h epaths.h charset.h $(config_h) \ termhooks.h coding.h msdos.h diff --git a/src/alloc.c b/src/alloc.c index 7be54aa1ae0..723d664cbe0 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -256,6 +256,7 @@ EMACS_INT gcs_done; /* accumulated GCs */ static void mark_buffer P_ ((Lisp_Object)); extern void mark_kboards P_ ((void)); +extern void mark_ttys P_ ((void)); static void gc_sweep P_ ((void)); static void mark_glyph_matrix P_ ((struct glyph_matrix *)); static void mark_face_cache P_ ((struct face_cache *)); @@ -4463,6 +4464,7 @@ returns nil, because real GC can't be done. */) mark_object (backlist->args[i]); } mark_kboards (); + mark_ttys (); /* Look thru every buffer's undo list for elements that update markers that were not marked, @@ -22,8 +22,13 @@ Boston, MA 02111-1307, USA. */ #include <config.h> #include <stdio.h> + +#include "lisp.h" +#include "frame.h" #include "cm.h" #include "termhooks.h" +#include "termchar.h" + /* For now, don't try to include termcap.h. On some systems, configure finds a non-standard termcap.h that the main build @@ -52,13 +57,16 @@ evalcost (c) return c; } +/* The terminal to use for low-level output. */ +struct tty_display_info *current_tty; + int cmputc (c) char c; { - if (termscript) - fputc (c & 0177, termscript); - putchar (c & 0177); + if (current_tty->termscript) + putc (c & 0177, current_tty->termscript); + putc (c & 0177, current_tty->output); return c; } @@ -71,9 +79,9 @@ cmputc (c) */ static -at (row, col) { - curY = row; - curX = col; +at (tty, row, col) { + curY (tty) = row; + curX (tty) = col; } /* @@ -81,8 +89,8 @@ at (row, col) { */ static -addcol (n) { - curX += n; +addcol (tty, n) { + curX (tty) += n; /* * If cursor hit edge of screen, what happened? @@ -92,21 +100,21 @@ addcol (n) { * of the last line. */ - if (curX == Wcm.cm_cols) { + if (curX (tty) == tty->Wcm->cm_cols) { /* * Well, if magicwrap, still there, past the edge of the * screen (!). If autowrap, on the col 0 of the next line. * Otherwise on last column. */ - if (Wcm.cm_magicwrap) + if (tty->Wcm->cm_magicwrap) ; /* "limbo" */ - else if (Wcm.cm_autowrap) { - curX = 0; - curY++; /* Beware end of screen! */ + else if (tty->Wcm->cm_autowrap) { + curX (tty) = 0; + curY (tty) ++; /* Beware end of screen! */ } else - curX--; + curX (tty)--; } } #endif @@ -122,20 +130,20 @@ addcol (n) { * after we reach the last column; this takes us to a known state. */ void -cmcheckmagic () +cmcheckmagic (struct tty_display_info *tty) { - if (curX == FrameCols) + if (curX (tty) == FrameCols (tty)) { - if (!MagicWrap || curY >= FrameRows - 1) + if (!MagicWrap (tty) || curY (tty) >= FrameRows (tty) - 1) abort (); - if (termscript) - putc ('\r', termscript); - putchar ('\r'); - if (termscript) - putc ('\n', termscript); - putchar ('\n'); - curX = 0; - curY++; + if (tty->termscript) + putc ('\r', tty->termscript); + putc ('\r', tty->output); + if (tty->termscript) + putc ('\n', tty->termscript); + putc ('\n', tty->output); + curX (tty) = 0; + curY (tty)++; } } @@ -147,21 +155,21 @@ cmcheckmagic () */ void -cmcostinit () +cmcostinit (struct tty_display_info *tty) { char *p; #define COST(x,e) (x ? (cost = 0, tputs (x, 1, e), cost) : BIG) #define CMCOST(x,e) ((x == 0) ? BIG : (p = tgoto(x, 0, 0), COST(p ,e))) - Wcm.cc_up = COST (Wcm.cm_up, evalcost); - Wcm.cc_down = COST (Wcm.cm_down, evalcost); - Wcm.cc_left = COST (Wcm.cm_left, evalcost); - Wcm.cc_right = COST (Wcm.cm_right, evalcost); - Wcm.cc_home = COST (Wcm.cm_home, evalcost); - Wcm.cc_cr = COST (Wcm.cm_cr, evalcost); - Wcm.cc_ll = COST (Wcm.cm_ll, evalcost); - Wcm.cc_tab = Wcm.cm_tabwidth ? COST (Wcm.cm_tab, evalcost) : BIG; + tty->Wcm->cc_up = COST (tty->Wcm->cm_up, evalcost); + tty->Wcm->cc_down = COST (tty->Wcm->cm_down, evalcost); + tty->Wcm->cc_left = COST (tty->Wcm->cm_left, evalcost); + tty->Wcm->cc_right = COST (tty->Wcm->cm_right, evalcost); + tty->Wcm->cc_home = COST (tty->Wcm->cm_home, evalcost); + tty->Wcm->cc_cr = COST (tty->Wcm->cm_cr, evalcost); + tty->Wcm->cc_ll = COST (tty->Wcm->cm_ll, evalcost); + tty->Wcm->cc_tab = tty->Wcm->cm_tabwidth ? COST (tty->Wcm->cm_tab, evalcost) : BIG; /* * These last three are actually minimum costs. When (if) they are @@ -172,9 +180,9 @@ cmcostinit () * cursor motion seem to take straight numeric values. --ACT) */ - Wcm.cc_abs = CMCOST (Wcm.cm_abs, evalcost); - Wcm.cc_habs = CMCOST (Wcm.cm_habs, evalcost); - Wcm.cc_vabs = CMCOST (Wcm.cm_vabs, evalcost); + tty->Wcm->cc_abs = CMCOST (tty->Wcm->cm_abs, evalcost); + tty->Wcm->cc_habs = CMCOST (tty->Wcm->cm_habs, evalcost); + tty->Wcm->cc_vabs = CMCOST (tty->Wcm->cm_vabs, evalcost); #undef CMCOST #undef COST @@ -187,8 +195,8 @@ cmcostinit () */ static int -calccost (srcy, srcx, dsty, dstx, doit) - int srcy, srcx, dsty, dstx, doit; +calccost (struct tty_display_info *tty, + int srcy, int srcx, int dsty, int dstx, int doit) { register int deltay, deltax, @@ -205,16 +213,16 @@ calccost (srcy, srcx, dsty, dstx, doit) don't believe the cursor position: give up here and force use of absolute positioning. */ - if (curX == Wcm.cm_cols) + if (curX (tty) == tty->Wcm->cm_cols) goto fail; totalcost = 0; if ((deltay = dsty - srcy) == 0) goto x; if (deltay < 0) - p = Wcm.cm_up, c = Wcm.cc_up, deltay = -deltay; + p = tty->Wcm->cm_up, c = tty->Wcm->cc_up, deltay = -deltay; else - p = Wcm.cm_down, c = Wcm.cc_down; + p = tty->Wcm->cm_down, c = tty->Wcm->cc_down; if (c == BIG) { /* caint get thar from here */ if (doit) printf ("OOPS"); @@ -223,16 +231,16 @@ calccost (srcy, srcx, dsty, dstx, doit) totalcost = c * deltay; if (doit) while (--deltay >= 0) - tputs (p, 1, cmputc); + emacs_tputs (tty, p, 1, cmputc); x: if ((deltax = dstx - srcx) == 0) goto done; if (deltax < 0) { - p = Wcm.cm_left, c = Wcm.cc_left, deltax = -deltax; + p = tty->Wcm->cm_left, c = tty->Wcm->cc_left, deltax = -deltax; goto dodelta; /* skip all the tab junk */ } /* Tabs (the toughie) */ - if (Wcm.cc_tab >= BIG || !Wcm.cm_usetabs) + if (tty->Wcm->cc_tab >= BIG || !tty->Wcm->cm_usetabs) goto olddelta; /* forget it! */ /* @@ -243,12 +251,12 @@ x: * we will put into tabx (for ntabs) and tab2x (for n2tabs)). */ - ntabs = (deltax + srcx % Wcm.cm_tabwidth) / Wcm.cm_tabwidth; + ntabs = (deltax + srcx % tty->Wcm->cm_tabwidth) / tty->Wcm->cm_tabwidth; n2tabs = ntabs + 1; - tabx = (srcx / Wcm.cm_tabwidth + ntabs) * Wcm.cm_tabwidth; - tab2x = tabx + Wcm.cm_tabwidth; + tabx = (srcx / tty->Wcm->cm_tabwidth + ntabs) * tty->Wcm->cm_tabwidth; + tab2x = tabx + tty->Wcm->cm_tabwidth; - if (tab2x >= Wcm.cm_cols) /* too far (past edge) */ + if (tab2x >= tty->Wcm->cm_cols) /* too far (past edge) */ n2tabs = 0; /* @@ -256,12 +264,12 @@ x: * for using n2tabs, then pick the minimum. */ - /* cost for ntabs + cost for right motion */ - tabcost = ntabs ? ntabs * Wcm.cc_tab + (dstx - tabx) * Wcm.cc_right + /* cost for ntabs + cost for right motion */ + tabcost = ntabs ? ntabs * tty->Wcm->cc_tab + (dstx - tabx) * tty->Wcm->cc_right : BIG; - /* cost for n2tabs + cost for left motion */ - c = n2tabs ? n2tabs * Wcm.cc_tab + (tab2x - dstx) * Wcm.cc_left + /* cost for n2tabs + cost for left motion */ + c = n2tabs ? n2tabs * tty->Wcm->cc_tab + (tab2x - dstx) * tty->Wcm->cc_left : BIG; if (c < tabcost) /* then cheaper to overshoot & back up */ @@ -274,11 +282,11 @@ x: * See if tabcost is less than just moving right */ - if (tabcost < (deltax * Wcm.cc_right)) { + if (tabcost < (deltax * tty->Wcm->cc_right)) { totalcost += tabcost; /* use the tabs */ if (doit) while (--ntabs >= 0) - tputs (Wcm.cm_tab, 1, cmputc); + emacs_tputs (tty, tty->Wcm->cm_tab, 1, cmputc); srcx = tabx; } @@ -291,9 +299,9 @@ newdelta: goto done; olddelta: if (deltax > 0) - p = Wcm.cm_right, c = Wcm.cc_right; + p = tty->Wcm->cm_right, c = tty->Wcm->cc_right; else - p = Wcm.cm_left, c = Wcm.cc_left, deltax = -deltax; + p = tty->Wcm->cm_left, c = tty->Wcm->cc_left, deltax = -deltax; dodelta: if (c == BIG) { /* caint get thar from here */ @@ -305,7 +313,7 @@ fail: totalcost += c * deltax; if (doit) while (--deltax >= 0) - tputs (p, 1, cmputc); + emacs_tputs (tty, p, 1, cmputc); done: return totalcost; } @@ -323,7 +331,8 @@ losecursor () #define USECR 3 void -cmgoto (row, col) +cmgoto (tty, row, col) + struct tty_display_info *tty; int row, col; { int homecost, @@ -336,47 +345,47 @@ cmgoto (row, col) *dcm; /* First the degenerate case */ - if (row == curY && col == curX) /* already there */ + if (row == curY (tty) && col == curX (tty)) /* already there */ return; - if (curY >= 0 && curX >= 0) + if (curY (tty) >= 0 && curX (tty) >= 0) { /* We may have quick ways to go to the upper-left, bottom-left, * start-of-line, or start-of-next-line. Or it might be best to * start where we are. Examine the options, and pick the cheapest. */ - relcost = calccost (curY, curX, row, col, 0); + relcost = calccost (tty, curY (tty), curX (tty), row, col, 0); use = USEREL; - if ((homecost = Wcm.cc_home) < BIG) - homecost += calccost (0, 0, row, col, 0); + if ((homecost = tty->Wcm->cc_home) < BIG) + homecost += calccost (tty, 0, 0, row, col, 0); if (homecost < relcost) - relcost = homecost, use = USEHOME; - if ((llcost = Wcm.cc_ll) < BIG) - llcost += calccost (Wcm.cm_rows - 1, 0, row, col, 0); + relcost = homecost, use = USEHOME; + if ((llcost = tty->Wcm->cc_ll) < BIG) + llcost += calccost (tty, tty->Wcm->cm_rows - 1, 0, row, col, 0); if (llcost < relcost) - relcost = llcost, use = USELL; - if ((crcost = Wcm.cc_cr) < BIG) { - if (Wcm.cm_autolf) - if (curY + 1 >= Wcm.cm_rows) - crcost = BIG; + relcost = llcost, use = USELL; + if ((crcost = tty->Wcm->cc_cr) < BIG) { + if (tty->Wcm->cm_autolf) + if (curY (tty) + 1 >= tty->Wcm->cm_rows) + crcost = BIG; else - crcost += calccost (curY + 1, 0, row, col, 0); + crcost += calccost (tty, curY (tty) + 1, 0, row, col, 0); else - crcost += calccost (curY, 0, row, col, 0); + crcost += calccost (tty, curY (tty), 0, row, col, 0); } if (crcost < relcost) relcost = crcost, use = USECR; - directcost = Wcm.cc_abs, dcm = Wcm.cm_abs; - if (row == curY && Wcm.cc_habs < BIG) - directcost = Wcm.cc_habs, dcm = Wcm.cm_habs; - else if (col == curX && Wcm.cc_vabs < BIG) - directcost = Wcm.cc_vabs, dcm = Wcm.cm_vabs; + directcost = tty->Wcm->cc_abs, dcm = tty->Wcm->cm_abs; + if (row == curY (tty) && tty->Wcm->cc_habs < BIG) + directcost = tty->Wcm->cc_habs, dcm = tty->Wcm->cm_habs; + else if (col == curX (tty) && tty->Wcm->cc_vabs < BIG) + directcost = tty->Wcm->cc_vabs, dcm = tty->Wcm->cm_vabs; } else { directcost = 0, relcost = 100000; - dcm = Wcm.cm_abs; + dcm = tty->Wcm->cm_abs; } /* @@ -387,13 +396,14 @@ cmgoto (row, col) { /* compute REAL direct cost */ cost = 0; - p = dcm == Wcm.cm_habs ? tgoto (dcm, row, col) : - tgoto (dcm, col, row); - tputs (p, 1, evalcost); + p = (dcm == tty->Wcm->cm_habs + ? tgoto (dcm, row, col) + : tgoto (dcm, col, row)); + emacs_tputs (tty, p, 1, evalcost); if (cost <= relcost) { /* really is cheaper */ - tputs (p, 1, cmputc); - curY = row, curX = col; + emacs_tputs (tty, p, 1, cmputc); + curY (tty) = row, curX (tty) = col; return; } } @@ -401,25 +411,25 @@ cmgoto (row, col) switch (use) { case USEHOME: - tputs (Wcm.cm_home, 1, cmputc); - curY = 0, curX = 0; + emacs_tputs (tty, tty->Wcm->cm_home, 1, cmputc); + curY (tty) = 0, curX (tty) = 0; break; case USELL: - tputs (Wcm.cm_ll, 1, cmputc); - curY = Wcm.cm_rows - 1, curX = 0; + emacs_tputs (tty, tty->Wcm->cm_ll, 1, cmputc); + curY (tty) = tty->Wcm->cm_rows - 1, curX (tty) = 0; break; case USECR: - tputs (Wcm.cm_cr, 1, cmputc); - if (Wcm.cm_autolf) - curY++; - curX = 0; + emacs_tputs (tty, tty->Wcm->cm_cr, 1, cmputc); + if (tty->Wcm->cm_autolf) + curY (tty)++; + curX (tty) = 0; break; } - (void) calccost (curY, curX, row, col, 1); - curY = row, curX = col; + (void) calccost (tty, curY (tty), curX (tty), row, col, 1); + curY (tty) = row, curX (tty) = col; } /* Clear out all terminal info. @@ -427,9 +437,9 @@ cmgoto (row, col) */ void -Wcm_clear () +Wcm_clear (struct tty_display_info *tty) { - bzero (&Wcm, sizeof Wcm); + bzero (tty->Wcm, sizeof (struct cm)); UP = 0; BC = 0; } @@ -442,21 +452,21 @@ Wcm_clear () */ int -Wcm_init () +Wcm_init (struct tty_display_info *tty) { #if 0 - if (Wcm.cm_abs && !Wcm.cm_ds) + if (tty->Wcm->cm_abs && !tty->Wcm->cm_ds) return 0; #endif - if (Wcm.cm_abs) + if (tty->Wcm->cm_abs) return 0; /* Require up and left, and, if no absolute, down and right */ - if (!Wcm.cm_up || !Wcm.cm_left) + if (!tty->Wcm->cm_up || !tty->Wcm->cm_left) return - 1; - if (!Wcm.cm_abs && (!Wcm.cm_down || !Wcm.cm_right)) + if (!tty->Wcm->cm_abs && (!tty->Wcm->cm_down || !tty->Wcm->cm_right)) return - 1; /* Check that we know the size of the screen.... */ - if (Wcm.cm_rows <= 0 || Wcm.cm_cols <= 0) + if (tty->Wcm->cm_rows <= 0 || tty->Wcm->cm_cols <= 0) return - 2; return 0; } @@ -98,76 +98,78 @@ struct cm int cc_vabs; }; -extern struct cm Wcm; /* Terminal capabilities */ extern char PC; /* Pad character */ /* Shorthand */ #ifndef NoCMShortHand -#define curY Wcm.cm_curY -#define curX Wcm.cm_curX -#define Up Wcm.cm_up -#define Down Wcm.cm_down -#define Left Wcm.cm_left -#define Right Wcm.cm_right -#define Tab Wcm.cm_tab -#define BackTab Wcm.cm_backtab -#define TabWidth Wcm.cm_tabwidth -#define CR Wcm.cm_cr -#define Home Wcm.cm_home -#define LastLine Wcm.cm_ll -#define AbsPosition Wcm.cm_abs -#define ColPosition Wcm.cm_habs -#define RowPosition Wcm.cm_vabs -#define MultiUp Wcm.cm_multiup -#define MultiDown Wcm.cm_multidown -#define MultiLeft Wcm.cm_multileft -#define MultiRight Wcm.cm_multiright -#define AutoWrap Wcm.cm_autowrap -#define MagicWrap Wcm.cm_magicwrap -#define UseTabs Wcm.cm_usetabs -#define FrameRows Wcm.cm_rows -#define FrameCols Wcm.cm_cols - -#define UpCost Wcm.cc_up -#define DownCost Wcm.cc_down -#define LeftCost Wcm.cc_left -#define RightCost Wcm.cc_right -#define HomeCost Wcm.cc_home -#define CRCost Wcm.cc_cr -#define LastLineCost Wcm.cc_ll -#define TabCost Wcm.cc_tab -#define BackTabCost Wcm.cc_backtab -#define AbsPositionCost Wcm.cc_abs -#define ColPositionCost Wcm.cc_habs -#define RowPositionCost Wcm.cc_vabs -#define MultiUpCost Wcm.cc_multiup -#define MultiDownCost Wcm.cc_multidown -#define MultiLeftCost Wcm.cc_multileft -#define MultiRightCost Wcm.cc_multiright +#define curY(tty) (tty)->Wcm->cm_curY +#define curX(tty) (tty)->Wcm->cm_curX +#define Up(tty) (tty)->Wcm->cm_up +#define Down(tty) (tty)->Wcm->cm_down +#define Left(tty) (tty)->Wcm->cm_left +#define Right(tty) (tty)->Wcm->cm_right +#define Tab(tty) (tty)->Wcm->cm_tab +#define BackTab(tty) (tty)->Wcm->cm_backtab +#define TabWidth(tty) (tty)->Wcm->cm_tabwidth +#define CR(tty) (tty)->Wcm->cm_cr +#define Home(tty) (tty)->Wcm->cm_home +#define LastLine(tty) (tty)->Wcm->cm_ll +#define AbsPosition(tty) (tty)->Wcm->cm_abs +#define ColPosition(tty) (tty)->Wcm->cm_habs +#define RowPosition(tty) (tty)->Wcm->cm_vabs +#define MultiUp(tty) (tty)->Wcm->cm_multiup +#define MultiDown(tty) (tty)->Wcm->cm_multidown +#define MultiLeft(tty) (tty)->Wcm->cm_multileft +#define MultiRight(tty) (tty)->Wcm->cm_multiright +#define AutoWrap(tty) (tty)->Wcm->cm_autowrap +#define MagicWrap(tty) (tty)->Wcm->cm_magicwrap +#define UseTabs(tty) (tty)->Wcm->cm_usetabs +#define FrameRows(tty) (tty)->Wcm->cm_rows +#define FrameCols(tty) (tty)->Wcm->cm_cols + +#define UpCost(tty) (tty)->Wcm->cc_up +#define DownCost(tty) (tty)->Wcm->cc_down +#define LeftCost(tty) (tty)->Wcm->cc_left +#define RightCost(tty) (tty)->Wcm->cc_right +#define HomeCost(tty) (tty)->Wcm->cc_home +#define CRCost(tty) (tty)->Wcm->cc_cr +#define LastLineCost(tty) (tty)->Wcm->cc_ll +#define TabCost(tty) (tty)->Wcm->cc_tab +#define BackTabCost(tty) (tty)->Wcm->cc_backtab +#define AbsPositionCost(tty) (tty)->Wcm->cc_abs +#define ColPositionCost(tty) (tty)->Wcm->cc_habs +#define RowPositionCost(tty) (tty)->Wcm->cc_vabs +#define MultiUpCost(tty) (tty)->Wcm->cc_multiup +#define MultiDownCost(tty) (tty)->Wcm->cc_multidown +#define MultiLeftCost(tty) (tty)->Wcm->cc_multileft +#define MultiRightCost(tty) (tty)->Wcm->cc_multiright #endif -#define cmat(row,col) (curY = (row), curX = (col)) -#define cmplus(n) \ - { \ - if ((curX += (n)) >= FrameCols && !MagicWrap) \ - { \ - if (Wcm.cm_losewrap) losecursor (); \ - else if (AutoWrap) curX = 0, curY++; \ - else curX--; \ - } \ +#define cmat(tty,row,col) (curY(tty) = (row), curX(tty) = (col)) +#define cmplus(tty,n) \ + { \ + if ((curX (tty) += (n)) >= FrameCols (tty) && !MagicWrap (tty)) \ + { \ + if ((tty)->Wcm->cm_losewrap) losecursor (tty); \ + else if (AutoWrap (tty)) curX (tty) = 0, curY (tty)++; \ + else curX (tty)--; \ + } \ } -#define losecursor() (curX = -1, curY = -1) +#define losecursor(tty) (curX(tty) = -1, curY(tty) = -1) extern int cost; extern int evalcost (); -extern void cmcheckmagic (); -extern int cmputc (); -extern void cmcostinit (); -extern void cmgoto (); -extern void Wcm_clear (); -extern int Wcm_init (); +#define emacs_tputs(tty, str, affcnt, putc) (current_tty = (tty), tputs (str, affcnt, putc)) + +extern struct tty_display_info *current_tty; +extern void cmcheckmagic P_ ((struct tty_display_info *)); +extern int cmputc P_ ((int)); +extern void cmcostinit P_ ((struct tty_display_info *)); +extern void cmgoto P_ ((struct tty_display_info *, int, int)); +extern void Wcm_clear P_ ((struct tty_display_info *)); +extern int Wcm_init P_ ((struct tty_display_info *)); /* arch-tag: acc1535a-7136-49d6-b22d-9bc85702251b (do not change this comment) */ diff --git a/src/config.in b/src/config.in index 0fb4b3f3444..4fe82cd8f2d 100644 --- a/src/config.in +++ b/src/config.in @@ -863,6 +863,12 @@ Boston, MA 02111-1307, USA. */ #define HAVE_MOUSE #endif +/* Multi-tty support relies on MULTI_KBOARD. It seems safe to turn it + on unconditionally. */ +#ifndef MULTI_KBOARD +#define MULTI_KBOARD +#endif + /* Define USER_FULL_NAME to return a string that is the user's full name. It can assume that the variable `pw' diff --git a/src/dispextern.h b/src/dispextern.h index bb421e0618b..00a27a9b326 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -1272,7 +1272,7 @@ struct glyph_string DESCENT = FONT->descent HEIGHT = FONT_HEIGHT (FONT) F_DESCENT = (FRAME_FONT (F)->descent - - F->output_data.x->baseline_offset) + - F->device->output_data.x->baseline_offset) F_HEIGHT = FRAME_LINE_HEIGHT (F) */ @@ -2029,16 +2029,16 @@ struct it /* Call produce_glyphs or produce_glyphs_hook, if set. Shortcut to avoid the function call overhead. */ -#define PRODUCE_GLYPHS(IT) \ - do { \ - extern int inhibit_free_realized_faces; \ - if (rif != NULL) \ - rif->produce_glyphs ((IT)); \ - else \ - produce_glyphs ((IT)); \ - if ((IT)->glyph_row != NULL) \ - inhibit_free_realized_faces = 1; \ - } while (0) +#define PRODUCE_GLYPHS(IT) \ + do { \ + extern int inhibit_free_realized_faces; \ + if (FRAME_RIF ((IT)->f) != NULL) \ + FRAME_RIF ((IT)->f)->produce_glyphs ((IT)); \ + else \ + produce_glyphs ((IT)); \ + if ((IT)->glyph_row != NULL) \ + inhibit_free_realized_faces = 1; \ + } while (0) /* Bit-flags indicating what operation move_it_to should perform. */ @@ -2212,10 +2212,6 @@ struct redisplay_interface #endif /* HAVE_WINDOW_SYSTEM */ }; -/* The current interface for window-based redisplay. */ - -extern struct redisplay_interface *rif; - /*********************************************************************** Images @@ -2597,11 +2593,11 @@ void w32_reset_fringes P_ ((void)); /* Defined in sysdep.c */ -void get_frame_size P_ ((int *, int *)); +void get_tty_size P_ ((int, int *, int *)); void request_sigio P_ ((void)); void unrequest_sigio P_ ((void)); -int tabs_safe_p P_ ((void)); -void init_baud_rate P_ ((void)); +int tabs_safe_p P_ ((int)); +void init_baud_rate P_ ((int)); void init_sigio P_ ((int)); /* Defined in xfaces.c */ @@ -2771,29 +2767,35 @@ extern Lisp_Object Qredisplay_dont_pause; /* Defined in term.c */ extern void ring_bell P_ ((void)); -extern void set_terminal_modes P_ ((void)); -extern void reset_terminal_modes P_ ((void)); extern void update_begin P_ ((struct frame *)); extern void update_end P_ ((struct frame *)); extern void set_terminal_window P_ ((int)); extern void set_scroll_region P_ ((int, int)); -extern void turn_off_insert P_ ((void)); -extern void turn_off_highlight P_ ((void)); -extern void background_highlight P_ ((void)); +extern void turn_off_insert P_ ((struct tty_display_info *)); +extern void turn_off_highlight P_ ((struct tty_display_info *)); +extern void background_highlight P_ ((struct tty_display_info *)); extern void clear_frame P_ ((void)); extern void clear_end_of_line P_ ((int)); extern void clear_end_of_line_raw P_ ((int)); +extern void tty_clear_end_of_line P_ ((int)); extern void delete_glyphs P_ ((int)); extern void ins_del_lines P_ ((int, int)); extern int string_cost P_ ((char *)); extern int per_line_cost P_ ((char *)); extern void calculate_costs P_ ((struct frame *)); extern void set_tty_color_mode P_ ((struct frame *, Lisp_Object)); -extern void tty_setup_colors P_ ((int)); -extern void term_init P_ ((char *)); +extern void tty_setup_colors P_ ((struct tty_display_info *, int)); +extern struct display *get_named_tty_display P_ ((char *)); +extern struct display *init_initial_display P_ ((void)); +extern struct display *term_init P_ ((char *, char *, int)); +extern void delete_tty P_ ((struct display *)); extern void fatal P_ ((/* char *, ... */)); -void cursor_to P_ ((int, int)); -extern int tty_capable_p P_ ((struct frame *, unsigned, unsigned long, unsigned long)); +extern void cursor_to P_ ((int, int)); +extern int tty_capable_p P_ ((struct tty_display_info *, unsigned, unsigned long, unsigned long)); +extern void tty_set_terminal_modes P_ ((struct display *)); +extern void tty_reset_terminal_modes P_ ((struct display *)); +extern void create_tty_output P_ ((struct frame *)); + /* Defined in scroll.c */ diff --git a/src/dispnew.c b/src/dispnew.c index e1a3ed93dab..b4d3020e81d 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -31,7 +31,6 @@ Boston, MA 02111-1307, USA. */ #include "lisp.h" #include "termchar.h" #include "termopts.h" -#include "termhooks.h" /* cm.h must come after dispextern.h on Windows. */ #include "dispextern.h" #include "cm.h" @@ -39,6 +38,7 @@ Boston, MA 02111-1307, USA. */ #include "charset.h" #include "keyboard.h" #include "frame.h" +#include "termhooks.h" #include "window.h" #include "commands.h" #include "disptab.h" @@ -214,9 +214,9 @@ int inverse_video; EMACS_INT baud_rate; /* Either nil or a symbol naming the window system under which Emacs - is running. */ + creates the first frame. */ -Lisp_Object Vwindow_system; +Lisp_Object Vinitial_window_system; /* Version number of X windows: 10, 11 or nil. */ @@ -258,14 +258,6 @@ Lisp_Object selected_frame; struct frame *last_nonminibuf_frame; -/* Stdio stream being used for copy of all output. */ - -FILE *termscript; - -/* Structure for info on cursor positioning. */ - -struct cm Wcm; - /* 1 means SIGWINCH happened when not safe. */ int delayed_size_change; @@ -304,11 +296,6 @@ int glyph_pool_count; static struct frame *frame_matrix_frame; -/* Current interface for window-based redisplay. Set from init_xterm. - A null value means we are not using window-based redisplay. */ - -struct redisplay_interface *rif; - /* Non-zero means that fonts have been loaded since the last glyph matrix adjustments. Redisplay must stop, and glyph matrices must be adjusted when this flag becomes non-zero during display. The @@ -1397,7 +1384,7 @@ line_hash_code (row) { int c = glyph->u.ch; int face_id = glyph->face_id; - if (must_write_spaces) + if (FRAME_MUST_WRITE_SPACES (SELECTED_FRAME ())) /* XXX Is SELECTED_FRAME OK here? */ c -= SPACEGLYPH; hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + c; hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + face_id; @@ -1429,7 +1416,7 @@ line_draw_cost (matrix, vpos) int glyph_table_len = GLYPH_TABLE_LENGTH; /* Ignore trailing and leading spaces if we can. */ - if (!must_write_spaces) + if (!FRAME_MUST_WRITE_SPACES (SELECTED_FRAME ())) /* XXX Is SELECTED_FRAME OK here? */ { /* Skip from the end over trailing spaces. */ while (end > beg && CHAR_GLYPH_SPACE_P (*(end - 1))) @@ -1645,8 +1632,10 @@ realloc_glyph_pool (pool, matrix_dim) #if GLYPH_DEBUG -/* Flush standard output. This is sometimes useful to call from - the debugger. */ +/* Flush standard output. This is sometimes useful to call from the debugger. + XXX Maybe this should be changed to flush the current terminal instead of + stdout. +*/ void flush_stdout () @@ -3319,12 +3308,15 @@ DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 1, 1, 0, return Qnil; update_begin (f); +#ifdef MSDOS if (FRAME_MSDOS_P (f)) - set_terminal_modes (); + set_terminal_modes (FRAME_DISPLAY (f)); +#endif clear_frame (); clear_current_matrices (f); update_end (f); - fflush (stdout); + if (FRAME_TERMCAP_P (f)) + fflush (FRAME_TTY (f)->output); windows_or_buffers_changed++; /* Mark all windows as inaccurate, so that every window will have its redisplay done. */ @@ -3465,7 +3457,7 @@ direct_output_for_insert (g) /* If we can't insert glyphs, we can use this method only at the end of a line. */ - if (!char_ins_del_ok) + if (!FRAME_CHAR_INS_DEL_OK (f)) if (PT != ZV && FETCH_BYTE (PT_BYTE) != '\n') return 0; @@ -3615,17 +3607,17 @@ direct_output_for_insert (g) updated_row = glyph_row; updated_area = TEXT_AREA; update_begin (f); - if (rif) + if (FRAME_RIF (f)) { - rif->update_window_begin_hook (w); + FRAME_RIF (f)->update_window_begin_hook (w); if (glyphs == end - n /* In front of a space added by append_space. */ || (glyphs == end - n - 1 && (end - n)->charpos <= 0)) - rif->write_glyphs (glyphs, n); + FRAME_RIF (f)->write_glyphs (glyphs, n); else - rif->insert_glyphs (glyphs, n); + FRAME_RIF (f)->insert_glyphs (glyphs, n); } else { @@ -3645,8 +3637,8 @@ direct_output_for_insert (g) a frame matrix is used, cursor_to expects frame coordinates, and the X and Y parameters are not used. */ if (window_redisplay_p) - rif->cursor_to (w->cursor.vpos, w->cursor.hpos, - w->cursor.y, w->cursor.x); + FRAME_RIF (f)->cursor_to (w->cursor.vpos, w->cursor.hpos, + w->cursor.y, w->cursor.x); else { int x, y; @@ -3662,11 +3654,12 @@ direct_output_for_insert (g) update_window_fringes (w, 0); #endif - if (rif) - rif->update_window_end_hook (w, 1, 0); + if (FRAME_RIF (f)) + FRAME_RIF (f)->update_window_end_hook (w, 1, 0); update_end (f); updated_row = NULL; - fflush (stdout); + if (FRAME_TERMCAP_P (f)) + fflush (FRAME_TTY (f)->output); TRACE ((stderr, "direct output for insert\n")); mark_window_display_accurate (it.window, 1); @@ -3744,8 +3737,8 @@ direct_output_forward_char (n) && w->cursor.hpos < w->desired_matrix->matrix_w); if (FRAME_WINDOW_P (f)) - rif->cursor_to (w->cursor.vpos, w->cursor.hpos, - w->cursor.y, w->cursor.x); + FRAME_RIF (f)->cursor_to (w->cursor.vpos, w->cursor.hpos, + w->cursor.y, w->cursor.x); else { int x, y; @@ -3757,7 +3750,8 @@ direct_output_forward_char (n) cursor_to (y, x); } - fflush (stdout); + if (FRAME_TERMCAP_P (f)) + fflush (FRAME_TTY (f)->output); redisplay_performed_directly_p = 1; return 1; } @@ -3830,14 +3824,14 @@ update_frame (f, force_p, inhibit_hairy_id_p) update_end (f); /* This flush is a performance bottleneck under X, - and it doesn't seem to be necessary anyway (in general). + and it doesn't seem to be necessary anyway (in general). It is necessary when resizing the window with the mouse, or - at least the fringes are not redrawn in a timely manner. ++kfs */ + at least the fringes are not redrawn in a timely manner. ++kfs */ if (f->force_flush_display_p) - { - rif->flush_display (f); - f->force_flush_display_p = 0; - } + { + FRAME_RIF (f)->flush_display (f); + f->force_flush_display_p = 0; + } } else { @@ -3853,9 +3847,12 @@ update_frame (f, force_p, inhibit_hairy_id_p) paused_p = update_frame_1 (f, force_p, inhibit_hairy_id_p); update_end (f); - if (termscript) - fflush (termscript); - fflush (stdout); + if (FRAME_TERMCAP_P (f)) + { + if (FRAME_TTY (f)->termscript) + fflush (FRAME_TTY (f)->termscript); + fflush (FRAME_TTY (f)->output); + } /* Check window matrices for lost pointers. */ #if GLYPH_DEBUG @@ -3938,7 +3935,8 @@ redraw_overlapped_rows (w, yb) int yb; { int i; - + struct frame *f = XFRAME (WINDOW_FRAME (w)); + /* If rows overlapping others have been changed, the rows being overlapped have to be redrawn. This won't draw lines that have already been drawn in update_window_line because overlapped_p in @@ -3961,10 +3959,12 @@ redraw_overlapped_rows (w, yb) { updated_row = row; updated_area = area; - rif->cursor_to (i, 0, row->y, area == TEXT_AREA ? row->x : 0); + FRAME_RIF (f)->cursor_to (i, 0, row->y, + area == TEXT_AREA ? row->x : 0); if (row->used[area]) - rif->write_glyphs (row->glyphs[area], row->used[area]); - rif->clear_end_of_line (-1); + FRAME_RIF (f)->write_glyphs (row->glyphs[area], + row->used[area]); + FRAME_RIF (f)->clear_end_of_line (-1); } row->overlapped_p = 0; @@ -3986,7 +3986,8 @@ redraw_overlapping_rows (w, yb) { int i, bottom_y; struct glyph_row *row; - + struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w))); + for (i = 0; i < w->current_matrix->nrows; ++i) { row = w->current_matrix->rows + i; @@ -4066,6 +4067,7 @@ update_window (w, force_p) #if GLYPH_DEBUG struct frame *f = XFRAME (WINDOW_FRAME (w)); #endif + struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w))); /* Check that W's frame doesn't have glyph matrices. */ xassert (FRAME_WINDOW_P (f)); @@ -4237,6 +4239,7 @@ update_marginal_area (w, area, vpos) int area, vpos; { struct glyph_row *desired_row = MATRIX_ROW (w->desired_matrix, vpos); + struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w))); /* Let functions in xterm.c know what area subsequent X positions will be relative to. */ @@ -4262,6 +4265,7 @@ update_text_area (w, vpos) { struct glyph_row *current_row = MATRIX_ROW (w->current_matrix, vpos); struct glyph_row *desired_row = MATRIX_ROW (w->desired_matrix, vpos); + struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w))); int changed_p = 0; /* Let functions in xterm.c know what area subsequent X positions @@ -4483,6 +4487,7 @@ update_window_line (w, vpos, mouse_face_overwritten_p) { struct glyph_row *current_row = MATRIX_ROW (w->current_matrix, vpos); struct glyph_row *desired_row = MATRIX_ROW (w->desired_matrix, vpos); + struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w))); int changed_p = 0; /* Set the row being updated. This is important to let xterm.c @@ -4551,6 +4556,7 @@ set_window_cursor_after_update (w) struct window *w; { struct frame *f = XFRAME (w->frame); + struct redisplay_interface *rif = FRAME_RIF (f); int cx, cy, vpos, hpos; /* Not intended for frame matrix updates. */ @@ -4774,6 +4780,7 @@ scrolling_window (w, header_line_p) int i, j, first_old, first_new, last_old, last_new; int nruns, nbytes, n, run_idx; struct row_entry *entry; + struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w))); /* Skip over rows equal at the start. */ for (i = header_line_p ? 1 : 0; i < current_matrix->nrows - 1; ++i) @@ -5098,7 +5105,7 @@ update_frame_1 (f, force_p, inhibit_id_p) } /* If we cannot insert/delete lines, it's no use trying it. */ - if (!line_ins_del_ok) + if (!FRAME_LINE_INS_DEL_OK (f)) inhibit_id_p = 1; /* See if any of the desired lines are enabled; don't compute for @@ -5126,18 +5133,18 @@ update_frame_1 (f, force_p, inhibit_id_p) Also flush out if likely to have more than 1k buffered otherwise. I'm told that some telnet connections get really screwed by more than 1k output at once. */ - int outq = PENDING_OUTPUT_COUNT (stdout); + int outq = PENDING_OUTPUT_COUNT (FRAME_TTY (f)->output); if (outq > 900 || (outq > 20 && ((i - 1) % preempt_count == 0))) { - fflush (stdout); + fflush (FRAME_TTY (f)->output); if (preempt_count == 1) { #ifdef EMACS_OUTQSIZE if (EMACS_OUTQSIZE (0, &outq) < 0) /* Probably not a tty. Ignore the error and reset the outq count. */ - outq = PENDING_OUTPUT_COUNT (stdout); + outq = PENDING_OUTPUT_COUNT (FRAME_TTY (f->output)); #endif outq *= 10; if (baud_rate <= outq && baud_rate > 0) @@ -5316,21 +5323,23 @@ scrolling (frame) } /* If changed lines are few, don't allow preemption, don't scroll. */ - if ((!scroll_region_ok && changed_lines < baud_rate / 2400) + if ((!FRAME_SCROLL_REGION_OK (frame) + && changed_lines < baud_rate / 2400) || unchanged_at_bottom == FRAME_LINES (frame)) return 1; window_size = (FRAME_LINES (frame) - unchanged_at_top - unchanged_at_bottom); - if (scroll_region_ok) + if (FRAME_SCROLL_REGION_OK (frame)) free_at_end_vpos -= unchanged_at_bottom; - else if (memory_below_frame) + else if (FRAME_MEMORY_BELOW_FRAME (frame)) free_at_end_vpos = -1; /* If large window, fast terminal and few lines in common between current frame and desired frame, don't bother with i/d calc. */ - if (!scroll_region_ok && window_size >= 18 && baud_rate > 2400 + if (!FRAME_SCROLL_REGION_OK (frame) + && window_size >= 18 && baud_rate > 2400 && (window_size >= 10 * scrolling_max_lines_saved (unchanged_at_top, FRAME_LINES (frame) - unchanged_at_bottom, @@ -5410,7 +5419,7 @@ update_frame_line (f, vpos) struct glyph_row *current_row = MATRIX_ROW (current_matrix, vpos); struct glyph_row *desired_row = MATRIX_ROW (desired_matrix, vpos); int must_write_whole_line_p; - int write_spaces_p = must_write_spaces; + int write_spaces_p = FRAME_MUST_WRITE_SPACES (f); int colored_spaces_p = (FACE_FROM_ID (f, DEFAULT_FACE_ID)->background != FACE_TTY_DEFAULT_BG_COLOR); @@ -5489,7 +5498,7 @@ update_frame_line (f, vpos) nlen--; /* If there's no i/d char, quickly do the best we can without it. */ - if (!char_ins_del_ok) + if (!FRAME_CHAR_INS_DEL_OK (f)) { int i, j; @@ -5592,7 +5601,8 @@ update_frame_line (f, vpos) tem = (nlen - nsp) - (olen - osp); if (endmatch && tem - && (!char_ins_del_ok || endmatch <= char_ins_del_cost (f)[tem])) + && (!FRAME_CHAR_INS_DEL_OK (f) + || endmatch <= char_ins_del_cost (f)[tem])) endmatch = 0; /* nsp - osp is the distance to insert or delete. @@ -5601,7 +5611,7 @@ update_frame_line (f, vpos) Is it worth it? */ if (nsp != osp - && (!char_ins_del_ok + && (!FRAME_CHAR_INS_DEL_OK (f) || begmatch + endmatch <= char_ins_del_cost (f)[nsp - osp])) { begmatch = 0; @@ -5978,28 +5988,31 @@ window_change_signal (signalnum) /* If we don't have an argument, */ #endif int old_errno = errno; - get_frame_size (&width, &height); + struct tty_display_info *tty; - /* The frame size change obviously applies to a termcap-controlled - frame. Find such a frame in the list, and assume it's the only - one (since the redisplay code always writes to stdout, not a - FILE * specified in the frame structure). Record the new size, - but don't reallocate the data structures now. Let that be done - later outside of the signal handler. */ + /* The frame size change obviously applies to a single + termcap-controlled terminal, but we can't decide which. + Therefore, we resize the frames corresponding to each tty. + */ + for (tty = tty_list; tty; tty = tty->next) { - { - Lisp_Object tail, frame; + if (! tty->term_initted) + continue; - FOR_EACH_FRAME (tail, frame) - { - if (FRAME_TERMCAP_P (XFRAME (frame))) - { - change_frame_size (XFRAME (frame), height, width, 0, 1, 0); - break; - } - } + get_tty_size (fileno (tty->input), &width, &height); + + { + Lisp_Object tail, frame; + + FOR_EACH_FRAME (tail, frame) + if (FRAME_TERMCAP_P (XFRAME (frame)) && FRAME_TTY (XFRAME (frame)) == tty) + /* Record the new sizes, but don't reallocate the data + structures now. Let that be done later outside of the + signal handler. */ + change_frame_size (XFRAME (frame), height, width, 0, 1, 0); + } } - + signal (SIGWINCH, window_change_signal); errno = old_errno; } @@ -6054,10 +6067,11 @@ change_frame_size (f, newheight, newwidth, pretend, delay, safe) { Lisp_Object tail, frame; - if (! FRAME_WINDOW_P (f)) + if (FRAME_MSDOS_P (f)) { - /* When using termcap, or on MS-DOS, all frames use - the same screen, so a change in size affects all frames. */ + /* On MS-DOS, all frames use the same screen, so a change in + size affects all frames. Termcap now supports multiple + ttys. */ FOR_EACH_FRAME (tail, frame) if (! FRAME_WINDOW_P (XFRAME (frame))) change_frame_size_1 (XFRAME (frame), newheight, newwidth, @@ -6137,7 +6151,7 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe) newheight - FRAME_TOP_MARGIN (f), 0); if (FRAME_TERMCAP_P (f) && !pretend) - FrameRows = newheight; + FrameRows (FRAME_TTY (f)) = newheight; } if (new_frame_total_cols != FRAME_TOTAL_COLS (f)) @@ -6147,7 +6161,7 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe) set_window_width (FRAME_MINIBUF_WINDOW (f), new_frame_total_cols, 0); if (FRAME_TERMCAP_P (f) && !pretend) - FrameCols = newwidth; + FrameCols (FRAME_TTY (f)) = newwidth; if (WINDOWP (f->tool_bar_window)) XSETFASTINT (XWINDOW (f->tool_bar_window)->total_cols, newwidth); @@ -6197,14 +6211,22 @@ FILE = nil means just close any termscript file currently open. */) (file) Lisp_Object file; { - if (termscript != 0) fclose (termscript); - termscript = 0; + struct tty_display_info *tty; + + if (! FRAME_TERMCAP_P (SELECTED_FRAME ())) + error ("Current frame is not on a tty device"); + + tty = CURTTY (); + + if (tty->termscript != 0) + fclose (tty->termscript); + tty->termscript = 0; if (! NILP (file)) { file = Fexpand_file_name (file, Qnil); - termscript = fopen (SDATA (file), "w"); - if (termscript == 0) + tty->termscript = fopen (SDATA (file), "w"); + if (tty->termscript == 0) report_file_error ("Opening termscript", Fcons (file, Qnil)); } return Qnil; @@ -6218,16 +6240,23 @@ Control characters in STRING will have terminal-dependent effects. */) (string) Lisp_Object string; { + struct tty_display_info *tty; + /* ??? Perhaps we should do something special for multibyte strings here. */ CHECK_STRING (string); - fwrite (SDATA (string), 1, SBYTES (string), stdout); - fflush (stdout); - if (termscript) + + if (! FRAME_TERMCAP_P (SELECTED_FRAME ())) + error ("Current frame is not on a tty device"); + + tty = CURTTY (); + + if (tty->termscript) { - fwrite (SDATA (string), 1, SBYTES (string), - termscript); - fflush (termscript); + fwrite (SDATA (string), 1, SBYTES (string), tty->termscript); + fflush (tty->termscript); } + fwrite (SDATA (string), 1, SBYTES (string), tty->output); + fflush (tty->output); return Qnil; } @@ -6245,7 +6274,8 @@ terminate any keyboard macro currently executing. */) putchar (07); else ring_bell (); - fflush (stdout); + if (FRAME_TERMCAP_P (XFRAME (selected_frame))) + fflush (CURTTY ()->output); } else bitch_at_user (); @@ -6262,7 +6292,8 @@ bitch_at_user () error ("Keyboard macro terminated by a command ringing the bell"); else ring_bell (); - fflush (stdout); + if (FRAME_TERMCAP_P (XFRAME (selected_frame))) + fflush (CURTTY ()->output); } @@ -6547,8 +6578,6 @@ the current state. */) Initialization ***********************************************************************/ -char *terminal_type; - /* Initialization done when Emacs fork is started, before doing stty. Determine terminal type and set terminal_driver. Then invoke its decoding routine to set up variables in the terminal package. */ @@ -6556,6 +6585,8 @@ char *terminal_type; void init_display () { + char *terminal_type; + #ifdef HAVE_X_WINDOWS extern int display_arg; #endif @@ -6565,14 +6596,13 @@ init_display () SET_CHAR_GLYPH_FROM_GLYPH (space_glyph, ' '); space_glyph.charpos = -1; - meta_key = 0; inverse_video = 0; cursor_in_echo_area = 0; terminal_type = (char *) 0; /* Now is the time to initialize this; it's used by init_sys_modes during startup. */ - Vwindow_system = Qnil; + Vinitial_window_system = Qnil; /* If the user wants to use a window system, we shouldn't bother initializing the terminal. This is especially important when the @@ -6601,7 +6631,7 @@ init_display () #endif ) { - Vwindow_system = intern ("x"); + Vinitial_window_system = intern ("x"); #ifdef HAVE_X11 Vwindow_system_version = make_number (11); #else @@ -6621,7 +6651,7 @@ init_display () #ifdef HAVE_NTGUI if (!inhibit_window_system) { - Vwindow_system = intern ("w32"); + Vinitial_window_system = intern ("w32"); Vwindow_system_version = make_number (1); adjust_frame_glyphs_initially (); return; @@ -6631,7 +6661,7 @@ init_display () #ifdef MAC_OS if (!inhibit_window_system) { - Vwindow_system = intern ("mac"); + Vinitial_window_system = intern ("mac"); Vwindow_system_version = make_number (1); adjust_frame_glyphs_initially (); return; @@ -6677,8 +6707,32 @@ For types not defined in VMS, use define emacs_term \"TYPE\".\n\ } #endif /* VMS */ - term_init (terminal_type); + { + struct display *d; + struct frame *f = XFRAME (selected_frame); + + /* Open a display on the controlling tty. */ + d = term_init (0, terminal_type, 1); /* Errors are fatal. */ + + /* Convert the initial frame to use the new display. */ + if (! f->output_method == output_initial) + abort (); + f->output_method = d->type; + f->display = d; +#ifdef MULTI_KBOARD + f->kboard = d->display_info.tty->kboard; +#endif + d->reference_count++; + d->display_info.tty->top_frame = selected_frame; + change_frame_size (XFRAME (selected_frame), FrameRows (d->display_info.tty), FrameCols (d->display_info.tty), 0, 0, 1); + + /* Delete the initial display. */ + if (--initial_display->reference_count == 0 + && initial_display->delete_display_hook) + (*initial_display->delete_display_hook) (initial_display); + } + { struct frame *sf = SELECTED_FRAME (); int width = FRAME_TOTAL_COLS (sf); @@ -6712,7 +6766,7 @@ For types not defined in VMS, use define emacs_term \"TYPE\".\n\ and internal_terminal_init. */ && (strcmp (terminal_type, "internal") != 0 || inhibit_window_system) #endif - && NILP (Vwindow_system)) + && NILP (Vinitial_window_system)) { /* For the initial frame, we don't have any way of knowing what are the foreground and background colors of the terminal. */ @@ -6824,8 +6878,8 @@ A non-nil value is useful if the terminal can automatically preserve Emacs's frame display when you reenter Emacs. It is up to you to set this variable if your terminal can do that. */); - DEFVAR_LISP ("window-system", &Vwindow_system, - doc: /* Name of window system that Emacs is displaying through. + DEFVAR_LISP ("initial-window-system", &Vinitial_window_system, + doc: /* Name of the window system that Emacs uses for the first frame. The value is a symbol--for instance, `x' for X windows. The value is nil if Emacs is using a text-only terminal. */); @@ -6861,7 +6915,7 @@ See `buffer-display-table' for more information. */); if (noninteractive) #endif { - Vwindow_system = Qnil; + Vinitial_window_system = Qnil; Vwindow_system_version = Qnil; } } diff --git a/src/emacs.c b/src/emacs.c index 66a2af72fb5..e74c9eaf412 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -54,6 +54,7 @@ Boston, MA 02111-1307, USA. */ #include "blockinput.h" #include "syssignal.h" #include "process.h" +#include "frame.h" #include "termhooks.h" #include "keyboard.h" #include "keymap.h" @@ -191,7 +192,7 @@ int display_arg; char *stack_bottom; #ifdef HAVE_WINDOW_SYSTEM -extern Lisp_Object Vwindow_system; +extern Lisp_Object Vinitial_window_system; #endif /* HAVE_WINDOW_SYSTEM */ extern Lisp_Object Vauto_save_list_file_name; @@ -1574,13 +1575,6 @@ main (argc, argv #endif /* end #ifdef HAVE_NTGUI */ } - if (!noninteractive) - { -#ifdef VMS - init_vms_input ();/* init_display calls get_frame_size, that needs this. */ -#endif /* VMS */ - init_display (); /* Determine terminal type. init_sys_modes uses results. */ - } #ifndef MAC_OS8 /* Called before init_window_once for Mac OS Classic. */ init_keyboard (); /* This too must precede init_sys_modes. */ @@ -1588,7 +1582,13 @@ main (argc, argv #ifdef VMS init_vmsproc (); /* And this too. */ #endif /* VMS */ - init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.). */ + if (!noninteractive) + { +#ifdef VMS + init_vms_input ();/* init_display calls get_tty_size, that needs this. */ +#endif /* VMS */ + init_display (); /* Determine terminal type. Calls init_sys_modes. */ + } #if defined (HAVE_X_WINDOWS) || defined (WINDOWSNT) || defined (HAVE_CARBON) init_xfns (); #endif /* HAVE_X_WINDOWS */ @@ -1926,9 +1926,9 @@ sort_args (argc, argv) bcopy (new, argv, sizeof (char *) * argc); - free (options); - free (new); - free (priority); + xfree (options); + xfree (new); + xfree (priority); } DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P", @@ -2007,15 +2007,14 @@ shut_down_emacs (sig, no_x, stuff) if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1 && tpgrp == pgrp) { - fflush (stdout); - reset_sys_modes (); + reset_all_sys_modes (); if (sig && sig != SIGTERM) fprintf (stderr, "Fatal error (%d)", sig); } } #else fflush (stdout); - reset_sys_modes (); + reset_all_sys_modes (); #endif stuff_buffered_input (stuff); @@ -2034,9 +2033,9 @@ shut_down_emacs (sig, no_x, stuff) #if 0 /* This triggers a bug in XCloseDisplay and is not needed. */ #ifdef HAVE_X_WINDOWS /* It's not safe to call intern here. Maybe we are crashing. */ - if (!noninteractive && SYMBOLP (Vwindow_system) - && SCHARS (SYMBOL_NAME (Vwindow_system)) == 1 - && SREF (SYMBOL_NAME (Vwindow_system), 0) == 'x' + if (!noninteractive && SYMBOLP (Vinitial_window_system) + && SCHARS (SYMBOL_NAME (Vinitial_window_system)) == 1 + && SREF (SYMBOL_NAME (Vinitial_window_system), 0) == 'x' && ! no_x) Fx_close_current_connection (); #endif /* HAVE_X_WINDOWS */ diff --git a/src/fontset.c b/src/fontset.c index 6ed1efff092..61e05b68c72 100644 --- a/src/fontset.c +++ b/src/fontset.c @@ -45,6 +45,7 @@ Boston, MA 02111-1307, USA. */ #ifdef MAC_OS #include "macterm.h" #endif +#include "termhooks.h" #ifdef FONTSET_DEBUG #undef xassert @@ -1280,7 +1281,7 @@ DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0, STORE_XCHAR2B (&char2b, c1, c2); else STORE_XCHAR2B (&char2b, 0, c1); - rif->encode_char (c, &char2b, fontp, NULL); + FRAME_RIF (f)->encode_char (c, &char2b, fontp, NULL); code = (XCHAR2B_BYTE1 (&char2b) << 8) | XCHAR2B_BYTE2 (&char2b); } return Fcons (build_string (face->font_name), make_number (code)); diff --git a/src/frame.c b/src/frame.c index 934c11d98bc..c7b5491500f 100644 --- a/src/frame.c +++ b/src/frame.c @@ -42,6 +42,7 @@ Boston, MA 02111-1307, USA. */ #include "fontset.h" #endif #include "blockinput.h" +#include "termchar.h" #include "termhooks.h" #include "dispextern.h" #include "window.h" @@ -106,12 +107,13 @@ Lisp_Object Qmenu_bar_lines, Qtool_bar_lines; Lisp_Object Qleft_fringe, Qright_fringe; Lisp_Object Qbuffer_predicate, Qbuffer_list; Lisp_Object Qtty_color_mode; +Lisp_Object Qtty, Qtty_type; +Lisp_Object Qwindow_system; Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth; Lisp_Object Qface_set_after_frame_default; - Lisp_Object Vterminal_frame; Lisp_Object Vdefault_frame_alist; Lisp_Object Vdefault_frame_scroll_bars; @@ -121,8 +123,8 @@ Lisp_Object Vdelete_frame_functions; static void set_menu_bar_lines_1 (window, n) - Lisp_Object window; - int n; + Lisp_Object window; + int n; { struct window *w = XWINDOW (window); @@ -180,8 +182,6 @@ set_menu_bar_lines (f, value, oldval) Lisp_Object Vemacs_iconified; Lisp_Object Vframe_list; -struct x_output tty_display; - extern Lisp_Object Vminibuffer_list; extern Lisp_Object get_minibuffer (); extern Lisp_Object Fhandle_switch_frame (); @@ -203,6 +203,7 @@ See also `frame-live-p'. */) return Qnil; switch (XFRAME (object)->output_method) { + case output_initial: /* The initial frame is like a termcap frame. */ case output_termcap: return Qt; case output_x_window: @@ -233,6 +234,30 @@ return values. */) : Qnil); } +DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0, + doc: /* The name of the window system that FRAME is displaying through. +The value is a symbol---for instance, 'x' for X windows. +The value is nil if Emacs is using a text-only terminal. + +FRAME defaults to the currently selected frame. */) + (frame) + Lisp_Object frame; +{ + Lisp_Object type; + if (NILP (frame)) + frame = selected_frame; + + type = Fframep (frame); + + if (NILP (type)) + wrong_type_argument (Qframep, frame); + + if (EQ (type, Qt)) + return Qnil; + else + return type; +} + struct frame * make_frame (mini_p) int mini_p; @@ -474,18 +499,19 @@ make_minibuffer_frame () } #endif /* HAVE_WINDOW_SYSTEM */ -/* Construct a frame that refers to the terminal (stdin and stdout). */ +/* Construct a frame that refers to a terminal. */ static int terminal_frame_count; struct frame * -make_terminal_frame () +make_initial_frame (void) { - register struct frame *f; + struct frame *f; + struct display *display; Lisp_Object frame; - char name[20]; #ifdef MULTI_KBOARD + /* Create the initial keyboard. */ if (!initial_kboard) { initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); @@ -499,6 +525,52 @@ make_terminal_frame () if (! (NILP (Vframe_list) || CONSP (Vframe_list))) Vframe_list = Qnil; + display = init_initial_display (); + + f = make_frame (1); + XSETFRAME (frame, f); + + Vframe_list = Fcons (frame, Vframe_list); + + terminal_frame_count = 1; + f->name = build_string ("F1"); + + f->visible = 1; + f->async_visible = 1; + + f->output_method = display->type; + f->display = display; + f->display->reference_count++; + f->output_data.nothing = 0; + + FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR; + FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR; + + FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; + FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none; + +#ifdef MULTI_KBOARD + f->kboard = initial_kboard; +#endif + + return f; +} + + +struct frame * +make_terminal_frame (tty_name, tty_type) + char *tty_name; + char *tty_type; +{ + register struct frame *f; + struct display *display; + Lisp_Object frame; + char name[20]; + + /* Open the display before creating the new frame, because + create_tty_display might throw an error. */ + display = term_init (tty_name, tty_type, 0); /* Errors are not fatal. */ + f = make_frame (1); XSETFRAME (frame, f); @@ -537,12 +609,35 @@ make_terminal_frame () #else #ifdef WINDOWSNT f->output_method = output_termcap; - f->output_data.x = &tty_display; + f->output_data.x = &tty_display; /* XXX ??? */ #else #ifdef MAC_OS8 make_mac_terminal_frame (f); #else - f->output_data.x = &tty_display; + { + f->output_method = output_termcap; + f->display = display; + f->display->reference_count++; + create_tty_output (f); + + FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR; + FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR; + + FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; + FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none; + +#ifdef MULTI_KBOARD + f->kboard = FRAME_TTY (f)->kboard; +#endif + + /* Set the top frame to the newly created frame. */ + if (FRAME_TTY (f)->top_frame + && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame))) + XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */ + + FRAME_TTY (f)->top_frame = frame; + } + #ifdef CANNOT_DUMP FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR; FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR; @@ -559,12 +654,21 @@ make_terminal_frame () DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame, 1, 1, 0, - doc: /* Create an additional terminal frame. -You can create multiple frames on a text-only terminal in this way. -Only the selected terminal frame is actually displayed. + doc: /* Create an additional terminal frame, possibly on another terminal. This function takes one argument, an alist specifying frame parameters. -In practice, generally you don't need to specify any parameters. -Note that changing the size of one terminal frame automatically affects all. */) + +You can create multiple frames on a single text-only terminal, but +only one of them (the selected terminal frame) is actually displayed. + +In practice, generally you don't need to specify any parameters, +except when you want to create a new frame on another terminal. +In that case, the `tty' parameter specifies the device file to open, +and the `tty-type' parameter specifies the terminal type. Example: + + (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm"))) + +Note that changing the size of one terminal frame automatically +affects all frames on the same terminal device. */) (parms) Lisp_Object parms; { @@ -582,20 +686,73 @@ Note that changing the size of one terminal frame automatically affects all. */ if (sf->output_method != output_mac) error ("Not running on a Macintosh screen; cannot make a new Macintosh frame"); #else +#if 0 /* This should work now! */ if (sf->output_method != output_termcap) error ("Not using an ASCII terminal now; cannot make a new ASCII frame"); #endif +#endif #endif /* not MSDOS */ - f = make_terminal_frame (); + { + Lisp_Object tty, tty_type; + char *name = 0, *type = 0; + + /* XXX Ugh, there must be a better way to do this. */ + tty = Fassq (Qtty, parms); + if (EQ (tty, Qnil)) + tty = Fassq (Qtty, XFRAME (selected_frame)->param_alist); + if (EQ (tty, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame)) + && FRAME_TTY (XFRAME (selected_frame))->name) + tty = build_string (FRAME_TTY (XFRAME (selected_frame))->name); + if (EQ (tty, Qnil)) + tty = Fassq (Qtty, Vdefault_frame_alist); + if (! EQ (tty, Qnil) && ! STRINGP (tty)) + tty = XCDR (tty); + if (EQ (tty, Qnil) || !STRINGP (tty)) + tty = Qnil; + + tty_type = Fassq (Qtty_type, parms); + if (EQ (tty_type, Qnil)) + tty_type = Fassq (Qtty, XFRAME (selected_frame)->param_alist); + if (EQ (tty_type, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame)) + && FRAME_TTY (XFRAME (selected_frame))->type) + tty_type = build_string (FRAME_TTY (XFRAME (selected_frame))->type); + if (EQ (tty_type, Qnil)) + tty_type = Fassq (Qtty_type, Vdefault_frame_alist); + if (! EQ (tty_type, Qnil) && ! STRINGP (tty_type)) + tty_type = XCDR (tty_type); + if (EQ (tty_type, Qnil) || !STRINGP (tty_type)) + tty_type = Qnil; + + if (! EQ (tty, Qnil)) + { + name = (char *) alloca (SBYTES (tty) + 1); + strncpy (name, SDATA (tty), SBYTES (tty)); + name[SBYTES (tty)] = 0; + } + + if (! EQ (tty_type, Qnil)) + { + type = (char *) alloca (SBYTES (tty_type) + 1); + strncpy (type, SDATA (tty_type), SBYTES (tty_type)); + type[SBYTES (tty_type)] = 0; + } + + f = make_terminal_frame (name, type); + } - change_frame_size (f, FRAME_LINES (sf), - FRAME_COLS (sf), 0, 0, 0); + { + int width, height; + get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height); + change_frame_size (f, height, width, 0, 0, 0); + } + adjust_glyphs (f); calculate_costs (f); XSETFRAME (frame, f); Fmodify_frame_parameters (frame, Vdefault_frame_alist); Fmodify_frame_parameters (frame, parms); + Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qnil), Qnil)); /* Make the frame face alist be frame-specific, so that each frame could change its face definitions independently. */ @@ -694,6 +851,15 @@ do_switch_frame (frame, track, for_deletion) if (!for_deletion && FRAME_HAS_MINIBUF_P (sf)) resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1); + if (FRAME_TERMCAP_P (XFRAME (selected_frame)) + && FRAME_TERMCAP_P (XFRAME (frame)) + && FRAME_TTY (XFRAME (selected_frame)) == FRAME_TTY (XFRAME (frame))) + { + XFRAME (selected_frame)->async_visible = 2; /* obscured */ + XFRAME (frame)->async_visible = 1; + FRAME_TTY (XFRAME (frame))->top_frame = frame; + } + selected_frame = frame; if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame))) last_nonminibuf_frame = XFRAME (selected_frame); @@ -927,7 +1093,10 @@ next_frame (frame, minibuf) f = XCAR (tail); if (passed - && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) + && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame)) + && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) + || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame)) + && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))) { /* Decide whether this frame is eligible to be returned. */ @@ -1004,7 +1173,10 @@ prev_frame (frame, minibuf) if (EQ (frame, f) && !NILP (prev)) return prev; - if (FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) + if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame)) + && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) + || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame)) + && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))) { /* Decide whether this frame is eligible to be returned, according to minibuf. */ @@ -1231,7 +1403,7 @@ The functions are run with one arg, the frame to be deleted. */) { FOR_EACH_FRAME (tail, frame1) { - if (! EQ (frame, frame1)) + if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1))) break; } } @@ -1298,13 +1470,26 @@ The functions are run with one arg, the frame to be deleted. */) promise that the display of the frame must be valid until we have called the window-system-dependent frame destruction routine. */ - /* I think this should be done with a hook. */ -#ifdef HAVE_WINDOW_SYSTEM - if (FRAME_WINDOW_P (f)) - x_destroy_window (f); -#endif + if (FRAME_DISPLAY (f)->delete_frame_hook) + (*FRAME_DISPLAY (f)->delete_frame_hook) (f); + + { + struct display *display = FRAME_DISPLAY (f); - f->output_data.nothing = 0; + f->output_data.nothing = 0; + f->display = 0; /* Now the frame is dead. */ + + /* If needed, delete the device that this frame was on. + (This must be done after the frame is killed.) */ + display->reference_count--; + if (display->reference_count == 0) + { + if (display->delete_display_hook) + (*display->delete_display_hook) (display); + else + delete_display (display); + } + } /* If we've deleted the last_nonminibuf_frame, then try to find another one. */ @@ -1419,11 +1604,11 @@ and returns whatever that function returns. */) #ifdef HAVE_MOUSE /* It's okay for the hook to refrain from storing anything. */ - if (mouse_position_hook) - (*mouse_position_hook) (&f, -1, - &lispy_dummy, &party_dummy, - &x, &y, - &long_dummy); + if (FRAME_DISPLAY (f)->mouse_position_hook) + (*FRAME_DISPLAY (f)->mouse_position_hook) (&f, -1, + &lispy_dummy, &party_dummy, + &x, &y, + &long_dummy); if (! NILP (x)) { col = XINT (x); @@ -1462,11 +1647,11 @@ and nil for X and Y. */) #ifdef HAVE_MOUSE /* It's okay for the hook to refrain from storing anything. */ - if (mouse_position_hook) - (*mouse_position_hook) (&f, -1, - &lispy_dummy, &party_dummy, - &x, &y, - &long_dummy); + if (FRAME_DISPLAY (f)->mouse_position_hook) + (*FRAME_DISPLAY (f)->mouse_position_hook) (&f, -1, + &lispy_dummy, &party_dummy, + &x, &y, + &long_dummy); #endif XSETFRAME (lispy_dummy, f); return Fcons (lispy_dummy, Fcons (x, y)); @@ -1728,16 +1913,19 @@ doesn't support multiple overlapping frames, this function does nothing. */) (frame) Lisp_Object frame; { + struct frame *f; if (NILP (frame)) frame = selected_frame; CHECK_LIVE_FRAME (frame); + f = XFRAME (frame); + /* Do like the documentation says. */ Fmake_frame_visible (frame); - if (frame_raise_lower_hook) - (*frame_raise_lower_hook) (XFRAME (frame), 1); + if (FRAME_DISPLAY (f)->frame_raise_lower_hook) + (*FRAME_DISPLAY (f)->frame_raise_lower_hook) (f, 1); return Qnil; } @@ -1751,13 +1939,17 @@ doesn't support multiple overlapping frames, this function does nothing. */) (frame) Lisp_Object frame; { + struct frame *f; + if (NILP (frame)) frame = selected_frame; CHECK_LIVE_FRAME (frame); - if (frame_raise_lower_hook) - (*frame_raise_lower_hook) (XFRAME (frame), 0); + f = XFRAME (frame); + + if (FRAME_DISPLAY (f)->frame_raise_lower_hook) + (*FRAME_DISPLAY (f)->frame_raise_lower_hook) (f, 0); return Qnil; } @@ -1791,6 +1983,8 @@ The redirection lasts until `redirect-frame-focus' is called to change it. */) (frame, focus_frame) Lisp_Object frame, focus_frame; { + struct frame *f; + /* Note that we don't check for a live frame here. It's reasonable to redirect the focus of a frame you're about to delete, if you know what other frame should receive those keystrokes. */ @@ -1799,10 +1993,12 @@ The redirection lasts until `redirect-frame-focus' is called to change it. */) if (! NILP (focus_frame)) CHECK_LIVE_FRAME (focus_frame); - XFRAME (frame)->focus_frame = focus_frame; + f = XFRAME (frame); + + f->focus_frame = focus_frame; - if (frame_rehighlight_hook) - (*frame_rehighlight_hook) (XFRAME (frame)); + if (FRAME_DISPLAY (f)->frame_rehighlight_hook) + (*FRAME_DISPLAY (f)->frame_rehighlight_hook) (f); return Qnil; } @@ -2691,8 +2887,8 @@ x_set_frame_parameters (f, alist) if (NATNUMP (param_index) && (XFASTINT (param_index) < sizeof (frame_parms)/sizeof (frame_parms[0])) - && rif->frame_parm_handlers[XINT (param_index)]) - (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value); + && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)]) + (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value); } } } @@ -2735,8 +2931,8 @@ x_set_frame_parameters (f, alist) if (NATNUMP (param_index) && (XFASTINT (param_index) < sizeof (frame_parms)/sizeof (frame_parms[0])) - && rif->frame_parm_handlers[XINT (param_index)]) - (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value); + && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)]) + (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value); } } @@ -3937,7 +4133,13 @@ syms_of_frame () staticpro (&Qbackground_mode); Qtty_color_mode = intern ("tty-color-mode"); staticpro (&Qtty_color_mode); - + Qtty = intern ("tty"); + staticpro (&Qtty); + Qtty_type = intern ("tty-type"); + staticpro (&Qtty_type); + Qwindow_system = intern ("window-system"); + staticpro (&Qwindow_system); + Qface_set_after_frame_default = intern ("face-set-after-frame-default"); staticpro (&Qface_set_after_frame_default); @@ -4026,7 +4228,7 @@ Setting this variable does not affect existing frames, only new ones. */); staticpro (&Qinhibit_default_face_x_resources); DEFVAR_LISP ("terminal-frame", &Vterminal_frame, - doc: /* The initial frame-object, which represents Emacs's stdout. */); + doc: /* The initial frame-object, which represents Emacs's stdout. */); DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified, doc: /* Non-nil if all of emacs is iconified and frame updates are not needed. */); @@ -4074,6 +4276,7 @@ This variable is local to the current terminal and cannot be buffer-local. */); defsubr (&Sactive_minibuffer_window); defsubr (&Sframep); defsubr (&Sframe_live_p); + defsubr (&Swindow_system); defsubr (&Smake_terminal_frame); defsubr (&Shandle_switch_frame); defsubr (&Signore_event); diff --git a/src/frame.h b/src/frame.h index 8bdaff99754..5037ffd0553 100644 --- a/src/frame.h +++ b/src/frame.h @@ -28,9 +28,7 @@ Boston, MA 02111-1307, USA. */ /* Miscellanea. */ -/* Nonzero means don't assume anything about current contents of - actual terminal frame */ - +/* Nonzero means there is at least one garbaged frame. */ extern int frame_garbaged; /* Nonzero means FRAME_MESSAGE_BUF (selected_frame) is being used by @@ -43,6 +41,7 @@ extern int message_buf_print; enum output_method { + output_initial, output_termcap, output_x_window, output_msdos_raw, @@ -67,30 +66,10 @@ enum text_cursor_kinds HBAR_CURSOR }; -#if !defined(MSDOS) && !defined(WINDOWSNT) && !defined(MAC_OS) - -#if !defined(HAVE_X_WINDOWS) - -#define PIX_TYPE int - -/* A (mostly empty) x_output structure definition for building Emacs - on Unix and GNU/Linux without X support. */ -struct x_output -{ - PIX_TYPE background_pixel; - PIX_TYPE foreground_pixel; -}; - -#endif /* ! HAVE_X_WINDOWS */ +#define FRAME_FOREGROUND_PIXEL(f) ((f)->foreground_pixel) +#define FRAME_BACKGROUND_PIXEL(f) ((f)->background_pixel) - -#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel) -#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel) - -/* A structure describing a termcap frame display. */ -extern struct x_output tty_display; - -#endif /* ! MSDOS && ! WINDOWSNT && ! MAC_OS */ +struct display; struct frame { @@ -278,20 +257,24 @@ struct frame /* Canonical Y unit. Height of a line, in pixels. */ int line_height; - /* The output method says how the contents of this frame - are displayed. It could be using termcap, or using an X window. */ + /* The output method says how the contents of this frame are + displayed. It could be using termcap, or using an X window. + This must be the same as the display->type. */ enum output_method output_method; - /* A structure of auxiliary data used for displaying the contents. - struct x_output is used for X window frames; - it is defined in xterm.h. - struct w32_output is used for W32 window frames; - it is defined in w32term.h. */ + /* The display that this frame uses. If this is NULL, then the + frame is deleted. */ + struct display *display; + + /* Display-dependent, frame-local auxiliary data used for displaying + the contents. When the frame is deleted, this data is deleted as + well. */ union output_data { - struct x_output *x; - struct w32_output *w32; - struct mac_output *mac; + struct tty_output *tty; /* termchar.h */ + struct x_output *x; /* xterm.h */ + struct w32_output *w32; /* w32term.h */ + struct mac_output *mac; /* macterm.h */ EMACS_INT nothing; } output_data; @@ -307,9 +290,12 @@ struct frame int left_fringe_width, right_fringe_width; #ifdef MULTI_KBOARD + /* XXX Maybe this should be moved to struct display, too. */ /* A pointer to the kboard structure associated with this frame. - For termcap frames, this points to initial_kboard. For X frames, - it will be the same as display.x->display_info->kboard. */ + For termcap frames, it will be the same as + display->display_info.tty->kboard. + For X frames, it will be the same as + display->display_info.x->kboard. */ struct kboard *kboard; #endif @@ -336,13 +322,13 @@ struct frame frame becomes visible again, it must be marked as garbaged. The FRAME_SAMPLE_VISIBILITY macro takes care of this. - On Windows NT/9X, to avoid wasting effort updating visible frames - that are actually completely obscured by other windows on the - display, we bend the meaning of visible slightly: if greater than - 1, then the frame is obscured - we still consider it to be - "visible" as seen from lisp, but we don't bother updating it. We - must take care to garbage the frame when it ceaces to be obscured - though. Note that these semantics are only used on NT/9X. + On ttys and on Windows NT/9X, to avoid wasting effort updating + visible frames that are actually completely obscured by other + windows on the display, we bend the meaning of visible slightly: + if greater than 1, then the frame is obscured - we still consider + it to be "visible" as seen from lisp, but we don't bother + updating it. We must take care to garbage the frame when it + ceaces to be obscured though. iconified is nonzero if the frame is currently iconified. @@ -455,7 +441,11 @@ struct frame /* Set to non-zero in when we want for force a flush_display in update_frame, usually after resizing the frame. */ unsigned force_flush_display_p : 1; - + + /* All display backends seem to need these two pixel values. */ + unsigned long background_pixel; + unsigned long foreground_pixel; + /* Set to non-zero if the default face for the frame has been realized. Reset to zero whenever the default face changes. Used to see the difference between a font change and face change. */ @@ -477,6 +467,7 @@ typedef struct frame *FRAME_PTR; #define WINDOW_FRAME(w) (w)->frame /* Test a frame for particular kinds of display methods. */ +#define FRAME_INITIAL_P(f) ((f)->output_method == output_initial) #define FRAME_TERMCAP_P(f) ((f)->output_method == output_termcap) #define FRAME_X_P(f) ((f)->output_method == output_x_window) #define FRAME_W32_P(f) ((f)->output_method == output_w32) @@ -500,7 +491,7 @@ typedef struct frame *FRAME_PTR; #endif /* Nonzero if frame F is still alive (not deleted). */ -#define FRAME_LIVE_P(f) ((f)->output_data.nothing != 0) +#define FRAME_LIVE_P(f) ((f)->display != 0) /* Nonzero if frame F is a minibuffer-only frame. */ #define FRAME_MINIBUF_ONLY_P(f) \ @@ -740,7 +731,10 @@ typedef struct frame *FRAME_PTR; Also, if a frame used to be invisible, but has just become visible, it must be marked as garbaged, since redisplay hasn't been keeping - up its contents. */ + up its contents. + + Note that a tty frame is visible if and only if it is the topmost + frame. */ #define FRAME_SAMPLE_VISIBILITY(f) \ (((f)->async_visible && (f)->visible != (f)->async_visible) ? \ @@ -783,7 +777,8 @@ extern Lisp_Object Qframep, Qframe_live_p; extern struct frame *last_nonminibuf_frame; -extern struct frame *make_terminal_frame P_ ((void)); +extern struct frame *make_initial_frame P_ ((void)); +extern struct frame *make_terminal_frame P_ ((char *, char *)); extern struct frame *make_frame P_ ((int)); #ifdef HAVE_WINDOW_SYSTEM extern struct frame *make_minibuffer_frame P_ ((void)); @@ -1011,6 +1006,8 @@ extern Lisp_Object Qx_resource_name; extern Lisp_Object Qleft, Qright, Qtop, Qbox; extern Lisp_Object Qdisplay; +extern Lisp_Object Qwindow_system; + #ifdef HAVE_WINDOW_SYSTEM /* The class of this X application. */ diff --git a/src/fringe.c b/src/fringe.c index ba4fbfdc7e0..b14668e8d7e 100644 --- a/src/fringe.c +++ b/src/fringe.c @@ -28,6 +28,7 @@ Boston, MA 02111-1307, USA. */ #include "dispextern.h" #include "buffer.h" #include "blockinput.h" +#include "termhooks.h" #ifdef HAVE_WINDOW_SYSTEM @@ -588,7 +589,7 @@ draw_fringe_bitmap_1 (w, row, left_p, overlay, which) break; } - rif->draw_fringe_bitmap (w, row, &p); + FRAME_RIF (f)->draw_fringe_bitmap (w, row, &p); } void @@ -998,8 +999,9 @@ If WHICH overrides a standard fringe bitmap, the original bitmap is restored. * fbp = &fringe_bitmaps[n]; if (*fbp && (*fbp)->dynamic) { - if (rif->destroy_fringe_bitmap) - rif->destroy_fringe_bitmap (n); + /* XXX Is SELECTED_FRAME OK here? */ + if (FRAME_RIF (SELECTED_FRAME ())->destroy_fringe_bitmap) + FRAME_RIF (SELECTED_FRAME ())->destroy_fringe_bitmap (n); xfree (*fbp); *fbp = NULL; } @@ -1080,8 +1082,9 @@ init_fringe_bitmap (which, fb, once_p) { Fdestroy_fringe_bitmap (make_number (which)); - if (rif->define_fringe_bitmap) - rif->define_fringe_bitmap (which, fb->bits, fb->height, fb->width); + /* XXX Is SELECTED_FRAME OK here? */ + if (FRAME_RIF (SELECTED_FRAME ())->define_fringe_bitmap) + FRAME_RIF (SELECTED_FRAME ())->define_fringe_bitmap (which, fb->bits, fb->height, fb->width); fringe_bitmaps[which] = fb; if (which >= max_used_fringe_bitmap) diff --git a/src/indent.c b/src/indent.c index 0d9fe9aaf9c..1b3e5847510 100644 --- a/src/indent.c +++ b/src/indent.c @@ -20,6 +20,8 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <config.h> +#include <stdio.h> + #include "lisp.h" #include "buffer.h" #include "charset.h" diff --git a/src/keyboard.c b/src/keyboard.c index 3e58a2a75a8..5e8397e7458 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -22,13 +22,13 @@ Boston, MA 02111-1307, USA. */ #include <config.h> #include <signal.h> #include <stdio.h> +#include "lisp.h" #include "termchar.h" #include "termopts.h" -#include "lisp.h" +#include "frame.h" #include "termhooks.h" #include "macros.h" #include "keyboard.h" -#include "frame.h" #include "window.h" #include "commands.h" #include "buffer.h" @@ -55,7 +55,6 @@ Boston, MA 02111-1307, USA. */ #endif /* not MSDOS */ #include "syssignal.h" -#include "systty.h" #include <sys/types.h> #ifdef HAVE_UNISTD_H @@ -89,9 +88,6 @@ int interrupt_input_blocked; int interrupt_input_pending; -/* File descriptor to use for input. */ -extern int input_fd; - #ifdef HAVE_WINDOW_SYSTEM /* Make all keyboard buffers much bigger when using X windows. */ #ifdef MAC_OS8 @@ -464,11 +460,6 @@ FILE *dribble; /* Nonzero if input is available. */ int input_pending; -/* 1 if should obey 0200 bit in input chars as "Meta", 2 if should - keep 0200 bit in input chars. 0 to ignore the 0200 bit. */ - -int meta_key; - /* Non-zero means force key bindings update in parse_menu_item. */ int update_menu_bindings; @@ -595,9 +586,6 @@ int interrupt_input; /* Nonzero while interrupts are temporarily deferred during redisplay. */ int interrupts_deferred; -/* Nonzero means use ^S/^Q for flow control. */ -int flow_control; - /* Allow m- file to inhibit use of FIONREAD. */ #ifdef BROKEN_FIONREAD #undef FIONREAD @@ -674,6 +662,7 @@ static Lisp_Object apply_modifiers P_ ((int, Lisp_Object)); static void clear_event P_ ((struct input_event *)); static void any_kboard_state P_ ((void)); static SIGTYPE interrupt_signal P_ ((int signalnum)); +static void handle_interrupt P_ ((void)); /* Nonzero means don't try to suspend even if the operating system seems to support it. */ @@ -1184,9 +1173,7 @@ cmd_error_internal (data, context) if (!sf->glyphs_initialized_p /* This is the case of the frame dumped with Emacs, when we're running under a window system. */ - || (!NILP (Vwindow_system) - && !inhibit_window_system - && FRAME_TERMCAP_P (sf)) + || FRAME_INITIAL_P (sf) || noninteractive) { stream = Qexternal_debugging_output; @@ -1335,6 +1322,7 @@ cancel_hourglass_unwind (arg) Lisp_Object arg; { cancel_hourglass (); + return Qnil; } #endif @@ -2050,7 +2038,10 @@ void start_polling () { #ifdef POLL_FOR_INPUT - if (read_socket_hook && !interrupt_input) + /* XXX This condition was (read_socket_hook && !interrupt_input), + but read_socket_hook is not global anymore. Let's pretend that + it's always set. */ + if (!interrupt_input) { /* Turn alarm handling on unconditionally. It might have been turned off in process.c. */ @@ -2084,7 +2075,10 @@ int input_polling_used () { #ifdef POLL_FOR_INPUT - return read_socket_hook && !interrupt_input; + /* XXX This condition was (read_socket_hook && !interrupt_input), + but read_socket_hook is not global anymore. Let's pretend that + it's always set. */ + return !interrupt_input; #else return 0; #endif @@ -2096,7 +2090,10 @@ void stop_polling () { #ifdef POLL_FOR_INPUT - if (read_socket_hook && !interrupt_input) + /* XXX This condition was (read_socket_hook && !interrupt_input), + but read_socket_hook is not global anymore. Let's pretend that + it's always set. */ + if (!interrupt_input) ++poll_suppress_count; #endif } @@ -3612,7 +3609,7 @@ kbd_buffer_store_event_hold (event, hold_quit) } last_event_timestamp = event->timestamp; - interrupt_signal (0 /* dummy */); + handle_interrupt (); return; } @@ -4088,7 +4085,11 @@ kbd_buffer_get_event (kbp, used_mouse_menu) If there is no valid info, it does not store anything so x remains nil. */ x = Qnil; - (*mouse_position_hook) (&f, 0, &bar_window, &part, &x, &y, &time); + + /* XXX Can f or mouse_position_hook be NULL here? */ + if (f && FRAME_DISPLAY (f)->mouse_position_hook) + (*FRAME_DISPLAY (f)->mouse_position_hook) (&f, 0, &bar_window, + &part, &x, &y, &time); obj = Qnil; @@ -6529,7 +6530,10 @@ gobble_input (expected) } else #ifdef POLL_FOR_INPUT - if (read_socket_hook && !interrupt_input && poll_suppress_count == 0) + /* XXX This condition was (read_socket_hook && !interrupt_input), + but read_socket_hook is not global anymore. Let's pretend that + it's always set. */ + if (!interrupt_input && poll_suppress_count == 0) { SIGMASKTYPE mask; mask = sigblock (sigmask (SIGALRM)); @@ -6608,145 +6612,215 @@ read_avail_input (expected) { register int i; int nread = 0; + int err; + struct display *d; - if (read_socket_hook) + /* Loop through the available displays, and call their input hooks. */ + d = display_list; + while (d) { - int discard = 0; - int nr; - struct input_event hold_quit; + struct display *next = d->next_display; - EVENT_INIT (hold_quit); - hold_quit.kind = NO_EVENT; + if (d->read_socket_hook) + { + int discard = 0; + int nr; - /* No need for FIONREAD or fcntl; just say don't wait. */ - while (nr = (*read_socket_hook) (input_fd, expected, &hold_quit), nr > 0) - { - nread += nr; - expected = 0; - } - if (hold_quit.kind != NO_EVENT) - kbd_buffer_store_event (&hold_quit); + struct input_event hold_quit; + + EVENT_INIT (hold_quit); + hold_quit.kind = NO_EVENT; + + /* No need for FIONREAD or fcntl; just say don't wait. */ + while (nr = (*d->read_socket_hook) (d, expected, &hold_quit), nr > 0) + { + nread += nr; + expected = 0; + } + + if (nr == -1) /* Not OK to read input now. */ + { + err = 1; + } + else if (nr == -2) /* Non-transient error. */ + { + /* The display device terminated; it should be closed. */ + + /* Kill Emacs if this was our last display. */ + if (! display_list->next_display) + /* Formerly simply reported no input, but that + sometimes led to a failure of Emacs to terminate. + SIGHUP seems appropriate if we can't reach the + terminal. */ + /* ??? Is it really right to send the signal just to + this process rather than to the whole process + group? Perhaps on systems with FIONREAD Emacs is + alone in its group. */ + kill (getpid (), SIGHUP); + + /* XXX Is calling delete_display safe here? It calls Fdelete_frame. */ + if (d->delete_display_hook) + (*d->delete_display_hook) (d); + else + delete_display (d); + } + + if (hold_quit.kind != NO_EVENT) + kbd_buffer_store_event (&hold_quit); + } + + d = next; } - else - { - /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than - the kbd_buffer can really hold. That may prevent loss - of characters on some systems when input is stuffed at us. */ - unsigned char cbuf[KBD_BUFFER_SIZE - 1]; - int n_to_read; - /* Determine how many characters we should *try* to read. */ + if (err && !nread) + nread = -1; + + return nread; +} + +/* This is the tty way of reading available input. + + Note that each terminal device has its own `struct display' object, + and so this function is called once for each individual termcap + display. The first parameter indicates which device to read from. */ + +int +tty_read_avail_input (struct display *display, + int expected, + struct input_event *hold_quit) +{ + /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than + the kbd_buffer can really hold. That may prevent loss + of characters on some systems when input is stuffed at us. */ + unsigned char cbuf[KBD_BUFFER_SIZE - 1]; + int n_to_read, i; + struct tty_display_info *tty = display->display_info.tty; + int nread = 0; + + if (display->type != output_termcap) + abort (); + + /* XXX I think the following code should be moved to separate hook + functions in system-dependent files. */ #ifdef WINDOWSNT - return 0; + return 0; #else /* not WINDOWSNT */ #ifdef MSDOS - n_to_read = dos_keysns (); - if (n_to_read == 0) - return 0; + n_to_read = dos_keysns (); + if (n_to_read == 0) + return 0; + + cbuf[0] = dos_keyread (); + nread = 1; + #else /* not MSDOS */ + + if (! tty->term_initted) /* In case we get called during bootstrap. */ + return 0; + + if (! tty->input) + return 0; /* The terminal is suspended. */ + + /* Determine how many characters we should *try* to read. */ #ifdef FIONREAD - /* Find out how much input is available. */ - if (ioctl (input_fd, FIONREAD, &n_to_read) < 0) - /* Formerly simply reported no input, but that sometimes led to - a failure of Emacs to terminate. - SIGHUP seems appropriate if we can't reach the terminal. */ - /* ??? Is it really right to send the signal just to this process - rather than to the whole process group? - Perhaps on systems with FIONREAD Emacs is alone in its group. */ - { - if (! noninteractive) - kill (getpid (), SIGHUP); - else - n_to_read = 0; - } - if (n_to_read == 0) - return 0; - if (n_to_read > sizeof cbuf) - n_to_read = sizeof cbuf; + /* Find out how much input is available. */ + if (ioctl (fileno (tty->input), FIONREAD, &n_to_read) < 0) + { + if (! noninteractive) + return -2; /* Close this display. */ + else + n_to_read = 0; + } + if (n_to_read == 0) + return 0; + if (n_to_read > sizeof cbuf) + n_to_read = sizeof cbuf; #else /* no FIONREAD */ #if defined (USG) || defined (DGUX) || defined(CYGWIN) - /* Read some input if available, but don't wait. */ - n_to_read = sizeof cbuf; - fcntl (input_fd, F_SETFL, O_NDELAY); + /* Read some input if available, but don't wait. */ + n_to_read = sizeof cbuf; + fcntl (fileno (tty->input), F_SETFL, O_NDELAY); #else - you lose; + you lose; #endif #endif -#endif /* not MSDOS */ -#endif /* not WINDOWSNT */ - /* Now read; for one reason or another, this will not block. - NREAD is set to the number of chars read. */ - do - { -#ifdef MSDOS - cbuf[0] = dos_keyread (); - nread = 1; -#else - nread = emacs_read (input_fd, cbuf, n_to_read); -#endif - /* POSIX infers that processes which are not in the session leader's - process group won't get SIGHUP's at logout time. BSDI adheres to - this part standard and returns -1 from read (0) with errno==EIO - when the control tty is taken away. - Jeffrey Honig <jch@bsdi.com> says this is generally safe. */ - if (nread == -1 && errno == EIO) - kill (0, SIGHUP); + /* Now read; for one reason or another, this will not block. + NREAD is set to the number of chars read. */ + do + { + nread = emacs_read (fileno (tty->input), cbuf, n_to_read); + /* POSIX infers that processes which are not in the session leader's + process group won't get SIGHUP's at logout time. BSDI adheres to + this part standard and returns -1 from read (0) with errno==EIO + when the control tty is taken away. + Jeffrey Honig <jch@bsdi.com> says this is generally safe. */ + if (nread == -1 && errno == EIO) + return -2; /* Close this display. */ #if defined (AIX) && (! defined (aix386) && defined (_BSD)) - /* The kernel sometimes fails to deliver SIGHUP for ptys. - This looks incorrect, but it isn't, because _BSD causes - O_NDELAY to be defined in fcntl.h as O_NONBLOCK, - and that causes a value other than 0 when there is no input. */ - if (nread == 0) - kill (0, SIGHUP); -#endif - } - while ( - /* We used to retry the read if it was interrupted. - But this does the wrong thing when O_NDELAY causes - an EAGAIN error. Does anybody know of a situation - where a retry is actually needed? */ + /* The kernel sometimes fails to deliver SIGHUP for ptys. + This looks incorrect, but it isn't, because _BSD causes + O_NDELAY to be defined in fcntl.h as O_NONBLOCK, + and that causes a value other than 0 when there is no input. */ + if (nread == 0) + return -2; /* Close this display. */ +#endif + } + while ( + /* We used to retry the read if it was interrupted. + But this does the wrong thing when O_NDELAY causes + an EAGAIN error. Does anybody know of a situation + where a retry is actually needed? */ #if 0 - nread < 0 && (errno == EAGAIN + nread < 0 && (errno == EAGAIN #ifdef EFAULT - || errno == EFAULT + || errno == EFAULT #endif #ifdef EBADSLT - || errno == EBADSLT + || errno == EBADSLT #endif - ) + ) #else - 0 + 0 #endif - ); + ); #ifndef FIONREAD #if defined (USG) || defined (DGUX) || defined (CYGWIN) - fcntl (input_fd, F_SETFL, 0); + fcntl (fileno (tty->input), F_SETFL, 0); #endif /* USG or DGUX or CYGWIN */ #endif /* no FIONREAD */ - for (i = 0; i < nread; i++) - { - struct input_event buf; - EVENT_INIT (buf); - buf.kind = ASCII_KEYSTROKE_EVENT; - buf.modifiers = 0; - if (meta_key == 1 && (cbuf[i] & 0x80)) - buf.modifiers = meta_modifier; - if (meta_key != 2) - cbuf[i] &= ~0x80; - - buf.code = cbuf[i]; - buf.frame_or_window = selected_frame; - buf.arg = Qnil; - - kbd_buffer_store_event (&buf); - /* Don't look at input that follows a C-g too closely. - This reduces lossage due to autorepeat on C-g. */ - if (buf.kind == ASCII_KEYSTROKE_EVENT - && buf.code == quit_char) - break; - } + + if (nread <= 0) + return nread; + +#endif /* not MSDOS */ +#endif /* not WINDOWSNT */ + + for (i = 0; i < nread; i++) + { + struct input_event buf; + EVENT_INIT (buf); + buf.kind = ASCII_KEYSTROKE_EVENT; + buf.modifiers = 0; + if (tty->meta_key == 1 && (cbuf[i] & 0x80)) + buf.modifiers = meta_modifier; + if (tty->meta_key != 2) + cbuf[i] &= ~0x80; + + buf.code = cbuf[i]; + /* Set the frame corresponding to the active tty. Note that the + value of selected_frame is not reliable here, redisplay tends + to temporarily change it. */ + buf.frame_or_window = tty->top_frame; + buf.arg = Qnil; + + kbd_buffer_store_event (&buf); + /* Don't look at input that follows a C-g too closely. + This reduces lossage due to autorepeat on C-g. */ + if (buf.kind == ASCII_KEYSTROKE_EVENT + && buf.code == quit_char) + break; } return nread; @@ -9862,8 +9936,12 @@ detect_input_pending_run_timers (do_display) from an idle timer function. The symptom of the bug is that the cursor sometimes doesn't become visible until the next X event is processed. --gerd. */ - if (rif) - rif->flush_display (NULL); + { + Lisp_Object tail, frame; + FOR_EACH_FRAME (tail, frame) + if (FRAME_RIF (XFRAME (frame))) + FRAME_RIF (XFRAME (frame))->flush_display (XFRAME (frame)); + } } return input_pending; @@ -10105,6 +10183,9 @@ On such systems, Emacs starts a subshell instead of suspending. */) int width, height; struct gcpro gcpro1; + if (tty_list && tty_list->next) + error ("Suspend is not supported with multiple ttys"); + if (!NILP (stuffstring)) CHECK_STRING (stuffstring); @@ -10113,11 +10194,11 @@ On such systems, Emacs starts a subshell instead of suspending. */) call1 (Vrun_hooks, intern ("suspend-hook")); GCPRO1 (stuffstring); - get_frame_size (&old_width, &old_height); - reset_sys_modes (); + get_tty_size (fileno (CURTTY ()->input), &old_width, &old_height); + reset_all_sys_modes (); /* sys_suspend can get an error if it tries to fork a subshell and the system resources aren't available for that. */ - record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes, + record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_all_sys_modes, Qnil); stuff_buffered_input (stuffstring); if (cannot_suspend) @@ -10129,7 +10210,7 @@ On such systems, Emacs starts a subshell instead of suspending. */) /* Check if terminal/window size has changed. Note that this is not useful when we are running directly with a window system; but suspend should be disabled in that case. */ - get_frame_size (&width, &height); + get_tty_size (fileno (CURTTY ()->input), &width, &height); if (width != old_width || height != old_height) change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0); @@ -10189,10 +10270,10 @@ set_waiting_for_input (time_to_clear) { input_available_clear_time = time_to_clear; - /* Tell interrupt_signal to throw back to read_char, */ + /* Tell handle_interrupt to throw back to read_char, */ waiting_for_input = 1; - /* If interrupt_signal was called before and buffered a C-g, + /* If handle_interrupt was called before and buffered a C-g, make it run again now, to avoid timing error. */ if (!NILP (Vquit_flag)) quit_throw_to_read_char (); @@ -10201,45 +10282,76 @@ set_waiting_for_input (time_to_clear) void clear_waiting_for_input () { - /* Tell interrupt_signal not to throw back to read_char, */ + /* Tell handle_interrupt not to throw back to read_char, */ waiting_for_input = 0; input_available_clear_time = 0; } -/* This routine is called at interrupt level in response to C-g. - - If interrupt_input, this is the handler for SIGINT. Otherwise, it - is called from kbd_buffer_store_event, in handling SIGIO or - SIGTINT. +/* The SIGINT handler. - If `waiting_for_input' is non zero, then unless `echoing' is - nonzero, immediately throw back to read_char. - - Otherwise it sets the Lisp variable quit-flag not-nil. This causes - eval to throw, when it gets a chance. If quit-flag is already - non-nil, it stops the job right away. */ + If we have a frame on the controlling tty, the SIGINT was generated + by C-g, so we call handle_interrupt. Otherwise, the handler kills + Emacs. */ static SIGTYPE interrupt_signal (signalnum) /* If we don't have an argument, */ int signalnum; /* some compilers complain in signal calls. */ { - char c; /* Must preserve main program's value of errno. */ int old_errno = errno; - struct frame *sf = SELECTED_FRAME (); + struct display *display; #if defined (USG) && !defined (POSIX_SIGNALS) - if (!read_socket_hook && NILP (Vwindow_system)) + /* USG systems forget handlers when they are used; + must reestablish each time */ + signal (SIGINT, interrupt_signal); + signal (SIGQUIT, interrupt_signal); +#endif /* USG */ + + /* See if we have a display on our controlling terminal. */ + display = get_named_tty_display (NULL); + if (!display) { - /* USG systems forget handlers when they are used; - must reestablish each time */ - signal (SIGINT, interrupt_signal); - signal (SIGQUIT, interrupt_signal); + /* If there are no frames there, let's pretend that we are a + well-behaving UN*X program and quit. */ + Fkill_emacs (Qnil); + } + else + { + /* Otherwise, the SIGINT was probably generated by C-g. */ + + /* Set internal_last_event_frame to the top frame of the + controlling tty, if we have a frame there. We disable the + interrupt key on secondary ttys, so the SIGINT must have come + from the controlling tty. */ + internal_last_event_frame = display->display_info.tty->top_frame; + + handle_interrupt (); } -#endif /* USG */ + + errno = old_errno; +} + +/* This routine is called at interrupt level in response to C-g. + + It is called from the SIGINT handler or kbd_buffer_store_event. + + If `waiting_for_input' is non zero, then unless `echoing' is + nonzero, immediately throw back to read_char. + + Otherwise it sets the Lisp variable quit-flag not-nil. This causes + eval to throw, when it gets a chance. If quit-flag is already + non-nil, it stops the job right away. */ + +static void +handle_interrupt () +{ + char c; + struct frame *sf = SELECTED_FRAME (); cancel_echoing (); + /* XXX This code needs to be revised for multi-tty support. */ if (!NILP (Vquit_flag) && (FRAME_TERMCAP_P (sf) || FRAME_MSDOS_P (sf))) { @@ -10249,7 +10361,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */ sigblock (sigmask (SIGINT)); fflush (stdout); - reset_sys_modes (); + reset_all_sys_modes (); #ifdef SIGTSTP /* Support possible in later USG versions */ /* @@ -10328,7 +10440,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */ printf ("Continuing...\n"); #endif /* not MSDOS */ fflush (stdout); - init_sys_modes (); + init_all_sys_modes (); sigfree (); } else @@ -10356,9 +10468,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */ } if (waiting_for_input && !echoing) - quit_throw_to_read_char (); - - errno = old_errno; + quit_throw_to_read_char (); } /* Handle a C-g by making read_char return C-g. */ @@ -10405,6 +10515,11 @@ See also `current-input-mode'. */) (interrupt, flow, meta, quit) Lisp_Object interrupt, flow, meta, quit; { + /* XXX This function needs to be revised for multi-device support. + Currently it compiles fine, but its semantics are wrong. It sets + global parameters (e.g. interrupt_input) based on only the + current frame's device. */ + if (!NILP (quit) && (!INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400)) error ("set-input-mode: QUIT must be an ASCII character"); @@ -10415,12 +10530,12 @@ See also `current-input-mode'. */) #ifndef DOS_NT /* this causes startup screen to be restored and messes with the mouse */ - reset_sys_modes (); + reset_all_sys_modes (); #endif #ifdef SIGIO /* Note SIGIO has been undef'd if FIONREAD is missing. */ - if (read_socket_hook) + if (FRAME_DISPLAY (SELECTED_FRAME ())->read_socket_hook) { /* When using X, don't give the user a real choice, because we haven't implemented the mechanisms to support it. */ @@ -10441,19 +10556,24 @@ See also `current-input-mode'. */) interrupt_input = 1; #endif - flow_control = !NILP (flow); - if (NILP (meta)) - meta_key = 0; - else if (EQ (meta, Qt)) - meta_key = 1; - else - meta_key = 2; + if (FRAME_TERMCAP_P (XFRAME (selected_frame))) + { + struct tty_display_info *tty = CURTTY (); + tty->flow_control = !NILP (flow); + if (NILP (meta)) + tty->meta_key = 0; + else if (EQ (meta, Qt)) + tty->meta_key = 1; + else + tty->meta_key = 2; + } + if (!NILP (quit)) /* Don't let this value be out of range. */ - quit_char = XINT (quit) & (meta_key ? 0377 : 0177); + quit_char = XINT (quit) & (NILP (meta) ? 0177 : 0377); #ifndef DOS_NT - init_sys_modes (); + init_all_sys_modes (); #endif #ifdef POLL_FOR_INPUT @@ -10480,10 +10600,21 @@ The elements of this list correspond to the arguments of () { Lisp_Object val[4]; + struct frame *sf = XFRAME (selected_frame); val[0] = interrupt_input ? Qt : Qnil; - val[1] = flow_control ? Qt : Qnil; - val[2] = meta_key == 2 ? make_number (0) : meta_key == 1 ? Qt : Qnil; + if (FRAME_TERMCAP_P (sf)) + { + val[1] = FRAME_TTY (sf)->flow_control ? Qt : Qnil; + val[2] = (FRAME_TTY (sf)->meta_key == 2 + ? make_number (0) + : (CURTTY ()->meta_key == 1 ? Qt : Qnil)); + } + else + { + val[1] = Qnil; + val[2] = Qt; + } XSETFASTINT (val[3], quit_char); return Flist (sizeof (val) / sizeof (val[0]), val); @@ -10591,8 +10722,14 @@ init_keyboard () wipe_kboard (current_kboard); init_kboard (current_kboard); - if (!noninteractive && !read_socket_hook && NILP (Vwindow_system)) + if (!noninteractive) { + /* Before multi-tty support, these handlers used to be installed + only if the current session was a tty session. Now an Emacs + session may have multiple display types, so we always handle + SIGINT. There is special code in interrupt_signal to exit + Emacs on SIGINT when there are no termcap frames on the + controlling terminal. */ signal (SIGINT, interrupt_signal); #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) /* For systems with SysV TERMIO, C-g is set up for both SIGINT and diff --git a/src/keyboard.h b/src/keyboard.h index d92f13a5059..3f38b7ded6b 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -21,7 +21,7 @@ Boston, MA 02111-1307, USA. */ /* Length of echobuf field in each KBOARD. */ /* Each KBOARD represents one logical input stream from which Emacs gets input. - If we are using an ordinary terminal, it has one KBOARD object. + If we are using ordinary terminals, it has one KBOARD object for each terminal device. Usually each X display screen has its own KBOARD, but when two of them are on the same X server, we assume they share a keyboard and give them one KBOARD in common. @@ -152,7 +152,7 @@ struct kboard }; #ifdef MULTI_KBOARD -/* Temporarily used before a frame has been opened, and for termcap frames */ +/* Temporarily used before a frame has been opened. */ extern KBOARD *initial_kboard; /* In the single-kboard state, this is the kboard @@ -342,5 +342,8 @@ extern void kbd_buffer_store_help_event P_ ((Lisp_Object, Lisp_Object)); extern Lisp_Object menu_item_eval_property P_ ((Lisp_Object)); extern int kbd_buffer_events_waiting P_ ((int)); +extern int tty_read_avail_input P_ ((struct display *, int, + struct input_event *)); + /* arch-tag: 769cbade-1ba9-4950-b886-db265b061aa3 (do not change this comment) */ diff --git a/src/keymap.c b/src/keymap.c index b181c3c5074..4cea62c10fb 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -27,6 +27,7 @@ Boston, MA 02111-1307, USA. */ #include "buffer.h" #include "charset.h" #include "keyboard.h" +#include "frame.h" #include "termhooks.h" #include "blockinput.h" #include "puresize.h" diff --git a/src/lisp.h b/src/lisp.h index 951f68862ce..371bd0d729d 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2997,26 +2997,28 @@ EXFUN (Fx_popup_menu, 2); EXFUN (Fx_popup_dialog, 2); extern void syms_of_xmenu P_ ((void)); +/* defined in termchar.h */ +struct tty_display_info; + +/* defined in termhooks.h */ +struct display; + /* defined in sysdep.c */ extern void stuff_char P_ ((char c)); extern void init_sigio P_ ((int)); -extern void request_sigio P_ ((void)); -extern void unrequest_sigio P_ ((void)); -extern void reset_sys_modes P_ ((void)); extern void sys_subshell P_ ((void)); extern void sys_suspend P_ ((void)); extern void discard_tty_input P_ ((void)); -extern void init_sys_modes P_ ((void)); -extern void reset_sys_modes P_ ((void)); -extern void get_frame_size P_ ((int *, int *)); +extern void init_sys_modes P_ ((struct tty_display_info *)); +extern void reset_sys_modes P_ ((struct tty_display_info *)); +extern void init_all_sys_modes P_ ((void)); +extern void reset_all_sys_modes P_ ((void)); extern void wait_for_termination P_ ((int)); extern void flush_pending_output P_ ((int)); extern void child_setup_tty P_ ((int)); extern void setup_pty P_ ((int)); extern int set_window_size P_ ((int, int, int)); extern void create_process P_ ((Lisp_Object, char **, Lisp_Object)); -extern int tabs_safe_p P_ ((void)); -extern void init_baud_rate P_ ((void)); extern int emacs_open P_ ((const char *, int, int)); extern int emacs_close P_ ((int)); extern int emacs_read P_ ((int, char *, unsigned int)); diff --git a/src/lread.c b/src/lread.c index 4aa49c59eef..ac353c798dc 100644 --- a/src/lread.c +++ b/src/lread.c @@ -33,6 +33,7 @@ Boston, MA 02111-1307, USA. */ #include <epaths.h> #include "commands.h" #include "keyboard.h" +#include "frame.h" #include "termhooks.h" #include "coding.h" diff --git a/src/macterm.c b/src/macterm.c index 4ff8972dacb..f6269791c51 100644 --- a/src/macterm.c +++ b/src/macterm.c @@ -9043,12 +9043,13 @@ mac_initialize () redeem_scroll_bar_hook = XTredeem_scroll_bar; judge_scroll_bars_hook = XTjudge_scroll_bars; - scroll_region_ok = 1; /* we'll scroll partial frames */ - char_ins_del_ok = 1; - line_ins_del_ok = 1; /* we'll just blt 'em */ - fast_clear_end_of_line = 1; /* X does this well */ - memory_below_frame = 0; /* we don't remember what scrolls - off the bottom */ + TTY_SCROLL_REGION_OK (CURTTY ()) = 1; /* we'll scroll partial frames */ + TTY_CHAR_INS_DEL_OK (CURTTY ()) = 1; + TTY_LINE_INS_DEL_OK (CURTTY ()) = 1; /* we'll just blt 'em */ + TTY_FAST_CLEAR_END_OF_LINE (CURTTY ()) = 1; /* X does this well */ + TTY_MEMORY_BELOW_FRAME (CURTTY ()) = 0; /* we don't remember what + scrolls off the + bottom */ baud_rate = 19200; x_noop_count = 0; diff --git a/src/macterm.h b/src/macterm.h index 17b8a0fb298..78a312e6125 100644 --- a/src/macterm.h +++ b/src/macterm.h @@ -392,9 +392,6 @@ typedef struct mac_output mac_output; #define FRAME_MAC_WINDOW(f) ((f)->output_data.mac->mWP) #define FRAME_X_WINDOW(f) ((f)->output_data.mac->mWP) -#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel) -#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel) - #define FRAME_FONT(f) ((f)->output_data.mac->font) #define FRAME_FONTSET(f) ((f)->output_data.mac->fontset) diff --git a/src/minibuf.c b/src/minibuf.c index b91a4a4fc2a..1f5a114540d 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -34,6 +34,7 @@ Boston, MA 02111-1307, USA. */ #include "syntax.h" #include "intervals.h" #include "keymap.h" +#include "termhooks.h" extern int quit_char; @@ -695,8 +696,12 @@ read_minibuf (map, initial, prompt, backup_n, expflag, XWINDOW (minibuf_window)->cursor.x = 0; XWINDOW (minibuf_window)->must_be_updated_p = 1; update_frame (XFRAME (selected_frame), 1, 1); - if (rif && rif->flush_display) - rif->flush_display (XFRAME (XWINDOW (minibuf_window)->frame)); + { + struct frame *f = XFRAME (XWINDOW (minibuf_window)->frame); + struct redisplay_interface *rif = FRAME_RIF (f); + if (rif && rif->flush_display) + rif->flush_display (f); + } } /* Make minibuffer contents into a string. */ diff --git a/src/msdos.c b/src/msdos.c index a2fd011e74c..e73f284fa4d 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -2580,7 +2580,7 @@ internal_terminal_init () set_terminal_modes_hook = IT_set_terminal_modes; reset_terminal_modes_hook = IT_reset_terminal_modes; set_terminal_window_hook = IT_set_terminal_window; - char_ins_del_ok = 0; + TTY_CHAR_INS_DEL_OK (CURTTY ()) = 0; #endif } @@ -4858,7 +4858,7 @@ croak (badfunc) char *badfunc; { fprintf (stderr, "%s not yet implemented\r\n", badfunc); - reset_sys_modes (); + reset_all_sys_modes (); exit (1); } diff --git a/src/process.c b/src/process.c index 0db0638f85d..3e4b5dbc673 100644 --- a/src/process.c +++ b/src/process.c @@ -126,11 +126,11 @@ Boston, MA 02111-1307, USA. */ #include "charset.h" #include "coding.h" #include "process.h" +#include "frame.h" #include "termhooks.h" #include "termopts.h" #include "commands.h" #include "keyboard.h" -#include "frame.h" #include "blockinput.h" #include "dispextern.h" #include "composite.h" @@ -302,11 +302,11 @@ extern int keyboard_bit_set P_ ((SELECT_TYPE *)); static SELECT_TYPE input_wait_mask; -/* Mask that excludes keyboard input descriptor (s). */ +/* Mask that excludes keyboard input descriptor(s). */ static SELECT_TYPE non_keyboard_wait_mask; -/* Mask that excludes process input descriptor (s). */ +/* Mask that excludes process input descriptor(s). */ static SELECT_TYPE non_process_wait_mask; @@ -6536,20 +6536,12 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p, -/* The first time this is called, assume keyboard input comes from DESC - instead of from where we used to expect it. - Subsequent calls mean assume input keyboard can come from DESC - in addition to other places. */ - -static int add_keyboard_wait_descriptor_called_flag; +/* Add DESC to the set of keyboard input descriptors. */ void add_keyboard_wait_descriptor (desc) int desc; { - if (! add_keyboard_wait_descriptor_called_flag) - FD_CLR (0, &input_wait_mask); - add_keyboard_wait_descriptor_called_flag = 1; FD_SET (desc, &input_wait_mask); FD_SET (desc, &non_process_wait_mask); if (desc > max_keyboard_desc) @@ -6614,7 +6606,12 @@ init_process () process_output_skip = 0; #endif + /* Don't do this, it caused infinite select loops. The display + method should call add_keyboard_wait_descriptor on stdin if it + needs that. */ +#if 0 FD_SET (0, &input_wait_mask); +#endif Vprocess_alist = Qnil; for (i = 0; i < MAXDESC; i++) diff --git a/src/scroll.c b/src/scroll.c index 6c6aa4abf98..8f83851a2e0 100644 --- a/src/scroll.c +++ b/src/scroll.c @@ -22,12 +22,13 @@ Boston, MA 02111-1307, USA. */ #include <config.h> #include <stdio.h> #include <string.h> -#include "termchar.h" #include "lisp.h" +#include "termchar.h" #include "dispextern.h" #include "keyboard.h" #include "frame.h" #include "window.h" +#include "termhooks.h" /* All costs measured in characters. So no cost can exceed the area of a frame, measured in characters. @@ -100,7 +101,8 @@ calculate_scrolling (frame, matrix, window_size, lines_below, register struct matrix_elt *p, *p1; register int cost, cost1; - int lines_moved = window_size + (scroll_region_ok ? 0 : lines_below); + int lines_moved = window_size + + (FRAME_SCROLL_REGION_OK (frame) ? 0 : lines_below); /* first_insert_cost[I] is the cost of doing the first insert-line at the i'th line of the lines we are considering, where I is origin 1 (as it is below). */ @@ -466,7 +468,8 @@ calculate_direct_scrolling (frame, matrix, window_size, lines_below, /* Overhead of setting the scroll window, plus the extra cost cost of scrolling by a distance of one. The extra cost is added once for consistency with the cost vectors */ - scroll_overhead = scroll_region_cost + extra_cost; + scroll_overhead + = FRAME_SCROLL_REGION_COST (frame) + extra_cost; /* initialize the top left corner of the matrix */ matrix->writecost = 0; @@ -818,7 +821,7 @@ scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom, matrix = ((struct matrix_elt *) alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix)); - if (scroll_region_ok) + if (FRAME_SCROLL_REGION_OK (frame)) { calculate_direct_scrolling (frame, matrix, window_size, unchanged_at_bottom, @@ -914,7 +917,7 @@ scroll_cost (frame, from, to, amount) if (amount == 0) return 0; - if (! scroll_region_ok) + if (! FRAME_SCROLL_REGION_OK (frame)) limit = height; else if (amount > 0) limit += amount; diff --git a/src/sysdep.c b/src/sysdep.c index 5ede3d27208..20d57b6a6a3 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -46,6 +46,8 @@ extern void srandom P_ ((unsigned int)); #endif #endif +#include "sysselect.h" + #include "blockinput.h" #undef NULL @@ -184,6 +186,7 @@ extern int quit_char; #include "termopts.h" #include "dispextern.h" #include "process.h" +#include "cm.h" /* for reset_sys_modes */ #ifdef WINDOWSNT #include <direct.h> @@ -246,16 +249,11 @@ static int baud_convert[] = int emacs_ospeed; -/* The file descriptor for Emacs's input terminal. - Under Unix, this is normally zero except when using X; - under VMS, we place the input channel number here. */ -int input_fd; - void croak P_ ((char *)); #ifdef AIXHFT -void hft_init (); -void hft_reset (); +void hft_init P_ ((struct tty_display_info *)); +void hft_reset P_ ((struct tty_display_info *)); #endif /* Temporary used by `sigblock' when defined in terms of signprocmask. */ @@ -263,16 +261,7 @@ void hft_reset (); SIGMASKTYPE sigprocmask_set; -/* Specify a different file descriptor for further input operations. */ - -void -change_input_fd (fd) - int fd; -{ - input_fd = fd; -} - -/* Discard pending input on descriptor input_fd. */ +/* Discard pending input on all input descriptors. */ void discard_tty_input () @@ -283,54 +272,61 @@ discard_tty_input () if (noninteractive) return; - /* Discarding input is not safe when the input could contain - replies from the X server. So don't do it. */ - if (read_socket_hook) - return; - #ifdef VMS end_kbd_input (); - SYS$QIOW (0, input_fd, IO$_READVBLK|IO$M_PURGE, input_iosb, 0, 0, + SYS$QIOW (0, fileno (CURTTY()->input), IO$_READVBLK|IO$M_PURGE, input_iosb, 0, 0, &buf.main, 0, 0, terminator_mask, 0, 0); queue_kbd_input (); #else /* not VMS */ #ifdef APOLLO { - int zero = 0; - ioctl (input_fd, TIOCFLUSH, &zero); + struct tty_display_info *tty; + for (tty = tty_list; tty; tty = tty->next) + { + int zero = 0; + if (tty->input) + ioctl (fileno (tty->input), TIOCFLUSH, &zero); + } } #else /* not Apollo */ #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ while (dos_keyread () != -1) ; #else /* not MSDOS */ - EMACS_GET_TTY (input_fd, &buf); - EMACS_SET_TTY (input_fd, &buf, 0); + { + struct tty_display_info *tty; + for (tty = tty_list; tty; tty = tty->next) + { + if (tty->input) /* Is the device suspended? */ + { + EMACS_GET_TTY (fileno (tty->input), &buf); + EMACS_SET_TTY (fileno (tty->input), &buf, 0); + } + } + } #endif /* not MSDOS */ #endif /* not Apollo */ #endif /* not VMS */ #endif /* not WINDOWSNT */ } + #ifdef SIGTSTP /* Arrange for character C to be read as the next input from - the terminal. */ + the terminal. + XXX What if we have multiple ttys? +*/ void -#ifdef PROTOTYPES stuff_char (char c) -#else -stuff_char (c) - char c; -#endif { - if (read_socket_hook) + if (! FRAME_TERMCAP_P (SELECTED_FRAME ())) return; /* Should perhaps error if in batch mode */ #ifdef TIOCSTI - ioctl (input_fd, TIOCSTI, &c); + ioctl (fileno (CURTTY()->input), TIOCSTI, &c); #else /* no TIOCSTI */ error ("Cannot stuff terminal input characters in this version of Unix"); #endif /* no TIOCSTI */ @@ -339,7 +335,7 @@ stuff_char (c) #endif /* SIGTSTP */ void -init_baud_rate () +init_baud_rate (int fd) { if (noninteractive) emacs_ospeed = 0; @@ -354,7 +350,7 @@ init_baud_rate () #ifdef VMS struct sensemode sg; - SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0, + SYS$QIOW (0, fd, IO$_SENSEMODE, &sg, 0, 0, &sg.class, 12, 0, 0, 0, 0 ); emacs_ospeed = sg.xmit_baud; #else /* not VMS */ @@ -362,7 +358,7 @@ init_baud_rate () struct termios sg; sg.c_cflag = B9600; - tcgetattr (input_fd, &sg); + tcgetattr (fd, &sg); emacs_ospeed = cfgetospeed (&sg); #if defined (USE_GETOBAUD) && defined (getobaud) /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */ @@ -375,16 +371,16 @@ init_baud_rate () sg.c_cflag = B9600; #ifdef HAVE_TCATTR - tcgetattr (input_fd, &sg); + tcgetattr (fd, &sg); #else - ioctl (input_fd, TCGETA, &sg); + ioctl (fd, TCGETA, &sg); #endif emacs_ospeed = sg.c_cflag & CBAUD; #else /* neither VMS nor TERMIOS nor TERMIO */ struct sgttyb sg; sg.sg_ospeed = B9600; - if (ioctl (input_fd, TIOCGETP, &sg) < 0) + if (ioctl (fd, TIOCGETP, &sg) < 0) abort (); emacs_ospeed = sg.sg_ospeed; #endif /* not HAVE_TERMIO */ @@ -400,6 +396,7 @@ init_baud_rate () baud_rate = 1200; } + /*ARGSUSED*/ void set_exclusive_use (fd) @@ -658,7 +655,7 @@ child_setup_tty (out) #ifdef BSD4_1 if (interrupt_input) - reset_sigio (); + reset_sigio (0); #endif /* BSD4_1 */ #ifdef RTU { @@ -915,53 +912,88 @@ restore_signal_handlers (saved_handlers) } } +#ifndef SIGIO +/* If SIGIO is broken, don't do anything. */ +void +init_sigio (int fd) +{ +} + +void +reset_sigio (int fd) +{ +} + +void +request_sigio (void) +{ +} + +void +unrequest_sigio (void) +{ +} + +#else #ifdef F_SETFL -int old_fcntl_flags; +int old_fcntl_flags[MAXDESC]; void init_sigio (fd) int fd; { #ifdef FASYNC - old_fcntl_flags = fcntl (fd, F_GETFL, 0) & ~FASYNC; - fcntl (fd, F_SETFL, old_fcntl_flags | FASYNC); + old_fcntl_flags[fd] = fcntl (fd, F_GETFL, 0) & ~FASYNC; + fcntl (fd, F_SETFL, old_fcntl_flags[fd] | FASYNC); #endif interrupts_deferred = 0; } void -reset_sigio () +reset_sigio (fd) + int fd; { - unrequest_sigio (); +#ifdef FASYNC + fcntl (fd, F_SETFL, old_fcntl_flags[fd]); +#endif } #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */ +/* XXX Uhm, FASYNC is not used anymore here. */ void request_sigio () { + /* XXX read_socket_hook is not global anymore. Is blocking SIGIO + bad under X? */ +#if 0 if (read_socket_hook) return; +#endif #ifdef SIGWINCH sigunblock (sigmask (SIGWINCH)); #endif - fcntl (input_fd, F_SETFL, old_fcntl_flags | FASYNC); + sigunblock (sigmask (SIGIO)); interrupts_deferred = 0; } void -unrequest_sigio () -{ +unrequest_sigio (void) +{ + /* XXX read_socket_hook is not global anymore. Is blocking SIGIO + bad under X? */ +#if 0 if (read_socket_hook) return; - +#endif + #ifdef SIGWINCH sigblock (sigmask (SIGWINCH)); #endif - fcntl (input_fd, F_SETFL, old_fcntl_flags); + sigblock (sigmask (SIGIO)); interrupts_deferred = 1; } @@ -976,7 +1008,8 @@ request_sigio () if (read_socket_hook) return; - ioctl (input_fd, FIOASYNC, &on); + /* XXX CURTTY() is bogus here. */ + ioctl (fileno (CURTTY ()->input), FIOASYNC, &on); interrupts_deferred = 0; } @@ -988,7 +1021,8 @@ unrequest_sigio () if (read_socket_hook) return; - ioctl (input_fd, FIOASYNC, &off); + /* XXX CURTTY() is bogus here. */ + ioctl (fileno (CURTTY ()->input), FIOASYNC, &off); interrupts_deferred = 1; } @@ -1009,7 +1043,7 @@ request_sigio () sigemptyset (&st); sigaddset (&st, SIGIO); - ioctl (input_fd, FIOASYNC, &on); + ioctl (0, FIOASYNC, &on); /* XXX This fails for multiple ttys. */ interrupts_deferred = 0; sigprocmask (SIG_UNBLOCK, &st, (sigset_t *)0); } @@ -1022,7 +1056,7 @@ unrequest_sigio () if (read_socket_hook) return; - ioctl (input_fd, FIOASYNC, &off); + ioctl (0, FIOASYNC, &off); /* XXX This fails for multiple ttys. */ interrupts_deferred = 1; } @@ -1052,6 +1086,7 @@ unrequest_sigio () #endif /* STRIDE */ #endif /* FASYNC */ #endif /* F_SETFL */ +#endif /* SIGIO */ /* Saving and restoring the process group of Emacs's terminal. */ @@ -1074,30 +1109,35 @@ unrequest_sigio () the tty's pgroup just like any other terminal setting. If inherited_group was not the tty's pgroup, then we'll get a SIGTTmumble when we try to change the tty's pgroup, and a CONT if - it goes foreground in the future, which is what should happen. */ + it goes foreground in the future, which is what should happen. + + This variable is initialized in emacs.c. */ int inherited_pgroup; -/* Split off the foreground process group to Emacs alone. - When we are in the foreground, but not started in our own process - group, redirect the TTY to point to our own process group. We need - to be in our own process group to receive SIGIO properly. */ +/* Split off the foreground process group to Emacs alone. When we are + in the foreground, but not started in our own process group, + redirect the tty device handle FD to point to our own process + group. We need to be in our own process group to receive SIGIO + properly. */ void -narrow_foreground_group () +narrow_foreground_group (int fd) { int me = getpid (); setpgrp (0, inherited_pgroup); + if (! inherited_pgroup) + abort (); /* Should not happen. */ if (inherited_pgroup != me) - EMACS_SET_TTY_PGRP (input_fd, &me); + EMACS_SET_TTY_PGRP (fd, &me); /* XXX This only works on the controlling tty. */ setpgrp (0, me); } /* Set the tty to our original foreground group. */ void -widen_foreground_group () +widen_foreground_group (int fd) { if (inherited_pgroup != getpid ()) - EMACS_SET_TTY_PGRP (input_fd, &inherited_pgroup); + EMACS_SET_TTY_PGRP (fd, &inherited_pgroup); setpgrp (0, inherited_pgroup); } @@ -1255,14 +1295,6 @@ emacs_set_tty (fd, settings, flushp) } -/* The initial tty mode bits */ -struct emacs_tty old_tty; - -/* 1 if we have been through init_sys_modes. */ -int term_initted; - -/* 1 if outer tty status has been recorded. */ -int old_tty_valid; #ifdef BSD4_1 /* BSD 4.1 needs to keep track of the lmode bits in order to start @@ -1272,7 +1304,7 @@ int lmode; #ifndef F_SETOWN_BUG #ifdef F_SETOWN -int old_fcntl_owner; +int old_fcntl_owner[MAXDESC]; #endif /* F_SETOWN */ #endif /* F_SETOWN_BUG */ @@ -1297,8 +1329,22 @@ static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1}; static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1}; #endif +/* Initialize the terminal mode on all tty devices that are currently + open. */ + void -init_sys_modes () +init_all_sys_modes (void) +{ + struct tty_display_info *tty; + for (tty = tty_list; tty; tty = tty->next) + init_sys_modes (tty); +} + +/* Initialize the terminal mode on the given tty device. */ + +void +init_sys_modes (tty_out) + struct tty_display_info *tty_out; { struct emacs_tty tty; @@ -1324,6 +1370,9 @@ nil means don't delete them until `list-processes' is run. */); if (noninteractive) return; + if (!tty_out->output) + return; /* The tty is suspended. */ + #ifdef VMS if (!input_ef) input_ef = get_kbd_event_flag (); @@ -1354,266 +1403,287 @@ nil means don't delete them until `list-processes' is run. */); #ifndef VMS4_4 sys_access_reinit (); #endif -#endif /* not VMS */ +#endif /* VMS */ #ifdef BSD_PGRPS - if (! read_socket_hook && EQ (Vwindow_system, Qnil)) - narrow_foreground_group (); +#if 0 + /* read_socket_hook is not global anymore. I think doing this + unconditionally will not cause any problems. */ + if (! read_socket_hook && EQ (Vinitial_window_system, Qnil)) #endif - -#ifdef HAVE_WINDOW_SYSTEM - /* Emacs' window system on MSDOG uses the `internal terminal' and therefore - needs the initialization code below. */ - if (!read_socket_hook && EQ (Vwindow_system, Qnil)) + narrow_foreground_group (fileno (tty_out->input)); #endif - { - EMACS_GET_TTY (input_fd, &old_tty); - old_tty_valid = 1; + if (! tty_out->old_tty) + tty_out->old_tty = (struct emacs_tty *) xmalloc (sizeof (struct emacs_tty)); + + EMACS_GET_TTY (fileno (tty_out->input), tty_out->old_tty); - tty = old_tty; + tty = *tty_out->old_tty; #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) - XSETINT (Vtty_erase_char, old_tty.main.c_cc[VERASE]); + XSETINT (Vtty_erase_char, tty.main.c_cc[VERASE]); #ifdef DGUX - /* This allows meta to be sent on 8th bit. */ - tty.main.c_iflag &= ~INPCK; /* don't check input for parity */ + /* This allows meta to be sent on 8th bit. */ + tty.main.c_iflag &= ~INPCK; /* don't check input for parity */ #endif - tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */ - tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */ + tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */ + tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */ #ifdef INLCR /* I'm just being cautious, since I can't check how widespread INLCR is--rms. */ - tty.main.c_iflag &= ~INLCR; /* Disable map of NL to CR on input */ + tty.main.c_iflag &= ~INLCR; /* Disable map of NL to CR on input */ #endif #ifdef ISTRIP - tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */ + tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */ #endif - tty.main.c_lflag &= ~ECHO; /* Disable echo */ - tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */ + tty.main.c_lflag &= ~ECHO; /* Disable echo */ + tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */ #ifdef IEXTEN - tty.main.c_lflag &= ~IEXTEN; /* Disable other editing characters. */ + tty.main.c_lflag &= ~IEXTEN; /* Disable other editing characters. */ #endif - tty.main.c_lflag |= ISIG; /* Enable signals */ - if (flow_control) - { - tty.main.c_iflag |= IXON; /* Enable start/stop output control */ + tty.main.c_lflag |= ISIG; /* Enable signals */ + if (tty_out->flow_control) + { + tty.main.c_iflag |= IXON; /* Enable start/stop output control */ #ifdef IXANY - tty.main.c_iflag &= ~IXANY; + tty.main.c_iflag &= ~IXANY; #endif /* IXANY */ - } - else - tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */ - tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL - on output */ - tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */ + } + else + tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */ + tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL + on output */ + tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */ #ifdef CS8 - if (meta_key) - { - tty.main.c_cflag |= CS8; /* allow 8th bit on input */ - tty.main.c_cflag &= ~PARENB;/* Don't check parity */ - } + if (tty_out->meta_key) + { + tty.main.c_cflag |= CS8; /* allow 8th bit on input */ + tty.main.c_cflag &= ~PARENB;/* Don't check parity */ + } #endif + if (tty_out->input == stdin) + { tty.main.c_cc[VINTR] = quit_char; /* C-g (usually) gives SIGINT */ /* Set up C-g for both SIGQUIT and SIGINT. - We don't know which we will get, but we handle both alike - so which one it really gives us does not matter. */ + We don't know which we will get, but we handle both alike + so which one it really gives us does not matter. */ tty.main.c_cc[VQUIT] = quit_char; - tty.main.c_cc[VMIN] = 1; /* Input should wait for at least 1 char */ - tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */ + } + else + { + /* We normally don't get interrupt or quit signals from tty + devices other than our controlling terminal; therefore, + we must handle C-g as normal input. Unfortunately, this + means that the interrupt and quit feature must be + disabled on secondary ttys, or we would not even see the + keypress. + + Note that even though emacsclient could have special code + to pass SIGINT to Emacs, we should _not_ enable + interrupt/quit keys for emacsclient frames. This means + that we can't break out of loops in C code from a + secondary tty frame, but we can always decide what + display the C-g came from, which is more important from a + usability point of view. (Consider the case when two + people work together using the same Emacs instance.) */ + tty.main.c_cc[VINTR] = CDISABLE; + tty.main.c_cc[VQUIT] = CDISABLE; + } + tty.main.c_cc[VMIN] = 1; /* Input should wait for at least 1 char */ + tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */ #ifdef VSWTCH - tty.main.c_cc[VSWTCH] = CDISABLE; /* Turn off shell layering use + tty.main.c_cc[VSWTCH] = CDISABLE; /* Turn off shell layering use of C-z */ #endif /* VSWTCH */ - + #if defined (mips) || defined (HAVE_TCATTR) #ifdef VSUSP - tty.main.c_cc[VSUSP] = CDISABLE; /* Turn off mips handling of C-z. */ + tty.main.c_cc[VSUSP] = CDISABLE; /* Turn off mips handling of C-z. */ #endif /* VSUSP */ #ifdef V_DSUSP - tty.main.c_cc[V_DSUSP] = CDISABLE; /* Turn off mips handling of C-y. */ + tty.main.c_cc[V_DSUSP] = CDISABLE; /* Turn off mips handling of C-y. */ #endif /* V_DSUSP */ #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */ - tty.main.c_cc[VDSUSP] = CDISABLE; + tty.main.c_cc[VDSUSP] = CDISABLE; #endif /* VDSUSP */ #ifdef VLNEXT - tty.main.c_cc[VLNEXT] = CDISABLE; + tty.main.c_cc[VLNEXT] = CDISABLE; #endif /* VLNEXT */ #ifdef VREPRINT - tty.main.c_cc[VREPRINT] = CDISABLE; + tty.main.c_cc[VREPRINT] = CDISABLE; #endif /* VREPRINT */ #ifdef VWERASE - tty.main.c_cc[VWERASE] = CDISABLE; + tty.main.c_cc[VWERASE] = CDISABLE; #endif /* VWERASE */ #ifdef VDISCARD - tty.main.c_cc[VDISCARD] = CDISABLE; + tty.main.c_cc[VDISCARD] = CDISABLE; #endif /* VDISCARD */ - if (flow_control) - { + if (tty_out->flow_control) + { #ifdef VSTART - tty.main.c_cc[VSTART] = '\021'; + tty.main.c_cc[VSTART] = '\021'; #endif /* VSTART */ #ifdef VSTOP - tty.main.c_cc[VSTOP] = '\023'; + tty.main.c_cc[VSTOP] = '\023'; #endif /* VSTOP */ - } - else - { + } + else + { #ifdef VSTART - tty.main.c_cc[VSTART] = CDISABLE; + tty.main.c_cc[VSTART] = CDISABLE; #endif /* VSTART */ #ifdef VSTOP - tty.main.c_cc[VSTOP] = CDISABLE; + tty.main.c_cc[VSTOP] = CDISABLE; #endif /* VSTOP */ - } + } #endif /* mips or HAVE_TCATTR */ #ifdef SET_LINE_DISCIPLINE - /* Need to explicitly request TERMIODISC line discipline or - Ultrix's termios does not work correctly. */ - tty.main.c_line = SET_LINE_DISCIPLINE; + /* Need to explicitly request TERMIODISC line discipline or + Ultrix's termios does not work correctly. */ + tty.main.c_line = SET_LINE_DISCIPLINE; #endif #ifdef AIX #ifndef IBMR2AIX - /* AIX enhanced edit loses NULs, so disable it. */ - tty.main.c_line = 0; - tty.main.c_iflag &= ~ASCEDIT; + /* AIX enhanced edit loses NULs, so disable it. */ + tty.main.c_line = 0; + tty.main.c_iflag &= ~ASCEDIT; #else - tty.main.c_cc[VSTRT] = 255; - tty.main.c_cc[VSTOP] = 255; - tty.main.c_cc[VSUSP] = 255; - tty.main.c_cc[VDSUSP] = 255; + tty.main.c_cc[VSTRT] = 255; + tty.main.c_cc[VSTOP] = 255; + tty.main.c_cc[VSUSP] = 255; + tty.main.c_cc[VDSUSP] = 255; #endif /* IBMR2AIX */ - if (flow_control) - { + if (tty_out->flow_control) + { #ifdef VSTART - tty.main.c_cc[VSTART] = '\021'; + tty.main.c_cc[VSTART] = '\021'; #endif /* VSTART */ #ifdef VSTOP - tty.main.c_cc[VSTOP] = '\023'; + tty.main.c_cc[VSTOP] = '\023'; #endif /* VSTOP */ - } - /* Also, PTY overloads NUL and BREAK. - don't ignore break, but don't signal either, so it looks like NUL. - This really serves a purpose only if running in an XTERM window - or via TELNET or the like, but does no harm elsewhere. */ - tty.main.c_iflag &= ~IGNBRK; - tty.main.c_iflag &= ~BRKINT; + } + /* Also, PTY overloads NUL and BREAK. + don't ignore break, but don't signal either, so it looks like NUL. + This really serves a purpose only if running in an XTERM window + or via TELNET or the like, but does no harm elsewhere. */ + tty.main.c_iflag &= ~IGNBRK; + tty.main.c_iflag &= ~BRKINT; #endif #else /* if not HAVE_TERMIO */ #ifdef VMS - tty.main.tt_char |= TT$M_NOECHO; - if (meta_key) - tty.main.tt_char |= TT$M_EIGHTBIT; - if (flow_control) - tty.main.tt_char |= TT$M_TTSYNC; - else - tty.main.tt_char &= ~TT$M_TTSYNC; - tty.main.tt2_char |= TT2$M_PASTHRU | TT2$M_XON; + tty.main.tt_char |= TT$M_NOECHO; + if (meta_key) + tty.main.tt_char |= TT$M_EIGHTBIT; + if (tty_out->flow_control) + tty.main.tt_char |= TT$M_TTSYNC; + else + tty.main.tt_char &= ~TT$M_TTSYNC; + tty.main.tt2_char |= TT2$M_PASTHRU | TT2$M_XON; #else /* not VMS (BSD, that is) */ #ifndef DOS_NT - XSETINT (Vtty_erase_char, tty.main.sg_erase); - tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS); - if (meta_key) - tty.main.sg_flags |= ANYP; - tty.main.sg_flags |= interrupt_input ? RAW : CBREAK; + XSETINT (Vtty_erase_char, tty.main.sg_erase); + tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS); + if (meta_key) + tty.main.sg_flags |= ANYP; + tty.main.sg_flags |= interrupt_input ? RAW : CBREAK; #endif /* not DOS_NT */ #endif /* not VMS (BSD, that is) */ #endif /* not HAVE_TERMIO */ - /* If going to use CBREAK mode, we must request C-g to interrupt - and turn off start and stop chars, etc. If not going to use - CBREAK mode, do this anyway so as to turn off local flow - control for user coming over network on 4.2; in this case, - only t_stopc and t_startc really matter. */ + /* If going to use CBREAK mode, we must request C-g to interrupt + and turn off start and stop chars, etc. If not going to use + CBREAK mode, do this anyway so as to turn off local flow + control for user coming over network on 4.2; in this case, + only t_stopc and t_startc really matter. */ #ifndef HAVE_TERMIO #ifdef HAVE_TCHARS - /* Note: if not using CBREAK mode, it makes no difference how we - set this */ - tty.tchars = new_tchars; - tty.tchars.t_intrc = quit_char; - if (flow_control) - { - tty.tchars.t_startc = '\021'; - tty.tchars.t_stopc = '\023'; - } - - tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH | old_tty.lmode; + /* Note: if not using CBREAK mode, it makes no difference how we + set this */ + tty.tchars = new_tchars; + tty.tchars.t_intrc = quit_char; + if (tty_out->flow_control) + { + tty.tchars.t_startc = '\021'; + tty.tchars.t_stopc = '\023'; + } + + tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH | tty_out->old_tty.lmode; #ifdef ultrix - /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt - anything, and leaving it in breaks the meta key. Go figure. */ - tty.lmode &= ~LLITOUT; + /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt + anything, and leaving it in breaks the meta key. Go figure. */ + tty.lmode &= ~LLITOUT; #endif - + #ifdef BSD4_1 - lmode = tty.lmode; + lmode = tty.lmode; #endif #endif /* HAVE_TCHARS */ #endif /* not HAVE_TERMIO */ #ifdef HAVE_LTCHARS - tty.ltchars = new_ltchars; + tty.ltchars = new_ltchars; #endif /* HAVE_LTCHARS */ #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */ - if (!term_initted) - internal_terminal_init (); - dos_ttraw (); + if (!tty_out->term_initted) + internal_terminal_init (); + dos_ttraw (); #endif - EMACS_SET_TTY (input_fd, &tty, 0); + EMACS_SET_TTY (fileno (tty_out->input), &tty, 0); - /* This code added to insure that, if flow-control is not to be used, - we have an unlocked terminal at the start. */ + /* This code added to insure that, if flow-control is not to be used, + we have an unlocked terminal at the start. */ #ifdef TCXONC - if (!flow_control) ioctl (input_fd, TCXONC, 1); + if (!tty_out->flow_control) ioctl (fileno (tty_out->input), TCXONC, 1); #endif #ifndef APOLLO #ifdef TIOCSTART - if (!flow_control) ioctl (input_fd, TIOCSTART, 0); + if (!tty_out->flow_control) ioctl (fileno (tty_out->input), TIOCSTART, 0); #endif #endif #if defined (HAVE_TERMIOS) || defined (HPUX9) #ifdef TCOON - if (!flow_control) tcflow (input_fd, TCOON); + if (!tty_out->flow_control) tcflow (fileno (tty_out->input), TCOON); #endif #endif #ifdef AIXHFT - hft_init (); + hft_init (tty_out); #ifdef IBMR2AIX - { - /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it - to be only LF. This is the way that is done. */ - struct termio tty; - - if (ioctl (1, HFTGETID, &tty) != -1) - write (1, "\033[20l", 5); - } + { + /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it + to be only LF. This is the way that is done. */ + struct termio tty; + + if (ioctl (1, HFTGETID, &tty) != -1) + write (1, "\033[20l", 5); + } #endif #endif /* AIXHFT */ #ifdef VMS /* Appears to do nothing when in PASTHRU mode. - SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0, + SYS$QIOW (0, fileno (tty_out->input), IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0, interrupt_signal, oob_chars, 0, 0, 0, 0); */ - queue_kbd_input (0); + queue_kbd_input (0); #endif /* VMS */ - } #ifdef F_SETFL #ifndef F_SETOWN_BUG #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */ - if (interrupt_input - && ! read_socket_hook && EQ (Vwindow_system, Qnil)) + if (interrupt_input) { - old_fcntl_owner = fcntl (input_fd, F_GETOWN, 0); - fcntl (input_fd, F_SETOWN, getpid ()); - init_sigio (input_fd); + old_fcntl_owner[fileno (tty_out->input)] = + fcntl (fileno (tty_out->input), F_GETOWN, 0); + fcntl (fileno (tty_out->input), F_SETOWN, getpid ()); + init_sigio (fileno (tty_out->input)); } #endif /* F_GETOWN */ #endif /* F_SETOWN_BUG */ @@ -1621,7 +1691,7 @@ nil means don't delete them until `list-processes' is run. */); #ifdef BSD4_1 if (interrupt_input) - init_sigio (input_fd); + init_sigio (fileno (tty_out->input)); #endif #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */ @@ -1631,53 +1701,55 @@ nil means don't delete them until `list-processes' is run. */); /* This symbol is defined on recent USG systems. Someone says without this call USG won't really buffer the file even with a call to setbuf. */ - setvbuf (stdout, (char *) _sobuf, _IOFBF, sizeof _sobuf); + setvbuf (tty_out->output, (char *) _sobuf, _IOFBF, sizeof _sobuf); #else - setbuf (stdout, (char *) _sobuf); -#endif -#ifdef HAVE_WINDOW_SYSTEM - /* Emacs' window system on MSDOG uses the `internal terminal' and therefore - needs the initialization code below. */ - if (EQ (Vwindow_system, Qnil) -#ifndef WINDOWSNT - /* When running in tty mode on NT/Win95, we have a read_socket - hook, but still need the rest of the initialization code below. */ - && (! read_socket_hook) + setbuf (tty_out->output, (char *) _sobuf); #endif - ) -#endif - set_terminal_modes (); - if (!term_initted - && FRAMEP (Vterminal_frame) - && FRAME_TERMCAP_P (XFRAME (Vterminal_frame))) - init_frame_faces (XFRAME (Vterminal_frame)); + tty_set_terminal_modes (tty_out->display); + + if (!tty_out->term_initted) + { + Lisp_Object tail, frame; + FOR_EACH_FRAME (tail, frame) + { + /* XXX This needs to be revised. */ + if (FRAME_TERMCAP_P (XFRAME (frame)) + && FRAME_TTY (XFRAME (frame)) == tty_out) + init_frame_faces (XFRAME (frame)); + } + } - if (term_initted && no_redraw_on_reenter) + if (tty_out->term_initted && no_redraw_on_reenter) { if (display_completed) direct_output_forward_char (0); } else { + Lisp_Object tail, frame; frame_garbaged = 1; - if (FRAMEP (Vterminal_frame)) - FRAME_GARBAGED_P (XFRAME (Vterminal_frame)) = 1; + FOR_EACH_FRAME (tail, frame) + { + if (FRAME_TERMCAP_P (XFRAME (frame)) + && FRAME_TTY (XFRAME (frame)) == tty_out) + FRAME_GARBAGED_P (XFRAME (frame)) = 1; + } } - term_initted = 1; + tty_out->term_initted = 1; } /* Return nonzero if safe to use tabs in output. At the time this is called, init_sys_modes has not been done yet. */ int -tabs_safe_p () +tabs_safe_p (int fd) { - struct emacs_tty tty; + struct emacs_tty etty; - EMACS_GET_TTY (input_fd, &tty); - return EMACS_TTY_TABS_OK (&tty); + EMACS_GET_TTY (fd, &etty); + return EMACS_TTY_TABS_OK (&etty); } /* Get terminal size from system. @@ -1685,8 +1757,7 @@ tabs_safe_p () We store 0 if there's no valid information. */ void -get_frame_size (widthp, heightp) - int *widthp, *heightp; +get_tty_size (int fd, int *widthp, int *heightp) { #ifdef TIOCGWINSZ @@ -1694,7 +1765,7 @@ get_frame_size (widthp, heightp) /* BSD-style. */ struct winsize size; - if (ioctl (input_fd, TIOCGWINSZ, &size) == -1) + if (ioctl (fd, TIOCGWINSZ, &size) == -1) *widthp = *heightp = 0; else { @@ -1708,7 +1779,7 @@ get_frame_size (widthp, heightp) /* SunOS - style. */ struct ttysize size; - if (ioctl (input_fd, TIOCGSIZE, &size) == -1) + if (ioctl (fd, TIOCGSIZE, &size) == -1) *widthp = *heightp = 0; else { @@ -1721,7 +1792,7 @@ get_frame_size (widthp, heightp) struct sensemode tty; - SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0, + SYS$QIOW (0, fd, IO$_SENSEMODE, &tty, 0, 0, &tty.class, 12, 0, 0, 0, 0); *widthp = tty.scr_wid; *heightp = tty.scr_len; @@ -1734,7 +1805,6 @@ get_frame_size (widthp, heightp) *widthp = 0; *heightp = 0; #endif - #endif /* not VMS */ #endif /* not SunOS-style */ #endif /* not BSD-style */ @@ -1778,37 +1848,58 @@ set_window_size (fd, height, width) } -/* Prepare the terminal for exiting Emacs; move the cursor to the - bottom of the frame, turn off interrupt-driven I/O, etc. */ + +/* Prepare all terminal devices for exiting Emacs. */ + void -reset_sys_modes () +reset_all_sys_modes (void) { - struct frame *sf; + struct tty_display_info *tty; + for (tty = tty_list; tty; tty = tty->next) + reset_sys_modes (tty); +} +/* Prepare the terminal for closing it; move the cursor to the + bottom of the frame, turn off interrupt-driven I/O, etc. */ + +void +reset_sys_modes (tty_out) + struct tty_display_info *tty_out; +{ if (noninteractive) { fflush (stdout); return; } - if (!term_initted) + if (!tty_out->term_initted) return; -#ifdef HAVE_WINDOW_SYSTEM - /* Emacs' window system on MSDOG uses the `internal terminal' and therefore - needs the clean-up code below. */ - if (!EQ (Vwindow_system, Qnil) -#ifndef WINDOWSNT - /* When running in tty mode on NT/Win95, we have a read_socket - hook, but still need the rest of the clean-up code below. */ - || read_socket_hook -#endif - ) - return; -#endif - sf = SELECTED_FRAME (); - cursor_to (FRAME_LINES (sf) - 1, 0); - clear_end_of_line (FRAME_COLS (sf)); - /* clear_end_of_line may move the cursor */ - cursor_to (FRAME_LINES (sf) - 1, 0); + + if (!tty_out->output) + return; /* The tty is suspended. */ + + /* Go to and clear the last line of the terminal. */ + + cmgoto (tty_out, FrameRows (tty_out) - 1, 0); + + /* Code adapted from tty_clear_end_of_line. */ + if (tty_out->TS_clr_line) + { + emacs_tputs (tty_out, tty_out->TS_clr_line, 1, cmputc); + } + else + { /* have to do it the hard way */ + int i; + turn_off_insert (tty_out); + + for (i = curX (tty_out); i < FrameCols (tty_out) - 1; i++) + { + fputc (' ', tty_out->output); + } + } + + cmgoto (tty_out, FrameRows (tty_out) - 1, 0); + fflush (tty_out->output); + #if defined (IBMR2AIX) && defined (AIXHFT) { /* HFT devices normally use ^J as a LF/CR. We forced it to @@ -1820,12 +1911,12 @@ reset_sys_modes () } #endif - reset_terminal_modes (); - fflush (stdout); + tty_reset_terminal_modes (tty_out->display); + fflush (tty_out->output); #ifdef BSD_SYSTEM #ifndef BSD4_1 /* Avoid possible loss of output when changing terminal modes. */ - fsync (fileno (stdout)); + fsync (fileno (tty_out->output)); #endif #endif @@ -1834,22 +1925,25 @@ reset_sys_modes () #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */ if (interrupt_input) { - reset_sigio (); - fcntl (input_fd, F_SETOWN, old_fcntl_owner); + reset_sigio (fileno (tty_out->input)); + fcntl (fileno (tty_out->input), F_SETOWN, + old_fcntl_owner[fileno (tty_out->input)]); } #endif /* F_SETOWN */ #endif /* F_SETOWN_BUG */ #ifdef O_NDELAY - fcntl (input_fd, F_SETFL, fcntl (input_fd, F_GETFL, 0) & ~O_NDELAY); + fcntl (fileno (tty_out->input), F_SETFL, + fcntl (fileno (tty_out->input), F_GETFL, 0) & ~O_NDELAY); #endif #endif /* F_SETFL */ #ifdef BSD4_1 if (interrupt_input) - reset_sigio (); + reset_sigio (fileno (tty_out->input)); #endif /* BSD4_1 */ - if (old_tty_valid) - while (EMACS_SET_TTY (input_fd, &old_tty, 0) < 0 && errno == EINTR) + if (tty_out->old_tty) + while (EMACS_SET_TTY (fileno (tty_out->input), + tty_out->old_tty, 0) < 0 && errno == EINTR) ; #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */ @@ -1860,7 +1954,7 @@ reset_sys_modes () /* Ultrix's termios *ignores* any line discipline except TERMIODISC. A different old line discipline is therefore not restored, yet. Restore the old line discipline by hand. */ - ioctl (0, TIOCSETD, &old_tty.main.c_line); + ioctl (0, TIOCSETD, &tty_out->old_tty.main.c_line); #endif #ifdef AIXHFT @@ -1868,7 +1962,7 @@ reset_sys_modes () #endif #ifdef BSD_PGRPS - widen_foreground_group (); + widen_foreground_group (fileno (tty_out->input)); #endif } @@ -1933,9 +2027,9 @@ init_vms_input () { int status; - if (input_fd == 0) + if (fileno (CURTTY ()->input)) == 0) { - status = SYS$ASSIGN (&input_dsc, &input_fd, 0, 0); + status = SYS$ASSIGN (&input_dsc, &fileno (CURTTY ()->input)), 0, 0); if (! (status & 1)) LIB$STOP (status); } @@ -1946,7 +2040,7 @@ init_vms_input () void stop_vms_input () { - return SYS$DASSGN (input_fd); + return SYS$DASSGN (fileno (CURTTY ()->input))); } short input_buffer; @@ -1962,7 +2056,7 @@ queue_kbd_input () waiting_for_ast = 0; stop_input = 0; - status = SYS$QIO (0, input_fd, IO$_READVBLK, + status = SYS$QIO (0, fileno (CURTTY()->input), IO$_READVBLK, &input_iosb, kbd_input_ast, 1, &input_buffer, 1, 0, terminator_mask, 0, 0); } @@ -2079,7 +2173,7 @@ end_kbd_input () #endif if (LIB$AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */ { - SYS$CANCEL (input_fd); + SYS$CANCEL (fileno (CURTTY()->input)); return; } @@ -2088,7 +2182,7 @@ end_kbd_input () SYS$CLREF (input_ef); waiting_for_ast = 1; stop_input = 1; - SYS$CANCEL (input_fd); + SYS$CANCEL (fileno (CURTTY()->input)); SYS$SETAST (1); SYS$WAITFR (input_ef); waiting_for_ast = 0; @@ -2150,7 +2244,8 @@ init_sigio (fd) request_sigio (); } -reset_sigio () +reset_sigio (fd) + int fd; { unrequest_sigio (); } @@ -2485,7 +2580,9 @@ sys_select (nfds, rfds, wfds, efds, timeout) SELECT_TYPE *rfds, *wfds, *efds; EMACS_TIME *timeout; { - int ravail = 0; + /* XXX This needs to be updated for multi-tty support. Is there + anybody who needs to emulate select these days? */ + int ravail = 0; SELECT_TYPE orfds; int timeoutval; int *local_timeout; @@ -2500,7 +2597,7 @@ sys_select (nfds, rfds, wfds, efds, timeout) #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS) /* If we're using X, then the native select will work; we only need the emulation for non-X usage. */ - if (!NILP (Vwindow_system)) + if (!NILP (Vinitial_window_system)) return select (nfds, rfds, wfds, efds, timeout); #endif timeoutval = timeout ? EMACS_SECS (*timeout) : 100000; @@ -2609,7 +2706,7 @@ sys_select (nfds, rfds, wfds, efds, timeout) } return ravail; } -#endif /* not WINDOWSNT */ +#endif not WINDOWSNT /* Read keyboard input into the standard buffer, waiting for at least one character. */ @@ -2617,6 +2714,8 @@ sys_select (nfds, rfds, wfds, efds, timeout) void read_input_waiting () { + /* XXX This needs to be updated for multi-tty support. Is there + anybody who needs to emulate select these days? */ int nread, i; extern int quit_char; @@ -2670,6 +2769,10 @@ read_input_waiting () } } +#if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X) +#define select sys_select +#endif + #endif /* not HAVE_SELECT */ #endif /* not VMS */ #endif /* not MSDOS */ @@ -2686,12 +2789,13 @@ init_sigio (fd) } void -reset_sigio () +reset_sigio (fd) + int fd; { if (noninteractive) return; lmode = ~LINTRUP & lmode; - ioctl (0, TIOCLSET, &lmode); + ioctl (fd, TIOCLSET, &lmode); } void @@ -3139,7 +3243,7 @@ sys_getenv (name) #undef abort sys_abort () { - reset_sys_modes (); + reset_all_sys_modes (); LIB$SIGNAL (SS$_DEBUG); } #endif /* abort */ @@ -3456,7 +3560,7 @@ croak (badfunc) char *badfunc; { printf ("%s not yet implemented\r\n", badfunc); - reset_sys_modes (); + reset_all_sys_modes (); exit (1); } @@ -5044,7 +5148,7 @@ croak (badfunc) char *badfunc; { printf ("%s not yet implemented\r\n", badfunc); - reset_sys_modes (); + reset_all_sys_modes (); exit (1); } @@ -5066,7 +5170,7 @@ srandom (seed) /* Called from init_sys_modes. */ void -hft_init () +hft_init (struct tty_display_info *tty_out) { int junk; @@ -5112,15 +5216,12 @@ hft_init () keymap.hfkey[1].hf_char = 127; hftctl (0, HFSKBD, &buf); } - /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly - at times. */ - line_ins_del_ok = char_ins_del_ok = 0; } /* Reset the rubout key to backspace. */ void -hft_reset () +hft_reset (struct tty_display_info *tty_out) { struct hfbuf buf; struct hfkeymap keymap; diff --git a/src/syssignal.h b/src/syssignal.h index 2b536758e27..7c3690903df 100644 --- a/src/syssignal.h +++ b/src/syssignal.h @@ -25,6 +25,7 @@ Boston, MA 02111-1307, USA. */ indicate that SIGIO doesn't work by #undef-ing SIGIO. If this file #includes <signal.h>, then that will re-#define SIGIO and confuse things. */ +/* XXX This is not correct anymore, there is a BROKEN_SIGIO macro. */ #define SIGMASKTYPE sigset_t diff --git a/src/term.c b/src/term.c index 317318eb8bf..785f2a3bb33 100644 --- a/src/term.c +++ b/src/term.c @@ -26,9 +26,14 @@ Boston, MA 02111-1307, USA. */ #include <ctype.h> #include <string.h> +#include <sys/file.h> + +#include <unistd.h> /* For isatty. */ +#include <sys/ioctl.h> /* For TIOCNOTTY. */ + +#include "lisp.h" #include "termchar.h" #include "termopts.h" -#include "lisp.h" #include "charset.h" #include "coding.h" #include "keyboard.h" @@ -60,226 +65,74 @@ extern int tgetnum P_ ((char *id)); #include "macterm.h" #endif -static void turn_on_face P_ ((struct frame *, int face_id)); -static void turn_off_face P_ ((struct frame *, int face_id)); -static void tty_show_cursor P_ ((void)); -static void tty_hide_cursor P_ ((void)); - -#define OUTPUT(a) \ - tputs (a, (int) (FRAME_LINES (XFRAME (selected_frame)) - curY), cmputc) -#define OUTPUT1(a) tputs (a, 1, cmputc) -#define OUTPUTL(a, lines) tputs (a, lines, cmputc) - -#define OUTPUT_IF(a) \ - do { \ - if (a) \ - tputs (a, (int) (FRAME_LINES (XFRAME (selected_frame)) \ - - curY), cmputc); \ - } while (0) - -#define OUTPUT1_IF(a) do { if (a) tputs (a, 1, cmputc); } while (0) - -/* Function to use to ring the bell. */ - -Lisp_Object Vring_bell_function; +#ifndef O_RDWR +#define O_RDWR 2 +#endif -/* Terminal characteristics that higher levels want to look at. - These are all extern'd in termchar.h */ +#ifndef O_NOCTTY +#define O_NOCTTY 0 +#endif -int must_write_spaces; /* Nonzero means spaces in the text - must actually be output; can't just skip - over some columns to leave them blank. */ -int min_padding_speed; /* Speed below which no padding necessary */ +static void turn_on_face P_ ((struct frame *, int face_id)); +static void turn_off_face P_ ((struct frame *, int face_id)); +static void tty_show_cursor P_ ((struct tty_display_info *)); +static void tty_hide_cursor P_ ((struct tty_display_info *)); -int line_ins_del_ok; /* Terminal can insert and delete lines */ -int char_ins_del_ok; /* Terminal can insert and delete chars */ -int scroll_region_ok; /* Terminal supports setting the - scroll window */ -int scroll_region_cost; /* Cost of setting a scroll window, - measured in characters */ -int memory_below_frame; /* Terminal remembers lines - scrolled off bottom */ -int fast_clear_end_of_line; /* Terminal has a `ce' string */ +void delete_initial_display P_ ((struct display *)); +void create_tty_output P_ ((struct frame *)); +void delete_tty_output P_ ((struct frame *)); -/* Nonzero means no need to redraw the entire frame on resuming - a suspended Emacs. This is useful on terminals with multiple pages, - where one page is used for Emacs and another for all else. */ +#define OUTPUT(tty, a) \ + emacs_tputs ((tty), a, \ + (int) (FRAME_LINES (XFRAME (selected_frame)) \ + - curY (tty)), \ + cmputc) -int no_redraw_on_reenter; +#define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc) +#define OUTPUTL(tty, a, lines) emacs_tputs ((tty), a, lines, cmputc) -/* Hook functions that you can set to snap out the functions in this file. - These are all extern'd in termhooks.h */ +#define OUTPUT_IF(tty, a) \ + do { \ + if (a) \ + emacs_tputs ((tty), a, \ + (int) (FRAME_LINES (XFRAME (selected_frame)) \ + - curY (tty) ), \ + cmputc); \ + } while (0) -void (*cursor_to_hook) P_ ((int, int)); -void (*raw_cursor_to_hook) P_ ((int, int)); -void (*clear_to_end_hook) P_ ((void)); -void (*clear_frame_hook) P_ ((void)); -void (*clear_end_of_line_hook) P_ ((int)); +#define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0) -void (*ins_del_lines_hook) P_ ((int, int)); +/* Function to use to ring the bell. */ -void (*delete_glyphs_hook) P_ ((int)); +Lisp_Object Vring_bell_function; -void (*ring_bell_hook) P_ ((void)); +/* Functions to call after deleting a tty. */ +Lisp_Object Vdelete_tty_after_functions; -void (*reset_terminal_modes_hook) P_ ((void)); -void (*set_terminal_modes_hook) P_ ((void)); -void (*update_begin_hook) P_ ((struct frame *)); -void (*update_end_hook) P_ ((struct frame *)); -void (*set_terminal_window_hook) P_ ((int)); -void (*insert_glyphs_hook) P_ ((struct glyph *, int)); -void (*write_glyphs_hook) P_ ((struct glyph *, int)); -void (*delete_glyphs_hook) P_ ((int)); +/* Functions to call after suspending a tty. */ +Lisp_Object Vsuspend_tty_functions; -int (*read_socket_hook) P_ ((int, int, struct input_event *)); +/* Functions to call after resuming a tty. */ +Lisp_Object Vresume_tty_functions; -void (*frame_up_to_date_hook) P_ ((struct frame *)); +/* Chain of all displays currently in use. */ +struct display *display_list; -/* Return the current position of the mouse. +/* The initial display device, created by initial_term_init. */ +struct display *initial_display; - Set *f to the frame the mouse is in, or zero if the mouse is in no - Emacs frame. If it is set to zero, all the other arguments are - garbage. +/* Chain of all tty device parameters. */ +struct tty_display_info *tty_list; - If the motion started in a scroll bar, set *bar_window to the - scroll bar's window, *part to the part the mouse is currently over, - *x to the position of the mouse along the scroll bar, and *y to the - overall length of the scroll bar. +/* Nonzero means no need to redraw the entire frame on resuming a + suspended Emacs. This is useful on terminals with multiple + pages, where one page is used for Emacs and another for all + else. */ +int no_redraw_on_reenter; - Otherwise, set *bar_window to Qnil, and *x and *y to the column and - row of the character cell the mouse is over. +Lisp_Object Qframe_tty_name, Qframe_tty_type; - Set *time to the time the mouse was at the returned position. - This should clear mouse_moved until the next motion - event arrives. */ - -void (*mouse_position_hook) P_ ((FRAME_PTR *f, int insist, - Lisp_Object *bar_window, - enum scroll_bar_part *part, - Lisp_Object *x, - Lisp_Object *y, - unsigned long *time)); - -/* When reading from a minibuffer in a different frame, Emacs wants - to shift the highlight from the selected frame to the mini-buffer's - frame; under X, this means it lies about where the focus is. - This hook tells the window system code to re-decide where to put - the highlight. */ - -void (*frame_rehighlight_hook) P_ ((FRAME_PTR f)); - -/* If we're displaying frames using a window system that can stack - frames on top of each other, this hook allows you to bring a frame - to the front, or bury it behind all the other windows. If this - hook is zero, that means the device we're displaying on doesn't - support overlapping frames, so there's no need to raise or lower - anything. - - If RAISE is non-zero, F is brought to the front, before all other - windows. If RAISE is zero, F is sent to the back, behind all other - windows. */ - -void (*frame_raise_lower_hook) P_ ((FRAME_PTR f, int raise)); - -/* Set the vertical scroll bar for WINDOW to have its upper left corner - at (TOP, LEFT), and be LENGTH rows high. Set its handle to - indicate that we are displaying PORTION characters out of a total - of WHOLE characters, starting at POSITION. If WINDOW doesn't yet - have a scroll bar, create one for it. */ - -void (*set_vertical_scroll_bar_hook) - P_ ((struct window *window, - int portion, int whole, int position)); - - -/* The following three hooks are used when we're doing a thorough - redisplay of the frame. We don't explicitly know which scroll bars - are going to be deleted, because keeping track of when windows go - away is a real pain - can you say set-window-configuration? - Instead, we just assert at the beginning of redisplay that *all* - scroll bars are to be removed, and then save scroll bars from the - fiery pit when we actually redisplay their window. */ - -/* Arrange for all scroll bars on FRAME to be removed at the next call - to `*judge_scroll_bars_hook'. A scroll bar may be spared if - `*redeem_scroll_bar_hook' is applied to its window before the judgment. - - This should be applied to each frame each time its window tree is - redisplayed, even if it is not displaying scroll bars at the moment; - if the HAS_SCROLL_BARS flag has just been turned off, only calling - this and the judge_scroll_bars_hook will get rid of them. - - If non-zero, this hook should be safe to apply to any frame, - whether or not it can support scroll bars, and whether or not it is - currently displaying them. */ - -void (*condemn_scroll_bars_hook) P_ ((FRAME_PTR frame)); - -/* Unmark WINDOW's scroll bar for deletion in this judgement cycle. - Note that it's okay to redeem a scroll bar that is not condemned. */ - -void (*redeem_scroll_bar_hook) P_ ((struct window *window)); - -/* Remove all scroll bars on FRAME that haven't been saved since the - last call to `*condemn_scroll_bars_hook'. - - This should be applied to each frame after each time its window - tree is redisplayed, even if it is not displaying scroll bars at the - moment; if the HAS_SCROLL_BARS flag has just been turned off, only - calling this and condemn_scroll_bars_hook will get rid of them. - - If non-zero, this hook should be safe to apply to any frame, - whether or not it can support scroll bars, and whether or not it is - currently displaying them. */ - -void (*judge_scroll_bars_hook) P_ ((FRAME_PTR FRAME)); - -/* Strings, numbers and flags taken from the termcap entry. */ - -char *TS_ins_line; /* "al" */ -char *TS_ins_multi_lines; /* "AL" (one parameter, # lines to insert) */ -char *TS_bell; /* "bl" */ -char *TS_clr_to_bottom; /* "cd" */ -char *TS_clr_line; /* "ce", clear to end of line */ -char *TS_clr_frame; /* "cl" */ -char *TS_set_scroll_region; /* "cs" (2 params, first line and last line) */ -char *TS_set_scroll_region_1; /* "cS" (4 params: total lines, - lines above scroll region, lines below it, - total lines again) */ -char *TS_del_char; /* "dc" */ -char *TS_del_multi_chars; /* "DC" (one parameter, # chars to delete) */ -char *TS_del_line; /* "dl" */ -char *TS_del_multi_lines; /* "DL" (one parameter, # lines to delete) */ -char *TS_delete_mode; /* "dm", enter character-delete mode */ -char *TS_end_delete_mode; /* "ed", leave character-delete mode */ -char *TS_end_insert_mode; /* "ei", leave character-insert mode */ -char *TS_ins_char; /* "ic" */ -char *TS_ins_multi_chars; /* "IC" (one parameter, # chars to insert) */ -char *TS_insert_mode; /* "im", enter character-insert mode */ -char *TS_pad_inserted_char; /* "ip". Just padding, no commands. */ -char *TS_end_keypad_mode; /* "ke" */ -char *TS_keypad_mode; /* "ks" */ -char *TS_pad_char; /* "pc", char to use as padding */ -char *TS_repeat; /* "rp" (2 params, # times to repeat - and character to be repeated) */ -char *TS_end_standout_mode; /* "se" */ -char *TS_fwd_scroll; /* "sf" */ -char *TS_standout_mode; /* "so" */ -char *TS_rev_scroll; /* "sr" */ -char *TS_end_termcap_modes; /* "te" */ -char *TS_termcap_modes; /* "ti" */ -char *TS_visible_bell; /* "vb" */ -char *TS_cursor_normal; /* "ve" */ -char *TS_cursor_visible; /* "vs" */ -char *TS_cursor_invisible; /* "vi" */ -char *TS_set_window; /* "wi" (4 params, start and end of window, - each as vpos and hpos) */ - -/* Value of the "NC" (no_color_video) capability, or 0 if not - present. */ - -static int TN_no_color_video; /* Meaning of bits in no_color_video. Each bit set means that the corresponding attribute cannot be combined with colors. */ @@ -297,68 +150,6 @@ enum no_color_bit NC_ALT_CHARSET = 1 << 8 }; -/* "md" -- turn on bold (extra bright mode). */ - -char *TS_enter_bold_mode; - -/* "mh" -- turn on half-bright mode. */ - -char *TS_enter_dim_mode; - -/* "mb" -- enter blinking mode. */ - -char *TS_enter_blink_mode; - -/* "mr" -- enter reverse video mode. */ - -char *TS_enter_reverse_mode; - -/* "us"/"ue" -- start/end underlining. */ - -char *TS_exit_underline_mode, *TS_enter_underline_mode; - -/* "as"/"ae" -- start/end alternate character set. Not really - supported, yet. */ - -char *TS_enter_alt_charset_mode, *TS_exit_alt_charset_mode; - -/* "me" -- switch appearances off. */ - -char *TS_exit_attribute_mode; - -/* "Co" -- number of colors. */ - -int TN_max_colors; - -/* "pa" -- max. number of color pairs on screen. Not handled yet. - Could be a problem if not equal to TN_max_colors * TN_max_colors. */ - -int TN_max_pairs; - -/* "op" -- SVr4 set default pair to its original value. */ - -char *TS_orig_pair; - -/* "AF"/"AB" or "Sf"/"Sb"-- set ANSI or SVr4 foreground/background color. - 1 param, the color index. */ - -char *TS_set_foreground, *TS_set_background; - -int TF_hazeltine; /* termcap hz flag. */ -int TF_insmode_motion; /* termcap mi flag: can move while in insert mode. */ -int TF_standout_motion; /* termcap mi flag: can move while in standout mode. */ -int TF_underscore; /* termcap ul flag: _ underlines if over-struck on - non-blank position. Must clear before writing _. */ -int TF_teleray; /* termcap xt flag: many weird consequences. - For t1061. */ - -static int RPov; /* # chars to start a TS_repeat */ - -static int delete_in_insert_mode; /* delete mode == insert mode */ - -static int se_is_so; /* 1 if same string both enters and leaves - standout mode */ - /* internal state */ /* The largest frame width in any call to calculate_costs. */ @@ -369,33 +160,19 @@ int max_frame_cols; int max_frame_lines; -static int costs_set; /* Nonzero if costs have been calculated. */ - -int insert_mode; /* Nonzero when in insert mode. */ -int standout_mode; /* Nonzero when in standout mode. */ - -/* Size of window specified by higher levels. - This is the number of lines, from the top of frame downwards, - which can participate in insert-line/delete-line operations. - - Effectively it excludes the bottom frame_lines - specified_window_size - lines from those operations. */ - -int specified_window; - /* Frame currently being redisplayed; 0 if not currently redisplaying. (Direct output does not count). */ FRAME_PTR updating_frame; +/* Non-zero if we have dropped our controlling tty and therefore + should not open a frame on stdout. */ +static int no_controlling_tty; + /* Provided for lisp packages. */ static int system_uses_terminfo; -/* Flag used in tty_show/hide_cursor. */ - -static int tty_cursor_hidden; - char *tparam (); extern char *tgetstr (); @@ -415,6 +192,8 @@ extern char *tgetstr (); void ring_bell () { + struct frame *f = XFRAME (selected_frame); + if (!NILP (Vring_bell_function)) { Lisp_Object function; @@ -434,42 +213,58 @@ ring_bell () Vring_bell_function = function; } - else if (!FRAME_TERMCAP_P (XFRAME (selected_frame))) - (*ring_bell_hook) (); - else - OUTPUT (TS_visible_bell && visible_bell ? TS_visible_bell : TS_bell); + else if (FRAME_DISPLAY (f)->ring_bell_hook) + (*FRAME_DISPLAY (f)->ring_bell_hook) (); +} + +/* Ring the bell on a tty. */ + +void +tty_ring_bell () +{ + struct frame *f = XFRAME (selected_frame); + struct tty_display_info *tty = FRAME_TTY (f); + + OUTPUT (tty, (tty->TS_visible_bell && visible_bell + ? tty->TS_visible_bell + : tty->TS_bell)); } +/* Set up termcap modes for Emacs. */ + void -set_terminal_modes () +tty_set_terminal_modes (struct display *display) { - if (FRAME_TERMCAP_P (XFRAME (selected_frame))) + struct tty_display_info *tty = display->display_info.tty; + + if (tty->output) { - OUTPUT_IF (TS_termcap_modes); - OUTPUT_IF (TS_cursor_visible); - OUTPUT_IF (TS_keypad_mode); - losecursor (); + OUTPUT_IF (tty, tty->TS_termcap_modes); + OUTPUT_IF (tty, tty->TS_cursor_visible); + OUTPUT_IF (tty, tty->TS_keypad_mode); + losecursor (tty); } - else - (*set_terminal_modes_hook) (); } +/* Reset termcap modes before exiting Emacs. */ + void -reset_terminal_modes () +tty_reset_terminal_modes (struct display *display) { - if (FRAME_TERMCAP_P (XFRAME (selected_frame))) + struct tty_display_info *tty = display->display_info.tty; + + if (tty->output) { - turn_off_highlight (); - turn_off_insert (); - OUTPUT_IF (TS_end_keypad_mode); - OUTPUT_IF (TS_cursor_normal); - OUTPUT_IF (TS_end_termcap_modes); - OUTPUT_IF (TS_orig_pair); + turn_off_highlight (tty); + turn_off_insert (tty); + OUTPUT_IF (tty, tty->TS_end_keypad_mode); + OUTPUT_IF (tty, tty->TS_cursor_normal); + OUTPUT_IF (tty, tty->TS_end_termcap_modes); + OUTPUT_IF (tty, tty->TS_orig_pair); /* Output raw CR so kernel can track the cursor hpos. */ + current_tty = tty; cmputc ('\r'); } - else if (reset_terminal_modes_hook) - (*reset_terminal_modes_hook) (); } void @@ -477,39 +272,59 @@ update_begin (f) struct frame *f; { updating_frame = f; - if (!FRAME_TERMCAP_P (f)) - update_begin_hook (f); + if (FRAME_DISPLAY (f)->update_begin_hook) + (*FRAME_DISPLAY (f)->update_begin_hook) (f); } void update_end (f) struct frame *f; { - if (FRAME_TERMCAP_P (f)) - { - if (!XWINDOW (selected_window)->cursor_off_p) - tty_show_cursor (); - turn_off_insert (); - background_highlight (); - } - else - update_end_hook (f); - + if (FRAME_DISPLAY (f)->update_end_hook) + (*FRAME_DISPLAY (f)->update_end_hook) (f); updating_frame = NULL; } +/* Flag the end of a display update on a termcap display. */ + +void +tty_update_end (struct frame *f) +{ + struct tty_display_info *tty = FRAME_TTY (f); + + if (!XWINDOW (selected_window)->cursor_off_p) + tty_show_cursor (tty); + turn_off_insert (tty); + background_highlight (tty); +} + +/* Specify how many text lines, from the top of the window, + should be affected by insert-lines and delete-lines operations. + This, and those operations, are used only within an update + that is bounded by calls to update_begin and update_end. */ + void set_terminal_window (size) int size; { - if (FRAME_TERMCAP_P (updating_frame)) - { - specified_window = size ? size : FRAME_LINES (updating_frame); - if (scroll_region_ok) - set_scroll_region (0, specified_window); - } - else - set_terminal_window_hook (size); + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + if (FRAME_DISPLAY (f)->set_terminal_window_hook) + (*FRAME_DISPLAY (f)->set_terminal_window_hook) (size); +} + +/* The implementation of set_terminal_window for termcap frames. */ + +void +tty_set_terminal_window (int size) +{ + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + struct tty_display_info *tty = FRAME_TTY (f); + + tty->specified_window = size ? size : FRAME_LINES (f); + if (FRAME_SCROLL_REGION_OK (f)) + set_scroll_region (0, tty->specified_window); } void @@ -517,77 +332,79 @@ set_scroll_region (start, stop) int start, stop; { char *buf; - struct frame *sf = XFRAME (selected_frame); - - if (TS_set_scroll_region) - buf = tparam (TS_set_scroll_region, 0, 0, start, stop - 1); - else if (TS_set_scroll_region_1) - buf = tparam (TS_set_scroll_region_1, 0, 0, - FRAME_LINES (sf), start, - FRAME_LINES (sf) - stop, - FRAME_LINES (sf)); + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + struct tty_display_info *tty = FRAME_TTY (f); + + if (tty->TS_set_scroll_region) + buf = tparam (tty->TS_set_scroll_region, 0, 0, start, stop - 1); + else if (tty->TS_set_scroll_region_1) + buf = tparam (tty->TS_set_scroll_region_1, 0, 0, + FRAME_LINES (f), start, + FRAME_LINES (f) - stop, + FRAME_LINES (f)); else - buf = tparam (TS_set_window, 0, 0, start, 0, stop, FRAME_COLS (sf)); + buf = tparam (tty->TS_set_window, 0, 0, start, 0, stop, FRAME_COLS (f)); - OUTPUT (buf); + OUTPUT (tty, buf); xfree (buf); - losecursor (); + losecursor (tty); } static void -turn_on_insert () +turn_on_insert (struct tty_display_info *tty) { - if (!insert_mode) - OUTPUT (TS_insert_mode); - insert_mode = 1; + if (!tty->insert_mode) + OUTPUT (tty, tty->TS_insert_mode); + tty->insert_mode = 1; } void -turn_off_insert () +turn_off_insert (struct tty_display_info *tty) { - if (insert_mode) - OUTPUT (TS_end_insert_mode); - insert_mode = 0; + if (tty->insert_mode) + OUTPUT (tty, tty->TS_end_insert_mode); + tty->insert_mode = 0; } /* Handle highlighting. */ void -turn_off_highlight () +turn_off_highlight (struct tty_display_info *tty) { - if (standout_mode) - OUTPUT_IF (TS_end_standout_mode); - standout_mode = 0; + if (tty->standout_mode) + OUTPUT_IF (tty, tty->TS_end_standout_mode); + tty->standout_mode = 0; } static void -turn_on_highlight () +turn_on_highlight (struct tty_display_info *tty) { - if (!standout_mode) - OUTPUT_IF (TS_standout_mode); - standout_mode = 1; + if (!tty->standout_mode) + OUTPUT_IF (tty, tty->TS_standout_mode); + tty->standout_mode = 1; } static void -toggle_highlight () +toggle_highlight (struct tty_display_info *tty) { - if (standout_mode) - turn_off_highlight (); + if (tty->standout_mode) + turn_off_highlight (tty); else - turn_on_highlight (); + turn_on_highlight (tty); } /* Make cursor invisible. */ static void -tty_hide_cursor () +tty_hide_cursor (struct tty_display_info *tty) { - if (tty_cursor_hidden == 0) + if (tty->cursor_hidden == 0) { - tty_cursor_hidden = 1; - OUTPUT_IF (TS_cursor_invisible); + tty->cursor_hidden = 1; + OUTPUT_IF (tty, tty->TS_cursor_invisible); } } @@ -595,13 +412,13 @@ tty_hide_cursor () /* Ensure that cursor is visible. */ static void -tty_show_cursor () +tty_show_cursor (struct tty_display_info *tty) { - if (tty_cursor_hidden) + if (tty->cursor_hidden) { - tty_cursor_hidden = 0; - OUTPUT_IF (TS_cursor_normal); - OUTPUT_IF (TS_cursor_visible); + tty->cursor_hidden = 0; + OUTPUT_IF (tty, tty->TS_cursor_normal); + OUTPUT_IF (tty, tty->TS_cursor_visible); } } @@ -611,23 +428,23 @@ tty_show_cursor () depends on the user option inverse-video. */ void -background_highlight () +background_highlight (struct tty_display_info *tty) { if (inverse_video) - turn_on_highlight (); + turn_on_highlight (tty); else - turn_off_highlight (); + turn_off_highlight (tty); } /* Set standout mode to the mode specified for the text to be output. */ static void -highlight_if_desired () +highlight_if_desired (struct tty_display_info *tty) { if (inverse_video) - turn_on_highlight (); + turn_on_highlight (tty); else - turn_off_highlight (); + turn_off_highlight (tty); } @@ -638,26 +455,32 @@ void cursor_to (vpos, hpos) int vpos, hpos; { - struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame); + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); - if (! FRAME_TERMCAP_P (f) && cursor_to_hook) - { - (*cursor_to_hook) (vpos, hpos); - return; - } + if (FRAME_DISPLAY (f)->cursor_to_hook) + (*FRAME_DISPLAY (f)->cursor_to_hook) (vpos, hpos); +} + +void +tty_cursor_to (int vpos, int hpos) +{ + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + struct tty_display_info *tty = FRAME_TTY (f); /* Detect the case where we are called from reset_sys_modes and the costs have never been calculated. Do nothing. */ - if (! costs_set) + if (! tty->costs_set) return; - if (curY == vpos && curX == hpos) + if (curY (tty) == vpos + && curX (tty) == hpos) return; - if (!TF_standout_motion) - background_highlight (); - if (!TF_insmode_motion) - turn_off_insert (); - cmgoto (vpos, hpos); + if (!tty->TF_standout_motion) + background_highlight (tty); + if (!tty->TF_insmode_motion) + turn_off_insert (tty); + cmgoto (tty, vpos, hpos); } /* Similar but don't take any account of the wasted characters. */ @@ -666,45 +489,61 @@ void raw_cursor_to (row, col) int row, col; { - struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame); - if (! FRAME_TERMCAP_P (f)) - { - (*raw_cursor_to_hook) (row, col); - return; - } - if (curY == row && curX == col) + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + if (FRAME_DISPLAY (f)->raw_cursor_to_hook) + (*FRAME_DISPLAY (f)->raw_cursor_to_hook) (row, col); +} + +void +tty_raw_cursor_to (int row, int col) +{ + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + struct tty_display_info *tty = FRAME_TTY (f); + + if (curY (tty) == row + && curX (tty) == col) return; - if (!TF_standout_motion) - background_highlight (); - if (!TF_insmode_motion) - turn_off_insert (); - cmgoto (row, col); + if (!tty->TF_standout_motion) + background_highlight (tty); + if (!tty->TF_insmode_motion) + turn_off_insert (tty); + cmgoto (tty, row, col); } /* Erase operations */ -/* clear from cursor to end of frame */ +/* Clear from cursor to end of frame. */ void clear_to_end () { + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + if (FRAME_DISPLAY (f)->clear_to_end_hook) + (*FRAME_DISPLAY (f)->clear_to_end_hook) (); +} + +/* Clear from cursor to end of frame on a termcap device. */ + +void +tty_clear_to_end (void) +{ register int i; + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + struct tty_display_info *tty = FRAME_TTY (f); - if (clear_to_end_hook && ! FRAME_TERMCAP_P (updating_frame)) + if (tty->TS_clr_to_bottom) { - (*clear_to_end_hook) (); - return; - } - if (TS_clr_to_bottom) - { - background_highlight (); - OUTPUT (TS_clr_to_bottom); + background_highlight (tty); + OUTPUT (tty, tty->TS_clr_to_bottom); } else { - for (i = curY; i < FRAME_LINES (XFRAME (selected_frame)); i++) + for (i = curY (tty); i < FRAME_LINES (f); i++) { cursor_to (i, 0); - clear_end_of_line (FRAME_COLS (XFRAME (selected_frame))); + clear_end_of_line (FRAME_COLS (f)); } } } @@ -714,19 +553,26 @@ clear_to_end () void clear_frame () { - struct frame *sf = XFRAME (selected_frame); + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); - if (clear_frame_hook - && ! FRAME_TERMCAP_P ((updating_frame ? updating_frame : sf))) - { - (*clear_frame_hook) (); - return; - } - if (TS_clr_frame) + if (FRAME_DISPLAY (f)->clear_frame_hook) + (*FRAME_DISPLAY (f)->clear_frame_hook) (); +} + +/* Clear an entire termcap frame. */ + +void +tty_clear_frame () +{ + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + struct tty_display_info *tty = FRAME_TTY (f); + + if (tty->TS_clr_frame) { - background_highlight (); - OUTPUT (TS_clr_frame); - cmat (0, 0); + background_highlight (tty); + OUTPUT (tty, tty->TS_clr_frame); + cmat (tty, 0, 0); } else { @@ -744,46 +590,52 @@ void clear_end_of_line (first_unused_hpos) int first_unused_hpos; { - register int i; + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); - if (clear_end_of_line_hook - && ! FRAME_TERMCAP_P ((updating_frame - ? updating_frame - : XFRAME (selected_frame)))) - { - (*clear_end_of_line_hook) (first_unused_hpos); - return; - } + if (FRAME_DISPLAY (f)->clear_end_of_line_hook) + (*FRAME_DISPLAY (f)->clear_end_of_line_hook) (first_unused_hpos); +} + +/* An implementation of clear_end_of_line for termcap frames. + + Note that the cursor may be moved, on terminals lacking a `ce' string. */ + +void +tty_clear_end_of_line (int first_unused_hpos) +{ + register int i; + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + struct tty_display_info *tty = FRAME_TTY (f); /* Detect the case where we are called from reset_sys_modes and the costs have never been calculated. Do nothing. */ - if (! costs_set) + if (! tty->costs_set) return; - if (curX >= first_unused_hpos) + if (curX (tty) >= first_unused_hpos) return; - background_highlight (); - if (TS_clr_line) + background_highlight (tty); + if (tty->TS_clr_line) { - OUTPUT1 (TS_clr_line); + OUTPUT1 (tty, tty->TS_clr_line); } else { /* have to do it the hard way */ - struct frame *sf = XFRAME (selected_frame); - turn_off_insert (); + turn_off_insert (tty); /* Do not write in last row last col with Auto-wrap on. */ - if (AutoWrap && curY == FRAME_LINES (sf) - 1 - && first_unused_hpos == FRAME_COLS (sf)) + if (AutoWrap (tty) + && curY (tty) == FrameRows (tty) - 1 + && first_unused_hpos == FrameCols (tty)) first_unused_hpos--; - for (i = curX; i < first_unused_hpos; i++) + for (i = curX (tty); i < first_unused_hpos; i++) { - if (termscript) - fputc (' ', termscript); - putchar (' '); + if (tty->termscript) + fputc (' ', tty->termscript); + fputc (' ', tty->output); } - cmplus (first_unused_hpos - curX); + cmplus (tty, first_unused_hpos - curX (tty)); } } @@ -896,38 +748,47 @@ encode_terminal_code (src, dst, src_len, dst_len, consumed) } +/* Output LEN glyphs starting at STRING at the nominal cursor position. + Advance the nominal cursor over the text. */ + void write_glyphs (string, len) register struct glyph *string; register int len; { + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + if (FRAME_DISPLAY (f)->write_glyphs_hook) + (*FRAME_DISPLAY (f)->write_glyphs_hook) (string, len); +} + +/* An implementation of write_glyphs for termcap frames. */ + +void +tty_write_glyphs (struct glyph *string, int len) +{ int produced, consumed; - struct frame *sf = XFRAME (selected_frame); - struct frame *f = updating_frame ? updating_frame : sf; unsigned char conversion_buffer[1024]; int conversion_buffer_size = sizeof conversion_buffer; - if (write_glyphs_hook - && ! FRAME_TERMCAP_P (f)) - { - (*write_glyphs_hook) (string, len); - return; - } + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + struct tty_display_info *tty = FRAME_TTY (f); - turn_off_insert (); - tty_hide_cursor (); + turn_off_insert (tty); + tty_hide_cursor (tty); /* Don't dare write in last column of bottom line, if Auto-Wrap, since that would scroll the whole frame on some terminals. */ - if (AutoWrap - && curY + 1 == FRAME_LINES (sf) - && (curX + len) == FRAME_COLS (sf)) + if (AutoWrap (tty) + && curY (tty) + 1 == FRAME_LINES (f) + && (curX (tty) + len) == FRAME_COLS (f)) len --; if (len <= 0) return; - cmplus (len); + cmplus (tty, len); /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */ @@ -944,7 +805,7 @@ write_glyphs (string, len) break; /* Turn appearance modes of the face of the run on. */ - highlight_if_desired (); + highlight_if_desired (tty); turn_on_face (f, face_id); while (n > 0) @@ -957,11 +818,13 @@ write_glyphs (string, len) &consumed); if (produced > 0) { - fwrite (conversion_buffer, 1, produced, stdout); - if (ferror (stdout)) - clearerr (stdout); - if (termscript) - fwrite (conversion_buffer, 1, produced, termscript); + fwrite (conversion_buffer, 1, produced, + tty->output); + if (ferror (tty->output)) + clearerr (tty->output); + if (tty->termscript) + fwrite (conversion_buffer, 1, produced, + tty->termscript); } len -= consumed; n -= consumed; @@ -970,7 +833,7 @@ write_glyphs (string, len) /* Turn appearance modes off. */ turn_off_face (f, face_id); - turn_off_highlight (); + turn_off_highlight (tty); } /* We may have to output some codes to terminate the writing. */ @@ -981,53 +844,60 @@ write_glyphs (string, len) 0, conversion_buffer_size); if (terminal_coding.produced > 0) { - fwrite (conversion_buffer, 1, terminal_coding.produced, stdout); - if (ferror (stdout)) - clearerr (stdout); - if (termscript) + fwrite (conversion_buffer, 1, terminal_coding.produced, + tty->output); + if (ferror (tty->output)) + clearerr (tty->output); + if (tty->termscript) fwrite (conversion_buffer, 1, terminal_coding.produced, - termscript); + tty->termscript); } } - cmcheckmagic (); + cmcheckmagic (tty); } -/* If start is zero, insert blanks instead of a string at start */ +/* Insert LEN glyphs from START at the nominal cursor position. + + If start is zero, insert blanks instead of a string at start */ void insert_glyphs (start, len) register struct glyph *start; register int len; { - char *buf; - struct glyph *glyph = NULL; - struct frame *f, *sf; + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); if (len <= 0) return; - if (insert_glyphs_hook) - { - (*insert_glyphs_hook) (start, len); - return; - } + if (FRAME_DISPLAY (f)->insert_glyphs_hook) + (*FRAME_DISPLAY (f)->insert_glyphs_hook) (start, len); +} + +/* An implementation of insert_glyphs for termcap frames. */ + +void +tty_insert_glyphs (struct glyph *start, int len) +{ + char *buf; + struct glyph *glyph = NULL; + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); - sf = XFRAME (selected_frame); - f = updating_frame ? updating_frame : sf; + struct tty_display_info *tty = FRAME_TTY (f); - if (TS_ins_multi_chars) + if (tty->TS_ins_multi_chars) { - buf = tparam (TS_ins_multi_chars, 0, 0, len); - OUTPUT1 (buf); + buf = tparam (tty->TS_ins_multi_chars, 0, 0, len); + OUTPUT1 (tty, buf); xfree (buf); if (start) write_glyphs (start, len); return; } - turn_on_insert (); - cmplus (len); + turn_on_insert (tty); + cmplus (tty, len); /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */ terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK; while (len-- > 0) @@ -1036,7 +906,7 @@ insert_glyphs (start, len) unsigned char conversion_buffer[1024]; int conversion_buffer_size = sizeof conversion_buffer; - OUTPUT1_IF (TS_ins_char); + OUTPUT1_IF (tty, tty->TS_ins_char); if (!start) { conversion_buffer[0] = SPACEGLYPH; @@ -1044,7 +914,7 @@ insert_glyphs (start, len) } else { - highlight_if_desired (); + highlight_if_desired (tty); turn_on_face (f, start->face_id); glyph = start; ++start; @@ -1052,7 +922,7 @@ insert_glyphs (start, len) occupies more than one column. */ while (len && CHAR_GLYPH_PADDING_P (*start)) { - OUTPUT1_IF (TS_ins_char); + OUTPUT1_IF (tty, tty->TS_ins_char); start++, len--; } @@ -1068,58 +938,70 @@ insert_glyphs (start, len) if (produced > 0) { - fwrite (conversion_buffer, 1, produced, stdout); - if (ferror (stdout)) - clearerr (stdout); - if (termscript) - fwrite (conversion_buffer, 1, produced, termscript); + fwrite (conversion_buffer, 1, produced, + tty->output); + if (ferror (tty->output)) + clearerr (tty->output); + if (tty->termscript) + fwrite (conversion_buffer, 1, produced, + tty->termscript); } - OUTPUT1_IF (TS_pad_inserted_char); + OUTPUT1_IF (tty, tty->TS_pad_inserted_char); if (start) { turn_off_face (f, glyph->face_id); - turn_off_highlight (); + turn_off_highlight (tty); } } - cmcheckmagic (); + cmcheckmagic (tty); } +/* Delete N glyphs at the nominal cursor position. */ + void delete_glyphs (n) register int n; { + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + if (FRAME_DISPLAY (f)->delete_glyphs_hook) + (*FRAME_DISPLAY (f)->delete_glyphs_hook) (n); +} + +/* An implementation of delete_glyphs for termcap frames. */ + +void +tty_delete_glyphs (int n) +{ char *buf; register int i; + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); - if (delete_glyphs_hook && ! FRAME_TERMCAP_P (updating_frame)) - { - (*delete_glyphs_hook) (n); - return; - } + struct tty_display_info *tty = FRAME_TTY (f); - if (delete_in_insert_mode) + if (tty->delete_in_insert_mode) { - turn_on_insert (); + turn_on_insert (tty); } else { - turn_off_insert (); - OUTPUT_IF (TS_delete_mode); + turn_off_insert (tty); + OUTPUT_IF (tty, tty->TS_delete_mode); } - if (TS_del_multi_chars) + if (tty->TS_del_multi_chars) { - buf = tparam (TS_del_multi_chars, 0, 0, n); - OUTPUT1 (buf); + buf = tparam (tty->TS_del_multi_chars, 0, 0, n); + OUTPUT1 (tty, buf); xfree (buf); } else for (i = 0; i < n; i++) - OUTPUT1 (TS_del_char); - if (!delete_in_insert_mode) - OUTPUT_IF (TS_end_delete_mode); + OUTPUT1 (tty, tty->TS_del_char); + if (!tty->delete_in_insert_mode) + OUTPUT_IF (tty, tty->TS_end_delete_mode); } /* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */ @@ -1128,21 +1010,26 @@ void ins_del_lines (vpos, n) int vpos, n; { - char *multi = n > 0 ? TS_ins_multi_lines : TS_del_multi_lines; - char *single = n > 0 ? TS_ins_line : TS_del_line; - char *scroll = n > 0 ? TS_rev_scroll : TS_fwd_scroll; - struct frame *sf; + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); + + if (FRAME_DISPLAY (f)->ins_del_lines_hook) + (*FRAME_DISPLAY (f)->ins_del_lines_hook) (vpos, n); +} - register int i = n > 0 ? n : -n; - register char *buf; +/* An implementation of ins_del_lines for termcap frames. */ - if (ins_del_lines_hook && ! FRAME_TERMCAP_P (updating_frame)) - { - (*ins_del_lines_hook) (vpos, n); - return; - } +void +tty_ins_del_lines (int vpos, int n) +{ + struct frame *f = (updating_frame ? updating_frame : XFRAME (selected_frame)); - sf = XFRAME (selected_frame); + struct tty_display_info *tty = FRAME_TTY (f); + char *multi = n > 0 ? tty->TS_ins_multi_lines : tty->TS_del_multi_lines; + char *single = n > 0 ? tty->TS_ins_line : tty->TS_del_line; + char *scroll = n > 0 ? tty->TS_rev_scroll : tty->TS_fwd_scroll; + + register int i = n > 0 ? n : -n; + register char *buf; /* If the lines below the insertion are being pushed into the end of the window, this is the same as clearing; @@ -1151,44 +1038,48 @@ ins_del_lines (vpos, n) /* If the lines below the deletion are blank lines coming out of the end of the window, don't bother, as there will be a matching inslines later that will flush them. */ - if (scroll_region_ok && vpos + i >= specified_window) + if (FRAME_SCROLL_REGION_OK (f) + && vpos + i >= tty->specified_window) return; - if (!memory_below_frame && vpos + i >= FRAME_LINES (sf)) + if (!FRAME_MEMORY_BELOW_FRAME (f) + && vpos + i >= FRAME_LINES (f)) return; - + if (multi) { raw_cursor_to (vpos, 0); - background_highlight (); + background_highlight (tty); buf = tparam (multi, 0, 0, i); - OUTPUT (buf); + OUTPUT (tty, buf); xfree (buf); } else if (single) { raw_cursor_to (vpos, 0); - background_highlight (); + background_highlight (tty); while (--i >= 0) - OUTPUT (single); - if (TF_teleray) - curX = 0; + OUTPUT (tty, single); + if (tty->TF_teleray) + curX (tty) = 0; } else { - set_scroll_region (vpos, specified_window); + set_scroll_region (vpos, tty->specified_window); if (n < 0) - raw_cursor_to (specified_window - 1, 0); + raw_cursor_to (tty->specified_window - 1, 0); else - raw_cursor_to (vpos, 0); - background_highlight (); + raw_cursor_to (vpos, 0); + background_highlight (tty); while (--i >= 0) - OUTPUTL (scroll, specified_window - vpos); - set_scroll_region (0, specified_window); + OUTPUTL (tty, scroll, tty->specified_window - vpos); + set_scroll_region (0, tty->specified_window); } - - if (!scroll_region_ok && memory_below_frame && n < 0) + + if (!FRAME_SCROLL_REGION_OK (f) + && FRAME_MEMORY_BELOW_FRAME (f) + && n < 0) { - cursor_to (FRAME_LINES (sf) + n, 0); + cursor_to (FRAME_LINES (f) + n, 0); clear_to_end (); } } @@ -1247,26 +1138,27 @@ int *char_ins_del_vector; /* ARGSUSED */ static void -calculate_ins_del_char_costs (frame) - FRAME_PTR frame; +calculate_ins_del_char_costs (f) + FRAME_PTR f; { + struct tty_display_info *tty = FRAME_TTY (f); int ins_startup_cost, del_startup_cost; int ins_cost_per_char, del_cost_per_char; register int i; register int *p; - if (TS_ins_multi_chars) + if (tty->TS_ins_multi_chars) { ins_cost_per_char = 0; - ins_startup_cost = string_cost_one_line (TS_ins_multi_chars); + ins_startup_cost = string_cost_one_line (tty->TS_ins_multi_chars); } - else if (TS_ins_char || TS_pad_inserted_char - || (TS_insert_mode && TS_end_insert_mode)) + else if (tty->TS_ins_char || tty->TS_pad_inserted_char + || (tty->TS_insert_mode && tty->TS_end_insert_mode)) { - ins_startup_cost = (30 * (string_cost (TS_insert_mode) - + string_cost (TS_end_insert_mode))) / 100; - ins_cost_per_char = (string_cost_one_line (TS_ins_char) - + string_cost_one_line (TS_pad_inserted_char)); + ins_startup_cost = (30 * (string_cost (tty->TS_insert_mode) + + string_cost (tty->TS_end_insert_mode))) / 100; + ins_cost_per_char = (string_cost_one_line (tty->TS_ins_char) + + string_cost_one_line (tty->TS_pad_inserted_char)); } else { @@ -1274,18 +1166,18 @@ calculate_ins_del_char_costs (frame) ins_cost_per_char = 0; } - if (TS_del_multi_chars) + if (tty->TS_del_multi_chars) { del_cost_per_char = 0; - del_startup_cost = string_cost_one_line (TS_del_multi_chars); + del_startup_cost = string_cost_one_line (tty->TS_del_multi_chars); } - else if (TS_del_char) + else if (tty->TS_del_char) { - del_startup_cost = (string_cost (TS_delete_mode) - + string_cost (TS_end_delete_mode)); - if (delete_in_insert_mode) + del_startup_cost = (string_cost (tty->TS_delete_mode) + + string_cost (tty->TS_end_delete_mode)); + if (tty->delete_in_insert_mode) del_startup_cost /= 2; - del_cost_per_char = string_cost_one_line (TS_del_char); + del_cost_per_char = string_cost_one_line (tty->TS_del_char); } else { @@ -1294,16 +1186,16 @@ calculate_ins_del_char_costs (frame) } /* Delete costs are at negative offsets */ - p = &char_ins_del_cost (frame)[0]; - for (i = FRAME_COLS (frame); --i >= 0;) + p = &char_ins_del_cost (f)[0]; + for (i = FRAME_COLS (f); --i >= 0;) *--p = (del_startup_cost += del_cost_per_char); /* Doing nothing is free */ - p = &char_ins_del_cost (frame)[0]; + p = &char_ins_del_cost (f)[0]; *p++ = 0; /* Insert costs are at positive offsets */ - for (i = FRAME_COLS (frame); --i >= 0;) + for (i = FRAME_COLS (f); --i >= 0;) *p++ = (ins_startup_cost += ins_cost_per_char); } @@ -1311,58 +1203,64 @@ void calculate_costs (frame) FRAME_PTR frame; { - register char *f = (TS_set_scroll_region - ? TS_set_scroll_region - : TS_set_scroll_region_1); - FRAME_COST_BAUD_RATE (frame) = baud_rate; - scroll_region_cost = string_cost (f); + if (FRAME_TERMCAP_P (frame)) + { + struct tty_display_info *tty = FRAME_TTY (frame); + register char *f = (tty->TS_set_scroll_region + ? tty->TS_set_scroll_region + : tty->TS_set_scroll_region_1); - /* These variables are only used for terminal stuff. They are allocated - once for the terminal frame of X-windows emacs, but not used afterwards. + FRAME_SCROLL_REGION_COST (frame) = string_cost (f); - char_ins_del_vector (i.e., char_ins_del_cost) isn't used because - X turns off char_ins_del_ok. */ + tty->costs_set = 1; - max_frame_lines = max (max_frame_lines, FRAME_LINES (frame)); - max_frame_cols = max (max_frame_cols, FRAME_COLS (frame)); + /* These variables are only used for terminal stuff. They are + allocated once for the terminal frame of X-windows emacs, but not + used afterwards. - costs_set = 1; + char_ins_del_vector (i.e., char_ins_del_cost) isn't used because + X turns off char_ins_del_ok. */ - if (char_ins_del_vector != 0) - char_ins_del_vector - = (int *) xrealloc (char_ins_del_vector, - (sizeof (int) - + 2 * max_frame_cols * sizeof (int))); - else - char_ins_del_vector - = (int *) xmalloc (sizeof (int) - + 2 * max_frame_cols * sizeof (int)); - - bzero (char_ins_del_vector, (sizeof (int) - + 2 * max_frame_cols * sizeof (int))); - - if (f && (!TS_ins_line && !TS_del_line)) - do_line_insertion_deletion_costs (frame, - TS_rev_scroll, TS_ins_multi_lines, - TS_fwd_scroll, TS_del_multi_lines, - f, f, 1); - else - do_line_insertion_deletion_costs (frame, - TS_ins_line, TS_ins_multi_lines, - TS_del_line, TS_del_multi_lines, - 0, 0, 1); + max_frame_lines = max (max_frame_lines, FRAME_LINES (frame)); + max_frame_cols = max (max_frame_cols, FRAME_COLS (frame)); - calculate_ins_del_char_costs (frame); + if (char_ins_del_vector != 0) + char_ins_del_vector + = (int *) xrealloc (char_ins_del_vector, + (sizeof (int) + + 2 * max_frame_cols * sizeof (int))); + else + char_ins_del_vector + = (int *) xmalloc (sizeof (int) + + 2 * max_frame_cols * sizeof (int)); - /* Don't use TS_repeat if its padding is worse than sending the chars */ - if (TS_repeat && per_line_cost (TS_repeat) * baud_rate < 9000) - RPov = string_cost (TS_repeat); - else - RPov = FRAME_COLS (frame) * 2; + bzero (char_ins_del_vector, (sizeof (int) + + 2 * max_frame_cols * sizeof (int))); + + + if (f && (!tty->TS_ins_line && !tty->TS_del_line)) + do_line_insertion_deletion_costs (frame, + tty->TS_rev_scroll, tty->TS_ins_multi_lines, + tty->TS_fwd_scroll, tty->TS_del_multi_lines, + f, f, 1); + else + do_line_insertion_deletion_costs (frame, + tty->TS_ins_line, tty->TS_ins_multi_lines, + tty->TS_del_line, tty->TS_del_multi_lines, + 0, 0, 1); + + calculate_ins_del_char_costs (frame); + + /* Don't use TS_repeat if its padding is worse than sending the chars */ + if (tty->TS_repeat && per_line_cost (tty->TS_repeat) * baud_rate < 9000) + tty->RPov = string_cost (tty->TS_repeat); + else + tty->RPov = FRAME_COLS (frame) * 2; - cmcostinit (); /* set up cursor motion costs */ + cmcostinit (FRAME_TTY (frame)); /* set up cursor motion costs */ + } } struct fkey_table { @@ -1812,10 +1710,10 @@ produce_special_glyphs (it, what) from them. Some display attributes may not be used together with color; the termcap capability `NC' specifies which ones. */ -#define MAY_USE_WITH_COLORS_P(ATTR) \ - (TN_max_colors > 0 \ - ? (TN_no_color_video & (ATTR)) == 0 \ - : 1) +#define MAY_USE_WITH_COLORS_P(tty, ATTR) \ + (tty->TN_max_colors > 0 \ + ? (tty->TN_no_color_video & (ATTR)) == 0 \ + : 1) /* Turn appearances of face FACE_ID on tty frame F on. */ @@ -1827,12 +1725,13 @@ turn_on_face (f, face_id) struct face *face = FACE_FROM_ID (f, face_id); long fg = face->foreground; long bg = face->background; + struct tty_display_info *tty = FRAME_TTY (f); /* Do this first because TS_end_standout_mode may be the same as TS_exit_attribute_mode, which turns all appearances off. */ - if (MAY_USE_WITH_COLORS_P (NC_REVERSE)) + if (MAY_USE_WITH_COLORS_P (tty, NC_REVERSE)) { - if (TN_max_colors > 0) + if (tty->TN_max_colors > 0) { if (fg >= 0 && bg >= 0) { @@ -1846,13 +1745,13 @@ turn_on_face (f, face_id) { if (fg == FACE_TTY_DEFAULT_FG_COLOR || bg == FACE_TTY_DEFAULT_BG_COLOR) - toggle_highlight (); + toggle_highlight (tty); } else { if (fg == FACE_TTY_DEFAULT_BG_COLOR || bg == FACE_TTY_DEFAULT_FG_COLOR) - toggle_highlight (); + toggle_highlight (tty); } } else @@ -1863,53 +1762,53 @@ turn_on_face (f, face_id) { if (fg == FACE_TTY_DEFAULT_FG_COLOR || bg == FACE_TTY_DEFAULT_BG_COLOR) - toggle_highlight (); + toggle_highlight (tty); } else { if (fg == FACE_TTY_DEFAULT_BG_COLOR || bg == FACE_TTY_DEFAULT_FG_COLOR) - toggle_highlight (); + toggle_highlight (tty); } } } if (face->tty_bold_p) { - if (MAY_USE_WITH_COLORS_P (NC_BOLD)) - OUTPUT1_IF (TS_enter_bold_mode); + if (MAY_USE_WITH_COLORS_P (tty, NC_BOLD)) + OUTPUT1_IF (tty, tty->TS_enter_bold_mode); } else if (face->tty_dim_p) - if (MAY_USE_WITH_COLORS_P (NC_DIM)) - OUTPUT1_IF (TS_enter_dim_mode); + if (MAY_USE_WITH_COLORS_P (tty, NC_DIM)) + OUTPUT1_IF (tty, tty->TS_enter_dim_mode); /* Alternate charset and blinking not yet used. */ if (face->tty_alt_charset_p - && MAY_USE_WITH_COLORS_P (NC_ALT_CHARSET)) - OUTPUT1_IF (TS_enter_alt_charset_mode); + && MAY_USE_WITH_COLORS_P (tty, NC_ALT_CHARSET)) + OUTPUT1_IF (tty, tty->TS_enter_alt_charset_mode); if (face->tty_blinking_p - && MAY_USE_WITH_COLORS_P (NC_BLINK)) - OUTPUT1_IF (TS_enter_blink_mode); + && MAY_USE_WITH_COLORS_P (tty, NC_BLINK)) + OUTPUT1_IF (tty, tty->TS_enter_blink_mode); - if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (NC_UNDERLINE)) - OUTPUT1_IF (TS_enter_underline_mode); + if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (tty, NC_UNDERLINE)) + OUTPUT1_IF (tty, tty->TS_enter_underline_mode); - if (TN_max_colors > 0) + if (tty->TN_max_colors > 0) { char *p; - if (fg >= 0 && TS_set_foreground) + if (fg >= 0 && tty->TS_set_foreground) { - p = tparam (TS_set_foreground, NULL, 0, (int) fg); - OUTPUT (p); + p = tparam (tty->TS_set_foreground, NULL, 0, (int) fg); + OUTPUT (tty, p); xfree (p); } - if (bg >= 0 && TS_set_background) + if (bg >= 0 && tty->TS_set_background) { - p = tparam (TS_set_background, NULL, 0, (int) bg); - OUTPUT (p); + p = tparam (tty->TS_set_background, NULL, 0, (int) bg); + OUTPUT (tty, p); xfree (p); } } @@ -1924,10 +1823,11 @@ turn_off_face (f, face_id) int face_id; { struct face *face = FACE_FROM_ID (f, face_id); + struct tty_display_info *tty = FRAME_TTY (f); xassert (face != NULL); - if (TS_exit_attribute_mode) + if (tty->TS_exit_attribute_mode) { /* Capability "me" will turn off appearance modes double-bright, half-bright, reverse-video, standout, underline. It may or @@ -1939,32 +1839,32 @@ turn_off_face (f, face_id) || face->tty_blinking_p || face->tty_underline_p) { - OUTPUT1_IF (TS_exit_attribute_mode); - if (strcmp (TS_exit_attribute_mode, TS_end_standout_mode) == 0) - standout_mode = 0; + OUTPUT1_IF (tty, tty->TS_exit_attribute_mode); + if (strcmp (tty->TS_exit_attribute_mode, tty->TS_end_standout_mode) == 0) + tty->standout_mode = 0; } if (face->tty_alt_charset_p) - OUTPUT_IF (TS_exit_alt_charset_mode); + OUTPUT_IF (tty, tty->TS_exit_alt_charset_mode); } else { /* If we don't have "me" we can only have those appearances that have exit sequences defined. */ if (face->tty_alt_charset_p) - OUTPUT_IF (TS_exit_alt_charset_mode); + OUTPUT_IF (tty, tty->TS_exit_alt_charset_mode); if (face->tty_underline_p) - OUTPUT_IF (TS_exit_underline_mode); + OUTPUT_IF (tty, tty->TS_exit_underline_mode); } /* Switch back to default colors. */ - if (TN_max_colors > 0 + if (tty->TN_max_colors > 0 && ((face->foreground != FACE_TTY_DEFAULT_COLOR && face->foreground != FACE_TTY_DEFAULT_FG_COLOR) || (face->background != FACE_TTY_DEFAULT_COLOR && face->background != FACE_TTY_DEFAULT_BG_COLOR))) - OUTPUT1_IF (TS_orig_pair); + OUTPUT1_IF (tty, tty->TS_orig_pair); } @@ -1973,26 +1873,72 @@ turn_off_face (f, face_id) colors FG and BG. */ int -tty_capable_p (f, caps, fg, bg) - struct frame *f; +tty_capable_p (tty, caps, fg, bg) + struct tty_display_info *tty; unsigned caps; unsigned long fg, bg; { -#define TTY_CAPABLE_P_TRY(cap, TS, NC_bit) \ - if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(NC_bit))) \ +#define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \ + if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \ return 0; - TTY_CAPABLE_P_TRY (TTY_CAP_INVERSE, TS_standout_mode, NC_REVERSE); - TTY_CAPABLE_P_TRY (TTY_CAP_UNDERLINE, TS_enter_underline_mode, NC_UNDERLINE); - TTY_CAPABLE_P_TRY (TTY_CAP_BOLD, TS_enter_bold_mode, NC_BOLD); - TTY_CAPABLE_P_TRY (TTY_CAP_DIM, TS_enter_dim_mode, NC_DIM); - TTY_CAPABLE_P_TRY (TTY_CAP_BLINK, TS_enter_blink_mode, NC_BLINK); - TTY_CAPABLE_P_TRY (TTY_CAP_ALT_CHARSET, TS_enter_alt_charset_mode, NC_ALT_CHARSET); + TTY_CAPABLE_P_TRY (tty, TTY_CAP_INVERSE, tty->TS_standout_mode, NC_REVERSE); + TTY_CAPABLE_P_TRY (tty, TTY_CAP_UNDERLINE, tty->TS_enter_underline_mode, NC_UNDERLINE); + TTY_CAPABLE_P_TRY (tty, TTY_CAP_BOLD, tty->TS_enter_bold_mode, NC_BOLD); + TTY_CAPABLE_P_TRY (tty, TTY_CAP_DIM, tty->TS_enter_dim_mode, NC_DIM); + TTY_CAPABLE_P_TRY (tty, TTY_CAP_BLINK, tty->TS_enter_blink_mode, NC_BLINK); + TTY_CAPABLE_P_TRY (tty, TTY_CAP_ALT_CHARSET, tty->TS_enter_alt_charset_mode, NC_ALT_CHARSET); /* We can do it! */ return 1; } +/* Return the tty display object specified by DISPLAY. DISPLAY may be + a frame, a string, or nil for the display device of the current + frame. */ + +static struct display * +get_tty_display (Lisp_Object display) +{ + struct display *d; + + if (NILP (display)) + display = selected_frame; + + if (! FRAMEP (display) && ! STRINGP (display)) + return 0; + + /* The initial frame does not support colors. */ + if (FRAMEP (display) && FRAME_INITIAL_P (XFRAME (display))) + return 0; + + if (FRAMEP (display)) + { + if (! FRAME_TERMCAP_P (XFRAME (display))) +#if 0 /* XXX We need a predicate as the first argument; find one. */ + wrong_type_argument ("Not a termcap frame", display); +#else /* Until we fix the wrong_type_argument call above, simply throw + a dumb error. */ + error ("DISPLAY is not a termcap frame"); +#endif + + d = FRAME_DISPLAY (XFRAME (display)); + } + else if (STRINGP (display)) + { + char *name = (char *) alloca (SBYTES (display) + 1); + strncpy (name, SDATA (display), SBYTES (display)); + name[SBYTES (display)] = 0; + + d = get_named_tty_display (name); + + if (!d) + error ("There is no tty display on %s", name); + } + + return d; +} + /* Return non-zero if the terminal is capable to display colors. */ @@ -2002,7 +1948,11 @@ DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p, (display) Lisp_Object display; { - return TN_max_colors > 0 ? Qt : Qnil; + struct display *d = get_tty_display (display); + if (!d) + return Qnil; + else + return d->display_info.tty->TN_max_colors > 0 ? Qt : Qnil; } /* Return the number of supported colors. */ @@ -2012,7 +1962,11 @@ DEFUN ("tty-display-color-cells", Ftty_display_color_cells, (display) Lisp_Object display; { - return make_number (TN_max_colors); + struct display *d = get_tty_display (display); + if (!d) + return Qnil; + else + return make_number (d->display_info.tty->TN_max_colors); } #ifndef WINDOWSNT @@ -2020,8 +1974,7 @@ DEFUN ("tty-display-color-cells", Ftty_display_color_cells, /* Save or restore the default color-related capabilities of this terminal. */ static void -tty_default_color_capabilities (save) - int save; +tty_default_color_capabilities (struct tty_display_info *tty, int save) { static char *default_orig_pair, *default_set_foreground, *default_set_background; @@ -2031,30 +1984,30 @@ tty_default_color_capabilities (save) { if (default_orig_pair) xfree (default_orig_pair); - default_orig_pair = TS_orig_pair ? xstrdup (TS_orig_pair) : NULL; + default_orig_pair = tty->TS_orig_pair ? xstrdup (tty->TS_orig_pair) : NULL; if (default_set_foreground) xfree (default_set_foreground); - default_set_foreground = TS_set_foreground ? xstrdup (TS_set_foreground) + default_set_foreground = tty->TS_set_foreground ? xstrdup (tty->TS_set_foreground) : NULL; if (default_set_background) xfree (default_set_background); - default_set_background = TS_set_background ? xstrdup (TS_set_background) + default_set_background = tty->TS_set_background ? xstrdup (tty->TS_set_background) : NULL; - default_max_colors = TN_max_colors; - default_max_pairs = TN_max_pairs; - default_no_color_video = TN_no_color_video; + default_max_colors = tty->TN_max_colors; + default_max_pairs = tty->TN_max_pairs; + default_no_color_video = tty->TN_no_color_video; } else { - TS_orig_pair = default_orig_pair; - TS_set_foreground = default_set_foreground; - TS_set_background = default_set_background; - TN_max_colors = default_max_colors; - TN_max_pairs = default_max_pairs; - TN_no_color_video = default_no_color_video; + tty->TS_orig_pair = default_orig_pair; + tty->TS_set_foreground = default_set_foreground; + tty->TS_set_background = default_set_background; + tty->TN_max_colors = default_max_colors; + tty->TN_max_pairs = default_max_pairs; + tty->TN_no_color_video = default_no_color_video; } } @@ -2063,8 +2016,7 @@ tty_default_color_capabilities (save) support; zero means set up for the default capabilities, the ones we saw at term_init time; -1 means turn off color support. */ void -tty_setup_colors (mode) - int mode; +tty_setup_colors (struct tty_display_info *tty, int mode) { /* Canonicalize all negative values of MODE. */ if (mode < -1) @@ -2073,27 +2025,27 @@ tty_setup_colors (mode) switch (mode) { case -1: /* no colors at all */ - TN_max_colors = 0; - TN_max_pairs = 0; - TN_no_color_video = 0; - TS_set_foreground = TS_set_background = TS_orig_pair = NULL; + tty->TN_max_colors = 0; + tty->TN_max_pairs = 0; + tty->TN_no_color_video = 0; + tty->TS_set_foreground = tty->TS_set_background = tty->TS_orig_pair = NULL; break; case 0: /* default colors, if any */ default: - tty_default_color_capabilities (0); + tty_default_color_capabilities (tty, 0); break; case 8: /* 8 standard ANSI colors */ - TS_orig_pair = "\033[0m"; + tty->TS_orig_pair = "\033[0m"; #ifdef TERMINFO - TS_set_foreground = "\033[3%p1%dm"; - TS_set_background = "\033[4%p1%dm"; + tty->TS_set_foreground = "\033[3%p1%dm"; + tty->TS_set_background = "\033[4%p1%dm"; #else - TS_set_foreground = "\033[3%dm"; - TS_set_background = "\033[4%dm"; + tty->TS_set_foreground = "\033[3%dm"; + tty->TS_set_background = "\033[4%dm"; #endif - TN_max_colors = 8; - TN_max_pairs = 64; - TN_no_color_video = 0; + tty->TN_max_colors = 8; + tty->TN_max_pairs = 64; + tty->TN_no_color_video = 0; break; } } @@ -2144,7 +2096,7 @@ set_tty_color_mode (f, val) if (mode != old_mode) { - tty_setup_colors (mode); + tty_setup_colors (FRAME_TTY (f), mode); /* This recomputes all the faces given the new color definitions. */ call0 (intern ("tty-set-up-initial-frame-faces")); @@ -2155,13 +2107,132 @@ set_tty_color_mode (f, val) #endif /* !WINDOWSNT */ + +/* Return the termcap display with the given name. If NAME is null, + return the display corresponding to our controlling terminal. + + Returns NULL if the named terminal device is not opened. */ + +struct display * +get_named_tty_display (name) + char *name; +{ + struct display *d; + + for (d = display_list; d; d = d->next_display) { + if (d->type == output_termcap + && ((d->display_info.tty->name == 0 && name == 0) + || (name && d->display_info.tty->name + && !strcmp (d->display_info.tty->name, name)))) + return d; + }; + + return 0; +} + + + +DEFUN ("frame-tty-name", Fframe_tty_name, Sframe_tty_name, 0, 1, 0, + doc: /* Return the name of the TTY device that FRAME is displayed on. */) + (frame) + Lisp_Object frame; +{ + struct frame *f; + + if (NILP (frame)) + { + f = XFRAME (selected_frame); + } + else + { + CHECK_LIVE_FRAME (frame); + f = XFRAME (frame); + } + + if (f->output_method != output_termcap) + wrong_type_argument (Qframe_tty_name, frame); + + if (FRAME_TTY (f)->name) + return build_string (FRAME_TTY (f)->name); + else + return Qnil; +} + +DEFUN ("frame-tty-type", Fframe_tty_type, Sframe_tty_type, 0, 1, 0, + doc: /* Return the type of the TTY device that FRAME is displayed on. */) + (frame) + Lisp_Object frame; +{ + struct frame *f; + + if (NILP (frame)) + { + f = XFRAME (selected_frame); + } + else + { + CHECK_LIVE_FRAME (frame); + f = XFRAME (frame); + } + + if (f->output_method != output_termcap) + wrong_type_argument (Qframe_tty_type, frame); + + if (FRAME_TTY (f)->type) + return build_string (FRAME_TTY (f)->type); + else + return Qnil; +} + + /*********************************************************************** Initialization ***********************************************************************/ +/* Create the bootstrap display device for the initial frame. + Returns a display of type output_initial. */ + +struct display * +init_initial_display (void) +{ + if (initialized || display_list || tty_list) + abort (); + + initial_display = create_display (); + initial_display->type = output_initial; + + initial_display->delete_display_hook = &delete_initial_display; + /* All other hooks are NULL. */ + + return initial_display; +} + +/* Deletes the bootstrap display device. + Called through delete_display_hook. */ + void -term_init (terminal_type) - char *terminal_type; +delete_initial_display (struct display *display) +{ + if (display != initial_display) + abort (); + + delete_display (display); + initial_display = NULL; +} + +/* Create a termcap display on the tty device with the given name and + type. + + If NAME is NULL, then use the controlling tty, i.e., stdin/stdout. + Otherwise NAME should be a path to the tty device file, + e.g. "/dev/pts/7". + + TERMINAL_TYPE is the termcap type of the device, e.g. "vt100". + + If MUST_SUCCEED is true, then all errors are fatal. */ + +struct display * +term_init (char *name, char *terminal_type, int must_succeed) { char *area; char **address = &area; @@ -2169,69 +2240,204 @@ term_init (terminal_type) int buffer_size = 4096; register char *p; int status; - struct frame *sf = XFRAME (selected_frame); + struct tty_display_info *tty; + struct display *display; + + static void maybe_fatal(); + + if (!terminal_type) + maybe_fatal (must_succeed, 0, 0, + "Unknown terminal type", + "Unknown terminal type"); + + display = get_named_tty_display (name); + if (display) + { + if (! display->display_info.tty->input) + error ("%s already has a suspended frame on it, can't open it twice", name); + return display; + } + + display = create_display (); + tty = (struct tty_display_info *) xmalloc (sizeof (struct tty_display_info)); + bzero (tty, sizeof (struct tty_display_info)); + tty->next = tty_list; + tty_list = tty; + + display->type = output_termcap; + display->display_info.tty = tty; + tty->display = display; + + tty->Wcm = (struct cm *) xmalloc (sizeof (struct cm)); + Wcm_clear (tty); + + display->rif = 0; /* ttys don't support window-based redisplay. */ + + display->cursor_to_hook = &tty_cursor_to; + display->raw_cursor_to_hook = &tty_raw_cursor_to; + + display->clear_to_end_hook = &tty_clear_to_end; + display->clear_frame_hook = &tty_clear_frame; + display->clear_end_of_line_hook = &tty_clear_end_of_line; + + display->ins_del_lines_hook = &tty_ins_del_lines; + + display->insert_glyphs_hook = &tty_insert_glyphs; + display->write_glyphs_hook = &tty_write_glyphs; + display->delete_glyphs_hook = &tty_delete_glyphs; + + display->ring_bell_hook = &tty_ring_bell; + + display->reset_terminal_modes_hook = &tty_reset_terminal_modes; + display->set_terminal_modes_hook = &tty_set_terminal_modes; + display->update_begin_hook = 0; /* Not needed. */ + display->update_end_hook = &tty_update_end; + display->set_terminal_window_hook = &tty_set_terminal_window; + + display->mouse_position_hook = 0; /* Not needed. */ + display->frame_rehighlight_hook = 0; /* Not needed. */ + display->frame_raise_lower_hook = 0; /* Not needed. */ + + display->set_vertical_scroll_bar_hook = 0; /* Not needed. */ + display->condemn_scroll_bars_hook = 0; /* Not needed. */ + display->redeem_scroll_bar_hook = 0; /* Not needed. */ + display->judge_scroll_bars_hook = 0; /* Not needed. */ + + display->read_socket_hook = &tty_read_avail_input; /* keyboard.c */ + display->frame_up_to_date_hook = 0; /* Not needed. */ + + display->delete_frame_hook = &delete_tty_output; + display->delete_display_hook = &delete_tty; + + if (name) + { + int fd; + FILE *file; + +#ifdef O_IGNORE_CTTY + /* Open the terminal device. Don't recognize it as our + controlling terminal, and don't make it the controlling tty + if we don't have one at the moment. */ + fd = emacs_open (name, O_RDWR | O_IGNORE_CTTY | O_NOCTTY, 0); +#else + /* Alas, O_IGNORE_CTTY is a GNU extension that is only defined + on Hurd. On other systems, we need to dissociate ourselves + from the controlling tty when we want to open a frame on the + same terminal. The function setsid should be used for this, + but it didn't work for me. */ + + fd = emacs_open (name, O_RDWR | O_NOCTTY, 0); + +#ifdef TIOCNOTTY + /* Drop our controlling tty if it is the same device. */ + if (ioctl (fd, TIOCNOTTY, 0) != -1) + { + no_controlling_tty = 1; + } +#endif +#endif /* O_IGNORE_CTTY */ + + if (fd < 0) + { + delete_tty (display); + error ("Could not open file: %s", name); + } + if (! isatty (fd)) + { + close (fd); + error ("Not a tty device: %s", name); + } + + file = fdopen (fd, "w+"); + tty->name = xstrdup (name); + tty->input = file; + tty->output = file; + } + else + { + if (no_controlling_tty) + { + /* Opening a frame on stdout is unsafe if we have + disconnected our controlling terminal. */ + error ("There is no controlling terminal any more"); + } + tty->name = 0; + tty->input = stdin; + tty->output = stdout; + } + + tty->type = xstrdup (terminal_type); + + add_keyboard_wait_descriptor (fileno (tty->input)); #ifdef WINDOWSNT initialize_w32_display (); - Wcm_clear (); + Wcm_clear (tty); area = (char *) xmalloc (2044); - FrameRows = FRAME_LINES (sf); - FrameCols = FRAME_COLS (sf); - specified_window = FRAME_LINES (sf); + FrameRows (tty) = FRAME_LINES (f); /* XXX */ + FrameCols (tty) = FRAME_COLS (f); /* XXX */ + tty->specified_window = FRAME_LINES (f); /* XXX */ - delete_in_insert_mode = 1; + tty->display->delete_in_insert_mode = 1; - UseTabs = 0; - scroll_region_ok = 0; + UseTabs (tty) = 0; + display->scroll_region_ok = 0; /* Seems to insert lines when it's not supposed to, messing up the display. In doing a trace, it didn't seem to be called much, so I don't think we're losing anything by turning it off. */ - - line_ins_del_ok = 0; - char_ins_del_ok = 1; + display->line_ins_del_ok = 0; + display->char_ins_del_ok = 1; baud_rate = 19200; - FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0; - FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none; + FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; /* XXX */ + FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none; /* XXX */ TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */ - return; + return display; #else /* not WINDOWSNT */ - Wcm_clear (); + Wcm_clear (tty); buffer = (char *) xmalloc (buffer_size); status = tgetent (buffer, terminal_type); if (status < 0) { #ifdef TERMINFO - fatal ("Cannot open terminfo database file"); + maybe_fatal (must_succeed, buffer, display, + "Cannot open terminfo database file", + "Cannot open terminfo database file"); #else - fatal ("Cannot open termcap database file"); + maybe_fatal (must_succeed, buffer, display, + "Cannot open termcap database file", + "Cannot open termcap database file"); #endif } if (status == 0) { #ifdef TERMINFO - fatal ("Terminal type %s is not defined.\n\ + maybe_fatal (must_succeed, buffer, display, + "Terminal type %s is not defined", + "Terminal type %s is not defined.\n\ If that is not the actual type of terminal you have,\n\ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ `setenv TERM ...') to specify the correct type. It may be necessary\n\ to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", - terminal_type); + terminal_type); #else - fatal ("Terminal type %s is not defined.\n\ + maybe_fatal (must_succeed, buffer, display, + "Terminal type %s is not defined", + "Terminal type %s is not defined.\n\ If that is not the actual type of terminal you have,\n\ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ `setenv TERM ...') to specify the correct type. It may be necessary\n\ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", - terminal_type); + terminal_type); #endif } @@ -2242,219 +2448,221 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", #endif area = (char *) xmalloc (buffer_size); - TS_ins_line = tgetstr ("al", address); - TS_ins_multi_lines = tgetstr ("AL", address); - TS_bell = tgetstr ("bl", address); - BackTab = tgetstr ("bt", address); - TS_clr_to_bottom = tgetstr ("cd", address); - TS_clr_line = tgetstr ("ce", address); - TS_clr_frame = tgetstr ("cl", address); - ColPosition = NULL; /* tgetstr ("ch", address); */ - AbsPosition = tgetstr ("cm", address); - CR = tgetstr ("cr", address); - TS_set_scroll_region = tgetstr ("cs", address); - TS_set_scroll_region_1 = tgetstr ("cS", address); - RowPosition = tgetstr ("cv", address); - TS_del_char = tgetstr ("dc", address); - TS_del_multi_chars = tgetstr ("DC", address); - TS_del_line = tgetstr ("dl", address); - TS_del_multi_lines = tgetstr ("DL", address); - TS_delete_mode = tgetstr ("dm", address); - TS_end_delete_mode = tgetstr ("ed", address); - TS_end_insert_mode = tgetstr ("ei", address); - Home = tgetstr ("ho", address); - TS_ins_char = tgetstr ("ic", address); - TS_ins_multi_chars = tgetstr ("IC", address); - TS_insert_mode = tgetstr ("im", address); - TS_pad_inserted_char = tgetstr ("ip", address); - TS_end_keypad_mode = tgetstr ("ke", address); - TS_keypad_mode = tgetstr ("ks", address); - LastLine = tgetstr ("ll", address); - Right = tgetstr ("nd", address); - Down = tgetstr ("do", address); - if (!Down) - Down = tgetstr ("nl", address); /* Obsolete name for "do" */ + tty->TS_ins_line = tgetstr ("al", address); + tty->TS_ins_multi_lines = tgetstr ("AL", address); + tty->TS_bell = tgetstr ("bl", address); + BackTab (tty) = tgetstr ("bt", address); + tty->TS_clr_to_bottom = tgetstr ("cd", address); + tty->TS_clr_line = tgetstr ("ce", address); + tty->TS_clr_frame = tgetstr ("cl", address); + ColPosition (tty) = NULL; /* tgetstr ("ch", address); */ + AbsPosition (tty) = tgetstr ("cm", address); + CR (tty) = tgetstr ("cr", address); + tty->TS_set_scroll_region = tgetstr ("cs", address); + tty->TS_set_scroll_region_1 = tgetstr ("cS", address); + RowPosition (tty) = tgetstr ("cv", address); + tty->TS_del_char = tgetstr ("dc", address); + tty->TS_del_multi_chars = tgetstr ("DC", address); + tty->TS_del_line = tgetstr ("dl", address); + tty->TS_del_multi_lines = tgetstr ("DL", address); + tty->TS_delete_mode = tgetstr ("dm", address); + tty->TS_end_delete_mode = tgetstr ("ed", address); + tty->TS_end_insert_mode = tgetstr ("ei", address); + Home (tty) = tgetstr ("ho", address); + tty->TS_ins_char = tgetstr ("ic", address); + tty->TS_ins_multi_chars = tgetstr ("IC", address); + tty->TS_insert_mode = tgetstr ("im", address); + tty->TS_pad_inserted_char = tgetstr ("ip", address); + tty->TS_end_keypad_mode = tgetstr ("ke", address); + tty->TS_keypad_mode = tgetstr ("ks", address); + LastLine (tty) = tgetstr ("ll", address); + Right (tty) = tgetstr ("nd", address); + Down (tty) = tgetstr ("do", address); + if (!Down (tty)) + Down (tty) = tgetstr ("nl", address); /* Obsolete name for "do" */ #ifdef VMS /* VMS puts a carriage return before each linefeed, so it is not safe to use linefeeds. */ - if (Down && Down[0] == '\n' && Down[1] == '\0') - Down = 0; + if (Down (tty) && Down (tty)[0] == '\n' && Down (tty)[1] == '\0') + Down (tty) = 0; #endif /* VMS */ if (tgetflag ("bs")) - Left = "\b"; /* can't possibly be longer! */ + Left (tty) = "\b"; /* can't possibly be longer! */ else /* (Actually, "bs" is obsolete...) */ - Left = tgetstr ("le", address); - if (!Left) - Left = tgetstr ("bc", address); /* Obsolete name for "le" */ - TS_pad_char = tgetstr ("pc", address); - TS_repeat = tgetstr ("rp", address); - TS_end_standout_mode = tgetstr ("se", address); - TS_fwd_scroll = tgetstr ("sf", address); - TS_standout_mode = tgetstr ("so", address); - TS_rev_scroll = tgetstr ("sr", address); - Wcm.cm_tab = tgetstr ("ta", address); - TS_end_termcap_modes = tgetstr ("te", address); - TS_termcap_modes = tgetstr ("ti", address); - Up = tgetstr ("up", address); - TS_visible_bell = tgetstr ("vb", address); - TS_cursor_normal = tgetstr ("ve", address); - TS_cursor_visible = tgetstr ("vs", address); - TS_cursor_invisible = tgetstr ("vi", address); - TS_set_window = tgetstr ("wi", address); - - TS_enter_underline_mode = tgetstr ("us", address); - TS_exit_underline_mode = tgetstr ("ue", address); - TS_enter_bold_mode = tgetstr ("md", address); - TS_enter_dim_mode = tgetstr ("mh", address); - TS_enter_blink_mode = tgetstr ("mb", address); - TS_enter_reverse_mode = tgetstr ("mr", address); - TS_enter_alt_charset_mode = tgetstr ("as", address); - TS_exit_alt_charset_mode = tgetstr ("ae", address); - TS_exit_attribute_mode = tgetstr ("me", address); - - MultiUp = tgetstr ("UP", address); - MultiDown = tgetstr ("DO", address); - MultiLeft = tgetstr ("LE", address); - MultiRight = tgetstr ("RI", address); + Left (tty) = tgetstr ("le", address); + if (!Left (tty)) + Left (tty) = tgetstr ("bc", address); /* Obsolete name for "le" */ + tty->TS_pad_char = tgetstr ("pc", address); + tty->TS_repeat = tgetstr ("rp", address); + tty->TS_end_standout_mode = tgetstr ("se", address); + tty->TS_fwd_scroll = tgetstr ("sf", address); + tty->TS_standout_mode = tgetstr ("so", address); + tty->TS_rev_scroll = tgetstr ("sr", address); + tty->Wcm->cm_tab = tgetstr ("ta", address); + tty->TS_end_termcap_modes = tgetstr ("te", address); + tty->TS_termcap_modes = tgetstr ("ti", address); + Up (tty) = tgetstr ("up", address); + tty->TS_visible_bell = tgetstr ("vb", address); + tty->TS_cursor_normal = tgetstr ("ve", address); + tty->TS_cursor_visible = tgetstr ("vs", address); + tty->TS_cursor_invisible = tgetstr ("vi", address); + tty->TS_set_window = tgetstr ("wi", address); + + tty->TS_enter_underline_mode = tgetstr ("us", address); + tty->TS_exit_underline_mode = tgetstr ("ue", address); + tty->TS_enter_bold_mode = tgetstr ("md", address); + tty->TS_enter_dim_mode = tgetstr ("mh", address); + tty->TS_enter_blink_mode = tgetstr ("mb", address); + tty->TS_enter_reverse_mode = tgetstr ("mr", address); + tty->TS_enter_alt_charset_mode = tgetstr ("as", address); + tty->TS_exit_alt_charset_mode = tgetstr ("ae", address); + tty->TS_exit_attribute_mode = tgetstr ("me", address); + + MultiUp (tty) = tgetstr ("UP", address); + MultiDown (tty) = tgetstr ("DO", address); + MultiLeft (tty) = tgetstr ("LE", address); + MultiRight (tty) = tgetstr ("RI", address); /* SVr4/ANSI color suppert. If "op" isn't available, don't support color because we can't switch back to the default foreground and background. */ - TS_orig_pair = tgetstr ("op", address); - if (TS_orig_pair) + tty->TS_orig_pair = tgetstr ("op", address); + if (tty->TS_orig_pair) { - TS_set_foreground = tgetstr ("AF", address); - TS_set_background = tgetstr ("AB", address); - if (!TS_set_foreground) + tty->TS_set_foreground = tgetstr ("AF", address); + tty->TS_set_background = tgetstr ("AB", address); + if (!tty->TS_set_foreground) { /* SVr4. */ - TS_set_foreground = tgetstr ("Sf", address); - TS_set_background = tgetstr ("Sb", address); + tty->TS_set_foreground = tgetstr ("Sf", address); + tty->TS_set_background = tgetstr ("Sb", address); } - TN_max_colors = tgetnum ("Co"); - TN_max_pairs = tgetnum ("pa"); + tty->TN_max_colors = tgetnum ("Co"); + tty->TN_max_pairs = tgetnum ("pa"); - TN_no_color_video = tgetnum ("NC"); - if (TN_no_color_video == -1) - TN_no_color_video = 0; + tty->TN_no_color_video = tgetnum ("NC"); + if (tty->TN_no_color_video == -1) + tty->TN_no_color_video = 0; } - tty_default_color_capabilities (1); + tty_default_color_capabilities (tty, 1); - MagicWrap = tgetflag ("xn"); + MagicWrap (tty) = tgetflag ("xn"); /* Since we make MagicWrap terminals look like AutoWrap, we need to have the former flag imply the latter. */ - AutoWrap = MagicWrap || tgetflag ("am"); - memory_below_frame = tgetflag ("db"); - TF_hazeltine = tgetflag ("hz"); - must_write_spaces = tgetflag ("in"); - meta_key = tgetflag ("km") || tgetflag ("MT"); - TF_insmode_motion = tgetflag ("mi"); - TF_standout_motion = tgetflag ("ms"); - TF_underscore = tgetflag ("ul"); - TF_teleray = tgetflag ("xt"); + AutoWrap (tty) = MagicWrap (tty) || tgetflag ("am"); + display->memory_below_frame = tgetflag ("db"); + tty->TF_hazeltine = tgetflag ("hz"); + display->must_write_spaces = tgetflag ("in"); + tty->meta_key = tgetflag ("km") || tgetflag ("MT"); + tty->TF_insmode_motion = tgetflag ("mi"); + tty->TF_standout_motion = tgetflag ("ms"); + tty->TF_underscore = tgetflag ("ul"); + tty->TF_teleray = tgetflag ("xt"); term_get_fkeys (address); /* Get frame size from system, or else from termcap. */ { int height, width; - get_frame_size (&width, &height); - FRAME_COLS (sf) = width; - FRAME_LINES (sf) = height; + get_tty_size (fileno (tty->input), &width, &height); + FrameCols (tty) = width; + FrameRows (tty) = height; } - if (FRAME_COLS (sf) <= 0) - SET_FRAME_COLS (sf, tgetnum ("co")); - else - /* Keep width and external_width consistent */ - SET_FRAME_COLS (sf, FRAME_COLS (sf)); - if (FRAME_LINES (sf) <= 0) - FRAME_LINES (sf) = tgetnum ("li"); + if (FrameCols (tty) <= 0) + FrameCols (tty) = tgetnum ("co"); + if (FrameRows (tty) <= 0) + FrameRows (tty) = tgetnum ("li"); - if (FRAME_LINES (sf) < 3 || FRAME_COLS (sf) < 3) - fatal ("Screen size %dx%d is too small", - FRAME_LINES (sf), FRAME_COLS (sf)); + if (FrameRows (tty) < 3 || FrameCols (tty) < 3) + maybe_fatal (must_succeed, NULL, display, + "Screen size %dx%d is too small" + "Screen size %dx%d is too small", + FrameCols (tty), FrameRows (tty)); - min_padding_speed = tgetnum ("pb"); - TabWidth = tgetnum ("tw"); +#if 0 /* This is not used anywhere. */ + tty->display->min_padding_speed = tgetnum ("pb"); +#endif + + TabWidth (tty) = tgetnum ("tw"); #ifdef VMS /* These capabilities commonly use ^J. I don't know why, but sending them on VMS does not work; it causes following spaces to be lost, sometimes. For now, the simplest fix is to avoid using these capabilities ever. */ - if (Down && Down[0] == '\n') - Down = 0; + if (Down (tty) && Down (tty)[0] == '\n') + Down (tty) = 0; #endif /* VMS */ - if (!TS_bell) - TS_bell = "\07"; + if (!tty->TS_bell) + tty->TS_bell = "\07"; - if (!TS_fwd_scroll) - TS_fwd_scroll = Down; + if (!tty->TS_fwd_scroll) + tty->TS_fwd_scroll = Down (tty); - PC = TS_pad_char ? *TS_pad_char : 0; + PC = tty->TS_pad_char ? *tty->TS_pad_char : 0; - if (TabWidth < 0) - TabWidth = 8; + if (TabWidth (tty) < 0) + TabWidth (tty) = 8; /* Turned off since /etc/termcap seems to have :ta= for most terminals and newer termcap doc does not seem to say there is a default. - if (!Wcm.cm_tab) - Wcm.cm_tab = "\t"; + if (!tty->Wcm->cm_tab) + tty->Wcm->cm_tab = "\t"; */ /* We don't support standout modes that use `magic cookies', so turn off any that do. */ - if (TS_standout_mode && tgetnum ("sg") >= 0) + if (tty->TS_standout_mode && tgetnum ("sg") >= 0) { - TS_standout_mode = 0; - TS_end_standout_mode = 0; + tty->TS_standout_mode = 0; + tty->TS_end_standout_mode = 0; } - if (TS_enter_underline_mode && tgetnum ("ug") >= 0) + if (tty->TS_enter_underline_mode && tgetnum ("ug") >= 0) { - TS_enter_underline_mode = 0; - TS_exit_underline_mode = 0; + tty->TS_enter_underline_mode = 0; + tty->TS_exit_underline_mode = 0; } /* If there's no standout mode, try to use underlining instead. */ - if (TS_standout_mode == 0) + if (tty->TS_standout_mode == 0) { - TS_standout_mode = TS_enter_underline_mode; - TS_end_standout_mode = TS_exit_underline_mode; + tty->TS_standout_mode = tty->TS_enter_underline_mode; + tty->TS_end_standout_mode = tty->TS_exit_underline_mode; } /* If no `se' string, try using a `me' string instead. If that fails, we can't use standout mode at all. */ - if (TS_end_standout_mode == 0) + if (tty->TS_end_standout_mode == 0) { char *s = tgetstr ("me", address); if (s != 0) - TS_end_standout_mode = s; + tty->TS_end_standout_mode = s; else - TS_standout_mode = 0; + tty->TS_standout_mode = 0; } - if (TF_teleray) + if (tty->TF_teleray) { - Wcm.cm_tab = 0; + tty->Wcm->cm_tab = 0; /* We can't support standout mode, because it uses magic cookies. */ - TS_standout_mode = 0; + tty->TS_standout_mode = 0; /* But that means we cannot rely on ^M to go to column zero! */ - CR = 0; + CR (tty) = 0; /* LF can't be trusted either -- can alter hpos */ /* if move at column 0 thru a line with TS_standout_mode */ - Down = 0; + Down (tty) = 0; } /* Special handling for certain terminal types known to need it */ if (!strcmp (terminal_type, "supdup")) { - memory_below_frame = 1; - Wcm.cm_losewrap = 1; + display->memory_below_frame = 1; + tty->Wcm->cm_losewrap = 1; } if (!strncmp (terminal_type, "c10", 3) || !strcmp (terminal_type, "perq")) @@ -2471,102 +2679,152 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", It would be simpler if the :wi string could go in the termcap entry, but it can't because it is not fully valid. If it were in the termcap entry, it would confuse other programs. */ - if (!TS_set_window) + if (!tty->TS_set_window) { - p = TS_termcap_modes; + p = tty->TS_termcap_modes; while (*p && strcmp (p, "\033v ")) p++; if (*p) - TS_set_window = "\033v%C %C %C %C "; + tty->TS_set_window = "\033v%C %C %C %C "; } /* Termcap entry often fails to have :in: flag */ - must_write_spaces = 1; + display->must_write_spaces = 1; /* :ti string typically fails to have \E^G! in it */ /* This limits scope of insert-char to one line. */ - strcpy (area, TS_termcap_modes); + strcpy (area, tty->TS_termcap_modes); strcat (area, "\033\007!"); - TS_termcap_modes = area; + tty->TS_termcap_modes = area; area += strlen (area) + 1; - p = AbsPosition; + p = AbsPosition (tty); /* Change all %+ parameters to %C, to handle - values above 96 correctly for the C100. */ + values above 96 correctly for the C100. */ while (*p) - { - if (p[0] == '%' && p[1] == '+') - p[1] = 'C'; - p++; - } + { + if (p[0] == '%' && p[1] == '+') + p[1] = 'C'; + p++; + } } - FrameRows = FRAME_LINES (sf); - FrameCols = FRAME_COLS (sf); - specified_window = FRAME_LINES (sf); + tty->specified_window = FrameRows (tty); - if (Wcm_init () == -1) /* can't do cursor motion */ + if (Wcm_init (tty) == -1) /* can't do cursor motion */ + { + maybe_fatal (must_succeed, NULL, display, + "Terminal type \"%s\" is not powerful enough to run Emacs", #ifdef VMS - fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ + "Terminal type \"%s\" is not powerful enough to run Emacs.\n\ It lacks the ability to position the cursor.\n\ If that is not the actual type of terminal you have, use either the\n\ DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\ or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.", - terminal_type); #else /* not VMS */ # ifdef TERMINFO - fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ + "Terminal type \"%s\" is not powerful enough to run Emacs.\n\ It lacks the ability to position the cursor.\n\ If that is not the actual type of terminal you have,\n\ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ `setenv TERM ...') to specify the correct type. It may be necessary\n\ to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", - terminal_type); # else /* TERMCAP */ - fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ + "Terminal type \"%s\" is not powerful enough to run Emacs.\n\ It lacks the ability to position the cursor.\n\ If that is not the actual type of terminal you have,\n\ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ `setenv TERM ...') to specify the correct type. It may be necessary\n\ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", - terminal_type); # endif /* TERMINFO */ #endif /*VMS */ - if (FRAME_LINES (sf) <= 0 - || FRAME_COLS (sf) <= 0) - fatal ("The frame size has not been specified"); + terminal_type); + } - delete_in_insert_mode - = TS_delete_mode && TS_insert_mode - && !strcmp (TS_delete_mode, TS_insert_mode); + if (FrameRows (tty) <= 0 || FrameCols (tty) <= 0) + maybe_fatal (must_succeed, NULL, display, + "Could not determine the frame size", + "Could not determine the frame size"); - se_is_so = (TS_standout_mode - && TS_end_standout_mode - && !strcmp (TS_standout_mode, TS_end_standout_mode)); + tty->delete_in_insert_mode + = tty->TS_delete_mode && tty->TS_insert_mode + && !strcmp (tty->TS_delete_mode, tty->TS_insert_mode); - UseTabs = tabs_safe_p () && TabWidth == 8; + tty->se_is_so = (tty->TS_standout_mode + && tty->TS_end_standout_mode + && !strcmp (tty->TS_standout_mode, tty->TS_end_standout_mode)); - scroll_region_ok - = (Wcm.cm_abs - && (TS_set_window || TS_set_scroll_region || TS_set_scroll_region_1)); + UseTabs (tty) = tabs_safe_p (fileno (tty->input)) && TabWidth (tty) == 8; - line_ins_del_ok = (((TS_ins_line || TS_ins_multi_lines) - && (TS_del_line || TS_del_multi_lines)) - || (scroll_region_ok && TS_fwd_scroll && TS_rev_scroll)); + display->scroll_region_ok + = (tty->Wcm->cm_abs + && (tty->TS_set_window || tty->TS_set_scroll_region || tty->TS_set_scroll_region_1)); - char_ins_del_ok = ((TS_ins_char || TS_insert_mode - || TS_pad_inserted_char || TS_ins_multi_chars) - && (TS_del_char || TS_del_multi_chars)); + display->line_ins_del_ok + = (((tty->TS_ins_line || tty->TS_ins_multi_lines) + && (tty->TS_del_line || tty->TS_del_multi_lines)) + || (display->scroll_region_ok + && tty->TS_fwd_scroll && tty->TS_rev_scroll)); - fast_clear_end_of_line = TS_clr_line != 0; + display->char_ins_del_ok + = ((tty->TS_ins_char || tty->TS_insert_mode + || tty->TS_pad_inserted_char || tty->TS_ins_multi_chars) + && (tty->TS_del_char || tty->TS_del_multi_chars)); - init_baud_rate (); - if (read_socket_hook) /* Baudrate is somewhat */ - /* meaningless in this case */ - baud_rate = 9600; + display->fast_clear_end_of_line = tty->TS_clr_line != 0; - FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0; - FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none; -#endif /* WINDOWSNT */ + init_baud_rate (fileno (tty->input)); + +#ifdef AIXHFT + /* The HFT system on AIX doesn't optimize for scrolling, so it's + really ugly at times. */ + display->line_ins_del_ok = 0; + display->char_ins_del_ok = 0; +#endif + +#ifdef MULTI_KBOARD + tty->kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); + init_kboard (tty->kboard); + tty->kboard->next_kboard = all_kboards; + all_kboards = tty->kboard; + /* Don't let the initial kboard remain current longer than necessary. + That would cause problems if a file loaded on startup tries to + prompt in the mini-buffer. */ + if (current_kboard == initial_kboard) + current_kboard = tty->kboard; + tty->kboard->reference_count++; +#endif + + /* Don't do this. I think termcap may still need the buffer. */ + /* xfree (buffer); */ + + /* Init system terminal modes (RAW or CBREAK, etc.). */ + init_sys_modes (tty); + + return display; +#endif /* not WINDOWSNT */ +} + +/* Auxiliary error-handling function for term_init. + Free BUFFER and delete DISPLAY, then call error or fatal + with str1 or str2, respectively, according to MUST_SUCCEED. */ - xfree (buffer); +static void +maybe_fatal (must_succeed, buffer, display, str1, str2, arg1, arg2) + int must_succeed; + char *buffer; + struct display *display; + char *str1, *str2, *arg1, *arg2; +{ + if (buffer) + xfree (buffer); + + if (display) + delete_tty (display); + + if (must_succeed) + fatal (str2, arg1, arg2); + else + error (str1, arg1, arg2); + + abort (); } /* VARARGS 1 */ @@ -2581,6 +2839,380 @@ fatal (str, arg1, arg2) exit (1); } + + +DEFUN ("delete-tty", Fdelete_tty, Sdelete_tty, 0, 1, 0, + doc: /* Delete all frames on the terminal named TTY, and close the device. +If omitted, TTY defaults to the controlling terminal. + +This function runs `delete-tty-after-functions' after closing the +tty. The functions are run with one arg, the frame to be deleted. */) + (tty) + Lisp_Object tty; +{ + struct display *d; + char *name = 0; + + CHECK_STRING (tty); + + if (SBYTES (tty) > 0) + { + name = (char *) alloca (SBYTES (tty) + 1); + strncpy (name, SDATA (tty), SBYTES (tty)); + name[SBYTES (tty)] = 0; + } + + d = get_named_tty_display (name); + + if (! d) + error ("No such terminal device: %s", name); + + delete_tty (d); + + return Qnil; +} + +static int deleting_tty = 0; + + +/* Delete the given terminal device, closing all frames on it. */ + +void +delete_tty (struct display *display) +{ + struct tty_display_info *tty; + Lisp_Object tail, frame; + char *tty_name; + int last_display; + + if (deleting_tty) + /* We get a recursive call when we delete the last frame on this + display. */ + return; + + if (display->type != output_termcap) + abort (); + + tty = display->display_info.tty; + + last_display = 1; + FOR_EACH_FRAME (tail, frame) + { + struct frame *f = XFRAME (frame); + if (FRAME_LIVE_P (f) && (!FRAME_TERMCAP_P (f) || FRAME_TTY (f) != tty)) + { + last_display = 0; + break; + } + } + if (last_display) + error ("Attempt to delete the sole display with live frames"); + + if (tty == tty_list) + tty_list = tty->next; + else + { + struct tty_display_info *p; + for (p = tty_list; p && p->next != tty; p = p->next) + ; + + if (! p) + /* This should not happen. */ + abort (); + + p->next = tty->next; + tty->next = 0; + } + + deleting_tty = 1; + + FOR_EACH_FRAME (tail, frame) + { + struct frame *f = XFRAME (frame); + if (FRAME_TERMCAP_P (f) && FRAME_LIVE_P (f) && FRAME_TTY (f) == tty) + { + Fdelete_frame (frame, Qt); + } + } + + /* reset_sys_modes needs a valid display, so this call needs to be + before delete_display. */ + reset_sys_modes (tty); + + delete_display (display); + + tty_name = tty->name; + if (tty->type) + xfree (tty->type); + + if (tty->input) + { + delete_keyboard_wait_descriptor (fileno (tty->input)); + if (tty->input != stdin) + fclose (tty->input); + } + if (tty->output && tty->output != stdout && tty->output != tty->input) + fclose (tty->output); + if (tty->termscript) + fclose (tty->termscript); + + if (tty->old_tty) + xfree (tty->old_tty); + + if (tty->Wcm) + xfree (tty->Wcm); + +#ifdef MULTI_KBOARD + if (tty->kboard && --tty->kboard->reference_count > 0) + abort (); + if (tty->kboard) + delete_kboard (tty->kboard); +#endif + + bzero (tty, sizeof (struct tty_display_info)); + xfree (tty); + deleting_tty = 0; + + /* Run `delete-tty-after-functions'. */ + if (!NILP (Vrun_hooks)) + { + Lisp_Object args[2]; + args[0] = intern ("delete-tty-after-functions"); + if (tty_name) + { + args[1] = build_string (tty_name); + xfree (tty_name); + } + else + args[1] = Qnil; + Frun_hook_with_args (2, args); + } +} + + + +/* Initialize the tty-dependent part of frame F. The frame must + already have its display initialized. */ + +void +create_tty_output (struct frame *f) +{ + struct tty_output *t; + + if (! FRAME_TERMCAP_P (f)) + abort (); + + t = xmalloc (sizeof (struct tty_output)); + bzero (t, sizeof (struct tty_output)); + + t->display_info = FRAME_DISPLAY (f)->display_info.tty; + + f->output_data.tty = t; +} + +/* Delete the tty-dependent part of frame F. */ + +void +delete_tty_output (struct frame *f) +{ + if (! FRAME_TERMCAP_P (f)) + abort (); + + xfree (f->output_data.tty); +} + + + + +/* Mark the pointers in the tty_display_info objects. + Called by the Fgarbage_collector. */ + +void +mark_ttys () +{ + struct tty_display_info *tty; + + for (tty = tty_list; tty; tty = tty->next) + { + if (tty->top_frame) + mark_object (tty->top_frame); + } +} + + + +/* Create a new display object and add it to the display list. */ + +struct display * +create_display (void) +{ + struct display *dev = (struct display *) xmalloc (sizeof (struct display)); + + bzero (dev, sizeof (struct display)); + dev->next_display = display_list; + display_list = dev; + + return dev; +} + +/* Remove a display from the display list and free its memory. */ + +void +delete_display (struct display *dev) +{ + struct display **dp; + Lisp_Object tail, frame; + + /* Check for and close live frames that are still on this + display. */ + FOR_EACH_FRAME (tail, frame) + { + struct frame *f = XFRAME (frame); + if (FRAME_LIVE_P (f) && f->display == dev) + { + Fdelete_frame (frame, Qt); + } + } + + for (dp = &display_list; *dp != dev; dp = &(*dp)->next_display) + if (! *dp) + abort (); + *dp = dev->next_display; + + bzero (dev, sizeof (struct display)); + xfree (dev); +} + + + +DEFUN ("suspend-tty", Fsuspend_tty, Ssuspend_tty, 0, 1, 0, + doc: /* Suspend the terminal device TTY. +The terminal is restored to its default state, and Emacs closes all +access to the terminal device. Frames that use the device are not +deleted, but input is not read from them and if they change, their +display is not updated. + +TTY may a string (a device name), a frame, or nil for the display +device of the currently selected frame. + +This function runs `suspend-tty-functions' after suspending the +device. The functions are run with one arg, the name of the terminal +device. + +`suspend-tty' does nothing if it is called on an already suspended +device. + +A suspended terminal device may be resumed by calling `resume-tty' on +it. */) + (tty) + Lisp_Object tty; +{ + struct display *d = get_tty_display (tty); + FILE *f; + + if (!d) + error ("Unknown tty device"); + + f = d->display_info.tty->input; + + if (f) + { + reset_sys_modes (d->display_info.tty); + + delete_keyboard_wait_descriptor (fileno (f)); + + fclose (f); + if (f != d->display_info.tty->output) + fclose (d->display_info.tty->output); + + d->display_info.tty->input = 0; + d->display_info.tty->output = 0; + + if (FRAMEP (d->display_info.tty->top_frame)) + FRAME_SET_VISIBLE (XFRAME (d->display_info.tty->top_frame), 0); + + /* Run `suspend-tty-functions'. */ + if (!NILP (Vrun_hooks)) + { + Lisp_Object args[2]; + args[0] = intern ("suspend-tty-functions"); + if (d->display_info.tty->name) + { + args[1] = build_string (d->display_info.tty->name); + } + else + args[1] = Qnil; + Frun_hook_with_args (2, args); + } + } + + return Qnil; +} + + +DEFUN ("resume-tty", Fresume_tty, Sresume_tty, 0, 1, 0, + doc: /* Resume the previously suspended terminal device TTY. +The terminal is opened and reinitialized. Frames that used the +suspended device are revived. + +This function runs `resume-tty-functions' after resuming the device. +The functions are run with one arg, the name of the terminal device. + +`resume-tty' does nothing if it is called on a device that is not +suspended. + +TTY may a string (a device name), a frame, or nil for the display +device of the currently selected frame. */) + (tty) + Lisp_Object tty; +{ + struct display *d = get_tty_display (tty); + int fd; + + if (!d) + error ("Unknown tty device"); + + if (!d->display_info.tty->input) + { + fd = emacs_open (d->display_info.tty->name, O_RDWR | O_NOCTTY, 0); + +#ifdef TIOCNOTTY + /* Drop our controlling tty if it is the same device. */ + if (ioctl (fd, TIOCNOTTY, 0) != -1) + { + no_controlling_tty = 1; + } +#endif + + d->display_info.tty->output = fdopen (fd, "w+"); + d->display_info.tty->input = d->display_info.tty->output; + + add_keyboard_wait_descriptor (fd); + + if (FRAMEP (d->display_info.tty->top_frame)) + FRAME_SET_VISIBLE (XFRAME (d->display_info.tty->top_frame), 1); + + init_sys_modes (d->display_info.tty); + + /* Run `suspend-tty-functions'. */ + if (!NILP (Vrun_hooks)) + { + Lisp_Object args[2]; + args[0] = intern ("resume-tty-functions"); + if (d->display_info.tty->name) + { + args[1] = build_string (d->display_info.tty->name); + } + else + args[1] = Qnil; + Frun_hook_with_args (2, args); + } + } + + return Qnil; +} + + void syms_of_term () { @@ -2598,9 +3230,45 @@ This variable can be used by terminal emulator packages. */); The function should accept no arguments. */); Vring_bell_function = Qnil; + DEFVAR_LISP ("delete-tty-after-functions", &Vdelete_tty_after_functions, + doc: /* Functions to be run after deleting a tty. +The functions are run with one argument, the name of the tty to be deleted. +See `delete-tty'. */); + Vdelete_tty_after_functions = Qnil; + + + DEFVAR_LISP ("suspend-tty-functions", &Vsuspend_tty_functions, + doc: /* Functions to be run after suspending a tty. +The functions are run with one argument, the name of the tty to be suspended. +See `suspend-tty'. */); + Vsuspend_tty_functions = Qnil; + + + DEFVAR_LISP ("resume-tty-functions", &Vresume_tty_functions, + doc: /* Functions to be run after resuming a tty. +The functions are run with one argument, the name of the tty that was revived. +See `resume-tty'. */); + Vresume_tty_functions = Qnil; + + Qframe_tty_name = intern ("frame-tty-name"); + staticpro (&Qframe_tty_name); + + Qframe_tty_type = intern ("frame-tty-type"); + staticpro (&Qframe_tty_type); + defsubr (&Stty_display_color_p); defsubr (&Stty_display_color_cells); + defsubr (&Sframe_tty_name); + defsubr (&Sframe_tty_type); + defsubr (&Sdelete_tty); + defsubr (&Ssuspend_tty); + defsubr (&Sresume_tty); + + Fprovide (intern ("multi-tty"), Qnil); + } + + /* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193 (do not change this comment) */ diff --git a/src/termchar.h b/src/termchar.h index b1d941adc27..3053061c1b7 100644 --- a/src/termchar.h +++ b/src/termchar.h @@ -1,5 +1,5 @@ /* Flags and parameters describing terminal's characteristics. - Copyright (C) 1985, 1986 Free Software Foundation, Inc. + Copyright (C) 1985, 1986, 2003 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -18,32 +18,189 @@ along with GNU Emacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* Each termcap frame points to its own struct tty_output object in + the output_data.tty field. The tty_output structure contains the + information that is specific to termcap frames. */ -/* extern EMACS_INT baud_rate; */ /* Output speed in baud */ -extern int must_write_spaces; /* Nonzero means spaces in the text - must actually be output; can't just skip - over some columns to leave them blank. */ -extern int min_padding_speed; /* Speed below which no padding necessary */ -extern int fast_clear_end_of_line; /* Nonzero means terminal has - command for this */ - -extern int line_ins_del_ok; /* Terminal can insert and delete lines */ -extern int char_ins_del_ok; /* Terminal can insert and delete chars */ -extern int scroll_region_ok; /* Terminal supports setting the scroll - window */ -extern int scroll_region_cost; /* Cost of setting the scroll window, - measured in characters */ -extern int memory_below_frame; /* Terminal remembers lines scrolled - off bottom */ -extern int fast_clear_end_of_line; /* Terminal has a `ce' string */ - -extern int dont_calculate_costs; /* Nonzero means don't bother computing - various cost tables; we won't use them. */ - -/* Nonzero means no need to redraw the entire frame on resuming - a suspended Emacs. This is useful on terminals with multiple pages, - where one page is used for Emacs and another for all else. */ -extern int no_redraw_on_reenter; +struct tty_output +{ + /* The Emacs structure for the tty device this frame is on. */ + struct tty_display_info *display_info; + + /* There is nothing else here at the moment... */ +}; + +/* Parameters that are shared between frames on the same tty device. */ + +struct tty_display_info +{ + struct tty_display_info *next; /* Chain of all tty devices. */ + + char *name; /* The name of the device file or 0 if + stdin/stdout. */ + char *type; /* The type of the tty. */ + + /* Input/output */ + + FILE *input; /* The stream to be used for terminal input. + NULL if the terminal is suspended. */ + FILE *output; /* The stream to be used for terminal output. + NULL if the terminal is suspended. */ + + FILE *termscript; /* If nonzero, send all terminal output + characters to this stream also. */ + + struct emacs_tty *old_tty; /* The initial tty mode bits */ + + int term_initted; /* 1 if we have been through init_sys_modes. */ + + + int reference_count; /* Number of frames that are on this display. */ + + struct display *display; /* Points back to the generic display + structure. This is sometimes handy. */ + + /* Info on cursor positioning. */ + struct cm *Wcm; + + /* Redisplay. */ + + Lisp_Object top_frame; /* The topmost frame on this tty. */ + + /* The previous terminal frame we displayed on this tty. */ + struct frame *previous_terminal_frame; + + /* Strings, numbers and flags taken from the termcap entry. */ + + char *TS_ins_line; /* "al" */ + char *TS_ins_multi_lines; /* "AL" (one parameter, # lines to insert) */ + char *TS_bell; /* "bl" */ + char *TS_clr_to_bottom; /* "cd" */ + char *TS_clr_line; /* "ce", clear to end of line */ + char *TS_clr_frame; /* "cl" */ + char *TS_set_scroll_region; /* "cs" (2 params, first line and last line) */ + char *TS_set_scroll_region_1; /* "cS" (4 params: total lines, + lines above scroll region, lines below it, + total lines again) */ + char *TS_del_char; /* "dc" */ + char *TS_del_multi_chars; /* "DC" (one parameter, # chars to delete) */ + char *TS_del_line; /* "dl" */ + char *TS_del_multi_lines; /* "DL" (one parameter, # lines to delete) */ + char *TS_delete_mode; /* "dm", enter character-delete mode */ + char *TS_end_delete_mode; /* "ed", leave character-delete mode */ + char *TS_end_insert_mode; /* "ei", leave character-insert mode */ + char *TS_ins_char; /* "ic" */ + char *TS_ins_multi_chars; /* "IC" (one parameter, # chars to insert) */ + char *TS_insert_mode; /* "im", enter character-insert mode */ + char *TS_pad_inserted_char; /* "ip". Just padding, no commands. */ + char *TS_end_keypad_mode; /* "ke" */ + char *TS_keypad_mode; /* "ks" */ + char *TS_pad_char; /* "pc", char to use as padding */ + char *TS_repeat; /* "rp" (2 params, # times to repeat + and character to be repeated) */ + char *TS_end_standout_mode; /* "se" */ + char *TS_fwd_scroll; /* "sf" */ + char *TS_standout_mode; /* "so" */ + char *TS_rev_scroll; /* "sr" */ + char *TS_end_termcap_modes; /* "te" */ + char *TS_termcap_modes; /* "ti" */ + char *TS_visible_bell; /* "vb" */ + char *TS_cursor_normal; /* "ve" */ + char *TS_cursor_visible; /* "vs" */ + char *TS_cursor_invisible; /* "vi" */ + char *TS_set_window; /* "wi" (4 params, start and end of window, + each as vpos and hpos) */ + + char *TS_enter_bold_mode; /* "md" -- turn on bold (extra bright mode). */ + char *TS_enter_dim_mode; /* "mh" -- turn on half-bright mode. */ + char *TS_enter_blink_mode; /* "mb" -- enter blinking mode. */ + char *TS_enter_reverse_mode; /* "mr" -- enter reverse video mode. */ + char *TS_exit_underline_mode; /* "us" -- start underlining. */ + char *TS_enter_underline_mode; /* "ue" -- end underlining. */ + + /* "as"/"ae" -- start/end alternate character set. Not really + supported, yet. */ + char *TS_enter_alt_charset_mode; + char *TS_exit_alt_charset_mode; + + char *TS_exit_attribute_mode; /* "me" -- switch appearances off. */ + + /* Value of the "NC" (no_color_video) capability, or 0 if not present. */ + int TN_no_color_video; + + int TN_max_colors; /* "Co" -- number of colors. */ + + /* "pa" -- max. number of color pairs on screen. Not handled yet. + Could be a problem if not equal to TN_max_colors * TN_max_colors. */ + int TN_max_pairs; + + /* "op" -- SVr4 set default pair to its original value. */ + char *TS_orig_pair; + + /* "AF"/"AB" or "Sf"/"Sb"-- set ANSI or SVr4 foreground/background color. + 1 param, the color index. */ + char *TS_set_foreground; + char *TS_set_background; + + int TF_hazeltine; /* termcap hz flag. */ + int TF_insmode_motion; /* termcap mi flag: can move while in insert mode. */ + int TF_standout_motion; /* termcap mi flag: can move while in standout mode. */ + int TF_underscore; /* termcap ul flag: _ underlines if over-struck on + non-blank position. Must clear before writing _. */ + int TF_teleray; /* termcap xt flag: many weird consequences. + For t1061. */ + + int RPov; /* # chars to start a TS_repeat */ + + int delete_in_insert_mode; /* delete mode == insert mode */ + + int se_is_so; /* 1 if same string both enters and leaves + standout mode */ + + int costs_set; /* Nonzero if costs have been calculated. */ + + int insert_mode; /* Nonzero when in insert mode. */ + int standout_mode; /* Nonzero when in standout mode. */ + + + + /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should + keep 0200 bit in input chars. 0 to ignore the 0200 bit. */ + + int meta_key; + + /* Size of window specified by higher levels. + This is the number of lines, from the top of frame downwards, + which can participate in insert-line/delete-line operations. + + Effectively it excludes the bottom frame_lines - specified_window_size + lines from those operations. */ + + int specified_window; + + /* Flag used in tty_show/hide_cursor. */ + + int cursor_hidden; + + /* Nonzero means use ^S/^Q for flow control. */ + int flow_control; + +#ifdef MULTI_KBOARD + /* The terminal's keyboard object. */ + struct kboard *kboard; +#endif +}; + +/* A chain of structures for all tty devices currently in use. */ +extern struct tty_display_info *tty_list; + + +#define FRAME_TTY(f) \ + ((f)->output_method == output_termcap \ + ? (f)->display->display_info.tty \ + : (abort(), (struct tty_display_info *) 0)) + +#define CURTTY() FRAME_TTY (SELECTED_FRAME()) /* arch-tag: bf9f0d49-842b-42fb-9348-ec8759b27193 (do not change this comment) */ diff --git a/src/termhooks.h b/src/termhooks.h index 83721f65912..49a0cbac85b 100644 --- a/src/termhooks.h +++ b/src/termhooks.h @@ -1,5 +1,4 @@ -/* Hooks by which low level terminal operations - can be made to call other routines. +/* Parameters and display hooks for output devices Copyright (C) 1985,86,93,94,2003 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -25,40 +24,11 @@ Boston, MA 02111-1307, USA. */ struct glyph; struct frame; -/* If nonzero, send all terminal output characters to this stream also. */ -extern FILE *termscript; - /* Only use prototypes when lisp.h has been included. */ #ifndef P_ #define P_(X) () #endif -/* Text display hooks. */ - -extern void (*cursor_to_hook) P_ ((int vpos, int hpos)); -extern void (*raw_cursor_to_hook) P_ ((int, int)); - -extern void (*clear_to_end_hook) P_ ((void)); -extern void (*clear_frame_hook) P_ ((void)); -extern void (*clear_end_of_line_hook) P_ ((int)); - -extern void (*ins_del_lines_hook) P_ ((int, int)); - -extern void (*insert_glyphs_hook) P_ ((struct glyph *s, int n)); -extern void (*write_glyphs_hook) P_ ((struct glyph *s, int n)); -extern void (*delete_glyphs_hook) P_ ((int)); - -extern void (*ring_bell_hook) P_ ((void)); - -extern void (*reset_terminal_modes_hook) P_ ((void)); -extern void (*set_terminal_modes_hook) P_ ((void)); -extern void (*update_begin_hook) P_ ((struct frame *)); -extern void (*update_end_hook) P_ ((struct frame *)); -extern void (*set_terminal_window_hook) P_ ((int)); - - - -/* Multi-frame and mouse support hooks. */ enum scroll_bar_part { scroll_bar_above_handle, @@ -72,125 +42,6 @@ enum scroll_bar_part { scroll_bar_move_ratio }; -/* Return the current position of the mouse. - - Set *f to the frame the mouse is in, or zero if the mouse is in no - Emacs frame. If it is set to zero, all the other arguments are - garbage. - - If the motion started in a scroll bar, set *bar_window to the - scroll bar's window, *part to the part the mouse is currently over, - *x to the position of the mouse along the scroll bar, and *y to the - overall length of the scroll bar. - - Otherwise, set *bar_window to Qnil, and *x and *y to the column and - row of the character cell the mouse is over. - - Set *time to the time the mouse was at the returned position. - - This should clear mouse_moved until the next motion - event arrives. */ -extern void (*mouse_position_hook) P_ ((struct frame **f, int, - Lisp_Object *bar_window, - enum scroll_bar_part *part, - Lisp_Object *x, - Lisp_Object *y, - unsigned long *time)); - -/* The window system handling code should set this if the mouse has - moved since the last call to the mouse_position_hook. Calling that - hook should clear this. */ -extern int mouse_moved; - -/* When a frame's focus redirection is changed, this hook tells the - window system code to re-decide where to put the highlight. Under - X, this means that Emacs lies about where the focus is. */ -extern void (*frame_rehighlight_hook) P_ ((struct frame *)); - -/* If we're displaying frames using a window system that can stack - frames on top of each other, this hook allows you to bring a frame - to the front, or bury it behind all the other windows. If this - hook is zero, that means the device we're displaying on doesn't - support overlapping frames, so there's no need to raise or lower - anything. - - If RAISE is non-zero, F is brought to the front, before all other - windows. If RAISE is zero, F is sent to the back, behind all other - windows. */ -extern void (*frame_raise_lower_hook) P_ ((struct frame *f, int raise)); - - -/* Scroll bar hooks. */ - -/* The representation of scroll bars is determined by the code which - implements them, except for one thing: they must be represented by - lisp objects. This allows us to place references to them in - Lisp_Windows without worrying about those references becoming - dangling references when the scroll bar is destroyed. - - The window-system-independent portion of Emacs just refers to - scroll bars via their windows, and never looks inside the scroll bar - representation; it always uses hook functions to do all the - scroll bar manipulation it needs. - - The `vertical_scroll_bar' field of a Lisp_Window refers to that - window's scroll bar, or is nil if the window doesn't have a - scroll bar. - - The `scroll_bars' and `condemned_scroll_bars' fields of a Lisp_Frame - are free for use by the scroll bar implementation in any way it sees - fit. They are marked by the garbage collector. */ - - -/* Set the vertical scroll bar for WINDOW to have its upper left corner - at (TOP, LEFT), and be LENGTH rows high. Set its handle to - indicate that we are displaying PORTION characters out of a total - of WHOLE characters, starting at POSITION. If WINDOW doesn't yet - have a scroll bar, create one for it. */ -extern void (*set_vertical_scroll_bar_hook) - P_ ((struct window *window, - int portion, int whole, int position)); - - -/* The following three hooks are used when we're doing a thorough - redisplay of the frame. We don't explicitly know which scroll bars - are going to be deleted, because keeping track of when windows go - away is a real pain - can you say set-window-configuration? - Instead, we just assert at the beginning of redisplay that *all* - scroll bars are to be removed, and then save scroll bars from the - fiery pit when we actually redisplay their window. */ - -/* Arrange for all scroll bars on FRAME to be removed at the next call - to `*judge_scroll_bars_hook'. A scroll bar may be spared if - `*redeem_scroll_bar_hook' is applied to its window before the judgement. - - This should be applied to each frame each time its window tree is - redisplayed, even if it is not displaying scroll bars at the moment; - if the HAS_SCROLL_BARS flag has just been turned off, only calling - this and the judge_scroll_bars_hook will get rid of them. - - If non-zero, this hook should be safe to apply to any frame, - whether or not it can support scroll bars, and whether or not it is - currently displaying them. */ -extern void (*condemn_scroll_bars_hook) P_ ((struct frame *frame)); - -/* Unmark WINDOW's scroll bar for deletion in this judgement cycle. - Note that it's okay to redeem a scroll bar that is not condemned. */ -extern void (*redeem_scroll_bar_hook) P_ ((struct window *window)); - -/* Remove all scroll bars on FRAME that haven't been saved since the - last call to `*condemn_scroll_bars_hook'. - - This should be applied to each frame after each time its window - tree is redisplayed, even if it is not displaying scroll bars at the - moment; if the HAS_SCROLL_BARS flag has just been turned off, only - calling this and condemn_scroll_bars_hook will get rid of them. - - If non-zero, this hook should be safe to apply to any frame, - whether or not it can support scroll bars, and whether or not it is - currently displaying them. */ -extern void (*judge_scroll_bars_hook) P_ ((struct frame *FRAME)); - /* Input queue declarations and hooks. */ @@ -373,13 +224,6 @@ struct input_event #define EVENT_INIT(event) bzero (&(event), sizeof (struct input_event)) -/* Called to read input events. */ -extern int (*read_socket_hook) P_ ((int, int, struct input_event *)); - -/* Called when a frame's display becomes entirely up to date. */ -extern void (*frame_up_to_date_hook) P_ ((struct frame *)); - - /* Bits in the modifiers member of the input_event structure. Note that reorder_modifiers assumes that the bits are in canonical order. @@ -429,7 +273,287 @@ enum { meta_modifier = CHAR_META /* Under X, the XK_Meta_[LR] keysyms. */ }; +#endif /* CONSP */ + + +/* Display-local parameters. */ +struct display +{ + /* Chain of all displays. */ + struct display *next_display; + + /* The number of frames that are on this display. */ + int reference_count; + + /* The type of the display. */ + enum output_method type; + + /* Display-type dependent data shared amongst all frames on this display. */ + union display_info + { + struct tty_display_info *tty; /* termchar.h */ + struct x_display_info *x; /* xterm.h */ + } display_info; + + + /* Terminal characteristics. */ + /* XXX Are these really used on non-termcap displays? */ + + int must_write_spaces; /* Nonzero means spaces in the text must + actually be output; can't just skip over + some columns to leave them blank. */ + int fast_clear_end_of_line; /* Nonzero means terminal has a `ce' string */ + + int line_ins_del_ok; /* Terminal can insert and delete lines */ + int char_ins_del_ok; /* Terminal can insert and delete chars */ + int scroll_region_ok; /* Terminal supports setting the scroll + window */ + int scroll_region_cost; /* Cost of setting the scroll window, + measured in characters. */ + int memory_below_frame; /* Terminal remembers lines scrolled + off bottom */ + +#if 0 /* These are not used anywhere. */ + /* EMACS_INT baud_rate; */ /* Output speed in baud */ + int min_padding_speed; /* Speed below which no padding necessary. */ + int dont_calculate_costs; /* Nonzero means don't bother computing + various cost tables; we won't use them. */ #endif + + /* Window-based redisplay interface for this device (0 for tty + devices). */ + struct redisplay_interface *rif; + + /* Frame-based redisplay interface. */ + + /* Text display hooks. */ + + void (*cursor_to_hook) P_ ((int vpos, int hpos)); + void (*raw_cursor_to_hook) P_ ((int, int)); + + void (*clear_to_end_hook) P_ ((void)); + void (*clear_frame_hook) P_ ((void)); + void (*clear_end_of_line_hook) P_ ((int)); + + void (*ins_del_lines_hook) P_ ((int, int)); + + void (*insert_glyphs_hook) P_ ((struct glyph *s, int n)); + void (*write_glyphs_hook) P_ ((struct glyph *s, int n)); + void (*delete_glyphs_hook) P_ ((int)); + + void (*ring_bell_hook) P_ ((void)); + + void (*reset_terminal_modes_hook) P_ ((struct display *)); + void (*set_terminal_modes_hook) P_ ((struct display *)); + void (*update_begin_hook) P_ ((struct frame *)); + void (*update_end_hook) P_ ((struct frame *)); + void (*set_terminal_window_hook) P_ ((int)); + + /* Multi-frame and mouse support hooks. */ + + /* Return the current position of the mouse. + + Set *f to the frame the mouse is in, or zero if the mouse is in no + Emacs frame. If it is set to zero, all the other arguments are + garbage. + + If the motion started in a scroll bar, set *bar_window to the + scroll bar's window, *part to the part the mouse is currently over, + *x to the position of the mouse along the scroll bar, and *y to the + overall length of the scroll bar. + + Otherwise, set *bar_window to Qnil, and *x and *y to the column and + row of the character cell the mouse is over. + + Set *time to the time the mouse was at the returned position. + + This should clear mouse_moved until the next motion + event arrives. */ + void (*mouse_position_hook) P_ ((struct frame **f, int, + Lisp_Object *bar_window, + enum scroll_bar_part *part, + Lisp_Object *x, + Lisp_Object *y, + unsigned long *time)); + + /* The window system handling code should set this if the mouse has + moved since the last call to the mouse_position_hook. Calling that + hook should clear this. */ + int mouse_moved; + + /* When a frame's focus redirection is changed, this hook tells the + window system code to re-decide where to put the highlight. Under + X, this means that Emacs lies about where the focus is. */ + void (*frame_rehighlight_hook) P_ ((struct frame *)); + + /* If we're displaying frames using a window system that can stack + frames on top of each other, this hook allows you to bring a frame + to the front, or bury it behind all the other windows. If this + hook is zero, that means the device we're displaying on doesn't + support overlapping frames, so there's no need to raise or lower + anything. + + If RAISE is non-zero, F is brought to the front, before all other + windows. If RAISE is zero, F is sent to the back, behind all other + windows. */ + void (*frame_raise_lower_hook) P_ ((struct frame *f, int raise)); + + + /* Scroll bar hooks. */ + + /* The representation of scroll bars is determined by the code which + implements them, except for one thing: they must be represented by + lisp objects. This allows us to place references to them in + Lisp_Windows without worrying about those references becoming + dangling references when the scroll bar is destroyed. + + The window-system-independent portion of Emacs just refers to + scroll bars via their windows, and never looks inside the scroll bar + representation; it always uses hook functions to do all the + scroll bar manipulation it needs. + + The `vertical_scroll_bar' field of a Lisp_Window refers to that + window's scroll bar, or is nil if the window doesn't have a + scroll bar. + + The `scroll_bars' and `condemned_scroll_bars' fields of a Lisp_Frame + are free for use by the scroll bar implementation in any way it sees + fit. They are marked by the garbage collector. */ + + + /* Set the vertical scroll bar for WINDOW to have its upper left corner + at (TOP, LEFT), and be LENGTH rows high. Set its handle to + indicate that we are displaying PORTION characters out of a total + of WHOLE characters, starting at POSITION. If WINDOW doesn't yet + have a scroll bar, create one for it. */ + void (*set_vertical_scroll_bar_hook) P_ ((struct window *window, + int portion, int whole, + int position)); + + + /* The following three hooks are used when we're doing a thorough + redisplay of the frame. We don't explicitly know which scroll bars + are going to be deleted, because keeping track of when windows go + away is a real pain - can you say set-window-configuration? + Instead, we just assert at the beginning of redisplay that *all* + scroll bars are to be removed, and then save scroll bars from the + fiery pit when we actually redisplay their window. */ + + /* Arrange for all scroll bars on FRAME to be removed at the next call + to `*judge_scroll_bars_hook'. A scroll bar may be spared if + `*redeem_scroll_bar_hook' is applied to its window before the judgement. + + This should be applied to each frame each time its window tree is + redisplayed, even if it is not displaying scroll bars at the moment; + if the HAS_SCROLL_BARS flag has just been turned off, only calling + this and the judge_scroll_bars_hook will get rid of them. + + If non-zero, this hook should be safe to apply to any frame, + whether or not it can support scroll bars, and whether or not it is + currently displaying them. */ + void (*condemn_scroll_bars_hook) P_ ((struct frame *frame)); + + /* Unmark WINDOW's scroll bar for deletion in this judgement cycle. + Note that it's okay to redeem a scroll bar that is not condemned. */ + void (*redeem_scroll_bar_hook) P_ ((struct window *window)); + + /* Remove all scroll bars on FRAME that haven't been saved since the + last call to `*condemn_scroll_bars_hook'. + + This should be applied to each frame after each time its window + tree is redisplayed, even if it is not displaying scroll bars at the + moment; if the HAS_SCROLL_BARS flag has just been turned off, only + calling this and condemn_scroll_bars_hook will get rid of them. + + If non-zero, this hook should be safe to apply to any frame, + whether or not it can support scroll bars, and whether or not it is + currently displaying them. */ + void (*judge_scroll_bars_hook) P_ ((struct frame *FRAME)); + + + /* Called to read input events. + + DISPLAY indicates which display to read from. Input events + should be read into BUF, the size of which is given in SIZE. + EXPECTED is non-zero if the caller suspects that new input is + available. + + A positive return value indicates that that many input events + where read into BUF. + Zero means no events were immediately available. + A value of -1 means a transient read error, while -2 indicates + that the display was closed (hangup), and it should be deleted. + + XXX Please note that a non-zero value of EXPECTED only means that + there is available input on at least one of the currently opened + display devices -- but not necessarily on this device. + Therefore, in most cases EXPECTED should be simply ignored. + + XXX This documentation needs to be updated. */ + int (*read_socket_hook) P_ ((struct display *display, + int expected, + struct input_event *hold_quit)); + + /* Called when a frame's display becomes entirely up to date. */ + void (*frame_up_to_date_hook) P_ ((struct frame *)); + + + /* Called to delete the device-specific portions of a frame that is + on this display. */ + void (*delete_frame_hook) P_ ((struct frame *)); + + /* Called after the last frame on this display is deleted, or when + the display device was closed (hangup). + + If this is NULL, then the generic delete_display() is called + instead. + + The hook must check for and close any live frames that are still + on the display. Fdelete_frame ensures that there are no live + frames on the display when it calls this hook, so infinite + recursion is prevented. */ + void (*delete_display_hook) P_ ((struct display *)); +}; + + +/* Chain of all displays currently in use. */ +extern struct display *display_list; + +#define FRAME_MUST_WRITE_SPACES(f) ((f)->display->must_write_spaces) +#define FRAME_FAST_CLEAR_END_OF_LINE(f) ((f)->display->fast_clear_end_of_line) +#define FRAME_LINE_INS_DEL_OK(f) ((f)->display->line_ins_del_ok) +#define FRAME_CHAR_INS_DEL_OK(f) ((f)->display->char_ins_del_ok) +#define FRAME_SCROLL_REGION_OK(f) ((f)->display->scroll_region_ok) +#define FRAME_SCROLL_REGION_COST(f) ((f)->display->scroll_region_cost) +#define FRAME_MEMORY_BELOW_FRAME(f) ((f)->display->memory_below_frame) + +#define FRAME_RIF(f) ((f)->display->rif) + +#define FRAME_DISPLAY(f) ((f)->display) + +/* FRAME_WINDOW_P tests whether the frame is a window, and is + defined to be the predicate for the window system being used. */ + +#ifdef HAVE_X_WINDOWS +#define FRAME_WINDOW_P(f) FRAME_X_P (f) +#endif +#ifdef HAVE_NTGUI +#define FRAME_WINDOW_P(f) FRAME_W32_P (f) +#endif +#ifdef MAC_OS +#define FRAME_WINDOW_P(f) FRAME_MAC_P (f) +#endif +#ifndef FRAME_WINDOW_P +#define FRAME_WINDOW_P(f) (0) +#endif + + +extern struct display *create_display P_ ((void)); +extern void delete_display P_ ((struct display *)); + +/* The initial display device, created by initial_term_init. */ +extern struct display *initial_display; + /* arch-tag: 33a00ecc-52b5-4186-a410-8801ac9f087d (do not change this comment) */ diff --git a/src/termopts.h b/src/termopts.h index 2dc798ea2c4..10f0083a667 100644 --- a/src/termopts.h +++ b/src/termopts.h @@ -40,5 +40,10 @@ extern int meta_key; /* Nonzero means truncate lines in all windows less wide than the frame */ extern int truncate_partial_width_windows; +/* Nonzero means no need to redraw the entire frame on resuming a suspended + Emacs. This is useful on terminals with multiple pages, where one page is + used for Emacs and another for all else. */ +extern int no_redraw_on_reenter; + /* arch-tag: 35d4d284-dc1a-4fff-97fa-0154a21aebdb (do not change this comment) */ diff --git a/src/w32term.c b/src/w32term.c index b9077a1e0b6..c59dabc27b0 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -6340,12 +6340,13 @@ w32_initialize () redeem_scroll_bar_hook = w32_redeem_scroll_bar; judge_scroll_bars_hook = w32_judge_scroll_bars; - scroll_region_ok = 1; /* we'll scroll partial frames */ - char_ins_del_ok = 1; - line_ins_del_ok = 1; /* we'll just blt 'em */ - fast_clear_end_of_line = 1; /* X does this well */ - memory_below_frame = 0; /* we don't remember what scrolls - off the bottom */ + TTY_SCROLL_REGION_OK (CURTTY ()) = 1; /* we'll scroll partial frames */ + TTY_CHAR_INS_DEL_OK (CURTTY ()) = 1; + TTY_LINE_INS_DEL_OK (CURTTY ()) = 1; /* we'll just blt 'em */ + TTY_FAST_CLEAR_END_OF_LINE (CURTTY ()) = 1; /* X does this well */ + TTY_MEMORY_BELOW_FRAME (CURTTY ()) = 0; /* we don't remember what + scrolls off the + bottom */ baud_rate = 19200; w32_system_caret_hwnd = NULL; diff --git a/src/w32term.h b/src/w32term.h index de28620c7b9..68967ad7d24 100644 --- a/src/w32term.h +++ b/src/w32term.h @@ -389,8 +389,6 @@ extern struct w32_output w32term_display; #define FRAME_W32_WINDOW(f) ((f)->output_data.w32->window_desc) #define FRAME_X_WINDOW(f) ((f)->output_data.w32->window_desc) -#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel) -#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel) #define FRAME_FONT(f) ((f)->output_data.w32->font) #define FRAME_FONTSET(f) ((f)->output_data.w32->fontset) #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.w32->baseline_offset) diff --git a/src/window.c b/src/window.c index 3294e5cbd05..7419239752a 100644 --- a/src/window.c +++ b/src/window.c @@ -21,6 +21,8 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <config.h> +#include <stdio.h> + #include "lisp.h" #include "buffer.h" #include "keyboard.h" @@ -6400,7 +6402,7 @@ and scrolling positions. */) void init_window_once () { - struct frame *f = make_terminal_frame (); + struct frame *f = make_initial_frame (); XSETFRAME (selected_frame, f); Vterminal_frame = selected_frame; minibuf_window = f->minibuffer_window; diff --git a/src/window.h b/src/window.h index 0a4bdb6e891..f45ca39bb93 100644 --- a/src/window.h +++ b/src/window.h @@ -744,7 +744,7 @@ extern Lisp_Object Vminibuf_scroll_window; /* Nil or a symbol naming the window system under which emacs is running ('x is the only current possibility) */ -extern Lisp_Object Vwindow_system; +extern Lisp_Object Vinitial_window_system; /* Version number of X windows: 10, 11 or nil. */ diff --git a/src/xdisp.c b/src/xdisp.c index a1bd50001c4..67f21446320 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -756,10 +756,6 @@ enum move_it_result #define CLEAR_FACE_CACHE_COUNT 500 static int clear_face_cache_count; -/* Record the previous terminal frame we displayed. */ - -static struct frame *previous_terminal_frame; - /* Non-zero while redisplay_internal is in progress. */ int redisplaying_p; @@ -2031,7 +2027,7 @@ init_iterator (it, w, charpos, bytepos, row, base_face_id) XSETWINDOW (it->window, w); it->w = w; it->f = XFRAME (w->frame); - + /* Extra space between lines (on window systems only). */ if (base_face_id == DEFAULT_FACE_ID && FRAME_WINDOW_P (it->f)) @@ -2044,9 +2040,9 @@ init_iterator (it, w, charpos, bytepos, row, base_face_id) /* If realized faces have been removed, e.g. because of face attribute changes of named faces, recompute them. When running - in batch mode, the face cache of Vterminal_frame is null. If + in batch mode, the face cache of the initial frame is null. If we happen to get called, make a dummy face cache. */ - if (noninteractive && FRAME_FACE_CACHE (it->f) == NULL) + if (FRAME_FACE_CACHE (it->f) == NULL) init_frame_faces (it->f); if (FRAME_FACE_CACHE (it->f)->used == 0) recompute_basic_faces (it->f); @@ -6573,8 +6569,8 @@ message2_nolog (m, nbytes, multibyte) do_pending_window_change (0); echo_area_display (1); do_pending_window_change (0); - if (frame_up_to_date_hook != 0 && ! gc_in_progress) - (*frame_up_to_date_hook) (f); + if (FRAME_DISPLAY (f)->frame_up_to_date_hook != 0 && ! gc_in_progress) + (*FRAME_DISPLAY (f)->frame_up_to_date_hook) (f); } } @@ -6659,8 +6655,8 @@ message3_nolog (m, nbytes, multibyte) do_pending_window_change (0); echo_area_display (1); do_pending_window_change (0); - if (frame_up_to_date_hook != 0 && ! gc_in_progress) - (*frame_up_to_date_hook) (f); + if (FRAME_DISPLAY (f)->frame_up_to_date_hook != 0 && ! gc_in_progress) + (*FRAME_DISPLAY (f)->frame_up_to_date_hook) (f); } } @@ -7683,11 +7679,11 @@ clear_garbaged_frames () { Lisp_Object tail, frame; int changed_count = 0; - + FOR_EACH_FRAME (tail, frame) { struct frame *f = XFRAME (frame); - + if (FRAME_VISIBLE_P (f) && FRAME_GARBAGED_P (f)) { if (f->resized_p) @@ -7701,7 +7697,7 @@ clear_garbaged_frames () f->resized_p = 0; } } - + frame_garbaged = 0; if (changed_count) ++windows_or_buffers_changed; @@ -7734,11 +7730,11 @@ echo_area_display (update_frame_p) /* The terminal frame is used as the first Emacs frame on the Mac OS. */ #ifndef MAC_OS8 #ifdef HAVE_WINDOW_SYSTEM - /* When Emacs starts, selected_frame may be a visible terminal - frame, even if we run under a window system. If we let this - through, a message would be displayed on the terminal. */ - if (EQ (selected_frame, Vterminal_frame) - && !NILP (Vwindow_system)) + /* When Emacs starts, selected_frame may be the initial terminal + frame. If we let this through, a message would be displayed on + the terminal. */ + if (FRAME_TERMCAP_P (XFRAME (selected_frame)) + && FRAME_TTY (XFRAME (selected_frame))->type == NULL) return 0; #endif /* HAVE_WINDOW_SYSTEM */ #endif @@ -7789,7 +7785,7 @@ echo_area_display (update_frame_p) Can do with a display update of the echo area, unless we displayed some mode lines. */ update_single_window (w, 1); - rif->flush_display (f); + FRAME_RIF (f)->flush_display (f); } else update_frame (f, 1, 1); @@ -8250,8 +8246,8 @@ x_cursor_to (vpos, hpos, y, x) { BLOCK_INPUT; display_and_set_cursor (w, 1, hpos, vpos, x, y); - if (rif->flush_display_optional) - rif->flush_display_optional (SELECTED_FRAME ()); + if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional) + FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ()); UNBLOCK_INPUT; } } @@ -9409,7 +9405,7 @@ select_frame_for_redisplay (frame) { Lisp_Object tail, sym, val; Lisp_Object old = selected_frame; - + selected_frame = frame; for (tail = XFRAME (frame)->param_alist; CONSP (tail); tail = XCDR (tail)) @@ -9525,17 +9521,16 @@ redisplay_internal (preserve_echo_area) if (face_change_count) ++windows_or_buffers_changed; - if (! FRAME_WINDOW_P (sf) - && previous_terminal_frame != sf) + if (FRAME_TERMCAP_P (sf) + && FRAME_TTY (sf)->previous_terminal_frame != sf) { - /* Since frames on an ASCII terminal share the same display - area, displaying a different frame means redisplay the whole - thing. */ + /* Since frames on a single ASCII terminal share the same + display area, displaying a different frame means redisplay + the whole thing. */ windows_or_buffers_changed++; SET_FRAME_GARBAGED (sf); - XSETFRAME (Vterminal_frame, sf); + FRAME_TTY (sf)->previous_terminal_frame = sf; } - previous_terminal_frame = sf; /* Set the visible flags for all frames. Do this before checking for resized or garbaged frames; they want to know if their frames @@ -9557,6 +9552,7 @@ redisplay_internal (preserve_echo_area) } } + /* Notice any pending interrupt request to change frame size. */ do_pending_window_change (1); @@ -9917,7 +9913,7 @@ redisplay_internal (preserve_echo_area) { struct frame *f = XFRAME (frame); - if (FRAME_WINDOW_P (f) || f == sf) + if (FRAME_WINDOW_P (f) || FRAME_TERMCAP_P (f) || f == sf) { if (! EQ (frame, selected_frame)) /* Select the frame, for the sake of frame-local @@ -9932,16 +9928,16 @@ redisplay_internal (preserve_echo_area) /* Mark all the scroll bars to be removed; we'll redeem the ones we want when we redisplay their windows. */ - if (condemn_scroll_bars_hook) - condemn_scroll_bars_hook (f); + if (FRAME_DISPLAY (f)->condemn_scroll_bars_hook) + FRAME_DISPLAY (f)->condemn_scroll_bars_hook (f); if (FRAME_VISIBLE_P (f) && !FRAME_OBSCURED_P (f)) redisplay_windows (FRAME_ROOT_WINDOW (f)); /* Any scroll bars which redisplay_windows should have nuked should now go away. */ - if (judge_scroll_bars_hook) - judge_scroll_bars_hook (f); + if (FRAME_DISPLAY (f)->judge_scroll_bars_hook) + FRAME_DISPLAY (f)->judge_scroll_bars_hook (f); /* If fonts changed, display again. */ /* ??? rms: I suspect it is a mistake to jump all the way @@ -9993,8 +9989,8 @@ redisplay_internal (preserve_echo_area) { struct frame *f = updated[i]; mark_window_display_accurate (f->root_window, 1); - if (frame_up_to_date_hook) - frame_up_to_date_hook (f); + if (FRAME_DISPLAY (f)->frame_up_to_date_hook) + FRAME_DISPLAY (f)->frame_up_to_date_hook (f); } } } @@ -10083,8 +10079,8 @@ redisplay_internal (preserve_echo_area) last_arrow_position = COERCE_MARKER (Voverlay_arrow_position); last_arrow_string = Voverlay_arrow_string; - if (frame_up_to_date_hook != 0) - frame_up_to_date_hook (sf); + if (FRAME_DISPLAY (sf)->frame_up_to_date_hook != 0) + FRAME_DISPLAY (sf)->frame_up_to_date_hook (sf); } update_mode_lines = 0; @@ -11222,7 +11218,9 @@ set_vertical_scroll_bar (w) start = end = whole = 0; /* Indicate what this scroll bar ought to be displaying now. */ - set_vertical_scroll_bar_hook (w, end - start, whole, start); + if (FRAME_DISPLAY (XFRAME (w->frame))->set_vertical_scroll_bar_hook) + (*FRAME_DISPLAY (XFRAME (w->frame))->set_vertical_scroll_bar_hook) + (w, end - start, whole, start); } @@ -11942,7 +11940,8 @@ redisplay_window (window, just_this_one_p) /* Note that we actually used the scroll bar attached to this window, so it shouldn't be deleted at the end of redisplay. */ - redeem_scroll_bar_hook (w); + if (FRAME_DISPLAY (f)->redeem_scroll_bar_hook) + (*FRAME_DISPLAY (f)->redeem_scroll_bar_hook) (w); } /* Restore current_buffer and value of point in it. */ @@ -12151,10 +12150,10 @@ try_window_reusing_current_matrix (w) if (run.height > 0 && run.current_y != run.desired_y) { update_begin (f); - rif->update_window_begin_hook (w); - rif->clear_window_mouse_face (w); - rif->scroll_run_hook (w, &run); - rif->update_window_end_hook (w, 0, 0); + FRAME_RIF (f)->update_window_begin_hook (w); + FRAME_RIF (f)->clear_window_mouse_face (w); + FRAME_RIF (f)->scroll_run_hook (w, &run); + FRAME_RIF (f)->update_window_end_hook (w, 0, 0); update_end (f); } @@ -12324,10 +12323,10 @@ try_window_reusing_current_matrix (w) if (run.height) { update_begin (f); - rif->update_window_begin_hook (w); - rif->clear_window_mouse_face (w); - rif->scroll_run_hook (w, &run); - rif->update_window_end_hook (w, 0, 0); + FRAME_RIF (f)->update_window_begin_hook (w); + FRAME_RIF (f)->clear_window_mouse_face (w); + FRAME_RIF (f)->scroll_run_hook (w, &run); + FRAME_RIF (f)->update_window_end_hook (w, 0, 0); update_end (f); } @@ -12752,7 +12751,7 @@ try_window_id (w) /* Window must either use window-based redisplay or be full width. */ if (!FRAME_WINDOW_P (f) - && (!line_ins_del_ok + && (!FRAME_LINE_INS_DEL_OK (f) || !WINDOW_FULL_WIDTH_P (w))) GIVE_UP (4); @@ -13160,10 +13159,10 @@ try_window_id (w) if (FRAME_WINDOW_P (f)) { - rif->update_window_begin_hook (w); - rif->clear_window_mouse_face (w); - rif->scroll_run_hook (w, &run); - rif->update_window_end_hook (w, 0, 0); + FRAME_RIF (f)->update_window_begin_hook (w); + FRAME_RIF (f)->clear_window_mouse_face (w); + FRAME_RIF (f)->scroll_run_hook (w, &run); + FRAME_RIF (f)->update_window_end_hook (w, 0, 0); } else { @@ -13185,7 +13184,7 @@ try_window_id (w) /* On dumb terminals delete dvpos lines at the end before inserting dvpos empty lines. */ - if (!scroll_region_ok) + if (!FRAME_SCROLL_REGION_OK (f)) ins_del_lines (end - dvpos, -dvpos); /* Insert dvpos empty lines in front of @@ -13206,7 +13205,7 @@ try_window_id (w) /* On a dumb terminal insert dvpos empty lines at the end. */ - if (!scroll_region_ok) + if (!FRAME_SCROLL_REGION_OK (f)) ins_del_lines (end + dvpos, -dvpos); } @@ -16730,7 +16729,7 @@ get_glyph_face_and_encoding (f, glyph, char2b, two_byte_p) = FONT_INFO_FROM_ID (f, face->font_info_id); if (font_info) glyph->font_type - = rif->encode_char (glyph->u.ch, char2b, font_info, two_byte_p); + = FRAME_RIF (f)->encode_char (glyph->u.ch, char2b, font_info, two_byte_p); } } @@ -16960,7 +16959,7 @@ x_get_glyph_overhangs (glyph, f, left, right) font = face->font; font_info = FONT_INFO_FROM_ID (f, face->font_info_id); if (font /* ++KFS: Should this be font_info ? */ - && (pcm = rif->per_char_metric (font, &char2b, glyph->font_type))) + && (pcm = FRAME_RIF (f)->per_char_metric (font, &char2b, glyph->font_type))) { if (pcm->rbearing > pcm->width) *right = pcm->rbearing - pcm->width; @@ -17128,7 +17127,7 @@ get_char_face_and_encoding (f, c, face_id, char2b, multibyte_p, display_p) struct font_info *font_info = FONT_INFO_FROM_ID (f, face->font_info_id); if (font_info) - rif->encode_char (c, char2b, font_info, 0); + FRAME_RIF (f)->encode_char (c, char2b, font_info, 0); } } @@ -17195,8 +17194,8 @@ compute_overhangs_and_x (s, x, backward_p) { while (s) { - if (rif->compute_glyph_string_overhangs) - rif->compute_glyph_string_overhangs (s); + if (FRAME_RIF (s->f)->compute_glyph_string_overhangs) + FRAME_RIF (s->f)->compute_glyph_string_overhangs (s); x -= s->width; s->x = x; s = s->prev; @@ -17206,8 +17205,8 @@ compute_overhangs_and_x (s, x, backward_p) { while (s) { - if (rif->compute_glyph_string_overhangs) - rif->compute_glyph_string_overhangs (s); + if (FRAME_RIF (s->f)->compute_glyph_string_overhangs) + FRAME_RIF (s->f)->compute_glyph_string_overhangs (s); s->x = x; x += s->width; s = s->next; @@ -17488,9 +17487,9 @@ draw_glyphs (w, x, row, area, start, end, hl, overlaps_p) struct glyph_string *h, *t; /* Compute overhangs for all glyph strings. */ - if (rif->compute_glyph_string_overhangs) + if (FRAME_RIF (f)->compute_glyph_string_overhangs) for (s = head; s; s = s->next) - rif->compute_glyph_string_overhangs (s); + FRAME_RIF (f)->compute_glyph_string_overhangs (s); /* Prepend glyph strings for glyphs in front of the first glyph string that are overwritten because of the first glyph @@ -17558,7 +17557,7 @@ draw_glyphs (w, x, row, area, start, end, hl, overlaps_p) /* Draw all strings. */ for (s = head; s; s = s->next) - rif->draw_glyph_string (s); + FRAME_RIF (f)->draw_glyph_string (s); if (area == TEXT_AREA && !row->full_width_p @@ -18260,8 +18259,8 @@ x_produce_glyphs (it) it->nglyphs = 1; - pcm = rif->per_char_metric (font, &char2b, - FONT_TYPE_FOR_UNIBYTE (font, it->char_to_display)); + pcm = FRAME_RIF (it->f)->per_char_metric (font, &char2b, + FONT_TYPE_FOR_UNIBYTE (font, it->char_to_display)); it->ascent = FONT_BASE (font) + boff; it->descent = FONT_DESCENT (font) - boff; @@ -18385,8 +18384,8 @@ x_produce_glyphs (it) from the charset width; this is what old redisplay code did. */ - pcm = rif->per_char_metric (font, &char2b, - FONT_TYPE_FOR_MULTIBYTE (font, it->c)); + pcm = FRAME_RIF (it->f)->per_char_metric (font, &char2b, + FONT_TYPE_FOR_MULTIBYTE (font, it->c)); if (font_not_found_p || !pcm) { @@ -18517,8 +18516,8 @@ x_produce_glyphs (it) /* Initialize the bounding box. */ if (font_info - && (pcm = rif->per_char_metric (font, &char2b, - FONT_TYPE_FOR_MULTIBYTE (font, it->c)))) + && (pcm = FRAME_RIF (it->f)->per_char_metric (font, &char2b, + FONT_TYPE_FOR_MULTIBYTE (font, it->c)))) { width = pcm->width; ascent = pcm->ascent; @@ -18576,8 +18575,8 @@ x_produce_glyphs (it) } if (font_info - && (pcm = rif->per_char_metric (font, &char2b, - FONT_TYPE_FOR_MULTIBYTE (font, ch)))) + && (pcm = FRAME_RIF (it->f)->per_char_metric (font, &char2b, + FONT_TYPE_FOR_MULTIBYTE (font, ch)))) { width = pcm->width; ascent = pcm->ascent; @@ -18812,8 +18811,8 @@ x_insert_glyphs (start, len) frame_x = window_box_left (w, updated_area) + output_cursor.x; frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, output_cursor.y); - rif->shift_glyphs_for_insert (f, frame_x, frame_y, shifted_region_width, - line_height, shift_by_width); + FRAME_RIF (f)->shift_glyphs_for_insert (f, frame_x, frame_y, shifted_region_width, + line_height, shift_by_width); /* Write the glyphs. */ hpos = start - row->glyphs[updated_area]; @@ -18895,8 +18894,8 @@ x_clear_end_of_line (to_x) if (to_x > from_x && to_y > from_y) { BLOCK_INPUT; - rif->clear_frame_area (f, from_x, from_y, - to_x - from_x, to_y - from_y); + FRAME_RIF (f)->clear_frame_area (f, from_x, from_y, + to_x - from_x, to_y - from_y); UNBLOCK_INPUT; } } @@ -19358,8 +19357,8 @@ erase_phys_cursor (w) x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); y = WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, cursor_row->y)); - rif->clear_frame_area (f, x, y, - cursor_glyph->pixel_width, cursor_row->visible_height); + FRAME_RIF (f)->clear_frame_area (f, x, y, + cursor_glyph->pixel_width, cursor_row->visible_height); } /* Erase the cursor by redrawing the character underneath it. */ @@ -19456,9 +19455,9 @@ display_and_set_cursor (w, on, hpos, vpos, x, y) w->phys_cursor.vpos = vpos; } - rif->draw_window_cursor (w, glyph_row, x, y, - new_cursor_type, new_cursor_width, - on, active_cursor); + FRAME_RIF (f)->draw_window_cursor (w, glyph_row, x, y, + new_cursor_type, new_cursor_width, + on, active_cursor); } @@ -19603,11 +19602,11 @@ show_mouse_face (dpyinfo, draw) /* Change the mouse cursor. */ if (draw == DRAW_NORMAL_TEXT) - rif->define_frame_cursor (f, FRAME_X_OUTPUT (f)->text_cursor); + FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->text_cursor); else if (draw == DRAW_MOUSE_FACE) - rif->define_frame_cursor (f, FRAME_X_OUTPUT (f)->hand_cursor); + FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->hand_cursor); else - rif->define_frame_cursor (f, FRAME_X_OUTPUT (f)->nontext_cursor); + FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->nontext_cursor); } /* EXPORT: @@ -20021,8 +20020,7 @@ on_hot_spot_p (hot_spot, x, y) return inside; } } - else - return 0; + return 0; } Lisp_Object @@ -20102,7 +20100,7 @@ define_frame_cursor1 (f, cursor, pointer) #else if (bcmp (&cursor, &No_Cursor, sizeof (Cursor))) #endif - rif->define_frame_cursor (f, cursor); + FRAME_RIF (f)->define_frame_cursor (f, cursor); } /* Take proper action when mouse has moved to the mode or header line @@ -20940,6 +20938,8 @@ void x_draw_vertical_border (w) struct window *w; { + struct frame *f = XFRAME (WINDOW_FRAME (w)); + /* We could do better, if we knew what type of scroll-bar the adjacent windows (on either side) have... But we don't :-( However, I think this works ok. ++KFS 2003-04-25 */ @@ -20956,7 +20956,7 @@ x_draw_vertical_border (w) window_box_edges (w, -1, &x0, &y0, &x1, &y1); y1 -= 1; - rif->draw_vertical_window_border (w, x1, y0, y1); + FRAME_RIF (f)->draw_vertical_window_border (w, x1, y0, y1); } else if (!WINDOW_LEFTMOST_P (w) && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) @@ -20966,7 +20966,7 @@ x_draw_vertical_border (w) window_box_edges (w, -1, &x0, &y0, &x1, &y1); y1 -= 1; - rif->draw_vertical_window_border (w, x0, y0, y1); + FRAME_RIF (f)->draw_vertical_window_border (w, x0, y0, y1); } } diff --git a/src/xfaces.c b/src/xfaces.c index d8034c1d5d7..7761282f9eb 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -195,11 +195,13 @@ Boston, MA 02111-1307, USA. */ #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> +#include <stdio.h> /* This needs to be before termchar.h */ #include "lisp.h" #include "charset.h" #include "keyboard.h" #include "frame.h" +#include "termhooks.h" #ifdef HAVE_WINDOW_SYSTEM #include "fontset.h" @@ -242,6 +244,7 @@ Boston, MA 02111-1307, USA. */ #include "blockinput.h" #include "window.h" #include "intervals.h" +#include "termchar.h" #ifdef HAVE_X_WINDOWS @@ -5406,7 +5409,7 @@ substitution of a `dim' face for italic. */) /* See if the capabilities we selected above are supported, with the given colors. */ if (test_caps != 0 && - ! tty_capable_p (f, test_caps, fg_tty_color.pixel, bg_tty_color.pixel)) + ! tty_capable_p (FRAME_TTY (f), test_caps, fg_tty_color.pixel, bg_tty_color.pixel)) return Qnil; @@ -6638,7 +6641,8 @@ realize_basic_faces (f) { FRAME_FACE_CACHE (f)->menu_face_changed_p = 0; #ifdef USE_X_TOOLKIT - x_update_menu_appearance (f); + if (FRAME_WINDOW_P (f)) + x_update_menu_appearance (f); #endif } @@ -6725,7 +6729,7 @@ realize_default_face (f) LFACE_FOREGROUND (lface) = XCDR (color); else if (FRAME_WINDOW_P (f)) return 0; - else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) + else if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) LFACE_FOREGROUND (lface) = build_string (unspecified_fg); else abort (); @@ -6740,7 +6744,7 @@ realize_default_face (f) LFACE_BACKGROUND (lface) = XCDR (color); else if (FRAME_WINDOW_P (f)) return 0; - else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) + else if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) LFACE_BACKGROUND (lface) = build_string (unspecified_bg); else abort (); @@ -6829,6 +6833,11 @@ realize_face (cache, attrs, c, base_face, former_face_id) face = realize_x_face (cache, attrs, c, base_face); else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f)) face = realize_tty_face (cache, attrs, c); + else if (FRAME_INITIAL_P (cache->f)) + { + /* Create a dummy face. */ + face = make_realized_face (attrs); + } else abort (); diff --git a/src/xfns.c b/src/xfns.c index f5e3c0c62e5..5b3f8ffe552 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -48,6 +48,7 @@ Boston, MA 02111-1307, USA. */ #include "systime.h" #include "termhooks.h" #include "atimer.h" +#include "termchar.h" #ifdef HAVE_X_WINDOWS @@ -1759,10 +1760,10 @@ x_set_scroll_bar_foreground (f, value, oldval) if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) { /* Remove all scroll bars because they have wrong colors. */ - if (condemn_scroll_bars_hook) - (*condemn_scroll_bars_hook) (f); - if (judge_scroll_bars_hook) - (*judge_scroll_bars_hook) (f); + if (FRAME_DISPLAY (f)->condemn_scroll_bars_hook) + (*FRAME_DISPLAY (f)->condemn_scroll_bars_hook) (f); + if (FRAME_DISPLAY (f)->judge_scroll_bars_hook) + (*FRAME_DISPLAY (f)->judge_scroll_bars_hook) (f); update_face_from_frame_parameter (f, Qscroll_bar_foreground, value); redraw_frame (f); @@ -1808,10 +1809,10 @@ x_set_scroll_bar_background (f, value, oldval) if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) { /* Remove all scroll bars because they have wrong colors. */ - if (condemn_scroll_bars_hook) - (*condemn_scroll_bars_hook) (f); - if (judge_scroll_bars_hook) - (*judge_scroll_bars_hook) (f); + if (FRAME_DISPLAY (f)->condemn_scroll_bars_hook) + (*FRAME_DISPLAY (f)->condemn_scroll_bars_hook) (f); + if (FRAME_DISPLAY (f)->judge_scroll_bars_hook) + (*FRAME_DISPLAY (f)->judge_scroll_bars_hook) (f); update_face_from_frame_parameter (f, Qscroll_bar_background, value); redraw_frame (f); @@ -3186,8 +3187,6 @@ This function is an internal primitive--use `make-frame' instead. */) Lisp_Object parent; struct kboard *kb; - check_x (); - /* Use this general default value to start with until we know if this frame has a specified name. */ Vx_resource_name = Vinvocation_name; @@ -3242,6 +3241,9 @@ This function is an internal primitive--use `make-frame' instead. */) /* Note that X Windows does support scroll bars. */ FRAME_CAN_HAVE_SCROLL_BARS (f) = 1; + f->display = dpyinfo->frame_display; + f->display->reference_count++; + f->output_method = output_x_window; f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output)); bzero (f->output_data.x, sizeof (struct x_output)); @@ -3331,6 +3333,8 @@ This function is an internal primitive--use `make-frame' instead. */) specbind (Qx_resource_name, name); } + Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qx), Qnil)); + /* Extract the window parameters from the supplied values that are needed to determine window geometry. */ { @@ -4119,8 +4123,10 @@ x_display_info_for_name (name) CHECK_STRING (name); - if (! EQ (Vwindow_system, intern ("x"))) - error ("Not using X Windows"); +#if 0 + if (! EQ (Vinitial_window_system, intern ("x"))) + error ("Not using X Windows"); /* That doesn't stop us anymore. */ +#endif for (dpyinfo = x_display_list, names = x_display_name_list; dpyinfo; @@ -4167,8 +4173,10 @@ terminate Emacs if we can't open the connection. */) if (! NILP (xrm_string)) CHECK_STRING (xrm_string); - if (! EQ (Vwindow_system, intern ("x"))) - error ("Not using X Windows"); +#if 0 + if (! EQ (Vinitial_window_system, intern ("x"))) + error ("Not using X Windows"); /* That doesn't stop us anymore. */ +#endif if (! NILP (xrm_string)) xrm_option = (unsigned char *) SDATA (xrm_string); @@ -9964,6 +9972,9 @@ x_create_tip_frame (dpyinfo, parms, text) FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; record_unwind_protect (unwind_create_tip_frame, frame); + f->display = dpyinfo->frame_display; + f->display->reference_count++; + /* By setting the output method, we're essentially saying that the frame is live, as per FRAME_LIVE_P. If we get a signal from this point on, x_destroy_window might screw up reference @@ -10187,6 +10198,8 @@ x_create_tip_frame (dpyinfo, parms, text) Qnil)); } + Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qx), Qnil)); + f->no_split = 1; UNGCPRO; diff --git a/src/xmenu.c b/src/xmenu.c index 473e29de88d..2ca6e247e12 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -39,10 +39,10 @@ Boston, MA 02111-1307, USA. */ #include <stdio.h> #include "lisp.h" -#include "termhooks.h" #include "keyboard.h" #include "keymap.h" #include "frame.h" +#include "termhooks.h" #include "window.h" #include "blockinput.h" #include "buffer.h" diff --git a/src/xselect.c b/src/xselect.c index b4d61f7c9a9..637b39272b7 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -308,13 +308,20 @@ x_own_selection (selection_name, selection_value) Lisp_Object selection_name, selection_value; { struct frame *sf = SELECTED_FRAME (); - Window selecting_window = FRAME_X_WINDOW (sf); - Display *display = FRAME_X_DISPLAY (sf); + Window selecting_window; + Display *display; Time time = last_event_timestamp; Atom selection_atom; - struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (sf); + struct x_display_info *dpyinfo; int count; + if (! FRAME_X_P (sf)) + return; + + selecting_window = FRAME_X_WINDOW (sf); + display = FRAME_X_DISPLAY (sf); + dpyinfo = FRAME_X_DISPLAY_INFO (sf); + CHECK_SYMBOL (selection_name); selection_atom = symbol_to_x_atom (dpyinfo, display, selection_name); @@ -578,7 +585,8 @@ some_frame_on_display (dpyinfo) FOR_EACH_FRAME (list, frame) { - if (FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo) + if (FRAME_X_P (XFRAME (frame)) + && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo) return frame; } @@ -1225,17 +1233,26 @@ x_get_foreign_selection (selection_symbol, target_type, time_stamp) Lisp_Object selection_symbol, target_type, time_stamp; { struct frame *sf = SELECTED_FRAME (); - Window requestor_window = FRAME_X_WINDOW (sf); - Display *display = FRAME_X_DISPLAY (sf); - struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (sf); + Window requestor_window; + Display *display; + struct x_display_info *dpyinfo; Time requestor_time = last_event_timestamp; - Atom target_property = dpyinfo->Xatom_EMACS_TMP; - Atom selection_atom = symbol_to_x_atom (dpyinfo, display, selection_symbol); + Atom target_property; + Atom selection_atom; Atom type_atom; int secs, usecs; int count; Lisp_Object frame; + if (! FRAME_X_P (sf)) + return Qnil; + + requestor_window = FRAME_X_WINDOW (sf); + display = FRAME_X_DISPLAY (sf); + dpyinfo = FRAME_X_DISPLAY_INFO (sf); + target_property = dpyinfo->Xatom_EMACS_TMP; + selection_atom = symbol_to_x_atom (dpyinfo, display, selection_symbol); + if (CONSP (target_type)) type_atom = symbol_to_x_atom (dpyinfo, display, XCAR (target_type)); else @@ -2009,6 +2026,9 @@ Disowning it means there is no such selection. */) struct frame *sf = SELECTED_FRAME (); check_x (); + if (! FRAME_X_P (sf)) + return Qnil; + display = FRAME_X_DISPLAY (sf); dpyinfo = FRAME_X_DISPLAY_INFO (sf); CHECK_SYMBOL (selection); @@ -2172,6 +2192,10 @@ DEFUN ("x-get-cut-buffer-internal", Fx_get_cut_buffer_internal, struct frame *sf = SELECTED_FRAME (); check_x (); + + if (! FRAME_X_P (sf)) + return Qnil; + display = FRAME_X_DISPLAY (sf); dpyinfo = FRAME_X_DISPLAY_INFO (sf); window = RootWindow (display, 0); /* Cut buffers are on screen 0 */ @@ -2213,6 +2237,10 @@ DEFUN ("x-store-cut-buffer-internal", Fx_store_cut_buffer_internal, struct frame *sf = SELECTED_FRAME (); check_x (); + + if (! FRAME_X_P (sf)) + return Qnil; + display = FRAME_X_DISPLAY (sf); window = RootWindow (display, 0); /* Cut buffers are on screen 0 */ @@ -2269,8 +2297,12 @@ Positive means shift the values forward, negative means backward. */) Atom props[8]; Display *display; struct frame *sf = SELECTED_FRAME (); - + check_x (); + + if (! FRAME_X_P (sf)) + return Qnil; + display = FRAME_X_DISPLAY (sf); window = RootWindow (display, 0); /* Cut buffers are on screen 0 */ CHECK_NUMBER (n); diff --git a/src/xsmfns.c b/src/xsmfns.c index e486e5c6e32..35c7429b66b 100644 --- a/src/xsmfns.c +++ b/src/xsmfns.c @@ -48,6 +48,7 @@ Boston, MA 02111-1307, USA. */ #include "systime.h" #include "sysselect.h" #include "lisp.h" +#include "frame.h" #include "termhooks.h" #include "termopts.h" #include "xterm.h" diff --git a/src/xterm.c b/src/xterm.c index 0f1faeafbbd..6100eaacffa 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -54,7 +54,6 @@ Boston, MA 02111-1307, USA. */ #include <sys/ioctl.h> #endif /* ! defined (BSD_SYSTEM) */ -#include "systty.h" #include "systime.h" #ifndef INCLUDED_FCNTL @@ -325,13 +324,15 @@ void x_raise_frame P_ ((struct frame *)); void x_set_window_size P_ ((struct frame *, int, int, int)); void x_wm_set_window_state P_ ((struct frame *, int)); void x_wm_set_icon_pixmap P_ ((struct frame *, int)); +struct display *x_create_frame_display P_ ((struct x_display_info *)); +void x_delete_frame_display P_ ((struct display *)); void x_initialize P_ ((void)); static void x_font_min_bounds P_ ((XFontStruct *, int *, int *)); static int x_compute_min_glyph_bounds P_ ((struct frame *)); static void x_update_end P_ ((struct frame *)); static void XTframe_up_to_date P_ ((struct frame *)); -static void XTset_terminal_modes P_ ((void)); -static void XTreset_terminal_modes P_ ((void)); +static void XTset_terminal_modes P_ ((struct display *)); +static void XTreset_terminal_modes P_ ((struct display *)); static void x_clear_frame P_ ((void)); static void frame_highlight P_ ((struct frame *)); static void frame_unhighlight P_ ((struct frame *)); @@ -373,7 +374,8 @@ x_flush (f) { Lisp_Object rest, frame; FOR_EACH_FRAME (rest, frame) - x_flush (XFRAME (frame)); + if (FRAME_X_P (XFRAME (frame))) + x_flush (XFRAME (frame)); } else if (FRAME_X_P (f)) XFlush (FRAME_X_DISPLAY (f)); @@ -460,7 +462,6 @@ x_update_begin (f) /* Nothing to do. */ } - /* Start update of window W. Set the global variable updated_window to the window being updated and set output_cursor to the cursor position of W. */ @@ -780,7 +781,7 @@ x_draw_fringe_bitmap (w, row, p) rarely happens). */ static void -XTset_terminal_modes () +XTset_terminal_modes (struct display *display) { } @@ -788,7 +789,7 @@ XTset_terminal_modes () the X-windows go away, and suspending requires no action. */ static void -XTreset_terminal_modes () +XTreset_terminal_modes (struct display *display) { } @@ -1399,7 +1400,8 @@ x_frame_of_widget (widget) for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) if (GC_FRAMEP (XCAR (tail)) && (f = XFRAME (XCAR (tail)), - (f->output_data.nothing != 1 + (FRAME_X_P (f) + && f->output_data.nothing != 1 && FRAME_X_DISPLAY_INFO (f) == dpyinfo)) && f->output_data.x->widget == widget) return f; @@ -3681,7 +3683,8 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time) /* Clear the mouse-moved flag for every frame on this display. */ FOR_EACH_FRAME (tail, frame) - if (FRAME_X_DISPLAY (XFRAME (frame)) == FRAME_X_DISPLAY (*fp)) + if (FRAME_X_P (XFRAME (frame)) + && FRAME_X_DISPLAY (XFRAME (frame)) == FRAME_X_DISPLAY (*fp)) XFRAME (frame)->mouse_moved = 0; last_mouse_scroll_bar = Qnil; @@ -3895,6 +3898,9 @@ x_window_to_scroll_bar (display, window_id) if (! GC_FRAMEP (frame)) abort (); + if (! FRAME_X_P (XFRAME (frame))) + continue; + /* Scan this frame's scroll bar list for a scroll bar with the right window ID. */ condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame)); @@ -3929,11 +3935,14 @@ x_window_to_menu_bar (window) XGCTYPE (tail) == Lisp_Cons; tail = XCDR (tail)) { - Lisp_Object frame = XCAR (tail); - Widget menu_bar = XFRAME (frame)->output_data.x->menubar_widget; + if (FRAME_X_P (XFRAME (XCAR (tail)))) + { + Lisp_Object frame = XCAR (tail); + Widget menu_bar = XFRAME (frame)->output_data.x->menubar_widget; - if (menu_bar && xlwmenu_window_p (menu_bar, window)) - return menu_bar; + if (menu_bar && xlwmenu_window_p (menu_bar, window)) + return menu_bar; + } } return NULL; @@ -6309,37 +6318,37 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) orig_keysym = keysym; - /* Common for all keysym input events. */ - XSETFRAME (inev.frame_or_window, f); - inev.modifiers - = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), modifiers); - inev.timestamp = event.xkey.time; - - /* First deal with keysyms which have defined - translations to characters. */ - if (keysym >= 32 && keysym < 128) - /* Avoid explicitly decoding each ASCII character. */ - { - inev.kind = ASCII_KEYSTROKE_EVENT; - inev.code = keysym; - goto done_keysym; - } - - /* Now non-ASCII. */ - if (HASH_TABLE_P (Vx_keysym_table) - && (NATNUMP (c = Fgethash (make_number (keysym), - Vx_keysym_table, - Qnil)))) - { - inev.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c)) - ? ASCII_KEYSTROKE_EVENT - : MULTIBYTE_CHAR_KEYSTROKE_EVENT); - inev.code = XFASTINT (c); - goto done_keysym; - } - - /* Random non-modifier sorts of keysyms. */ - if (((keysym >= XK_BackSpace && keysym <= XK_Escape) + /* Common for all keysym input events. */ + XSETFRAME (inev.frame_or_window, f); + inev.modifiers + = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), modifiers); + inev.timestamp = event.xkey.time; + + /* First deal with keysyms which have defined + translations to characters. */ + if (keysym >= 32 && keysym < 128) + /* Avoid explicitly decoding each ASCII character. */ + { + inev.kind = ASCII_KEYSTROKE_EVENT; + inev.code = keysym; + goto done_keysym; + } + + /* Now non-ASCII. */ + if (HASH_TABLE_P (Vx_keysym_table) + && (NATNUMP (c = Fgethash (make_number (keysym), + Vx_keysym_table, + Qnil)))) + { + inev.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c)) + ? ASCII_KEYSTROKE_EVENT + : MULTIBYTE_CHAR_KEYSTROKE_EVENT); + inev.code = XFASTINT (c); + goto done_keysym; + } + + /* Random non-modifier sorts of keysyms. */ + if (((keysym >= XK_BackSpace && keysym <= XK_Escape) || keysym == XK_Delete #ifdef XK_ISO_Left_Tab || (keysym >= XK_ISO_Left_Tab @@ -6955,8 +6964,8 @@ x_dispatch_event (event, display) EXPECTED is nonzero if the caller knows input is available. */ static int -XTread_socket (sd, expected, hold_quit) - register int sd; +XTread_socket (display, expected, hold_quit) + struct display *display; int expected; struct input_event *hold_quit; { @@ -7544,7 +7553,11 @@ x_catch_errors_unwind (old_val) first = XCAR (old_val); +#if 0 /* XXX This has dumped core on me several times when my X + server crashed. If this call is important, maybe we should + check that the display is still alive. -- lorentey */ XSync (XSAVE_VALUE (first)->pointer, False); +#endif x_error_message_string = XCDR (old_val); return Qnil; @@ -7737,7 +7750,7 @@ x_connection_closed (dpy, error_message) x_uncatch_errors (dpy, count); - if (x_display_list == 0) + if (display_list == 0) { fprintf (stderr, "%s\n", error_msg); shut_down_emacs (0, 0, Qnil); @@ -7934,7 +7947,7 @@ xim_destroy_callback (xim, client_data, call_data) FOR_EACH_FRAME (tail, frame) { struct frame *f = XFRAME (frame); - if (FRAME_X_DISPLAY_INFO (f) == dpyinfo) + if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo) { FRAME_XIC (f) = NULL; if (FRAME_XIC_FONTSET (f)) @@ -8037,7 +8050,8 @@ xim_instantiate_callback (display, client_data, call_data) { struct frame *f = XFRAME (frame); - if (FRAME_X_DISPLAY_INFO (f) == xim_inst->dpyinfo) + if (FRAME_X_P (f) + && FRAME_X_DISPLAY_INFO (f) == xim_inst->dpyinfo) if (FRAME_XIC (f) == NULL) { create_frame_xic (f); @@ -10126,6 +10140,7 @@ x_term_init (display_name, xrm_option, resource_name) { int connection; Display *dpy; + struct display *display; struct x_display_info *dpyinfo; XrmDatabase xrdb; @@ -10260,6 +10275,8 @@ x_term_init (display_name, xrm_option, resource_name) dpyinfo = (struct x_display_info *) xmalloc (sizeof (struct x_display_info)); bzero (dpyinfo, sizeof *dpyinfo); + display = x_create_frame_display (dpyinfo); + #ifdef MULTI_KBOARD { struct x_display_info *share; @@ -10610,7 +10627,18 @@ x_delete_display (dpyinfo) struct x_display_info *dpyinfo; { int i; - + + { + /* Delete the generic struct display for this X display. */ + struct display *d; + for (d = display_list; d; d = d->next_display) + if (d->type == output_x_window && d->display_info.x == dpyinfo) + { + delete_display (d); + break; + } + } + delete_keyboard_wait_descriptor (dpyinfo->connection); /* Discard this display from x_display_name_list and x_display_list. @@ -10708,70 +10736,97 @@ x_process_timeouts (timer) extern frame_parm_handler x_frame_parm_handlers[]; static struct redisplay_interface x_redisplay_interface = -{ - x_frame_parm_handlers, - x_produce_glyphs, - x_write_glyphs, - x_insert_glyphs, - x_clear_end_of_line, - x_scroll_run, - x_after_update_window_line, - x_update_window_begin, - x_update_window_end, - x_cursor_to, - x_flush, + { + x_frame_parm_handlers, + x_produce_glyphs, + x_write_glyphs, + x_insert_glyphs, + x_clear_end_of_line, + x_scroll_run, + x_after_update_window_line, + x_update_window_begin, + x_update_window_end, + x_cursor_to, + x_flush, #ifndef XFlush - x_flush, + x_flush, #else - 0, /* flush_display_optional */ + 0, /* flush_display_optional */ #endif - x_clear_window_mouse_face, - x_get_glyph_overhangs, - x_fix_overlapping_area, - x_draw_fringe_bitmap, - 0, /* define_fringe_bitmap */ - 0, /* destroy_fringe_bitmap */ - x_per_char_metric, - x_encode_char, - x_compute_glyph_string_overhangs, - x_draw_glyph_string, - x_define_frame_cursor, - x_clear_frame_area, - x_draw_window_cursor, - x_draw_vertical_window_border, - x_shift_glyphs_for_insert -}; + x_clear_window_mouse_face, + x_get_glyph_overhangs, + x_fix_overlapping_area, + x_draw_fringe_bitmap, + 0, /* define_fringe_bitmap */ + 0, /* destroy_fringe_bitmap */ + x_per_char_metric, + x_encode_char, + x_compute_glyph_string_overhangs, + x_draw_glyph_string, + x_define_frame_cursor, + x_clear_frame_area, + x_draw_window_cursor, + x_draw_vertical_window_border, + x_shift_glyphs_for_insert + }; + + +/* This function is called when the last frame on a display is deleted. */ +void +x_delete_frame_display (struct display *display) +{ + /* We don't do anything, the connection to the X server must remain + open. */ +} + + +struct display * +x_create_frame_display (struct x_display_info *dpyinfo) +{ + struct display *display; + + display = create_display (); + + display->type = output_x_window; + display->display_info.x = dpyinfo; + dpyinfo->frame_display = display; + + display->clear_frame_hook = x_clear_frame; + display->ins_del_lines_hook = x_ins_del_lines; + display->delete_glyphs_hook = x_delete_glyphs; + display->ring_bell_hook = XTring_bell; + display->reset_terminal_modes_hook = XTreset_terminal_modes; + display->set_terminal_modes_hook = XTset_terminal_modes; + display->update_begin_hook = x_update_begin; + display->update_end_hook = x_update_end; + display->set_terminal_window_hook = XTset_terminal_window; + display->read_socket_hook = XTread_socket; + display->frame_up_to_date_hook = XTframe_up_to_date; + display->mouse_position_hook = XTmouse_position; + display->frame_rehighlight_hook = XTframe_rehighlight; + display->frame_raise_lower_hook = XTframe_raise_lower; + display->set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar; + display->condemn_scroll_bars_hook = XTcondemn_scroll_bars; + display->redeem_scroll_bar_hook = XTredeem_scroll_bar; + display->judge_scroll_bars_hook = XTjudge_scroll_bars; + + display->delete_frame_hook = x_destroy_window; + display->delete_display_hook = x_delete_frame_display; + + display->rif = &x_redisplay_interface; + display->scroll_region_ok = 1; /* We'll scroll partial frames. */ + display->char_ins_del_ok = 1; + display->line_ins_del_ok = 1; /* We'll just blt 'em. */ + display->fast_clear_end_of_line = 1; /* X does this well. */ + display->memory_below_frame = 0; /* We don't remember what scrolls + off the bottom. */ + + return display; +} void x_initialize () { - rif = &x_redisplay_interface; - - clear_frame_hook = x_clear_frame; - ins_del_lines_hook = x_ins_del_lines; - delete_glyphs_hook = x_delete_glyphs; - ring_bell_hook = XTring_bell; - reset_terminal_modes_hook = XTreset_terminal_modes; - set_terminal_modes_hook = XTset_terminal_modes; - update_begin_hook = x_update_begin; - update_end_hook = x_update_end; - set_terminal_window_hook = XTset_terminal_window; - read_socket_hook = XTread_socket; - frame_up_to_date_hook = XTframe_up_to_date; - mouse_position_hook = XTmouse_position; - frame_rehighlight_hook = XTframe_rehighlight; - frame_raise_lower_hook = XTframe_raise_lower; - set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar; - condemn_scroll_bars_hook = XTcondemn_scroll_bars; - redeem_scroll_bar_hook = XTredeem_scroll_bar; - judge_scroll_bars_hook = XTjudge_scroll_bars; - - scroll_region_ok = 1; /* we'll scroll partial frames */ - char_ins_del_ok = 1; - line_ins_del_ok = 1; /* we'll just blt 'em */ - fast_clear_end_of_line = 1; /* X does this well */ - memory_below_frame = 0; /* we don't remember what scrolls - off the bottom */ baud_rate = 19200; x_noop_count = 0; diff --git a/src/xterm.h b/src/xterm.h index b7f46a8abd4..4a19d2c0d56 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -382,6 +382,9 @@ struct x_display_info X_WMTYPE_A, X_WMTYPE_B } wm_type; + + /* The generic display parameters corresponding to this X display. */ + struct display *frame_display; }; #ifdef HAVE_X_I18N |