I was going crazy wondering why the numbering started at 2 instead of 1, then I realised my laptop is #1, even though my big monitor is designated the main screen and it sits above in the geometry of X. BTW winum gets this right.
(let ((count 0))
(message "%-5s | %-20s | %-15s | %-15s" "Rank" "Buffer" "Frame Pos (X,Y)" "Edges (L,T,R,B)")
(message (make-string 65 ?-))
(dolist (win (aw-window-list))
(setq count (1+ count))
(let* ((f (window-frame win))
(f-pos (frame-position f))
(w-edges (window-edges win))
(buf-name (buffer-name (window-buffer win))))
(message "#%-4d | %-20s | %-15s | %-15s"
count
(truncate-string-to-width buf-name 20 nil nil "…")
(format "(%s,%s)" (car f-pos) (cdr f-pos))
(format "%S" w-edges))))
(message "--- Global Sort Analysis Complete ---"))
"--- Global Sort Analysis Complete ---"
Rank | Buffer | Frame Pos (X,Y) | Edges (L,T,R,B)
-----------------------------------------------------------------
#1 | G:Google Gemini — M… | (0,2160) | (0 1 160 43)
#2 | *Treemacs-Buffer-#… | (0,0) | (0 1 32 45)
#3 | *:Buffers:* | (0,0) | (0 45 32 88)
#4 | *scratch* | (0,0) | (32 1 128 44)
#5 | treemacs.el<config> | (0,0) | (32 45 128 88)
#6 | G:Jumping to Emacs … | (0,0) | (128 1 224 47)
#7 | *Messages* | (0,0) | (128 48 224 88)
#8 | treemacs-compatibil… | (0,0) | (224 1 320 44)
#9 | ace-window.el | (0,0) | (224 45 320 88)
There's my laptop at #1, even though it's at coordinates 0, 2160 whereas the main monitor is at 0, 0.
The problem is in aw-window<
(defun aw-window< (wnd1 wnd2)
"Return true if WND1 is less than WND2.
This is determined by their respective window coordinates.
Windows are numbered top down, left to right."
(let* ((f1 (window-frame wnd1))
(f2 (window-frame wnd2))
(e1 (window-edges wnd1))
(e2 (window-edges wnd2))
(p1 (frame-position f1))
(p2 (frame-position f2))
(nl (or (null (car p1)) (null (car p2)))))
(cond ((and (not nl) (< (car p1) (car p2)))
(not aw-reverse-frame-list))
((and (not nl) (> (car p1) (car p2)))
aw-reverse-frame-list)
((< (car e1) (car e2))
t)
((> (car e1) (car e2))
nil)
((< (cadr e1) (cadr e2))
t))))
which completely ignores the Y coordinate.
To fix it, that function should be changed to this:
(defun aw-window< (wnd1 wnd2)
(let* ((f1 (window-frame wnd1))
(f2 (window-frame wnd2))
(p1 (frame-position f1))
(p2 (frame-position f2)))
(cond
;; 1. Compare Frame X
((< (car p1) (car p2)) t)
((> (car p1) (car p2)) nil)
;; 2. Compare Frame Y (The missing step!)
((< (cdr p1) (cdr p2)) t)
((> (cdr p1) (cdr p2)) nil)
;; 3. If same frame/coordinates, compare window edges
(t (let ((e1 (window-edges wnd1))
(e2 (window-edges wnd2)))
(cond ((< (car e1) (car e2)) t)
((> (car e1) (car e2)) nil)
((< (cadr e1) (cadr e2)) t)
(t nil)))))))
I was going crazy wondering why the numbering started at 2 instead of 1, then I realised my laptop is #1, even though my big monitor is designated the main screen and it sits above in the geometry of X. BTW winum gets this right.
There's my laptop at #1, even though it's at coordinates 0, 2160 whereas the main monitor is at 0, 0.
The problem is in aw-window<
which completely ignores the Y coordinate.
To fix it, that function should be changed to this: