Subject: bug#34516: Multi-monitor frame sets

From: Robert Pluim <[email-masked]>
Date: Sun, 24 Feb 2019 13:56:31 +0100

Juri Linkov <[email-masked]> 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);