Compare commits

...

5 Commits

1 changed files with 19 additions and 11 deletions

View File

@ -1,7 +1,12 @@
;;; pip-frame.el --- PIP frame support -*- lexical-binding: t -*-
;;; pip-frame.el --- Display and manage a PIP frame -*- lexical-binding: t -*-
;; Copyright (C) 2022 Milan Zamazal <pdm@zamazal.org>
;; Author: Milan Zamazal <pdm@zamazal.org>
;; Package-Version: 1
;; Keywords: frames
;; URL: https://git.zamazal.org/pdm/pip-frame
;; COPYRIGHT NOTICE
;;
;; This program is free software: you can redistribute it and/or modify
@ -17,6 +22,8 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Display a floating Emacs frame with selected buffers.
;; Similar to PIP on screens. Probably most useful in EXWM.
;;
@ -28,7 +35,8 @@
(require 'cl-lib)
(defgroup pip-frame ()
"Display PIP frame.")
"Display PIP frame."
:group 'frames)
(defcustom pip-frame-scale 4
"How many times to shrink the PIP frame relative to the display size."
@ -71,7 +79,7 @@ custom option but it can be overriden here."
(defun pip-frame--get-frame (&optional no-error)
(let ((frame (cl-find pip-frame--name (frame-list)
:key #'(lambda (f) (frame-parameter f 'name)))))
:key (lambda (f) (frame-parameter f 'name)))))
(or frame
(unless no-error
(error "No PIP frame")))))
@ -85,8 +93,8 @@ custom option but it can be overriden here."
(frame-inhibit-implied-resize t)
(face-height (round (/ (face-attribute 'default :height) pip-frame-font-scale))))
(set-face-attribute 'default frame :height face-height)
(mapc #'(lambda (p) (set-face-attribute 'default frame (car p) (cdr p)))
pip-frame-face-attributes)
(dolist (p pip-frame-face-attributes)
(set-face-attribute 'default frame (car p) (cdr p)))
(set-window-buffer (car (window-list frame)) buffer)
frame))
@ -102,11 +110,11 @@ custom option but it can be overriden here."
(let ((windows (window-list (pip-frame--get-frame))))
(unless (and temporary
(cl-find buffer windows :key #'window-buffer :test #'eq))
(let* ((sizes (mapcar #'(lambda (w)
(let ((width (window-body-width w t))
(height (window-body-height w t)))
(cons (+ (* width width) (* height height))
w)))
(let* ((sizes (mapcar (lambda (w)
(let ((width (window-body-width w t))
(height (window-body-height w t)))
(cons (+ (* width width) (* height height))
w)))
windows))
(largest (cdr (cl-first (cl-sort sizes #'> :key #'car))))
(side (if (> (window-body-width largest t)
@ -170,7 +178,7 @@ If the buffer is not present in the PIP frame, do nothing."
:test-not #'eq)))
(if (= (length windows-to-delete) (length windows))
(pip-frame-delete-frame)
(mapc #'delete-window windows-to-delete))))
(seq-do #'delete-window windows-to-delete))))
(defun pip-frame--move (x y)
(let ((frame (pip-frame--get-frame)))