Compare commits

...

5 Commits

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