Function: frameset-move-onscreen
frameset-move-onscreen is a byte-compiled function defined in
frameset.el.gz.
Signature
(frameset-move-onscreen FRAME FORCE-ONSCREEN)
Documentation
If FRAME is offscreen, move it back onscreen and, if necessary, resize it.
For the description of FORCE-ONSCREEN, see frameset-restore.
When forced onscreen, frames wider than the monitor's workarea are converted
to fullwidth, and frames taller than the workarea are converted to fullheight.
NOTE: This only works for non-iconified frames.
Source Code
;; Defined in /usr/src/emacs/lisp/frameset.el.gz
(defun frameset-move-onscreen (frame force-onscreen)
"If FRAME is offscreen, move it back onscreen and, if necessary, resize it.
For the description of FORCE-ONSCREEN, see `frameset-restore'.
When forced onscreen, frames wider than the monitor's workarea are converted
to fullwidth, and frames taller than the workarea are converted to fullheight.
NOTE: This only works for non-iconified frames."
(pcase-let* ((`(,left ,top ,width ,height) (cdadr (frame-monitor-attributes frame)))
(right (+ left width -1))
(bottom (+ top height -1))
(fr-left (frameset-compute-pos (frame-parameter frame 'left) left right))
(fr-top (frameset-compute-pos (frame-parameter frame 'top) top bottom))
(ch-width (frame-char-width frame))
(ch-height (frame-char-height frame))
(fr-width (max (frame-pixel-width frame) (* ch-width (frame-width frame))))
(fr-height (max (frame-pixel-height frame) (* ch-height (frame-height frame))))
(fr-right (+ fr-left fr-width -1))
(fr-bottom (+ fr-top fr-height -1)))
(when (pcase force-onscreen
;; A predicate.
((pred functionp)
(funcall force-onscreen
frame
(list fr-left fr-top fr-width fr-height)
(list left top width height)))
;; Any corner is outside the screen.
(:all (or (< fr-bottom top) (> fr-bottom bottom)
(< fr-left left) (> fr-left right)
(< fr-right left) (> fr-right right)
(< fr-top top) (> fr-top bottom)))
;; Displaced to the left, right, above or below the screen.
('t (or (> fr-left right)
(< fr-right left)
(> fr-top bottom)
(< fr-bottom top)))
;; Fully inside, no need to do anything.
(_ nil))
(let ((fullwidth (> fr-width width))
(fullheight (> fr-height height))
(params nil))
;; Position frame horizontally.
(cond (fullwidth
(push `(left . ,left) params))
((> fr-right right)
(push `(left . ,(+ left (- width fr-width))) params))
((< fr-left left)
(push `(left . ,left) params)))
;; Position frame vertically.
(cond (fullheight
(push `(top . ,top) params))
((> fr-bottom bottom)
(push `(top . ,(+ top (- height fr-height))) params))
((< fr-top top)
(push `(top . ,top) params)))
;; Compute fullscreen state, if required.
(when (or fullwidth fullheight)
(push (cons 'fullscreen
(cond ((not fullwidth) 'fullheight)
((not fullheight) 'fullwidth)
(t 'maximized)))
params))
;; Finally, move the frame back onscreen.
(when params
(modify-frame-parameters frame params))))))