Subject: bug#76691: `display-monitor-attributes-list` not working properly on macOS

From: Robert Pluim <[email-masked]>
Date: Tue, 04 Mar 2025 16:34:06 +0100

>>>>> On Tue, 4 Mar 2025 09:58:13 -0500, Ship Mints <[email-masked]> said:
    Ship> And a synthesized name: (((name . "3200x1775@0,25") (geometry 0 0 3200
    Ship> 1800) (workarea 0 25 3200 1775) (mm-size 599 339) (frames #<frame *scratch*
    0x7f7c7009d430> ) (source . "NS")))

    Ship> We could use something like a UUID that's more opaque.

    Ship> I haven't made either name bi-directional yet to allow specifying it when
    Ship> operating on frames.

Yes, emacs crashes when I run `make-frame-on-monitor' :-)

    Ship> Thanks for the help.  Patch attached.

It gives me reasonable looking names here:

(((name . "PL3467WQ") (geometry 0 0 3440 1440) (workarea 0 25 3440
1415) (mm-size 801 329) (frames #<frame *scratch* 0x131887028>)
(source . "NS")) ((name . "Built-in Display") (geometry 459 1440 2048
1332) (workarea 459 1440 2048 1287) (mm-size 290 189) (frames) (source
. "NS")))

    Ship>  #ifdef NS_IMPL_COCOA
    Ship> -      m->name = ns_screen_name (did);
    Ship> +      m->name = NULL;
    Ship> +      if ([s respondsToSelector:@selector(localizedName)])
    Ship> +        {
    Ship> +	  NSString *name = [s valueForKey:@"localizedName"];
    Ship> +	  if (name != NULL)
    Ship> +	    {
    Ship> +	      m->name = xmalloc ([name lengthOfBytesUsingEncoding: NSUTF8StringEncoding]);
    Ship> +	      strcpy(m->name, [name UTF8String]);
    Ship> +	    }
    Ship> +        }
    Ship> +      /* If necessary, synthesize a name of the following form:
    Ship> +	  %dx%d@%d,%d width height x y */
    Ship> +      if (m->name == NULL)
    Ship> +	{
    Ship> +	  char buf[25]; /* sufficient for 12345x78901@34567,90123 */
    Ship> +	  snprintf (buf, sizeof(buf), "%ux%u@%d,%d", m->work.width, m->work.height, m->work.x, m->work.y);
    Ship> +	  m->name = xmalloc (strlen (buf));
    Ship> +	  strcpy(m->name, buf);
    Ship> +	}

How many version back of macOS does localizedName work for?

Robert
--