Subject: Possible race in make-frame

From: Anders Blomdell <[email-masked]>
Date: Wed, 2 Aug 2023 16:02:06 +0200

When running

   /usr/bin/emacsclient --eval '(make-frame)'

it sometimes (often) opens up a small window (10x21) instead of the expected 40x80 window.

Setting a hook for after-make-frame-functions like this:

(progn
   (setq after-make-frame-functions nil)
   (add-hook
    'after-make-frame-functions
    (lambda (frame)
      (let ((width 80)
            (height 40)
            (start-width (frame-width frame))
            (start-height (frame-height frame))
            (visible (frame-visible-p frame)))
        (print (format "Start %dx%d %S"
                       start-height start-width visible))
        (if (not visible)
            (progn
              (while
                  (not (frame-visible-p frame))
                (progn
                  (sleep-for 0.001)
                  (print (format "X %dx%d"
                                 (frame-height frame)
                                 (frame-width frame)))
                  ))
              (sleep-for 0.001)
              (print (format "Resetting %dx%d -> %dx%d"
                             (frame-height frame) (frame-width frame)
                             height width))
              (set-frame-width frame width)
              (set-frame-height frame height)
              (sleep-for 0.1)
              (print (format "Resetting %dx%d -> %dx%d"
                             (frame-height frame) (frame-width frame)
                             height width))
              (set-frame-width frame width)
              (set-frame-height frame height)
              )
              )
          )
        (print (format "Done %dx%d"
                       (frame-height frame)
                       (frame-width frame)))
        )
    )
   )

usually has two different outcomes:

   "Start 10x38 t"
   "Done 10x38"

or

   "Start 40x80 nil"
   "X 40x80"
   "X 40x80"
   "X 40x80"
   "X 10x21"
   "Resetting 10x21 -> 40x80"
   "Resetting 40x80 -> 40x80"
   "Done 40x80"

-- 
Anders Blomdell                  Email: [email-masked]
Department of Automatic Control
Lund University                  Phone:    +46 46 222 8793
P.O. Box 118
SE-221 00 Lund, Sweden