all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#74750: clone-frame and make-frame pixelwise issues
@ 2024-12-09 15:51 Ship Mints
  2024-12-10 12:27 ` Eli Zaretskii
  0 siblings, 1 reply; 41+ messages in thread
From: Ship Mints @ 2024-12-09 15:51 UTC (permalink / raw)
  To: 74750

[-- Attachment #1: Type: text/plain, Size: 5696 bytes --]

While trying to reconcile pixelwise frame sizing behaviors, I narrowed down
two related issues.

clone-frame does not correctly clone frames on a pixelwise basis.

make-frame's text-pixels geometry support does not produce specified
pixelwise geometry. This also impacts frameset-restore's ability to
precisely reproduce pixelwise frame sizes.

I consider these to be related as clone-frame's use of make-frame could be
using text-pixels but if that doesn't work then pixelwise cloning won't
work. I did read through the code base as best as I could but could not
find the source of the text-pixels issue.

The following reproducer, under -Q, shows the same results on 29.4 and
30.0.92. My main platform is NS and I also did some testing on GTK. GTK's
issues seem a bit "messier" and I didn't spend any time trying to
understand them in depth as I was more interested to know if GTK worked
correctly or not, which it doesn't.

(switch-to-buffer "*Messages*")
(let ((target-text-width 1700)
      (target-text-height 1000)
      (native-width)
      (native-height)
      (msg (lambda (s frame)
             (message "%s text-width=%d (Δ%d) text-height=%d (Δ%d)
native-width=%d (Δ%d) native-height %d (Δ%d)\n"
                      s
                      (frame-text-width frame) (- (frame-text-width frame)
target-text-width)
                      (frame-text-height frame) (- (frame-text-height
frame) target-text-height)
                      (frame-native-width frame) (- (frame-native-width
frame) native-width)
                      (frame-native-height frame) (- (frame-native-height
frame) native-height)))))
  (set-frame-position nil 0 0)
  (set-frame-size nil target-text-width target-text-height 'pixelwise)
  (setq native-width (frame-native-width)
        native-height (frame-native-height))
  (message "Targets: text-width=%d text-height=%d\n" target-text-width
target-text-height)
  (funcall msg "orig" (selected-frame))

  (message "clone-frame under frame-resize-pixelwise nil; expectation: use
lines/columns geometry; outcome: met")
  (let ((frame-resize-pixelwise nil))
    (let ((new-frame (clone-frame)))
      (funcall msg "new" new-frame)
      (delete-frame new-frame)))

  (message "clone-frame under frame-resize-pixelwise t; expectation:
pixelwise geometry; outcome: unmet")
  (let ((frame-resize-pixelwise t))
    (let ((new-frame (clone-frame)))
      (funcall msg "new" new-frame)
      (delete-frame new-frame)))

  (message "clone-frame followed by manual resize; expectation: pixelwise
geometry; outcome: met (but two steps)")
  (let ((new-frame (clone-frame)))
    (set-frame-size new-frame target-text-width target-text-height
'pixelwise)
    (funcall msg "new" new-frame)
    (delete-frame new-frame))

  (message "manual clone under frame-resize-pixelwise using text-pixels;
expectation: pixelwise geometry; outcome: unmet")
  ;; code lifted from clone-frame
  ;; incorrect width offset seems to be equal to frame-scroll-bar-width
  (let* ((frame-resize-pixelwise t)
         (frame (selected-frame))
         (no-windows nil)
         (windows (unless no-windows
                    (window-state-get (frame-root-window frame))))
         (default-frame-alist
          (seq-remove (lambda (elem)
                        (memq (car elem) frame-internal-parameters))
                      (frame-parameters frame)))
         (new-frame))
    (when (and (display-graphic-p frame) frame-resize-pixelwise)
      (push (cons 'width (cons 'text-pixels (frame-text-width frame)))
default-frame-alist)
      (push (cons 'height (cons 'text-pixels (frame-text-height frame)))
default-frame-alist))
    (setq new-frame (make-frame))
    (when windows
      (window-state-put windows (frame-root-window new-frame) 'safe))
    (unless (display-graphic-p frame)
      (select-frame new-frame))
    (funcall msg "new" new-frame)
    (delete-frame new-frame)))

This is an implementation of clone-frame that uses text-pixels under
make-frame. This depends on make-frame text-pixels being corrected. Happy
to supply this as a patch should the discussion of these issues progress in
that direction.

(defun clone-frame (&optional frame no-windows pixelwise)
  "Make a new frame with the same parameters and windows as FRAME.
With a prefix arg NO-WINDOWS, don't clone the window configuration.  When
PIXELWISE is non-nil or if `frame-resize-pixelwise' is non-nil, and frame
is not text-only, clone the originating frame's pixel size.

FRAME defaults to the selected frame.  The frame is created on the
same terminal as FRAME.  If the terminal is a text-only terminal then
also select the new frame."
  (interactive (list (selected-frame) current-prefix-arg))
  (let* ((frame (or frame (selected-frame)))
         (windows (unless no-windows
                    (window-state-get (frame-root-window frame))))
         (default-frame-alist
          (seq-remove (lambda (elem)
                        (memq (car elem) frame-internal-parameters))
                      (frame-parameters frame)))
         (new-frame))
    (when (and (display-graphic-p frame)
               (or pixelwise frame-resize-pixelwise))
      (push (cons 'width (cons 'text-pixels (frame-text-width frame)))
            default-frame-alist)
      (push (cons 'height (cons 'text-pixels (frame-text-height frame)))
            default-frame-alist))
    (setq new-frame (make-frame))
    (when windows
      (window-state-put windows (frame-root-window new-frame) 'safe))
    (unless (display-graphic-p frame)
      (select-frame new-frame))
    new-frame))

-Stephane

[-- Attachment #2: Type: text/html, Size: 6564 bytes --]

^ permalink raw reply	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2024-12-22 12:04 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-09 15:51 bug#74750: clone-frame and make-frame pixelwise issues Ship Mints
2024-12-10 12:27 ` Eli Zaretskii
2024-12-10 15:56   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-10 16:24     ` Ship Mints
2024-12-11  9:37       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-11 22:41         ` Ship Mints
2024-12-12  6:05           ` Eli Zaretskii
2024-12-12  9:22           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-13 10:30             ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-13 16:28               ` Ship Mints
2024-12-13 18:15                 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-13 18:25                   ` Ship Mints
2024-12-14  8:27                     ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-15 20:34                       ` Ship Mints
2024-12-16  9:23                         ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-16  9:32                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-16 10:40                             ` Ship Mints
2024-12-16 10:48                               ` Ship Mints
2024-12-16 15:49                                 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-16 15:55                                   ` Ship Mints
2024-12-16 16:01                                     ` Ship Mints
2024-12-16 16:02                                       ` Ship Mints
2024-12-16 16:39                                   ` Ship Mints
2024-12-16 17:06                                     ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-16 17:32                                     ` Eli Zaretskii
2024-12-16 17:51                                       ` Ship Mints
2024-12-16 19:10                                         ` Eli Zaretskii
2024-12-17  1:20                                           ` Ship Mints
2024-12-17  9:02                                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-17 13:34                                             ` Eli Zaretskii
2024-12-16 19:13                                         ` Eli Zaretskii
2024-12-16 19:26                                           ` Ship Mints
2024-12-17  9:00                                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-17 13:29                                         ` Eli Zaretskii
2024-12-18 10:05                                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-16 16:07                               ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-16 16:41                                 ` Ship Mints
2024-12-16 17:06                                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-16 16:07                         ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-20 15:39                         ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-22 12:04                           ` Ship Mints

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.