Function: corfu--make-frame

corfu--make-frame is a byte-compiled function defined in corfu.el.

Signature

(corfu--make-frame FRAME X Y WIDTH HEIGHT)

Documentation

Show current buffer in child frame at X/Y with WIDTH/HEIGHT.

FRAME is the existing frame.

Source Code

;; Defined in ~/.emacs.d/elpa/corfu-20260813.950/corfu.el
;; Function adapted from posframe.el by tumashu
(defun corfu--make-frame (frame x y width height)
  "Show current buffer in child frame at X/Y with WIDTH/HEIGHT.
FRAME is the existing frame."
  (when-let* (((frame-live-p frame))
              (timer (frame-parameter frame 'corfu--hide-timer)))
    (cancel-timer timer)
    (set-frame-parameter frame 'corfu--hide-timer nil))
  (let* ((window-min-height 1)
         (window-min-width 1)
         (inhibit-redisplay t)
         (x-fast-protocol-requests t)
         (x-gtk-resize-child-frames corfu--gtk-resize-child-frames)
         (before-make-frame-hook)
         (after-make-frame-functions)
         (parent (window-frame))
         (graphic (display-graphic-p parent))
         (params `((background-color
                    . ,(face-attribute 'corfu-default :background nil 'default))
                   (font . ,(frame-parameter parent 'font))
                   (right-fringe . ,right-fringe-width)
                   (left-fringe . ,left-fringe-width)
                   (internal-border-width . ,corfu-border-width)
                   (child-frame-border-width . ,corfu-border-width)
                   ,@corfu--frame-parameters)))
    (unless (and (frame-live-p frame)
                 (eq (frame-parent frame)
                     (and (not (and graphic (bound-and-true-p exwm--connection)))
                          parent))
                 ;; Handle mixed tty/graphical sessions
                 (eq graphic (display-graphic-p frame))
                 ;; If there is more than one window, `frame-root-window' may
                 ;; return nil.  Recreate the frame in this case.
                 (window-live-p (frame-root-window frame)))
      (when frame (delete-frame frame))
      (setq frame (make-frame
                   `((name . ,(if graphic "EmacsCorfuGUI" "EmacsCorfuTTY"))
                     (parent-frame . ,parent)
                     (minibuffer . ,(minibuffer-window parent))
                     (width . 0) (height . 0) (visibility . nil)
                     ,@params))))
    ;; XXX HACK Setting the same frame-parameter/face-background is not a nop.
    ;; Check before applying the setting. Without the check, the frame flickers
    ;; on Mac. We have to apply the face background before adjusting the frame
    ;; parameter, otherwise the border is not updated.
    (let ((new (face-attribute 'corfu-border :background nil 'default)))
      (unless (equal (face-attribute 'internal-border :background frame 'default) new)
        (set-face-background 'internal-border new frame))
      ;; XXX The Emacs Mac Port does not support `internal-border', we also have
      ;; to set `child-frame-border'.
      (unless (equal (face-attribute 'child-frame-border :background frame 'default) new)
        (set-face-background 'child-frame-border new frame)))
    ;; Reset frame parameters if they changed.  For example `tool-bar-mode'
    ;; overrides the parameter `tool-bar-lines' for every frame, including child
    ;; frames.  The child frame API is a pleasure to work with.  It is full of
    ;; lovely surprises.
    (let* ((win (frame-root-window frame))
           (is (frame-parameters frame))
           (params `((corfu--geometry ,x ,y ,width ,height) ,@params))
           (diff (cl-loop for p in params for (k . v) = p
                          unless (equal (alist-get k is) v) collect p)))
      (when diff (modify-frame-parameters frame diff))
      ;; XXX HACK: `set-window-buffer' must be called to force fringe update.
      (when (or diff (not (eq (window-buffer win) (current-buffer))))
        (set-window-buffer win (current-buffer)))
      ;; Disallow selection of root window (gh:minad/corfu#63)
      (set-window-parameter win 'no-delete-other-windows t)
      (set-window-parameter win 'no-other-window t)
      ;; Mark window as dedicated to prevent frame reuse (gh:minad/corfu#60)
      (set-window-dedicated-p win t)
      (redirect-frame-focus frame parent)
      (pcase-let* ((`(,ox ,oy ,ow ,oh) (alist-get 'corfu--geometry is '(0 0 0 0)))
                   (pos-change (or (/= x ox) (/= y oy)))
                   (size-change (or (/= ow width) (/= oh height))))
        (cond
         ((and pos-change size-change)
          ;; TODO: New Emacs 31 function for faster resizing/movement in one go.
          ;; Add this function to Compat 31 as backport.
          (static-if (fboundp 'set-frame-size-and-position-pixelwise)
              (set-frame-size-and-position-pixelwise frame width height x y)
            (set-frame-size frame width height t)
            (set-frame-position frame x y)))
         (pos-change (set-frame-position frame x y))
         (size-change (set-frame-size frame width height t))))))
  (make-frame-visible frame)
  ;; Unparent child frame if EXWM is used, otherwise EXWM buffers are drawn on
  ;; top of the Corfu child frame.
  (when-let* (((bound-and-true-p exwm--connection))
              ((display-graphic-p frame))
              (parent (frame-parent frame)))
    (redisplay t)
    (modify-frame-parameters frame `((delete-before . ,parent)
                                     (parent-frame . nil))))
  frame)