;;; -*- Mode: Common-Lisp; Package: User; Base: 10.; Patch-File: T -*-

;;; Reason: Fixes problem where Explorer temporary windows such as
;;;  TERM-G and TERM-N get overwritten by X. SPR 9706.

;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 2909, M/S 2151             
;;;   AUSTIN, TEXAS 78769                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Written 11/10/89 10:45:57 by HAGY,
;;; Code read by TWE
;;; while running on Zwingli from band LOD1
;;; With SYSTEM 6.15, VIRTUAL-MEMORY 6.1, EH 6.4, MAKE-SYSTEM 6.0, MICRONET 6.0, LOCAL-FILE 6.0,
;;;  BASIC-PATHNAME 6.1, NETWORK-SUPPORT-COLD 6.0, BASIC-NAMESPACE 6.2, NETWORK-NAMESPACE 6.0,
;;;  DISK-IO 6.1, DISK-LABEL 6.0, BASIC-FILE 6.2, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.0,
;;;  COMPILER 6.10, TV 6.15, DATALINK 6.0, CHAOSNET 6.0, GC 6.3, MEMORY-AUX 6.0, NVRAM 6.1,
;;;  SYSLOG 6.1, STREAMER-TAPE 6.4, UCL 6.0, INPUT-EDITOR 6.0, METER 6.1, ZWEI 6.5,
;;;  DEBUG-TOOLS 6.3, NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.1, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.3, MAC-PRINTER-TYPES 6.1, PRINTER-TYPES 6.1,
;;;  IMAGEN 6.0, SUGGESTIONS 6.0, MAIL-DAEMON 6.2, MAIL-READER 6.2, TELNET 6.0, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.0, PROFILE 6.1, VISIDOC 6.4, TI-CLOS 6.20, CLEH 6.5, IP 3.47,
;;;  Experimental CLX 6.2, CLUE 6.10, X11M 6.15, Experimental BUG 11.15,  microcode 429,
;;;  Band Name: Rel 6.0 + SLE 9/8

#!C
; From file SYSDEPENDENT.LISP#> X11M.SERVER; SYS:
#10R X11#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "X11"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* SYS:COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: X11M.SERVER; SYSDEPENDENT.#"


(DEFUN DEVICE-PRIVATE-WINDOW-ARRAY (WINDOW)
  "Gets the screen array for an X window."
  ;; The window has a visual, which is an atom.  We use this atom to obtain the
  ;; visual object.  The visual object has a screen, which is also an atom.  We
  ;; use this atom to obtain the screen object.  The screen has a dev-private
  ;; which is an Explorer window instance.
  (LET* ((sheet (SCREEN.DEV-PRIVATE (GETHASH (VISUAL.SCREEN
					       (GETHASH (WINDOW.VISUAL WINDOW)
							*RESOURCES*))
					     *RESOURCES*)))
	 (screen-array (W:SHEET-SCREEN-ARRAY sheet))
	 lock)
    ;; HACK ALERT!!  THIS WILL NOT WORK WITH CLOS!!!  If we have a color system and are using
    ;; the monochrome server (assumed) then we return the expansion mode buffer from the cold
    ;; load stream.  (TWE)
    (IF (EQ (ARRAY-TYPE SCREEN-ARRAY) 'ART-8B)
        (SYMEVAL-IN-INSTANCE SI:COLD-LOAD-STREAM 'ARRAY)
        ;;ELSE
	;; NOTE: The following is for monchrome only. It will
	;;  not work for a color system because the temporary
	;;  bit array would be an ART8B array in that case.
	;; If the window is locked by an Explorer pop up window,
	;;  use the temporary bit array of the pop up window. This
	;;  is a "save under" kind of array whose contents will be
	;;  restored to the screen when the pop up window goes away.
	(IF (setf lock (W:SHEET-LOCK sheet))
	    (PROGN
	      (WHEN (LISTP lock)
		(setf lock (CAR lock)))
	      (IF (AND (SYS:SEND-IF-HANDLES lock :temporary-bit-array)
		              ;; send-if-handles used because locker
		              ;;  may not always be a window
		       (>= (W:SHEET-WIDTH lock) (W:SHEET-WIDTH sheet))
		       (>= (W:SHEET-HEIGHT lock) (W:SHEET-HEIGHT sheet)))
		  (TV:SHEET-TEMPORARY-BIT-ARRAY lock)
		  ;; If no temporary bit array in locking window or
		  ;;  locking window is smaller, just use screen array
		  SCREEN-ARRAY))
	    SCREEN-ARRAY))))
))
