GNU bug report logs - #34516
Multi-monitor frame sets

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Sun, 17 Feb 2019 21:10:02 UTC

Severity: normal

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 34516 in the body.
You can then email your comments to 34516 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sun, 17 Feb 2019 21:10:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> linkov.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 17 Feb 2019 21:10:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: bug-gnu-emacs <at> gnu.org
Subject: Multi-monitor frame sets
Date: Sun, 17 Feb 2019 21:34:19 +0200
[Message part 1 (text/plain, inline)]
Shouldn't frame.el provide a command like make-frame-on-display,
but to make a frame on the specified monitor instead of display?

Isn't the following patch the right way to do this?
(It also adds completion for the existing command):

[make-frame-on-monitor.patch (text/x-diff, inline)]
diff --git a/lisp/frame.el b/lisp/frame.el
index dc81302939..38f2653905 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -644,9 +644,33 @@ window-system-for-display
 (defun make-frame-on-display (display &optional parameters)
   "Make a frame on display DISPLAY.
 The optional argument PARAMETERS specifies additional frame parameters."
-  (interactive "sMake frame on display: ")
+  (interactive (list (completing-read
+                      (format "Make frame on display: ")
+                      (delete-dups
+                       (mapcar (lambda (frame)
+                                 (frame-parameter frame 'display))
+                               (frame-list))))))
   (make-frame (cons (cons 'display display) parameters)))
 
+(defun make-frame-on-monitor (monitor &optional parameters)
+  "Make a frame on monitor MONITOR.
+The optional argument PARAMETERS specifies additional frame parameters."
+  (interactive (list (completing-read
+                      (format "Make frame on monitor: ")
+                      (mapcar (lambda (a)
+                                (cdr (assq 'name a)))
+                              (display-monitor-attributes-list)))))
+  (let ((geometry (car (delq nil (mapcar (lambda (a)
+                                           (when (equal (cdr (assq 'name a)) monitor)
+                                             (cdr (assq 'geometry a))))
+                                         (display-monitor-attributes-list))))))
+    (make-frame (append (x-parse-geometry (format "%dx%d+%d+%d"
+                                                  (nth 2 geometry)
+                                                  (nth 3 geometry)
+                                                  (nth 0 geometry)
+                                                  (nth 1 geometry)))
+                        parameters))))
+
 (declare-function x-close-connection "xfns.c" (terminal))
 
 (defun close-display-connection (display)

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 18 Feb 2019 10:48:02 GMT) Full text and rfc822 format available.

Message #8 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 18 Feb 2019 11:47:08 +0100
Juri Linkov <juri <at> linkov.net> writes:

> Shouldn't frame.el provide a command like make-frame-on-display,
> but to make a frame on the specified monitor instead of display?
>
> Isn't the following patch the right way to do this?
> (It also adds completion for the existing command):
>

I donʼt mind it, but it won't work on macOS, since thereʼs no 'name
entries in 'display-monitor-attributes-list' (and adding them looks
non-trivial, unless we go for 'Monitor-1', Monitor-2' etc.)

Robert




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 18 Feb 2019 16:50:01 GMT) Full text and rfc822 format available.

Message #11 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 18 Feb 2019 18:48:59 +0200
> From: Juri Linkov <juri <at> linkov.net>
> Date: Sun, 17 Feb 2019 21:34:19 +0200
> 
> Shouldn't frame.el provide a command like make-frame-on-display,
> but to make a frame on the specified monitor instead of display?
> 
> Isn't the following patch the right way to do this?
> (It also adds completion for the existing command):

What kind of list does display-monitor-attributes-list return on your
system, and how can you tell which part there refers to what physical
monitor?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 18 Feb 2019 21:24:02 GMT) Full text and rfc822 format available.

Message #14 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 18 Feb 2019 23:03:02 +0200
> Juri Linkov <juri <at> linkov.net> writes:
>
>> Shouldn't frame.el provide a command like make-frame-on-display,
>> but to make a frame on the specified monitor instead of display?
>>
>> Isn't the following patch the right way to do this?
>> (It also adds completion for the existing command):
>>
>
> I donʼt mind it, but it won't work on macOS, since thereʼs no 'name
> entries in 'display-monitor-attributes-list' (and adding them looks
> non-trivial, unless we go for 'Monitor-1', Monitor-2' etc.)

Are there other NS-specific attributes that could provide
a clear reference to a specific monitor?  Maybe ‘geometry’
could be used to deduce a relative arrangement of monitors?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 18 Feb 2019 21:24:02 GMT) Full text and rfc822 format available.

Message #17 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 18 Feb 2019 23:16:01 +0200
>> Shouldn't frame.el provide a command like make-frame-on-display,
>> but to make a frame on the specified monitor instead of display?
>> 
>> Isn't the following patch the right way to do this?
>> (It also adds completion for the existing command):
>
> What kind of list does display-monitor-attributes-list return on your
> system, and how can you tell which part there refers to what physical
> monitor?

It returns a list with such meaningless monitor names as “LVDS”, “eDP-1”, “DP-2-2”,
etc. that don't help to refer to a physical monitor.  However, I noticed that
the only attribute that could help is ‘geometry’ in the form of (X Y WIDTH HEIGHT),
e.g. when two adjacent monitors have such geometry attributes:

  (geometry    0  0 1920 1080)
  (geometry 1920 16 2560 1440)

the right edge of the first monitor ends (1920px) is where the left edge
of the second monitor begins.  Based on this guess I tried to deduce
a relative placement of new frames, but maybe I'm wrong.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Tue, 19 Feb 2019 03:33:02 GMT) Full text and rfc822 format available.

Message #20 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Tue, 19 Feb 2019 05:32:17 +0200
> From: Juri Linkov <juri <at> linkov.net>
> Cc: 34516 <at> debbugs.gnu.org
> Date: Mon, 18 Feb 2019 23:16:01 +0200
> 
> > What kind of list does display-monitor-attributes-list return on your
> > system, and how can you tell which part there refers to what physical
> > monitor?
> 
> It returns a list with such meaningless monitor names as “LVDS”, “eDP-1”, “DP-2-2”,
> etc. that don't help to refer to a physical monitor.  However, I noticed that
> the only attribute that could help is ‘geometry’ in the form of (X Y WIDTH HEIGHT),
> e.g. when two adjacent monitors have such geometry attributes:
> 
>   (geometry    0  0 1920 1080)
>   (geometry 1920 16 2560 1440)
> 
> the right edge of the first monitor ends (1920px) is where the left edge
> of the second monitor begins.  Based on this guess I tried to deduce
> a relative placement of new frames, but maybe I'm wrong.

Does the proposed function sound useful, given these issues?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Tue, 19 Feb 2019 09:18:02 GMT) Full text and rfc822 format available.

Message #23 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Tue, 19 Feb 2019 10:17:20 +0100
Juri Linkov <juri <at> linkov.net> writes:

>> Juri Linkov <juri <at> linkov.net> writes:
>>
>>> Shouldn't frame.el provide a command like make-frame-on-display,
>>> but to make a frame on the specified monitor instead of display?
>>>
>>> Isn't the following patch the right way to do this?
>>> (It also adds completion for the existing command):
>>>
>>
>> I donʼt mind it, but it won't work on macOS, since thereʼs no 'name
>> entries in 'display-monitor-attributes-list' (and adding them looks
>> non-trivial, unless we go for 'Monitor-1', Monitor-2' etc.)
>
> Are there other NS-specific attributes that could provide
> a clear reference to a specific monitor?  Maybe ‘geometry’
> could be used to deduce a relative arrangement of monitors?

I guess it could. Or we could fake up a monitor name on those systems
where ns_screen_name doesnʼt work.

Robert




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Tue, 19 Feb 2019 10:42:02 GMT) Full text and rfc822 format available.

Message #26 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Tue, 19 Feb 2019 10:40:34 +0000
On Mon 18 Feb 2019, Juri Linkov wrote:

>>> Shouldn't frame.el provide a command like make-frame-on-display,
>>> but to make a frame on the specified monitor instead of display?
>>> 
>>> Isn't the following patch the right way to do this?
>>> (It also adds completion for the existing command):
>>
>> What kind of list does display-monitor-attributes-list return on your
>> system, and how can you tell which part there refers to what physical
>> monitor?
>
> It returns a list with such meaningless monitor names as “LVDS”, “eDP-1”, “DP-2-2”,
> etc. that don't help to refer to a physical monitor.

Those names are not meaningless, it is just that you do not find them
helpful. The names describe the hardware port used to attach the
monitor:

  https://en.wikipedia.org/wiki/Low-voltage_differential_signaling
  https://en.wikipedia.org/wiki/DisplayPort
  https://en.wikipedia.org/wiki/DisplayPort#eDP

>  However, I noticed that the only attribute that could help is
> ‘geometry’ in the form of (X Y WIDTH HEIGHT), e.g. when two adjacent
> monitors have such geometry attributes:
>
>   (geometry    0  0 1920 1080)
>   (geometry 1920 16 2560 1440)
>
> the right edge of the first monitor ends (1920px) is where the left edge
> of the second monitor begins.  Based on this guess I tried to deduce
> a relative placement of new frames, but maybe I'm wrong.

Why guess ? Read the documentation for `display-monitor-attributes-list'
which describes the meaning of the list elements in great detail.

Note that you will need to take note of the `workarea' element of the
list which describes the usuable space on a given monitor (which
excludes space for toolbars etc that are not available to display a
frame).

    AndyM





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Tue, 19 Feb 2019 22:02:01 GMT) Full text and rfc822 format available.

Message #29 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Andy Moreton <andrewjmoreton <at> gmail.com>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Tue, 19 Feb 2019 23:31:46 +0200
> Why guess ? Read the documentation for `display-monitor-attributes-list'
> which describes the meaning of the list elements in great detail.
>
> Note that you will need to take note of the `workarea' element of the
> list which describes the usuable space on a given monitor (which
> excludes space for toolbars etc that are not available to display a
> frame).

Thanks for the information.  Do you think it's possible to use
the list elements from `display-monitor-attributes-list'
to unambiguously select a monitor where to make a new frame?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Tue, 19 Feb 2019 22:02:02 GMT) Full text and rfc822 format available.

Message #32 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Tue, 19 Feb 2019 23:37:51 +0200
>> > What kind of list does display-monitor-attributes-list return on your
>> > system, and how can you tell which part there refers to what physical
>> > monitor?
>> 
>> It returns a list with such meaningless monitor names as “LVDS”, “eDP-1”, “DP-2-2”,
>> etc. that don't help to refer to a physical monitor.  However, I noticed that
>> the only attribute that could help is ‘geometry’ in the form of (X Y WIDTH HEIGHT),
>> e.g. when two adjacent monitors have such geometry attributes:
>> 
>>   (geometry    0  0 1920 1080)
>>   (geometry 1920 16 2560 1440)
>> 
>> the right edge of the first monitor ends (1920px) is where the left edge
>> of the second monitor begins.  Based on this guess I tried to deduce
>> a relative placement of new frames, but maybe I'm wrong.
>
> Does the proposed function sound useful, given these issues?

The proposed function tries to provide the right geometry for
‘make-frame’, i.e. the geometry of the selected monitor, but I see
that it doesn't always makes a new frame on the specified monitor.
Also I don't understand the logic how currently ‘make-frame’ decides
on which monitor to make a new frame.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Tue, 19 Feb 2019 23:31:02 GMT) Full text and rfc822 format available.

Message #35 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Tue, 19 Feb 2019 23:29:47 +0000
On Tue 19 Feb 2019, Juri Linkov wrote:

>> Why guess ? Read the documentation for `display-monitor-attributes-list'
>> which describes the meaning of the list elements in great detail.
>>
>> Note that you will need to take note of the `workarea' element of the
>> list which describes the usuable space on a given monitor (which
>> excludes space for toolbars etc that are not available to display a
>> frame).
>
> Thanks for the information.  Do you think it's possible to use
> the list elements from `display-monitor-attributes-list'
> to unambiguously select a monitor where to make a new frame?

Yes. The list describes all monitors available for displaying frames, so
any new frame you wish to create must be shown (at least partially) on
one of those monitors.

The monitors may have different sizes, and be physically arranged in
fairly arbitrary ways. For example, on Windows (from bug#21173):

  +----------+
  |          |
  | DISPLAY2 |
  |          |+----------+
  +----------+|          |
              | DISPLAY1 |
              | (primary)|
              +----------+

  (display-monitor-attributes-list)
  ;; ==>
  '(((geometry 0 0 1920 1080)
     (workarea 0 0 1920 1050)
     (mm-size 677 381)
     (name . "\\\\.\\DISPLAY1")
     (frames ...))
    ((geometry -1680 -1050 1680 1050)
     (workarea -1680 -1050 1680 1050)
     (mm-size 593 370)
     (name . "\\\\.\\DISPLAY2")
     (frames ...)))

  ;; For a frame on DISPLAY2:
  (frame-parameter (window-frame) 'left) ;; ==>  (+ -1668)
  (frame-parameter (window-frame) 'top)  ;; ==>  (+ -1046)






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Wed, 20 Feb 2019 21:23:02 GMT) Full text and rfc822 format available.

Message #38 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Andy Moreton <andrewjmoreton <at> gmail.com>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Wed, 20 Feb 2019 23:20:39 +0200
[Message part 1 (text/plain, inline)]
>   (display-monitor-attributes-list)
>   ;; ==>
>   '(((geometry 0 0 1920 1080)
>      (workarea 0 0 1920 1050)
>      (mm-size 677 381)
>      (name . "\\\\.\\DISPLAY1")
>      (frames ...))
>     ((geometry -1680 -1050 1680 1050)
>      (workarea -1680 -1050 1680 1050)
>      (mm-size 593 370)
>      (name . "\\\\.\\DISPLAY2")
>      (frames ...)))

I see that ‘geometry’ is the same as ‘workarea’ on the second monitor,
but slightly different on the first one.  Mine are all the same,
so I don't know whether to use ‘geometry’ or ‘workarea’.

Meanwhile I found a mistake in my previous patch.  I assumed that
both pairs of attributes top/left and height/width for ‘make-frame’
are measured in pixels.  In fact, only top/left are in pixels,
whereas height/width are in text units.  So needed to wrap them
in ‘text-pixels’.  Now with this patch everything is fine:

[make-frame-on-monitor.2.patch (text/x-diff, inline)]
diff --git a/lisp/frame.el b/lisp/frame.el
index dc81302939..208748ef1d 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -644,9 +644,37 @@ window-system-for-display
 (defun make-frame-on-display (display &optional parameters)
   "Make a frame on display DISPLAY.
 The optional argument PARAMETERS specifies additional frame parameters."
-  (interactive "sMake frame on display: ")
+  (interactive (list (completing-read
+                      (format "Make frame on display: ")
+                      (delete-dups
+                       (mapcar (lambda (frame)
+                                 (frame-parameter frame 'display))
+                               (frame-list))))))
   (make-frame (cons (cons 'display display) parameters)))
 
+(defun make-frame-on-monitor (monitor &optional display parameters)
+  "Make a frame on monitor MONITOR.
+The optional argument PARAMETERS specifies additional frame parameters."
+  (interactive (list (completing-read
+                      (format "Make frame on monitor: ")
+                      (mapcar (lambda (a)
+                                (cdr (assq 'name a)))
+                              (display-monitor-attributes-list)))))
+  (let* ((monitor-geometry (car (delq nil (mapcar (lambda (a)
+                                                    (when (equal (cdr (assq 'name a)) monitor)
+                                                      (cdr (assq 'geometry a))))
+                                                  (display-monitor-attributes-list display)))))
+         (frame-geometry (x-parse-geometry (format "%dx%d+%d+%d"
+                                                   (nth 2 monitor-geometry)
+                                                   (nth 3 monitor-geometry)
+                                                   (nth 0 monitor-geometry)
+                                                   (nth 1 monitor-geometry))))
+         (frame-geometry-in-pixels `((top . ,(cdr (assq 'top frame-geometry)))
+                                     (left . ,(cdr (assq 'left frame-geometry)))
+                                     (height . (text-pixels . ,(cdr (assq 'height frame-geometry))))
+                                     (width . (text-pixels . ,(cdr (assq 'width frame-geometry)))))))
+    (make-frame (append frame-geometry-in-pixels parameters))))
+
 (declare-function x-close-connection "xfns.c" (terminal))
 
 (defun close-display-connection (display)

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Wed, 20 Feb 2019 21:39:01 GMT) Full text and rfc822 format available.

Message #41 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Wed, 20 Feb 2019 21:38:02 +0000
On Wed 20 Feb 2019, Juri Linkov wrote:

>>   (display-monitor-attributes-list)
>>   ;; ==>
>>   '(((geometry 0 0 1920 1080)
>>      (workarea 0 0 1920 1050)
>>      (mm-size 677 381)
>>      (name . "\\\\.\\DISPLAY1")
>>      (frames ...))
>>     ((geometry -1680 -1050 1680 1050)
>>      (workarea -1680 -1050 1680 1050)
>>      (mm-size 593 370)
>>      (name . "\\\\.\\DISPLAY2")
>>      (frames ...)))
>
> I see that ‘geometry’ is the same as ‘workarea’ on the second monitor,
> but slightly different on the first one.  Mine are all the same,
> so I don't know whether to use ‘geometry’ or ‘workarea’.

In the example above, the DISPLAY1 monitor has the Windows task bar
along the bottom edge (with auto-hide disabled), so space there is not
available for displaying emacs frames.

The Windows task bar is not displayed on the DISPLAY2 monitor in this
setup, so the DISPLAY2 workarea matches the geometry, as the whole
monitor can be used to display frames.

You should always use the workarea values for displaying emacs frames.

    AndyM





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sat, 23 Feb 2019 21:04:02 GMT) Full text and rfc822 format available.

Message #44 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sat, 23 Feb 2019 22:43:41 +0200
>>> I donʼt mind it, but it won't work on macOS, since thereʼs no 'name
>>> entries in 'display-monitor-attributes-list' (and adding them looks
>>> non-trivial, unless we go for 'Monitor-1', Monitor-2' etc.)
>>
>> Are there other NS-specific attributes that could provide
>> a clear reference to a specific monitor?  Maybe ‘geometry’
>> could be used to deduce a relative arrangement of monitors?
>
> I guess it could. Or we could fake up a monitor name on those systems
> where ns_screen_name doesnʼt work.

Since on Windows 'display-monitor-attributes-list' returns such
fake monitor names:

  \\.\DISPLAY1
  \\.\DISPLAY2

on macOS it could return something like that or generate fake names
from geometry like "1920x1080+0+0", "2560x1440+1920+16".




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sat, 23 Feb 2019 21:04:02 GMT) Full text and rfc822 format available.

Message #47 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Andy Moreton <andrewjmoreton <at> gmail.com>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sat, 23 Feb 2019 22:48:25 +0200
[Message part 1 (text/plain, inline)]
> You should always use the workarea values for displaying emacs frames.

Ok, this patch uses the workarea instead:

[make-frame-on-monitor.3.patch (text/x-diff, inline)]
diff --git a/lisp/frame.el b/lisp/frame.el
index dc81302939..648944952f 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -644,9 +644,43 @@ window-system-for-display
 (defun make-frame-on-display (display &optional parameters)
   "Make a frame on display DISPLAY.
 The optional argument PARAMETERS specifies additional frame parameters."
-  (interactive "sMake frame on display: ")
+  (interactive (list (completing-read
+                      (format "Make frame on display: ")
+                      (delete-dups
+                       (mapcar (lambda (frame)
+                                 (frame-parameter frame 'display))
+                               (frame-list))))))
   (make-frame (cons (cons 'display display) parameters)))
 
+(defun make-frame-on-monitor (monitor &optional display parameters)
+  "Make a frame on monitor MONITOR.
+The optional argument DISPLAY can be a display name, and the optional
+argument PARAMETERS specifies additional frame parameters."
+  (interactive (list (completing-read
+                      (format "Make frame on monitor: ")
+                      (mapcar (lambda (a)
+                                (cdr (assq 'name a)))
+                              (display-monitor-attributes-list)))))
+  (let* ((monitor-geometry
+          (car (delq nil (mapcar (lambda (a)
+                                   (when (equal (cdr (assq 'name a)) monitor)
+                                     (cdr (assq 'workarea a))))
+                                 (display-monitor-attributes-list display)))))
+         (frame-geometry
+          (when monitor-geometry
+            (x-parse-geometry (format "%dx%d+%d+%d"
+                                      (nth 2 monitor-geometry)
+                                      (nth 3 monitor-geometry)
+                                      (nth 0 monitor-geometry)
+                                      (nth 1 monitor-geometry)))))
+         (frame-geometry-in-pixels
+          (when frame-geometry
+            `((top . ,(cdr (assq 'top frame-geometry)))
+              (left . ,(cdr (assq 'left frame-geometry)))
+              (height . (text-pixels . ,(cdr (assq 'height frame-geometry))))
+              (width . (text-pixels . ,(cdr (assq 'width frame-geometry))))))))
+    (make-frame (append frame-geometry-in-pixels parameters))))
+
 (declare-function x-close-connection "xfns.c" (terminal))
 
 (defun close-display-connection (display)

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sun, 24 Feb 2019 08:45:02 GMT) Full text and rfc822 format available.

Message #50 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> linkov.net>, 
 Andy Moreton <andrewjmoreton <at> gmail.com>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sun, 24 Feb 2019 09:44:31 +0100
>> You should always use the workarea values for displaying emacs frames.

Much easier said than done.

> Ok, this patch uses the workarea instead:

AFAICT, the workarea may "move" from one display to another.  So to be
on the safe side, code should always assume the presence of a workarea
even when there's none at the very moment.  But I have no idea whether
the workarea size and position may change when moving from one display
to another.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sun, 24 Feb 2019 12:57:01 GMT) Full text and rfc822 format available.

Message #53 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sun, 24 Feb 2019 13:56:31 +0100
Juri Linkov <juri <at> linkov.net> writes:

>>>> I donʼt mind it, but it won't work on macOS, since thereʼs no 'name
>>>> entries in 'display-monitor-attributes-list' (and adding them looks
>>>> non-trivial, unless we go for 'Monitor-1', Monitor-2' etc.)
>>>
>>> Are there other NS-specific attributes that could provide
>>> a clear reference to a specific monitor?  Maybe ‘geometry’
>>> could be used to deduce a relative arrangement of monitors?
>>
>> I guess it could. Or we could fake up a monitor name on those systems
>> where ns_screen_name doesnʼt work.
>
> Since on Windows 'display-monitor-attributes-list' returns such
> fake monitor names:
>
>   \\.\DISPLAY1
>   \\.\DISPLAY2
>
> on macOS it could return something like that or generate fake names
> from geometry like "1920x1080+0+0", "2560x1440+1920+16".

I often have two identical monitors attached, so that would be
confusing :-)

Something like this (assuming nobody every connects more than 9
monitors to the same system).

diff --git a/src/nsfns.m b/src/nsfns.m
index edcdb988f7..91ab17032c 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -2698,6 +2698,12 @@ and GNUstep implementations ("distributor-specific release
 
 #ifdef NS_IMPL_COCOA
       m->name = ns_screen_name (did);
+      if (m->name == NULL)      /* Fallback value.  */
+        {
+          char name[9];
+          snprintf (name, sizeof(name), "DISPLAY%1d", i+1);
+          m->name = xstrdup (name);
+        }
 
       {
         CGSize mms = CGDisplayScreenSize (did);






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sun, 24 Feb 2019 21:10:01 GMT) Full text and rfc822 format available.

Message #56 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sun, 24 Feb 2019 23:08:13 +0200
>> Since on Windows 'display-monitor-attributes-list' returns such
>> fake monitor names:
>>
>>   \\.\DISPLAY1
>>   \\.\DISPLAY2
>>
>> on macOS it could return something like that or generate fake names
>> from geometry like "1920x1080+0+0", "2560x1440+1920+16".
>
> I often have two identical monitors attached, so that would be
> confusing :-)
>
> Something like this (assuming nobody every connects more than 9
> monitors to the same system).

I hope at least the primary monitor always comes first in the list.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sun, 24 Feb 2019 21:10:02 GMT) Full text and rfc822 format available.

Message #59 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 34516 <at> debbugs.gnu.org, Andy Moreton <andrewjmoreton <at> gmail.com>
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sun, 24 Feb 2019 23:08:46 +0200
>>> You should always use the workarea values for displaying emacs frames.
>
> Much easier said than done.
>
>> Ok, this patch uses the workarea instead:
>
> AFAICT, the workarea may "move" from one display to another.  So to be
> on the safe side, code should always assume the presence of a workarea
> even when there's none at the very moment.  But I have no idea whether
> the workarea size and position may change when moving from one display
> to another.

Then geometry is a safer option?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sun, 24 Feb 2019 22:13:02 GMT) Full text and rfc822 format available.

Message #62 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sun, 24 Feb 2019 22:11:44 +0000
On Sun 24 Feb 2019, Juri Linkov wrote:

>>> Since on Windows 'display-monitor-attributes-list' returns such
>>> fake monitor names:
>>>
>>>   \\.\DISPLAY1
>>>   \\.\DISPLAY2
>>>
>>> on macOS it could return something like that or generate fake names
>>> from geometry like "1920x1080+0+0", "2560x1440+1920+16".
>>
>> I often have two identical monitors attached, so that would be
>> confusing :-)
>>
>> Something like this (assuming nobody every connects more than 9
>> monitors to the same system).
>
> I hope at least the primary monitor always comes first in the list.

The `display-monitor-attributes-list' docstring states:

"Return a list of physical monitor attributes on DISPLAY.
DISPLAY can be a display name, a terminal name, or a frame.
If DISPLAY is omitted or nil, it defaults to the selected frame’s display.
Each element of the list represents the attributes of a physical
monitor.  The first element corresponds to the primary monitor."
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Why are you still guessing, instead of reading the documentation ?

    AndyM





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sun, 24 Feb 2019 22:16:01 GMT) Full text and rfc822 format available.

Message #65 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sun, 24 Feb 2019 22:13:26 +0000
On Sun 24 Feb 2019, martin rudalics wrote:

>>> You should always use the workarea values for displaying emacs frames.
>
> Much easier said than done.
>
>> Ok, this patch uses the workarea instead:
>
> AFAICT, the workarea may "move" from one display to another.  So to be
> on the safe side, code should always assume the presence of a workarea
> even when there's none at the very moment.  But I have no idea whether
> the workarea size and position may change when moving from one display
> to another.

Please explain what you mean here with an example, as what you have
written makes no sense.

    AndyM





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 25 Feb 2019 10:14:01 GMT) Full text and rfc822 format available.

Message #68 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Andy Moreton <andrewjmoreton <at> gmail.com>, 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 25 Feb 2019 11:13:47 +0100
> Please explain what you mean here with an example, as what you have
> written makes no sense.

Since I don't use multiple monitors it might not make sense indeed.
AFAIK usually only the primary monitor shows a taskbar, dock, or
panel.  Whether these can be shown on or moved to secondary monitors
is system dependent.  Hence IMO showing a frame on a secondary monitor
should pessimistically assume that a non-workarea object can appear
there even if 'display-monitor-attributes-list' says otherwise.  If
you are sure that this may not happen, just disregard what I said.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 25 Feb 2019 15:02:02 GMT) Full text and rfc822 format available.

Message #71 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 25 Feb 2019 15:00:39 +0000
On Mon 25 Feb 2019, martin rudalics wrote:

>> Please explain what you mean here with an example, as what you have
>> written makes no sense.
>
> Since I don't use multiple monitors it might not make sense indeed.
> AFAIK usually only the primary monitor shows a taskbar, dock, or
> panel.  Whether these can be shown on or moved to secondary monitors
> is system dependent.  Hence IMO showing a frame on a secondary monitor
> should pessimistically assume that a non-workarea object can appear
> there even if 'display-monitor-attributes-list' says otherwise.  If
> you are sure that this may not happen, just disregard what I said.

The workarea should always be the same size or smaller than the geometry
on each monitor, and this information (while system dependent) should
always be accurate when display-monitor-attributes-list is called.

However, it is entirely possible that the user reconfigures the taskbar,
dock panel etc. between a call to display-monitor-attributes-list and
using the information it returns.

   AndyM





Reply sent to Juri Linkov <juri <at> linkov.net>:
You have taken responsibility. (Mon, 25 Feb 2019 21:14:02 GMT) Full text and rfc822 format available.

Notification sent to Juri Linkov <juri <at> linkov.net>:
bug acknowledged by developer. (Mon, 25 Feb 2019 21:14:02 GMT) Full text and rfc822 format available.

Message #76 received at 34516-done <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Andy Moreton <andrewjmoreton <at> gmail.com>
Cc: 34516-done <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 25 Feb 2019 23:11:47 +0200
>>>> Since on Windows 'display-monitor-attributes-list' returns such
>>>> fake monitor names:
>>>>
>>>>   \\.\DISPLAY1
>>>>   \\.\DISPLAY2
>>>>
>>>> on macOS it could return something like that or generate fake names
>>>> from geometry like "1920x1080+0+0", "2560x1440+1920+16".
>>>
>>> I often have two identical monitors attached, so that would be
>>> confusing :-)
>>>
>>> Something like this (assuming nobody every connects more than 9
>>> monitors to the same system).
>>
>> I hope at least the primary monitor always comes first in the list.
>
> The `display-monitor-attributes-list' docstring states:
>
> "Return a list of physical monitor attributes on DISPLAY.
> DISPLAY can be a display name, a terminal name, or a frame.
> If DISPLAY is omitted or nil, it defaults to the selected frame’s display.
> Each element of the list represents the attributes of a physical
> monitor.  The first element corresponds to the primary monitor."
>           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> Why are you still guessing, instead of reading the documentation ?

Right, the documentation should be the ultimate source of truth.
So I committed the patch to master.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sat, 02 Mar 2019 20:55:01 GMT) Full text and rfc822 format available.

Message #79 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Alan Third <alan <at> idiocy.org>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: 34516 <at> debbugs.gnu.org, Juri Linkov <juri <at> linkov.net>
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sat, 2 Mar 2019 20:54:24 +0000
On Sun, Feb 24, 2019 at 01:56:31PM +0100, Robert Pluim wrote:
> Juri Linkov <juri <at> linkov.net> writes:
> 
> > Since on Windows 'display-monitor-attributes-list' returns such
> > fake monitor names:
> >
> >   \\.\DISPLAY1
> >   \\.\DISPLAY2
> >
> > on macOS it could return something like that or generate fake names
> > from geometry like "1920x1080+0+0", "2560x1440+1920+16".
> 
> I often have two identical monitors attached, so that would be
> confusing :-)

I’m a bit late to this conversation, sorry.

I’d hope that the geometry would contain the origin of the monitor in
the overall screen ‘space’, so the primary monitor would have 0, 0,
and one to the left would have -1920, 0, or something. So it might not
be too confusing.

> Something like this (assuming nobody every connects more than 9
> monitors to the same system).
> 
> diff --git a/src/nsfns.m b/src/nsfns.m
> index edcdb988f7..91ab17032c 100644
> --- a/src/nsfns.m
> +++ b/src/nsfns.m
> @@ -2698,6 +2698,12 @@ and GNUstep implementations ("distributor-specific release
>  
>  #ifdef NS_IMPL_COCOA
>        m->name = ns_screen_name (did);
> +      if (m->name == NULL)      /* Fallback value.  */
> +        {
> +          char name[9];
> +          snprintf (name, sizeof(name), "DISPLAY%1d", i+1);
> +          m->name = xstrdup (name);
> +        }
>  
>        {
>          CGSize mms = CGDisplayScreenSize (did);

This appears to be the only place that ns_screen_name is called, so it
would probably be better to put this code in it and make
ns_screen_name return a name no matter what.

Also, it might be worth considering using the ‘did’ value instead of
‘i’. As far as I can tell it’s just a uint32_t, and should stay the
same as long as the system isn’t rebooted.
-- 
Alan Third




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sat, 02 Mar 2019 23:58:01 GMT) Full text and rfc822 format available.

Message #82 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sat, 02 Mar 2019 23:57:35 +0000
On Sat 02 Mar 2019, Alan Third wrote:

> On Sun, Feb 24, 2019 at 01:56:31PM +0100, Robert Pluim wrote:
>> Juri Linkov <juri <at> linkov.net> writes:
>> 
>> > Since on Windows 'display-monitor-attributes-list' returns such
>> > fake monitor names:
>> >
>> >   \\.\DISPLAY1
>> >   \\.\DISPLAY2

These names are *not* fake: they are the name of the underlying device
that represents the monitor. 

>> > on macOS it could return something like that or generate fake names
>> > from geometry like "1920x1080+0+0", "2560x1440+1920+16".

It would be more usefulr to use the underlying device name, like on other
platforms.

> I’m a bit late to this conversation, sorry.
>
> I’d hope that the geometry would contain the origin of the monitor in
> the overall screen ‘space’, so the primary monitor would have 0, 0,
> and one to the left would have -1920, 0, or something. So it might not
> be too confusing.

Yes, that is exactly how it works: the geometry shows where the monitor
is positioned in the overall coordinate system, and the workspace shows
the area on that monitor that is available to display frames (i.e. not
occupied by system tray toolbar, dock etc).

>> Something like this (assuming nobody every connects more than 9
>> monitors to the same system).

Not a sound assumption: why add an arbitrary limitation when there is no
need to ? Allow an arbitrary number of monitors, since there is no
reason to restrict it.

>> 
>> diff --git a/src/nsfns.m b/src/nsfns.m
>> index edcdb988f7..91ab17032c 100644
>> --- a/src/nsfns.m
>> +++ b/src/nsfns.m
>> @@ -2698,6 +2698,12 @@ and GNUstep implementations ("distributor-specific release
>>  
>>  #ifdef NS_IMPL_COCOA
>>        m->name = ns_screen_name (did);
>> +      if (m->name == NULL)      /* Fallback value.  */
>> +        {
>> +          char name[9];
>> +          snprintf (name, sizeof(name), "DISPLAY%1d", i+1);
>> +          m->name = xstrdup (name);
>> +        }
>>  
>>        {
>>          CGSize mms = CGDisplayScreenSize (did);
>
> This appears to be the only place that ns_screen_name is called, so it
> would probably be better to put this code in it and make
> ns_screen_name return a name no matter what.
>
> Also, it might be worth considering using the ‘did’ value instead of
> ‘i’. As far as I can tell it’s just a uint32_t, and should stay the
> same as long as the system isn’t rebooted.

Is the did value reused if monitors are dynamically plugged and
unplugged ? This may happen when using a laptop with docking
stations and external monitors.

    AndyM





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sun, 03 Mar 2019 11:44:02 GMT) Full text and rfc822 format available.

Message #85 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Alan Third <alan <at> idiocy.org>
To: Andy Moreton <andrewjmoreton <at> gmail.com>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sun, 3 Mar 2019 11:43:24 +0000
On Sat, Mar 02, 2019 at 11:57:35PM +0000, Andy Moreton wrote:
> On Sat 02 Mar 2019, Alan Third wrote:
> 
> > On Sun, Feb 24, 2019 at 01:56:31PM +0100, Robert Pluim wrote:
> >> Juri Linkov <juri <at> linkov.net> writes:
> >> 
> >> > on macOS it could return something like that or generate fake names
> >> > from geometry like "1920x1080+0+0", "2560x1440+1920+16".
> 
> It would be more usefulr to use the underlying device name, like on other
> platforms.

It doesn’t look like macOS gives displays any sort of human readable
name. The closest I can find is the monitor’s make and model, which
appears to be lifted directly from the device driver. I expect if you
have two identical monitors then it will be the same for both.

> > Also, it might be worth considering using the ‘did’ value instead of
> > ‘i’. As far as I can tell it’s just a uint32_t, and should stay the
> > same as long as the system isn’t rebooted.
> 
> Is the did value reused if monitors are dynamically plugged and
> unplugged ? This may happen when using a laptop with docking
> stations and external monitors.

The documentation implies it may remain the same for the same monitor,
but then again, maybe not. It’s not very clear.

It shouldn’t be the same for two different monitors, though.
-- 
Alan Third




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 04 Mar 2019 09:53:02 GMT) Full text and rfc822 format available.

Message #88 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Alan Third <alan <at> idiocy.org>
Cc: 34516 <at> debbugs.gnu.org, Andy Moreton <andrewjmoreton <at> gmail.com>
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 04 Mar 2019 10:52:09 +0100
Alan Third <alan <at> idiocy.org> writes:

> On Sat, Mar 02, 2019 at 11:57:35PM +0000, Andy Moreton wrote:
>> On Sat 02 Mar 2019, Alan Third wrote:
>> 
>> > On Sun, Feb 24, 2019 at 01:56:31PM +0100, Robert Pluim wrote:
>> >> Juri Linkov <juri <at> linkov.net> writes:
>> >> 
>> >> > on macOS it could return something like that or generate fake names
>> >> > from geometry like "1920x1080+0+0", "2560x1440+1920+16".
>> 
>> It would be more usefulr to use the underlying device name, like on other
>> platforms.
>
> It doesn’t look like macOS gives displays any sort of human readable
> name. The closest I can find is the monitor’s make and model, which
> appears to be lifted directly from the device driver. I expect if you
> have two identical monitors then it will be the same for both.
>

At least in 'system preferences/display', when you have two identical monitors
attached, they're called something like 'DELL 1234X' and 'DELL 1234X
(2)' (I canʼt test that right now). If you can show me code on how to
get those names in 10.14, I can confirm. That would be better than
making up names.

>> > Also, it might be worth considering using the ‘did’ value instead of
>> > ‘i’. As far as I can tell it’s just a uint32_t, and should stay the
>> > same as long as the system isn’t rebooted.
>> 
>> Is the did value reused if monitors are dynamically plugged and
>> unplugged ? This may happen when using a laptop with docking
>> stations and external monitors.
>
> The documentation implies it may remain the same for the same monitor,
> but then again, maybe not. It’s not very clear.
>
> It shouldn’t be the same for two different monitors, though.

I can respin to use the did, if thereʼs no better alternative.

Robert




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 04 Mar 2019 13:58:01 GMT) Full text and rfc822 format available.

Message #91 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 04 Mar 2019 13:56:42 +0000
On Mon 04 Mar 2019, Robert Pluim wrote:

> Alan Third <alan <at> idiocy.org> writes:
>
>> On Sat, Mar 02, 2019 at 11:57:35PM +0000, Andy Moreton wrote:
>>> On Sat 02 Mar 2019, Alan Third wrote:
>>> 
>>> > On Sun, Feb 24, 2019 at 01:56:31PM +0100, Robert Pluim wrote:
>>> >> Juri Linkov <juri <at> linkov.net> writes:
>>> >> 
>>> >> > on macOS it could return something like that or generate fake names
>>> >> > from geometry like "1920x1080+0+0", "2560x1440+1920+16".
>>> 
>>> It would be more usefulr to use the underlying device name, like on other
>>> platforms.
>>
>> It doesn’t look like macOS gives displays any sort of human readable
>> name. The closest I can find is the monitor’s make and model, which
>> appears to be lifted directly from the device driver. I expect if you
>> have two identical monitors then it will be the same for both.
>>
>
> At least in 'system preferences/display', when you have two identical monitors
> attached, they're called something like 'DELL 1234X' and 'DELL 1234X
> (2)' (I canʼt test that right now). If you can show me code on how to
> get those names in 10.14, I can confirm. That would be better than
> making up names.

There are usually two different names involved: the name of the
file/device that represents the monitor, and a human-readable name for
the UI.

In Windows, the GUI settings/display describes the monitors as 1 and
2. In emacs, display-monitor-attributes-list reports the device
names \\.\DISPLAY1 and \\.\DISPLAY2 (you can see these device names
with the WinObj tool from SysInternals). Note that the device names do
not mention the make/model of the hardware.

For OSX, ioreg or the IoRegistryExplorer app show similar information
from the IO registry (a non-persistent database of IO device
information). I don't use a mac any more, so I don't know if these tools
are still available).

    AndyM





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 04 Mar 2019 16:12:01 GMT) Full text and rfc822 format available.

Message #94 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Andy Moreton <andrewjmoreton <at> gmail.com>
Cc: 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 04 Mar 2019 17:10:59 +0100
Andy Moreton <andrewjmoreton <at> gmail.com> writes:

>> At least in 'system preferences/display', when you have two identical monitors
>> attached, they're called something like 'DELL 1234X' and 'DELL 1234X
>> (2)' (I canʼt test that right now). If you can show me code on how to
>> get those names in 10.14, I can confirm. That would be better than
>> making up names.
>

So 'DELL 1234X (1)' and 'DELL 1234X (2)', where (1) is the primary
monitor.

> There are usually two different names involved: the name of the
> file/device that represents the monitor, and a human-readable name for
> the UI.
>
> In Windows, the GUI settings/display describes the monitors as 1 and
> 2. In emacs, display-monitor-attributes-list reports the device
> names \\.\DISPLAY1 and \\.\DISPLAY2 (you can see these device names
> with the WinObj tool from SysInternals). Note that the device names do
> not mention the make/model of the hardware.
>
> For OSX, ioreg or the IoRegistryExplorer app show similar information
> from the IO registry (a non-persistent database of IO device
> information). I don't use a mac any more, so I don't know if these tools
> are still available).

I donʼt know, but the code in ns_screen_name which appears to do
something similar does not work for me in 10.14

Iʼm not so sure about using the did, as someone suggested, since that
has a large value, eg here itʼs 724851601, Iʼd prefer to use a simple
index.

Robert




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 04 Mar 2019 19:21:01 GMT) Full text and rfc822 format available.

Message #97 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Alan Third <alan <at> idiocy.org>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: 34516 <at> debbugs.gnu.org, Andy Moreton <andrewjmoreton <at> gmail.com>
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 4 Mar 2019 19:20:17 +0000
On Mon, Mar 04, 2019 at 05:10:59PM +0100, Robert Pluim wrote:
> Andy Moreton <andrewjmoreton <at> gmail.com> writes:
> 
> >> At least in 'system preferences/display', when you have two identical monitors
> >> attached, they're called something like 'DELL 1234X' and 'DELL 1234X
> >> (2)' (I canʼt test that right now). If you can show me code on how to
> >> get those names in 10.14, I can confirm. That would be better than
> >> making up names.
> >
> 
> So 'DELL 1234X (1)' and 'DELL 1234X (2)', where (1) is the primary
> monitor.
> 
> > There are usually two different names involved: the name of the
> > file/device that represents the monitor, and a human-readable name for
> > the UI.
> >
> > In Windows, the GUI settings/display describes the monitors as 1 and
> > 2. In emacs, display-monitor-attributes-list reports the device
> > names \\.\DISPLAY1 and \\.\DISPLAY2 (you can see these device names
> > with the WinObj tool from SysInternals). Note that the device names do
> > not mention the make/model of the hardware.
> >
> > For OSX, ioreg or the IoRegistryExplorer app show similar information
> > from the IO registry (a non-persistent database of IO device
> > information). I don't use a mac any more, so I don't know if these tools
> > are still available).
> 
> I donʼt know, but the code in ns_screen_name which appears to do
> something similar does not work for me in 10.14

Try this:

    ioreg -lw0 | grep IODisplayEDID | sed "/[^<]*</s///" | xxd -p -r | strings -6

and see if it returns usable information. If so then that’s what we
should be targeting in ns_screen_name.

I think the approach used in ns_screen_name must have been removed in
some version of macOS. I tried to modify it to find the information
returned by the above command, but it looks like there’s no direct way
to match up the DID number with IODisplayConnect, which is where
IODisplayEDID is stored.

I’d never heard of ioreg before yesterday, though, so if anyone knows
better I’d be happy to learn otherwise.

> Iʼm not so sure about using the did, as someone suggested, since that
> has a large value, eg here itʼs 724851601, Iʼd prefer to use a simple
> index.

I did think that might be an issue, the main advantage over the simple
index is that it shouldn’t change, whereas I don’t think the index is
guaranteed to be the same on any two consecutive calls.
-- 
Alan Third




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 04 Mar 2019 20:19:01 GMT) Full text and rfc822 format available.

Message #100 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Alan Third <alan <at> idiocy.org>
Cc: 34516 <at> debbugs.gnu.org, Andy Moreton <andrewjmoreton <at> gmail.com>
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 04 Mar 2019 21:18:05 +0100
Alan Third <alan <at> idiocy.org> writes:

>> I donʼt know, but the code in ns_screen_name which appears to do
>> something similar does not work for me in 10.14
>
> Try this:
>
>     ioreg -lw0 | grep IODisplayEDID | sed "/[^<]*</s///" | xxd -p -r | strings -6
>
> and see if it returns usable information. If so then that’s what we
> should be targeting in ns_screen_name.
>

When just using the built-in display, that gives me:
    Color LCD
    LP133WQ5-SJA2
    F0Y843102PCJ465AT

I can run the same test tomorrow when Iʼm by my external screens
again. Only the first line here is remotely intelligible, none of them
are displayed by macOS as far as I know.

> I think the approach used in ns_screen_name must have been removed in
> some version of macOS. I tried to modify it to find the information
> returned by the above command, but it looks like there’s no direct way
> to match up the DID number with IODisplayConnect, which is where
> IODisplayEDID is stored.
>
> I’d never heard of ioreg before yesterday, though, so if anyone knows
> better I’d be happy to learn otherwise.
>
>> Iʼm not so sure about using the did, as someone suggested, since that
>> has a large value, eg here itʼs 724851601, Iʼd prefer to use a simple
>> index.
>
> I did think that might be an issue, the main advantage over the simple
> index is that it shouldn’t change, whereas I don’t think the index is
> guaranteed to be the same on any two consecutive calls.

ns-display-monitor-attributes-list assumes that the first monitor has
index '0', so having that change would be surprising.

Robert




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Tue, 05 Mar 2019 00:56:01 GMT) Full text and rfc822 format available.

Message #103 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Tue, 05 Mar 2019 00:44:44 +0000
On Mon 04 Mar 2019, Alan Third wrote:

> On Mon, Mar 04, 2019 at 05:10:59PM +0100, Robert Pluim wrote:
>> Andy Moreton <andrewjmoreton <at> gmail.com> writes:
>> 
>> >> At least in 'system preferences/display', when you have two identical monitors
>> >> attached, they're called something like 'DELL 1234X' and 'DELL 1234X
>> >> (2)' (I canʼt test that right now). If you can show me code on how to
>> >> get those names in 10.14, I can confirm. That would be better than
>> >> making up names.
>> >
>> 
>> So 'DELL 1234X (1)' and 'DELL 1234X (2)', where (1) is the primary
>> monitor.
>> 
>> > There are usually two different names involved: the name of the
>> > file/device that represents the monitor, and a human-readable name for
>> > the UI.
>> >
>> > In Windows, the GUI settings/display describes the monitors as 1 and
>> > 2. In emacs, display-monitor-attributes-list reports the device
>> > names \\.\DISPLAY1 and \\.\DISPLAY2 (you can see these device names
>> > with the WinObj tool from SysInternals). Note that the device names do
>> > not mention the make/model of the hardware.
>> >
>> > For OSX, ioreg or the IoRegistryExplorer app show similar information
>> > from the IO registry (a non-persistent database of IO device
>> > information). I don't use a mac any more, so I don't know if these tools
>> > are still available).
>> 
>> I donʼt know, but the code in ns_screen_name which appears to do
>> something similar does not work for me in 10.14
>
> Try this:
>
>     ioreg -lw0 | grep IODisplayEDID | sed "/[^<]*</s///" | xxd -p -r | strings -6
>
> and see if it returns usable information. If so then that’s what we
> should be targeting in ns_screen_name.
>
> I think the approach used in ns_screen_name must have been removed in
> some version of macOS. I tried to modify it to find the information
> returned by the above command, but it looks like there’s no direct way
> to match up the DID number with IODisplayConnect, which is where
> IODisplayEDID is stored.

The #if tests in ns_screen_name suggest that the old method is no longer
available in OSX 10.9 and later.

From a quick web search, GLFW (a graphics library) seems to have
encountered this problem, and added a workaround in this commit:

https://github.com/glfw/glfw/commit/8101d7a7b67fc3414769b25944dc7c02b58d53d0

The patch matches on "IODisplayConnect" instances and then iterates over
the collection checking that the vendor ID and product ID match those
values looked up from the DID number.

A similar approach should help to solve this problem.

    AndyM





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Tue, 19 Mar 2019 21:35:02 GMT) Full text and rfc822 format available.

Message #106 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: Andy Moreton <andrewjmoreton <at> gmail.com>, Alan Third <alan <at> idiocy.org>,
 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Tue, 19 Mar 2019 23:33:30 +0200
> I can run the same test tomorrow when Iʼm by my external screens
> again. Only the first line here is remotely intelligible, none of them
> are displayed by macOS as far as I know.

Did you have a chance to run the test?

Meanwhile, I pushed the fix based on your recommendations on emacs-devel.
Feel free to improve it if your test reveals a problem.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Tue, 26 Mar 2019 07:26:01 GMT) Full text and rfc822 format available.

Message #109 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Andy Moreton <andrewjmoreton <at> gmail.com>, Alan Third <alan <at> idiocy.org>,
 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Tue, 26 Mar 2019 08:24:56 +0100
>>>>> On Tue, 19 Mar 2019 23:33:30 +0200, Juri Linkov <juri <at> linkov.net> said:

    >> I can run the same test tomorrow when Iʼm by my external
    >> screens again. Only the first line here is remotely
    >> intelligible, none of them are displayed by macOS as far as I
    >> know.

    Juri> Did you have a chance to run the test?

I did, but I forgot to send the results:

--begin--
q8-@X,E
JC9H65BD0ZLS
DELL P2714H

q8-@X,E
JC9H65BD1BHS
DELL P2714H
--end--

Weʼd need to extract that 'DELL' bit, and check if we have other
monitors with the same description string so we can add a suffix.

    Juri> Meanwhile, I pushed the fix based on your recommendations on
    Juri> emacs-devel.  Feel free to improve it if your test reveals a
    Juri> problem.

It works fine for me. Of course, now that Iʼm using it, Iʼd like a
'make-frame-on-current-monitor' :-) I guess I can iterate over the
frames elements of 'display-monitor-attributes-list', unless thereʼs a
'what monitor is this frame on' primitive.

Robert




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Tue, 26 Mar 2019 07:28:02 GMT) Full text and rfc822 format available.

Message #112 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Andy Moreton <andrewjmoreton <at> gmail.com>, Alan Third <alan <at> idiocy.org>,
 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Tue, 26 Mar 2019 08:26:58 +0100
>>>>> On Tue, 26 Mar 2019 08:24:56 +0100, Robert Pluim <rpluim <at> gmail.com> said:
    Robert> It works fine for me. Of course, now that Iʼm using it,
    Robert> Iʼd like a 'make-frame-on-current-monitor' :-) I guess I
    Robert> can iterate over the frames elements of
    Robert> 'display-monitor-attributes-list', unless thereʼs a 'what
    Robert> monitor is this frame on' primitive.

D'oh. 'frame-monitor-attributes'.

Robert




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Wed, 27 Mar 2019 21:48:02 GMT) Full text and rfc822 format available.

Message #115 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: Andy Moreton <andrewjmoreton <at> gmail.com>, Alan Third <alan <at> idiocy.org>,
 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Wed, 27 Mar 2019 23:46:57 +0200
>     Robert> It works fine for me. Of course, now that Iʼm using it,
>     Robert> Iʼd like a 'make-frame-on-current-monitor' :-) I guess I
>     Robert> can iterate over the frames elements of
>     Robert> 'display-monitor-attributes-list', unless thereʼs a 'what
>     Robert> monitor is this frame on' primitive.
>
> D'oh. 'frame-monitor-attributes'.

Thanks for the hint.  Now I added the default value to
make-frame-on-monitor, so for the current monitor you can just do:
M-x make-frame-on-monitor RET RET




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Thu, 28 Mar 2019 07:57:01 GMT) Full text and rfc822 format available.

Message #118 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Andy Moreton <andrewjmoreton <at> gmail.com>, Alan Third <alan <at> idiocy.org>,
 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Thu, 28 Mar 2019 08:56:19 +0100
>>>>> On Wed, 27 Mar 2019 23:46:57 +0200, Juri Linkov <juri <at> linkov.net> said:

    Robert> It works fine for me. Of course, now that Iʼm using it,
    Robert> Iʼd like a 'make-frame-on-current-monitor' :-) I guess I
    Robert> can iterate over the frames elements of
    Robert> 'display-monitor-attributes-list', unless thereʼs a 'what
    Robert> monitor is this frame on' primitive.
    >> 
    >> D'oh. 'frame-monitor-attributes'.

    Juri> Thanks for the hint.  Now I added the default value to
    Juri> make-frame-on-monitor, so for the current monitor you can
    Juri> just do: M-x make-frame-on-monitor RET RET

Thanks for that. I guess we can close the bug, if it isnʼt closed
already.

Robert




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Thu, 28 Mar 2019 22:00:03 GMT) Full text and rfc822 format available.

Message #121 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 34516 <at> debbugs.gnu.org
Cc: Alan Third <alan <at> idiocy.org>, Andy Moreton <andrewjmoreton <at> gmail.com>
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Thu, 28 Mar 2019 23:57:43 +0200
>     Juri> Thanks for the hint.  Now I added the default value to
>     Juri> make-frame-on-monitor, so for the current monitor you can
>     Juri> just do: M-x make-frame-on-monitor RET RET
>
> Thanks for that. I guess we can close the bug, if it isnʼt closed
> already.

But what about your implementation of monitor names for macOS?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Fri, 29 Mar 2019 08:18:02 GMT) Full text and rfc822 format available.

Message #124 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Andy Moreton <andrewjmoreton <at> gmail.com>, Alan Third <alan <at> idiocy.org>,
 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Fri, 29 Mar 2019 09:16:54 +0100
>>>>> On Thu, 28 Mar 2019 23:57:43 +0200, Juri Linkov <juri <at> linkov.net> said:

    Juri> Thanks for the hint.  Now I added the default value to
    Juri> make-frame-on-monitor, so for the current monitor you can
    Juri> just do: M-x make-frame-on-monitor RET RET
    >> 
    >> Thanks for that. I guess we can close the bug, if it isnʼt
    >> closed already.

    Juri> But what about your implementation of monitor names for
    Juri> macOS?

The fake ones? I guess I can push that, unless we have a working way
to get the real ones. I havenʼt had a chance to look at the other
project suggested by someone on this thread, nor do I know what
license itʼs under. Current version below.

Robert

From abcc4431240f9a9b3b9d8a22b3acbdb30b28f7d4 Mon Sep 17 00:00:00 2001
From: Robert Pluim <rpluim <at> gmail.com>
Date: Thu, 28 Feb 2019 10:13:05 +0100
Subject: [PATCH] Provide a fallback monitor name on macOS
To: emacs-devel <at> gnu.org

The fix for Bug#34516 provides a way to make a frame on a specific
monitor.  It relies on monitor names being available, which is not the
case for recent versions of macOS, so provide fake ones of the form
Monitorx.

* src/nsfns.m (Fns_display_monitor_attributes_list): Provide a
fallback for the monitor name if the existing methods don't work.
---
 src/nsfns.m | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/nsfns.m b/src/nsfns.m
index ee7598a1c7..3c4d8c91f3 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -2587,6 +2587,12 @@ Frames are listed from topmost (first) to bottommost (last).  */)
 
 #ifdef NS_IMPL_COCOA
       m->name = ns_screen_name (did);
+      if (m->name == NULL)      /* Fallback value.  */
+        {
+          char name[28];
+          snprintf (name, sizeof(name), "Monitor%lu", i+1);
+          m->name = xstrdup (name);
+        }
 
       {
         CGSize mms = CGDisplayScreenSize (did);
-- 
2.21.0.196.g041f5ea1cf




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Sat, 30 Mar 2019 22:17:01 GMT) Full text and rfc822 format available.

Message #127 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 34516 <at> debbugs.gnu.org
Cc: Alan Third <alan <at> idiocy.org>, Andy Moreton <andrewjmoreton <at> gmail.com>
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Sat, 30 Mar 2019 23:47:51 +0200
>     Juri> But what about your implementation of monitor names for
>     Juri> macOS?
>
> The fake ones? I guess I can push that, unless we have a working way
> to get the real ones. I havenʼt had a chance to look at the other
> project suggested by someone on this thread, nor do I know what
> license itʼs under. Current version below.

I think better fake than none, when it produces consistent names
at least within one Emacs session.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34516; Package emacs. (Mon, 01 Apr 2019 11:30:02 GMT) Full text and rfc822 format available.

Message #130 received at 34516 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Andy Moreton <andrewjmoreton <at> gmail.com>, Alan Third <alan <at> idiocy.org>,
 34516 <at> debbugs.gnu.org
Subject: Re: bug#34516: Multi-monitor frame sets
Date: Mon, 01 Apr 2019 13:29:44 +0200
>>>>> On Sat, 30 Mar 2019 23:47:51 +0200, Juri Linkov <juri <at> linkov.net> said:

    Juri> But what about your implementation of monitor names for
    Juri> macOS?
    >> 
    >> The fake ones? I guess I can push that, unless we have a
    >> working way to get the real ones. I havenʼt had a chance to
    >> look at the other project suggested by someone on this thread,
    >> nor do I know what license itʼs under. Current version below.

    Juri> I think better fake than none, when it produces consistent
    Juri> names at least within one Emacs session.

I think it should do, except if the user changes which monitor is the
primary one.

Robert




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 30 Apr 2019 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 334 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.