From a9603c77f8b08ff17cccd2938dd22206e37871fe Mon Sep 17 00:00:00 2001
From: Jen-Chieh Shen <jcs090218@gmail.com>
Date: Tue, 18 Aug 2020 15:25:21 +0200
Subject: [PATCH] Add optional ALL-FRAMES arfument to count-windows

* lisp/window.el (count-windows): Allow counting the windows on
all frames (bug#42872).
---
 lisp/window.el | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/lisp/window.el b/lisp/window.el
index c02c9f37ee6..bb34a6d7b4c 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -2642,12 +2642,17 @@ and no others."
   "Return t if WINDOW is the currently active minibuffer window."
   (and (window-live-p window) (eq window (active-minibuffer-window))))
 
-(defun count-windows (&optional minibuf)
+(defun count-windows (&optional minibuf all-frames)
    "Return the number of live windows on the selected frame.
+
 The optional argument MINIBUF specifies whether the minibuffer
-window shall be counted.  See `walk-windows' for the precise
-meaning of this argument."
-   (length (window-list-1 nil minibuf)))
+window is included in the count.
+
+If ALL-FRAMES is non-nil, count the windows in all frames instead
+just the selected frame.
+
+See `walk-windows' for the precise meaning of this argument."
+   (length (window-list-1 nil minibuf all-frames)))
 
 ;;; Resizing windows.
 (defun window--size-to-pixel (window size &optional horizontal pixelwise round-maybe)
-- 
2.39.5