🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.epoch.misc
Article #1903

Re: minibuf.el maddness

#1903
From: Heinz Schmidt
Date: Mon, 01 Jul 1991 02:12
277 lines
11355 bytes
cfr@u02.svl.cdc.com (Chet Richards) writes:

  > tynor@prism.gatech.EDU (STEVE TYNOR) writes:
  >
  > >I'm using twm as my window manager (though olwm and gwm seem to have the
  > >same problem). I'm using the minibuf.el code to make the minibuf attach
  [...]
  > I found that the problem appears to be timing related, thus it appears
  > intermittently.  It seemed to be easier to reproduce if my window manager
  > were running on a faster machine than the machine running epoch, but that
  [...]
  > My approach was to allow a delay before asking for the new location, allowing
  > for repeated attempts if the first ones should yield a value not "close
  > "enough".  I encountered a few hangs where it never moved "close enough", so
  [...]

Depending on the speed and load of the machines involved one may not
escape the problem this way.  
Below I include a new version of minibuf.el that takes another
approach.  It postpones minibuffer placement until it sees the first
select request. This happens when you move the mouse into the epoch
screen the first time or simply when the screen comes up under the
mouse. This is based on the belief that minibuffer placement obtains
wrong information when the epoch main screen is not yet up.  (My
guess: the X server can generate move and resize events and yet not
have brought up the X window. When the X application then asks for the
X window position, the corresponding data structures may not yet
reflect the right position).  I have not seen the behavior again for
some time now. But I wouldn't be surprised in case, there's some
guesswork involved.

-- hws
--------------------------------------------------------------------------
Heinz W. Schmidt                                     hws@icsi.berkeley.edu
International Computer Science Institute, Berkeley   (415) 642-4274   x175
on leave from: German Natl Research Ctr for Comp Sci, Bonn

O\ /
o/ \  --------------------------------------------------------------------
#!/bin/sh
# This is a shell archive (shar 3.24)
# made 07/01/1991 01:49 UTC by hws@icsib37
# Source directory /da/hws/emacs/stuff
#
# existing files WILL be overwritten
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   7544 -rw-r--r-- minibuf.el
#
if touch 2>&1 | fgrep '[-amc]' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= minibuf.el ==============
echo "x - extracting minibuf.el (Text)"
sed 's/^X//' << 'SHAR_EOF' > minibuf.el &&
X;;;
X;;; minbuf.el
X;;;
X;;; make the minibuffer screen stay attached to the bottom
X;;; of a particular window. the minibuffer takes on the same
X;;; width and font as the screen it's attached to; it's height
X;;; is unaltered.
X;;;
X;;; the function "anchor-minibuffer-to-selected-screen" can be used
X;;; interactively to attach the minibuffer to the current screen
X;;;
X;;; if the variable *minibuffer-sticks-to-selected-screen-p* is
X;;; non-null, the minibuffer follows the focus (i.e. it attaches
X;;; itself to whichever screen has the input focus).
X;;;
X;;; this file should be loaded after epoch.el, as it hacks the
X;;; event-alist and handle-focus-change
X;;;
X;;; Original author unknown.
X;;; Contributed by Dan L. Pierson, pierson@encore.com
X;;; Reworked by Alan Carroll and Chris Love
X;;; Additions by Heinz W. Schmidt (hws@ICSI.Berkeley.EDU)
X;;;* HISTORY:
X;;;* Last edited: Jun 30 18:37 1991 (hws)
X;;;*  Jun 30 17:50 1991 (hws): remove misleading docu and unused defvar, avoid
X;;;*                           multi positioning at startup (move,resize,select)
X;;;*  May 26 22:48 1991 (hws): anchor resize invisibly
X;;;*  May 20 09:05 1991 (hws): reset-minibuffer on first anchor action
X;;;*  May  7 11:51 1991 (hws): reset-minibuffer command added
X;;;                             and auto-deiconify minibuffer
X
X(require 'mini-cl) 
X
X(defvar *minibuffer-anchor-screen* (current-screen)
X  "The screen that the minibuffer sticks to.")
X
X(defvar *minibuffer-sticks-to-selected-screen-p* t
X  "If non-null, causes the minibuffer to follow the input focus.")
X
X(defvar *minibuffer-anchor-inhibit* nil)
X
X;;; When this file is loaded the current screen may not be exposed.
X;;; So let's postpone the proper setting until the first time, the minibuffer
X;;; really is to move to the right place.
X
X(defvar first-time-after-startup t)
X
X(defun handle-move-event (type event screen)
X  (setq *minibuffer-anchor-screen* (current-screen))
X  (if (and *minibuffer-sticks-to-selected-screen-p*
X	   (not first-time-after-startup))
X    (cond
X      ((eq screen *minibuffer-anchor-screen*)
X	(move-minibuffer-screen-with-anchor-screen)
X	(setq *minibuffer-anchor-inhibit* nil)
X      )
X      ((and (not *minibuffer-anchor-inhibit*) (eq screen (minibuf-screen)))
X	(move-minibuffer-screen-with-anchor-screen)
X	(setq *minibuffer-anchor-inhibit* t)
X      )
X      (t (setq *minibuffer-anchor-inhibit* nil)
X      )))
X  (on-event::handler type event screen))
X
X(push-event 'move 'handle-move-event)
X
X(defun handle-resize-event (type event screen)
X  (setq *minibuffer-anchor-screen* (current-screen))
X  (and *minibuffer-sticks-to-selected-screen-p*
X       (not first-time-after-startup)
X       (or (eq screen *minibuffer-anchor-screen*)
X	   (eq screen (minibuf-screen)))
X       (resize-minibuffer-screen-with-anchor-screen))
X  (on-event::handler type event screen))
X
X(push-event 'resize 'handle-resize-event)
X
X;;; --------------------------------------------------------------------------
X(defvar minibuf-delta-x 0)
X(defvar minibuf-delta-y 0)
X
X(defun backing-screen-info (&optional win)
X"Return the screen information for the backing X-window of the given screen"
X  (setq win (or win (current-screen)))
X  (let ((parent nil)
X	(root   nil)
X	(wlist  nil))
X    (while (and (setq wlist (query-tree win))
X		(setq parent (cadr wlist))
X		(setq root   (car wlist))
X		(not (equal root parent)))
X      (setq win parent))
X    (and parent (screen-information win))))
X
X(defun wm-location-delta (&optional win)
X"Given optional SCREEN-OR-XWIN, this function returns a list of (DX DY)
Xfor how much the window manager changes move-screen requests."
X  (setq win (or win (current-screen)))
X  (let
X    (
X      (start-info (screen-information win))
X      x y dx dy info
X    )
X    (move-screen 0 0 win)		;move it to a fixed location
X    (setq info (screen-information win)) ; where did it actually end up?
X    (setq dx (- (car info)))
X    (setq dy (- (cadr info)))
X    (move-screen (+ (car start-info) dx) (+ (cadr start-info) dy) win)
X    (setq start-wm-loc-delta (list dx dy))
X  ))
X
X;;; Allright, calculate the actual deltas
X;;; Things to account for -
X;;; 1. Size of WM borders
X;;; 2. Size of X window borders
X;;; 3. WM fudging of move requests
X;;;
X
X(defun reset-minibuffer ()
X  "Resets the minibuffer state. Recalculates the window manager
Xspecific information like title-bar offsets etc. Also
Xdeiconizes the minibuffer and puts it back in place."
X  (interactive)
X  (requires-screen-visible (minibuf-screen))
X  (let*
X      ((minfo (screen-information (minibuf-screen)))
X       (mbinfo (backing-screen-info (minibuf-screen)))
X       ;; When this is called the minibuffer may be
X       ;; the selected screen, but then 
X       (screen (if (eq (current-screen) (minibuf-screen))
X		   (car (screen-list))
X		 (current-screen)))
X       (einfo (screen-information screen))
X       (ebinfo (backing-screen-info screen))
X       (wm-fudge (wm-location-delta (minibuf-screen))))
X    (setq minibuf-delta-x
X	  (+
X	   ;; for now, just line up the edge of the edit screen with the edge of
X	   ;; the minibuffer screen, so only account for the WM fudge factor.
X	   (car wm-fudge)
X	   ))
X    (setq minibuf-delta-y
X	  (+
X	   (cadr wm-fudge)
X	   ;; size of the minibuffer title
X	   (- (nth 1 minfo) (nth 1 mbinfo))
X	   ;; the size of the bottom bar on the edit screen
X	   (- (+ (nth 1 ebinfo) (nth 3 ebinfo)) (+ (nth 1 einfo) (nth 3 einfo)))
X	   (nth 4 mbinfo)		; borders
X	   (nth 4 ebinfo)
X	   ))))
X
X;;; --------------------------------------------------------------------------
X
X(defun requires-screen-visible (win)
X  (if (not (screen-mapped-p win)) (epoch::iconify-screen win)))
X
X(defun move-minibuffer-screen-with-anchor-screen ()
X  (requires-screen-visible (minibuf-screen))
X  (let* ((mbscreen (minibuf-screen))
X	 (info (screen-information *minibuffer-anchor-screen*))
X	 )
X    (move-screen
X     (+ (car info) minibuf-delta-x)
X     (+ (nth 1 info) (nth 3 info) minibuf-delta-y)
X     mbscreen)
X    ))
X
X(defun resize-minibuffer-screen-with-anchor-screen ()
X  (requires-screen-visible (minibuf-screen))
X  (let* ((char-width (epoch::screen-width *minibuffer-anchor-screen*))
X	 (mbscreen (minibuf-screen))
X	 (font (car (font nil *minibuffer-anchor-screen*)))
X	 (mbfont (car (font nil mbscreen)))
X	 )
X    (move-minibuffer-screen-with-anchor-screen)
X    ;; make the minibuffer have the same font as the screen it's attached to
X    (when (and font mbfont (not (string= font mbfont)))
X      (font font mbscreen))
X    (change-screen-size char-width nil mbscreen)
X    ))
X
X(defun anchor-minibuffer-to-selected-screen ()
X  "Make the minibuffer stick to the current screen."
X  (interactive)
X  (requires-screen-visible (minibuf-screen))
X  (cond (first-time-after-startup
X	 (reset-minibuffer)
X	 (resize-minibuffer-screen-with-anchor-screen)
X	 (setq first-time-after-startup nil)))
X  (cond ((not (eq *minibuffer-anchor-screen* (current-screen)))
X	 (setq *minibuffer-anchor-screen* (current-screen))
X	 (and *minibuffer-sticks-to-selected-screen-p*
X	      (progn (unmap-screen (minibuf-screen))
X		     (resize-minibuffer-screen-with-anchor-screen)
X		     (map-screen (minibuf-screen)))))))
X
X;;Avoid this, there are other hooks around, too
X;;(setq *select-screen-hook* 'anchor-minibuffer-to-selected-screen)
X(if (not (memq 'anchor-minibuffer-to-selected-screen
X	       *select-screen-hook*))
X    (push 'anchor-minibuffer-to-selected-screen *select-screen-hook*))
X
X(defun iconify-emacs ()
X  "Iconifies all screens of this emacs process."
X  (interactive)
X  (dolist (s (screen-list))
X    (iconify-screen s))
X  (iconify-screen (minibuf-screen)))
SHAR_EOF
$TOUCH -am 0630183791 minibuf.el &&
chmod 0644 minibuf.el ||
echo "restore of minibuf.el failed"
set `wc -c minibuf.el`;Wc_c=$1
if test "$Wc_c" != "7544"; then
	echo original size 7544, current size $Wc_c
fi
exit 0
Technical Details
Message-ID: <9107010212.AA24934@icsib37.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!spool.mu.edu!caen!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!icsi.berkeley.edu!hws

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fc7ee,f2fcf3e3070146f2
X-Google-Attributes: gidfc7ee,public
X-Google-ArrivalTime: 1991-07-01 01:38:11 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!spool.mu.edu!caen!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!icsi.berkeley.edu!hws
From: hws@icsi.berkeley.edu (Heinz Schmidt)
Newsgroups: gnu.epoch.misc
Subject: Re: minibuf.el maddness
Message-ID: <9107010212.AA24934@icsib37.Berkeley.EDU>
Date: 1 Jul 91 02:12:47 GMT
Sender: daemon@cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 277