changeset 83014:f5cadabb36dd

Support for opening X frames from a tty session. lisp/cus-face.el (custom-declare-face): Handle multiple concurrent display methods correctly. lisp/faces.el (x-create-frame-with-faces): Set the window-system frame parameter instead of frame-creation-function. (tty-create-frame-with-faces): Ditto. lisp/frame.el (frame-creation-function): Removed. (frame-creation-function-alist): New variable. (frame-initialize): Use initial-window-system instead of window-system. Add window-system parameter to initial-frame-alist. Removed tty initialization, it was moved to frame-creation-function-alist. (frame-notice-user-settings): Use initial-window-system instead of window-system. (make-frame-on-display): Make sure term/x-win is loaded. Added window-system parameter for make-frame. (make-frame-on-tty): Removed unnecessary autoload declaration. Added window-system parameter for make-frame. (make-frame): Use frame-creation-function-alist to determine the function to use depending on the specified window system. (select-frame-by-name): Use the window-system function instead of the variable. lisp/startup.el (window-system): New variable (previously built-in, now frame-local). (normal-top-level, command-line): Use initial-window-system instead of window-system. lisp/loadup.el: Load startup.el before faces.el, for the window-system variable. lisp/term/x-win.el: Check for the x-create-frame function instead of window-system to see if X is available. Don't exit Emacs if the display can not be opened when X is not the initial display method. Set up frame-creation-function-alist instead of frame-creation-function. Provide the x-win feature. src/dispnew.c (Vwindow_system): Renamed to Vinitial_window_system. (init_display, syms_of_display): Updated to use Vinitial_window_system instead of Vwindow_system. src/emacs.c (shut_down_emacs): Updated to use Vinitial_window_system instead of Vwindow_system. src/keyboard.c (Fset_input_mode): Call reset_all_sys_modes, not reset_sys_modes. Ditto for init_all_sys_modes. Process the quit parameter correctly. src/sysdep.c (init_sys_modes, reset_sys_modes): Unconditionally set up the terminal. We don't get called if there is nothing to do anymore. (sys_select): Use Vinitial_window_system, not Vwindow_system. src/window.h (Vwindow_system): Renamed to Vinitial_window_system. src/xfns.c (Fx_create_frame): Don't check_x. We initialize it anyway. (x_display_info_for_name, Fx_open_connection): Don't look at Vinitial_window_system. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-54
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 11 Jan 2004 21:59:40 +0000
parents e77d1a63471b
children ae6d0d2ecb1d
files README.multi-tty lisp/cus-face.el lisp/faces.el lisp/frame.el lisp/loadup.el lisp/startup.el lisp/term/x-win.el src/dispnew.c src/emacs.c src/keyboard.c src/sysdep.c src/window.h src/xfns.c
diffstat 13 files changed, 329 insertions(+), 326 deletions(-) [+]
line wrap: on
line diff
--- a/README.multi-tty	Sun Jan 11 11:26:00 2004 +0000
+++ b/README.multi-tty	Sun Jan 11 21:59:40 2004 +0000
@@ -2,9 +2,9 @@
 GOAL
 ----
 
-The ultimate goal of this branch is to implement support for opening
-multiple, different tty devices and simultaneous X and tty frames from
-a single Emacs session.
+The goal of this branch is to implement support for opening multiple,
+different tty devices and simultaneous X and tty frames from a single
+Emacs session.
 
 Some use cases:
 
@@ -27,7 +27,7 @@
 
 I'm Károly Lőrentey.  My address: lorentey@elte.hu.
 
-Patches or suggestions are welcome!
+Comments, bug reports, suggestions and patches are welcome!
 
 Retrieving the latest version of the branch:
 
@@ -46,9 +46,13 @@
 ------
 
 Multi-tty support is stable, I think most of the problems were fixed.
-(It still needs testing on other architectures, though.)  Please let
-me know if you find any bugs in it.  Emacsclient has been extended to
-support opening a new terminal frame.
+(It still needs testing on other architectures, though.)  Simultaneous
+X and tty frame support works fine, although there are some small
+issues.  Emacsclient has been extended to support opening a new
+terminal frame.
+
+
+Please let me know if you find any bugs in this branch.
 
 To try it out, compile and run the multi-tty branch with the following
 commands:
@@ -57,7 +61,7 @@
 	cd +build
 	../configure
 	make bootstrap
-	src/emacs -nw
+	src/emacs -nw		# You can also try without -nw
 	M-x server-start
 
 and then (from a shell prompt on another terminal) start emacsclient
@@ -77,7 +81,7 @@
 
 This is work in progress, and probably full of bugs.  You should
 always run emacs from gdb, so that you'll have a live instance to
-debug if something goes wrong.  Please send me your reports.
+debug if something goes wrong.  Please send me your bug reports.
 
 Problems:
 
@@ -85,39 +89,48 @@
 	  devices.  Also, there is no way to suspend emacsclient. This
 	  will be fixed.
 
-	* X support is (I hope) working, but at the moment there are
-	  problems with simultaneous X and tty devices, so don't do
-	  that - start a separate Emacs with -nw and run the server
-	  there.
-
 	* Mac, Windows and DOS support is broken, probably doesn't
 	  even compile -- this will be solved later.
 
-	* Only tested on my GNU/Linux box.
+	* Only tested on my GNU/Linux box and on Solaris 8.
 
 NEWS
 ----
 
 For the NEWS file:
 
-** Support for multiple terminal devices has been added.  You can
-   specify a terminal device (`tty' parameter) and a terminal type
-   (`tty-type' parameter) to `make-terminal-frame'. `tty' must be a
-   terminal device created by the updated emacsclient, or there will
-   be problems with terminal input and window resizes.
+** Support for multiple terminal devices has been added.
+
+*** You can specify a terminal device (`tty' parameter) and a terminal
+    type (`tty-type' parameter) to `make-terminal-frame'.
 
-   You can test for the presence of multiple terminal support by
-   testing for the `multi-tty' feature.
+*** You can test for the presence of multiple terminal support by
+    testing for the `multi-tty' feature.
+
+*** Emacsclient has been extended to support opening a new terminal
+    frame (see -t option).
+
+*** A make-frame-on-tty function has been added to make it easier to
+    create frames on new terminals.
 
-** A make-frame-on-tty function has been added to make it easier to
-   create frames on new terminals.
+*** New functions: frame-tty-name, frame-tty-type for accessing
+    terminal parameters, and delete-tty for closing the terminal
+    device.
+
+*** talk.el has been extended for multiple tty support.
+
 
-** New functions: frame-tty-name, frame-tty-type for accessing
-   terminal parameters, and delete-tty for closing the terminal
-   device.
+** Support for simultaneous graphical and terminal frames has been
+   added.
+
+*** The function `make-frame-on-display' now works during a terminal
+    session, and `make-frame-on-tty' works during a graphical session.
 
-** Emacsclient has been extended to support opening a new terminal
-   frame.
+*** The `window-system' variable has been made frame-local.
+
+*** The new `initial-window-system' variable contains the
+    `window-system' value for the first frame.
+
 
 CHANGELOG
 ---------
@@ -127,11 +140,13 @@
 THINGS TO DO
 ------------
 
-** Fix color handling during X+tty combo sessions.  (It seems that tty
+** Fix color handling during tty+X combo sessions.  (It seems that tty
    sessions automatically convert the face colors to terminal colors
    when the face is loaded.  This conversion must happen instead on
    the fly in write_glyphs, which might be problematic, as color
    approximation is currently done in lisp (term/tty-colors.el).)
+   (Update: hm, colors seem to work fine if I start emacs with -nw and
+   then create an X frame.  Maybe it's just a small buglet somewhere.)
 
 ** Fix interactive use of temacs.  There are face-related SEGVs, most
    likely because of changes in realize_default_face, realize_face.
@@ -139,17 +154,12 @@
 ** Very strange bug: visible-bell does not work on secondary
    terminals.  This might be something xterm (konsole) specific.
 
-** Allow opening an X session after -nw.
-
 ** Find out the best way to support suspending Emacs with multiple
    ttys.  My guess: disable it on the controlling tty, but from other
    ttys pass it on to emacsclient somehow.  (It is (I hope) trivial to
    extend emacsclient to handle suspend/resume.  A `kill -STOP' almost
    works right now.)
 
-** Exiting Emacs while there are emacsclient frames doesn't restore the
-   ttys to their default states.
-
 ** Move baud_rate to struct display.
 
 ** Implement support for starting an interactive Emacs session without
@@ -187,6 +197,8 @@
    single_kboard mode, and is not easily solvable.  The best thing to
    do is to simply refuse to create a tty frame of type `eterm'.
 
+** Maybe standard-display-table should be display-local.
+
 DIARY OF CHANGES
 ----------------
 
@@ -545,4 +557,14 @@
    Note that the above strace output seems to be an unrelated but
    similar bug.  I think that is now fixed.)
 
+-- Exiting Emacs while there are emacsclient frames doesn't restore the
+   ttys to their default states.
+
+   (This seems to be fixed by some previous change.)
+
+-- Allow opening an X session after -nw.
+
+   (Done.)
+
+
 ;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d
--- a/lisp/cus-face.el	Sun Jan 11 11:26:00 2004 +0000
+++ b/lisp/cus-face.el	Sun Jan 11 21:59:40 2004 +0000
@@ -41,6 +41,7 @@
 	;; If the user has already created the face, respect that.
 	(let ((value (or (get face 'saved-face) spec))
 	      (frames (frame-list))
+	      (have-window-system (memq initial-window-system '(x w32)))
 	      frame)
 	  ;; Create global face.
 	  (make-empty-face face)
@@ -48,10 +49,12 @@
 	  (while frames
 	    (setq frame (car frames)
 		  frames (cdr frames))
-	    (face-spec-set face value frame)))
-	;; When making a face after frames already exist
-	(if (memq window-system '(x w32))
-	    (make-face-x-resource-internal face))))
+	    (face-spec-set face value frame)
+	    (when (memq (window-system frame) '(x w32))
+	      (setq have-window-system t)))
+	  ;; When making a face after frames already exist
+	  (if have-window-system
+	      (make-face-x-resource-internal face)))))
     ;; Don't record SPEC until we see it causes no errors.
     (put face 'face-defface-spec spec)
     (when (and doc (null (face-documentation face)))
--- a/lisp/faces.el	Sun Jan 11 11:26:00 2004 +0000
+++ b/lisp/faces.el	Sun Jan 11 21:59:40 2004 +0000
@@ -1658,8 +1658,7 @@
   (setq parameters (x-handle-named-frame-geometry parameters))
   (let ((visibility-spec (assq 'visibility parameters))
 	(frame-list (frame-list))
-	(frame (x-create-frame `((frame-creation-function . x-create-frame-with-faces)
-				 (visibility . nil) . ,parameters)))
+	(frame (x-create-frame `((window-system . x) (visibility . nil) . ,parameters)))
 	success)
     (unwind-protect
 	(progn
@@ -1745,8 +1744,7 @@
 `default-frame-alist'.  If either PARAMETERS or `default-frame-alist'
 contains a `reverse' parameter, handle that.  Value is the new frame
 created."
-  (let ((frame (make-terminal-frame `((frame-creation-function . tty-create-frame-with-faces) .
-				      ,parameters)))
+  (let ((frame (make-terminal-frame `((window-system . nil) . ,parameters)))
 	success)
     (unwind-protect
 	(progn
--- a/lisp/frame.el	Sun Jan 11 11:26:00 2004 +0000
+++ b/lisp/frame.el	Sun Jan 11 21:59:40 2004 +0000
@@ -27,12 +27,17 @@
 
 ;;; Code:
 
-(defvar frame-creation-function nil
-  "Window-system dependent function to call to create a new frame.
-The window system startup file should set this to its frame creation
-function, which should take an alist of parameters as its argument.")
-
-(make-variable-frame-local 'frame-creation-function)
+(defvar frame-creation-function-alist
+  (list (cons nil
+	      (if (fboundp 'tty-create-frame-with-faces)
+		  'tty-create-frame-with-faces
+		(function
+		 (lambda (parameters)
+		   (error "Can't create multiple frames without a window system"))))))
+  "Alist of window-system dependent functions to call to create a new frame.
+The window system startup file should add its frame creation
+function to this list, which should take an alist of parameters
+as its argument.")
 
 ;; The initial value given here used to ask for a minibuffer.
 ;; But that's not necessary, because the default is to have one.
@@ -188,7 +193,9 @@
 (defun frame-initialize ()
   "Create an initial frame if necessary."
   ;; Are we actually running under a window system at all?
-  (if (and window-system (not noninteractive) (not (eq window-system 'pc)))
+  (if (and initial-window-system
+	   (not noninteractive)
+	   (not (eq initial-window-system 'pc)))
       (progn
 	;; Turn on special-display processing only if there's a window system.
 	(setq special-display-function 'special-display-popup-frame)
@@ -205,6 +212,9 @@
 		  (setq frame-initial-frame-alist
 			(cons '(horizontal-scroll-bars . t)
 			      frame-initial-frame-alist)))
+	      (setq frame-initial-frame-alist
+		    (cons (cons 'window-system initial-window-system)
+			  frame-initial-frame-alist))
 	      (setq default-minibuffer-frame
 		    (setq frame-initial-frame
 			  (make-frame frame-initial-frame-alist)))
@@ -217,18 +227,7 @@
 	;; At this point, we know that we have a frame open, so we
 	;; can delete the terminal frame.
 	(delete-frame terminal-frame)
-	(setq terminal-frame nil))
-
-    ;; No, we're not running a window system.  Use make-terminal-frame if
-    ;; we support that feature, otherwise arrange to cause errors.
-    (or (eq window-system 'pc)
-	(setq frame-creation-function
-	      (if (fboundp 'tty-create-frame-with-faces)
-		  'tty-create-frame-with-faces
-		(function
-		 (lambda (parameters)
-		   (error
-		    "Can't create multiple frames without a window system"))))))))
+	(setq terminal-frame nil))))
 
 (defvar frame-notice-user-settings t
   "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
@@ -278,7 +277,7 @@
 	;; Can't modify the minibuffer parameter, so don't try.
 	(setq parms (delq (assq 'minibuffer parms) parms))
 	(modify-frame-parameters nil
-				 (if (null window-system)
+				 (if (null initial-window-system)
 				     (append initial-frame-alist
 					     default-frame-alist
 					     parms
@@ -287,7 +286,7 @@
 				   ;; default-frame-alist were already
 				   ;; applied in pc-win.el.
 				   parms))
-	(if (null window-system) ;; MS-DOS does this differently in pc-win.el
+	(if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el
 	    (let ((newparms (frame-parameters))
 		  (frame (selected-frame)))
 	      (tty-handle-reverse-video frame newparms)
@@ -571,26 +570,18 @@
   (interactive "sMake frame on display: ")
   (or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
       (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
-  (make-frame (cons (cons 'display display) parameters)))
+  (load (concat term-file-prefix "x-win"))
+  (make-frame `((window-system . x) (display . ,display) . ,parameters)))
 
-;;;###autoload
 (defun make-frame-on-tty (device type &optional parameters)
   "Make a frame on terminal DEVICE which is of type TYPE (e.g., \"xterm\").
-The optional third argument PARAMETERS specifies additional frame parameters.
-
-DEVICE must be a proxy psudo terminal created by emacsclient,
-otherwise there will be problems with terminal input and window
-resizes. (The kernel notifies processes about pending input or
-terminal resizes only on the controlling terminal, so we need
-emacsclient to sit on the real terminal device, create SIGIO
-signals upon terminal input, and forward SIGWINCH signals to
-us.)"
+The optional third argument PARAMETERS specifies additional frame parameters."
   (interactive "fOpen frame on tty device: \nsTerminal type of %s: ")
   (unless device
     (error "Invalid terminal device"))
   (unless type
     (error "Invalid terminal type"))
-  (tty-create-frame-with-faces (append (list (cons 'tty device) (cons 'tty-type type)) parameters)))
+  (make-frame `((window-system . nil) (tty . ,device) (tty-type . ,type) . ,parameters)))
 
 (defun make-frame-command ()
   "Make a new frame, and select it if the terminal displays only one frame."
@@ -630,12 +621,22 @@
  (minibuffer . only)	The frame should contain only a minibuffer.
  (minibuffer . WINDOW)	The frame should use WINDOW as its minibuffer window.
 
-Before the frame is created (via `frame-creation-function'), functions on the
+ (window-system . nil)	The frame should be displayed on a terminal device.
+ (window-system . x)	The frame should be displayed in an X window.
+
+Before the frame is created (via `frame-creation-function-alist'), functions on the
 hook `before-make-frame-hook' are run.  After the frame is created, functions
 on `after-make-frame-functions' are run with one arg, the newly created frame."
   (interactive)
-  (run-hooks 'before-make-frame-hook)
-  (let ((frame (funcall frame-creation-function parameters)))
+  (let* ((w (if (assq 'window-system parameters)
+		(cdr (assq 'window-system parameters))
+	      window-system))
+	 (frame-creation-function (cdr (assq w frame-creation-function-alist)))
+	 frame)
+    (unless frame-creation-function
+      (error "Don't know how to create a frame on window system %s" w))
+    (run-hooks 'before-make-frame-hook)
+    (funcall frame-creation-function parameters)
     (run-hook-with-args 'after-make-frame-functions frame)
     frame))
 
@@ -780,9 +781,9 @@
     (raise-frame frame)
     (select-frame frame)
     ;; Ensure, if possible, that frame gets input focus.
-    (cond ((eq window-system 'x)
+    (cond ((eq (window-system frame) 'x)
 	   (x-focus-frame frame))
-	  ((eq window-system 'w32)
+	  ((eq (window-system frame) 'w32)
 	   (w32-focus-frame frame)))
     (when focus-follows-mouse
       (set-mouse-position frame (1- (frame-width frame)) 0))))
--- a/lisp/loadup.el	Sun Jan 11 11:26:00 2004 +0000
+++ b/lisp/loadup.el	Sun Jan 11 21:59:40 2004 +0000
@@ -67,6 +67,8 @@
 (setq load-source-file-function 'load-with-code-conversion)
 (load "files")
 
+(load "startup")
+
 (load "cus-face")
 (load "faces")  ; after here, `defface' may be used.
 
@@ -146,7 +148,6 @@
 (message "%s" (garbage-collect))
 (load "menu-bar")
 (load "paths.el")  ;Don't get confused if someone compiled paths by mistake.
-(load "startup")
 (load "emacs-lisp/lisp")
 (load "textmodes/page")
 (load "register")
--- a/lisp/startup.el	Sun Jan 11 11:26:00 2004 +0000
+++ b/lisp/startup.el	Sun Jan 11 21:59:40 2004 +0000
@@ -128,6 +128,13 @@
 (defvar command-line-processed nil
   "Non-nil once command line has been processed.")
 
+(defvar window-system initial-window-system
+  "Name of window system the selected frame is displaying through.
+The value is a symbol--for instance, `x' for X windows.
+The value is nil if the selected frame is on a text-only-terminal.")
+
+(make-variable-frame-local 'window-system)
+
 (defgroup initialization nil
   "Emacs start-up procedure"
   :group 'internal)
@@ -512,9 +519,9 @@
 	;; for instance due to a dense colormap.
 	(when (or frame-initial-frame
 		  ;; If frame-initial-frame has no meaning, do this anyway.
-		  (not (and window-system
+		  (not (and initial-window-system
 			    (not noninteractive)
-			    (not (eq window-system 'pc)))))
+			    (not (eq initial-window-system 'pc)))))
 	  ;; Modify the initial frame based on what .emacs puts into
 	  ;; ...-frame-alist.
 	  (if (fboundp 'frame-notice-user-settings)
@@ -527,7 +534,7 @@
 	      (let ((frame-background-mode frame-background-mode)
 		    (frame (selected-frame))
 		    term)
-		(when (and (null window-system)
+		(when (and (null initial-window-system)
 			   ;; Don't override a possibly customized value.
 			   (null frame-background-mode)
 			   ;; Don't override user specifications.
@@ -702,9 +709,9 @@
 
   ;; Read window system's init file if using a window system.
   (condition-case error
-      (if (and window-system (not noninteractive))
+      (if (and initial-window-system (not noninteractive))
 	  (load (concat term-file-prefix
-			(symbol-name window-system)
+			(symbol-name initial-window-system)
 			"-win")
 		;; Every window system should have a startup file;
 		;; barf if we can't find it.
@@ -725,7 +732,7 @@
                              (cdr error) ", "))))
       'external-debugging-output)
      (terpri 'external-debugging-output)
-     (setq window-system nil)
+     (setq initial-window-system nil)
      (kill-emacs)))
 
   ;; Windowed displays do this inside their *-win.el.
@@ -808,7 +815,7 @@
 
   ;; If frame was created with a menu bar, set menu-bar-mode on.
   (unless (or noninteractive
-              (and (memq window-system '(x w32))
+              (and (memq initial-window-system '(x w32))
                    (<= (frame-parameter nil 'menu-bar-lines) 0)))
     (menu-bar-mode 1))
 
@@ -818,10 +825,10 @@
               (<= (frame-parameter nil 'tool-bar-lines) 0))
     (tool-bar-mode 1))
 
-  ;; Can't do this init in defcustom because window-system isn't set.
+  ;; Can't do this init in defcustom because initial-window-system isn't set.
   (unless (or noninteractive
               (eq system-type 'ms-dos)
-              (not (memq window-system '(x w32))))
+              (not (memq initial-window-system '(x w32))))
     (setq-default blink-cursor t)
     (blink-cursor-mode 1))
 
@@ -829,13 +836,13 @@
     ;; DOS/Windows systems have a PC-type keyboard which has both
     ;; <delete> and <backspace> keys.
     (when (or (memq system-type '(ms-dos windows-nt))
-	      (and (memq window-system '(x))
+	      (and (memq initial-window-system '(x))
 		   (fboundp 'x-backspace-delete-keys-p)
 		   (x-backspace-delete-keys-p))
 	      ;; If the terminal Emacs is running on has erase char
 	      ;; set to ^H, use the Backspace key for deleting
 	      ;; backward and, and the Delete key for deleting forward.
-	      (and (null window-system)
+	      (and (null initial-window-system)
 		   (eq tty-erase-char 8)))
       (setq-default normal-erase-is-backspace t)
       (normal-erase-is-backspace-mode 1)))
@@ -848,7 +855,7 @@
 
   ;; Register default TTY colors for the case the terminal hasn't a
   ;; terminal init file.
-  (unless (memq window-system '(x w32))
+  (unless (memq initial-window-system '(x w32))
     ;; We do this regardles of whether the terminal supports colors
     ;; or not, since they can switch that support on or off in
     ;; mid-session by setting the tty-color-mode frame parameter.
@@ -1046,7 +1053,7 @@
   ;; Load library for our terminal type.
   ;; User init file can set term-file-prefix to nil to prevent this.
   (unless (or noninteractive
-              window-system
+              initial-window-system
               (null term-file-prefix))
     (let ((term (getenv "TERM"))
           hyphend)
--- a/lisp/term/x-win.el	Sun Jan 11 11:26:00 2004 +0000
+++ b/lisp/term/x-win.el	Sun Jan 11 21:59:40 2004 +0000
@@ -66,7 +66,7 @@
 ;; An alist of X options and the function which handles them.  See
 ;; ../startup.el.
 
-(if (not (eq window-system 'x))
+(if (not (fboundp 'x-create-frame))
     (error "%s: Loading x-win.el but not compiled for X" (invocation-name)))
 
 (require 'frame)
@@ -1159,6 +1159,7 @@
 
 ;;;; Function keys
 
+;;; XXX This might be wrong with multi-tty support.
 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
 			   global-map)
 
@@ -2346,10 +2347,11 @@
 (x-open-connection (or x-display-name
 		       (setq x-display-name (getenv "DISPLAY")))
 		   x-command-line-resources
-		   ;; Exit Emacs with fatal error if this fails.
-		   t)
+		   ;; Exit Emacs with fatal error if this fails and we
+		   ;; are the initial display.
+		   (eq initial-window-system 'x))
 
-(setq frame-creation-function 'x-create-frame-with-faces)
+(add-to-list 'frame-creation-function-alist '(x . x-create-frame-with-faces))
 
 (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
 			    x-cut-buffer-max))
@@ -2431,6 +2433,7 @@
   (if res-selection-timeout
       (setq x-selection-timeout (string-to-number res-selection-timeout))))
 
+;; XXX This is wrong with multi-tty support.
 (defun x-win-suspend-error ()
   (error "Suspending an Emacs running under X makes no sense"))
 (add-hook 'suspend-hook 'x-win-suspend-error)
@@ -2453,5 +2456,7 @@
 ;; Turn on support for mouse wheels.
 (mouse-wheel-mode 1)
 
+(provide 'x-win)
+
 ;;; arch-tag: f1501302-db8b-4d95-88e3-116697d89f78
 ;;; x-win.el ends here
--- a/src/dispnew.c	Sun Jan 11 11:26:00 2004 +0000
+++ b/src/dispnew.c	Sun Jan 11 21:59:40 2004 +0000
@@ -214,9 +214,9 @@
 EMACS_INT baud_rate;
 
 /* Either nil or a symbol naming the window system under which Emacs
-   is running.  */
-
-Lisp_Object Vwindow_system;
+   creates the first frame.  */
+
+Lisp_Object Vinitial_window_system;
 
 /* Version number of X windows: 10, 11 or nil.  */
 
@@ -6569,7 +6569,7 @@
 
   /* 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
@@ -6598,7 +6598,7 @@
 #endif
      )
     {
-      Vwindow_system = intern ("x");
+      Vinitial_window_system = intern ("x");
 #ifdef HAVE_X11
       Vwindow_system_version = make_number (11);
 #else
@@ -6618,7 +6618,7 @@
 #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;
@@ -6628,7 +6628,7 @@
 #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;
@@ -6730,7 +6730,7 @@
 	 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.  */
@@ -6842,8 +6842,8 @@
 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.  */);
 
@@ -6879,7 +6879,7 @@
   if (noninteractive)
 #endif
     {
-      Vwindow_system = Qnil;
+      Vinitial_window_system = Qnil;
       Vwindow_system_version = Qnil;
     }
 }
--- a/src/emacs.c	Sun Jan 11 11:26:00 2004 +0000
+++ b/src/emacs.c	Sun Jan 11 21:59:40 2004 +0000
@@ -192,7 +192,7 @@
 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;
@@ -2017,9 +2017,9 @@
 #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 */
--- a/src/keyboard.c	Sun Jan 11 11:26:00 2004 +0000
+++ b/src/keyboard.c	Sun Jan 11 21:59:40 2004 +0000
@@ -10503,8 +10503,7 @@
 
 #ifndef DOS_NT
   /* this causes startup screen to be restored and messes with the mouse */
-  if (FRAME_TERMCAP_P (SELECTED_FRAME ()))
-    reset_sys_modes (CURTTY ());
+  reset_all_sys_modes ();
 #endif
 
 #ifdef SIGIO
@@ -10542,13 +10541,12 @@
         tty->meta_key = 2;
     }
   
-  if (FRAME_TERMCAP_P (XFRAME (selected_frame)) && !NILP (quit))
+  if (!NILP (quit))
     /* Don't let this value be out of range.  */
-    quit_char = XINT (quit) & (CURTTY ()->meta_key ? 0377 : 0177);
+    quit_char = XINT (quit) & (NILP (meta) ? 0177 : 0377);
 
 #ifndef DOS_NT
-  if (FRAME_TERMCAP_P (XFRAME (selected_frame)) && CURTTY ()->type)
-    init_sys_modes (CURTTY ());
+  init_all_sys_modes ();
 #endif
 
 #ifdef POLL_FOR_INPUT
--- a/src/sysdep.c	Sun Jan 11 11:26:00 2004 +0000
+++ b/src/sysdep.c	Sun Jan 11 21:59:40 2004 +0000
@@ -1394,267 +1394,261 @@
 #if 0
   /* read_socket_hook is not global anymore.  I think doing this
      unconditionally will not cause any problems. */
-  if (! read_socket_hook && EQ (Vwindow_system, Qnil))
+  if (! read_socket_hook && EQ (Vinitial_window_system, Qnil))
 #endif
     narrow_foreground_group (fileno (TTY_INPUT (tty_out)));
 #endif
 
-#ifdef HAVE_WINDOW_SYSTEM
-  /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
-     needs the initialization code below.  */
-  if (tty_out->input != stdin || EQ (Vwindow_system, Qnil))
-#endif
-    {
-      if (! tty_out->old_tty)
-        tty_out->old_tty = (struct emacs_tty *) xmalloc (sizeof (struct emacs_tty));
+  if (! tty_out->old_tty)
+    tty_out->old_tty = (struct emacs_tty *) xmalloc (sizeof (struct emacs_tty));
       
-      EMACS_GET_TTY (fileno (TTY_INPUT (tty_out)), tty_out->old_tty);
-
-      tty = *tty_out->old_tty;
+  EMACS_GET_TTY (fileno (TTY_INPUT (tty_out)), tty_out->old_tty);
+
+  tty = *tty_out->old_tty;
 
 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
-      XSETINT (Vtty_erase_char, 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 (tty_out->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 (tty_out->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.  */
-          tty.main.c_cc[VQUIT] = quit_char;
-        }
-      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.  */
+  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.  */
+      tty.main.c_cc[VQUIT] = quit_char;
+    }
+  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 (tty_out->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 (tty_out->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 (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;
+  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 (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;
+  /* 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 (!tty_out->term_initted)
-	internal_terminal_init ();
-      dos_ttraw ();
+  if (!tty_out->term_initted)
+    internal_terminal_init ();
+  dos_ttraw ();
 #endif
 
-      EMACS_SET_TTY (fileno (TTY_INPUT (tty_out)), &tty, 0);
-
-      /* This code added to insure that, if flow-control is not to be used,
-	 we have an unlocked terminal at the start. */
+  EMACS_SET_TTY (fileno (TTY_INPUT (tty_out)), &tty, 0);
+
+  /* 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 (!tty_out->flow_control) ioctl (fileno (TTY_INPUT (tty_out)), TCXONC, 1);
+  if (!tty_out->flow_control) ioctl (fileno (TTY_INPUT (tty_out)), TCXONC, 1);
 #endif
 #ifndef APOLLO
 #ifdef TIOCSTART
-      if (!tty_out->flow_control) ioctl (fileno (TTY_INPUT (tty_out)), TIOCSTART, 0);
+  if (!tty_out->flow_control) ioctl (fileno (TTY_INPUT (tty_out)), TIOCSTART, 0);
 #endif
 #endif
 
 #if defined (HAVE_TERMIOS) || defined (HPUX9)
 #ifdef TCOON
-      if (!tty_out->flow_control) tcflow (fileno (TTY_INPUT (tty_out)), TCOON);
+  if (!tty_out->flow_control) tcflow (fileno (TTY_INPUT (tty_out)), TCOON);
 #endif
 #endif
 
 #ifdef AIXHFT
-      hft_init (tty_out);
+  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 */
 
@@ -1663,15 +1657,13 @@
       SYS$QIOW (0, fileno (TTY_INPUT (tty_out)), 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
-      && (tty_out->input != stdin || EQ (Vwindow_system, Qnil)))
+  if (interrupt_input)
     {
       old_fcntl_owner[fileno (TTY_INPUT (tty_out))] =
         fcntl (fileno (TTY_INPUT (tty_out)), F_GETOWN, 0);
@@ -1699,20 +1691,7 @@
   setbuf (TTY_OUTPUT (tty_out), (char *) _sobuf);
 #endif
 
-#if 0                /* We always need this with multi-tty support. */
-#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)
-#endif
-      )
-#endif
-#endif
-    tty_set_terminal_modes (tty_out->display);
+  tty_set_terminal_modes (tty_out->display);
 
   if (!tty_out->term_initted)
     {
@@ -1875,21 +1854,6 @@
     }
   if (!tty_out->term_initted)
     return;
-#if 0                           /* We always need to do this with multi-tty support. */
-#ifdef HAVE_WINDOW_SYSTEM
-  /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
-     needs the clean-up code below.  */
-  if (tty_out->input != stdin
-      || (!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
-#endif
   
   cmgoto (tty_out, FrameRows (tty_out) - 1, 0);
 #if 0  /* XXX This doesn't work anymore, the signature has changed. */
@@ -2578,7 +2542,9 @@
      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;
@@ -2593,7 +2559,7 @@
 #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;
@@ -2717,8 +2683,8 @@
 void
 read_input_waiting ()
 {
-  /* XXX This needs to be updated for multi-tty support.  Does
-     anybody need to emulate select these days?  */
+  /* 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;
 
--- a/src/window.h	Sun Jan 11 11:26:00 2004 +0000
+++ b/src/window.h	Sun Jan 11 21:59:40 2004 +0000
@@ -744,7 +744,7 @@
 /* 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.  */
 
--- a/src/xfns.c	Sun Jan 11 11:26:00 2004 +0000
+++ b/src/xfns.c	Sun Jan 11 21:59:40 2004 +0000
@@ -3188,8 +3188,6 @@
   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;
@@ -4124,8 +4122,10 @@
 
   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;
@@ -4172,8 +4172,10 @@
   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);