mpv icon indicating copy to clipboard operation
mpv copied to clipboard

mac: fix screen selection edge case

Open makigumo opened this issue 2 years ago • 16 comments

For one of my monitors NSScreen.displayName was reporting nil. This lead to the following two issues.

  • It was not possible to select the monitor by name, e.g. --screen-name or --fs-screen-name. This is addressed by an additional name check with the system provided localizedName.
  • If no output monitor was specified, it would always default to this nil-monitor because there would be a match for screen.displayName == screenName thus returning this monitor, instead of returning nil (the default). This is addressed with a check for nil.

makigumo avatar Feb 18 '22 13:02 makigumo

#9697 may be related

makigumo avatar Feb 18 '22 13:02 makigumo

if we want to use the localizedName if the displayName is not available we also need to adjust the retrieval for the display-names property. since they should match. this part of the code https://github.com/mpv-player/mpv/blob/master/video/out/mac/common.swift#L642-L651

also localizedName is only available on macOS 10.15+, so it can't be used like this without a check.

maybe there is a bug in the retrieval of the display name in our custom code/extension https://github.com/mpv-player/mpv/blob/master/osdep/macos/swift_extensions.swift#L32-L62 that should be fixed instead.

ist this on an ARM mac?

Akemi avatar Feb 18 '22 16:02 Akemi

Ah I see. I wasn't aware localizedName was kind of new. Btw, I'm on Intel.

I agree its probably best to fix it in swift_extensions.swift

After digging a little deeper I found that the nil-monitor doesn't satisfy the last condition here: https://github.com/mpv-player/mpv/blob/5186651f304fb49867f2542d2eb149f8191cf0de/osdep/macos/swift_extensions.swift#L47

info[kDisplaySerialNumber] is nil but CGDisplaySerialNumber(displayID) is not 0. I'm not sure why that is. Maybe because it's an old DVI monitor.

makigumo avatar Feb 18 '22 18:02 makigumo

if the localizedName is the new official way to retrieve the display name now, we should replace all the usages of displayName with localizedName. i only added displayName since there wasn't a property to retrieve it before 10.15.

i think the best way would probably be, to move the displayName extension to https://github.com/mpv-player/mpv/blob/master/osdep/macos/swift_compat.swift, rename it to localizedName, make it conditional compile only for SDKs older than 10.15 (we should be done anyway) and then replace all the usages of displayName with localizedName. that way it can be removed easily at some point of time when we drop support for those older macOS versions.

Akemi avatar Feb 20 '22 19:02 Akemi

I have tried to follow your suggestion. I hope I didn't miss anything. Please have a look.

makigumo avatar Feb 20 '22 23:02 makigumo

you can completely remove the code from osdep/macos/swift_extensions.swift, the one for the displayName i mean.

also i think the macOS detection for macOS versions after 10.15 can be simplified. something like:

if int(version_parts.group(1)) >= 20:
    build_version = str(major-9) + '.' + str(minor)

Akemi avatar Feb 20 '22 23:02 Akemi

Thank you, somehow I missed to remove displayName.

makigumo avatar Feb 20 '22 23:02 makigumo

the compile time check won't work like that. mpv build with SDK 10.15 but min system set to 10.14 for example will fail, since the localizedName is not available. sry about not catching that earlier.

we probably need to keep the displayName and what you had there before, returning the localizedName inside the displayName. though addtional to the run time system check we also need the compile time check, but for availability.

Akemi avatar Feb 21 '22 06:02 Akemi

No problem. Next try.

makigumo avatar Feb 21 '22 12:02 makigumo

https://github.com/mpv-player/mpv/blob/5186651f304fb49867f2542d2eb149f8191cf0de/osdep/macos/swift_extensions.swift#L47

info[kDisplaySerialNumber] is nil but CGDisplaySerialNumber(displayID) is not 0. I'm not sure why that is. Maybe because it's an old DVI monitor.

would you mind telling what the values the keys in the dictionary contain and the CGDisplay* return values, eg

info[kDisplayVendorID]
CGDisplayVendorNumber(displayID)
info[kDisplayProductID]
CGDisplayModelNumber(displayID)
info[kDisplaySerialNumber]
CGDisplaySerialNumber(displayID))

i would like to fix the old case too if possible.

Akemi avatar Feb 26 '22 12:02 Akemi

No problem, here it is.

----
info[kDisplayProductName] = Optional({
    "en_US" = X223HQ;
})
--
info[kDisplayVendorID] = Optional(1138)
CGDisplayVendorNumber(displayID) = 1138
info[kDisplayProductID] = Optional(152)
CGDisplayModelNumber(displayID) = 152
info[kDisplaySerialNumber] = Optional(-1807666473)
info[kDisplaySerialNumber] as? UInt32 = nil
CGDisplaySerialNumber(displayID) = 2487300823

I would probably just remove the serial number check. As I would expect the monitor name to be the same for all models with a specific vendor and model number anyway.

makigumo avatar Feb 26 '22 16:02 makigumo

any updates? MPV suffer from this issue

noma4i avatar Mar 16 '22 14:03 noma4i

there are a few things i still need to think about and some possible changes. though i am currently short on time.

Akemi avatar Mar 16 '22 15:03 Akemi

I think I have found a fix for the serial number mismatch. Please have a look as I'm not that experienced with Swift.

makigumo avatar Mar 23 '22 03:03 makigumo

@Akemi Anything more required? Only cd9dbd41a479865d6d18a075a36b63918fe97a63 is really needed to solve the issue. And maybe ea78d494e7044587b9661bc94f7b5e80163c6e13 to be on the safer side. The other commits are more of a nice-to-have.

makigumo avatar Jul 16 '22 17:07 makigumo

Addressed https://github.com/mpv-player/mpv/pull/9885#issuecomment-1046307112, which I somehow totally missed. Sorry about that.

makigumo avatar Oct 25 '22 16:10 makigumo

as a heads up, i didn't forget about this and am trying to look at this soonish. sorry for the long wait.

Akemi avatar Jan 22 '23 13:01 Akemi

Applying only https://github.com/mpv-player/mpv/commit/ea78d494e7044587b9661bc94f7b5e80163c6e13 resolved this for me. When will it be merged into master? It's quite an important fix, since one can't watch movies in setups with external screens without it (ie. something as essential as a media center and a TV).

forthrin avatar Mar 26 '23 10:03 forthrin

it should probably also be mentioned in our https://github.com/mpv-player/mpv/blob/master/DOCS/interface-changes.rst file. since the output of VOCTRL_GET_DISPLAY_NAMES changed and scripts/properties etc depend on it.

Akemi avatar Apr 01 '23 12:04 Akemi

it should probably also be mentioned in our https://github.com/mpv-player/mpv/blob/master/DOCS/interface-changes.rst file. since the output of VOCTRL_GET_DISPLAY_NAMES changed and scripts/properties etc depend on it.

Not sure what if the provided info is sufficient. So please feel free to edit/correct this further.

makigumo avatar Apr 01 '23 14:04 makigumo

@makigumo @Akemi is there something we can do to help?

#9697 is the last bug that prevents me from using the newest mpv on MacOS (I'm still on 0.30...).

nightfriendly avatar Jul 14 '23 12:07 nightfriendly

not really. i am without a working mac still. so it's basically my fault for being stuck.

Akemi avatar Jul 14 '23 13:07 Akemi

Don't beat yourself too hard man, it's really not your fault if developing for MacOS is such a pain.

Is there any way we can help as a community? I am ready to donate. A former mplayer user, I have been using mpv since 2014. First on Linux, then on Mac, and I cannot imagine my life without it!

nightfriendly avatar Jul 20 '23 07:07 nightfriendly

@Akemi: What is the earliest Mac/macOS you can use?

forthrin avatar Jul 20 '23 07:07 forthrin

@Akemi: What is the earliest Mac/macOS you can use?

i am not sure how to answer or rather what the intention behind that question is. the first macOS/OSX i used was 10.5.

anyway i finally ordered a new mac now, since my backup computer broke too a few days ago.

Akemi avatar Jul 24 '23 00:07 Akemi

@Akemi: Maybe someone had a surplus Mac lying around. PS! It's not paranoia when they're really after you.

forthrin avatar Jul 24 '23 05:07 forthrin

ah i see, thanks. that would have been very kind of you.

Akemi avatar Jul 24 '23 05:07 Akemi

closing in favour of #12846

Akemi avatar Nov 10 '23 13:11 Akemi

EDIT: It's fine.

makigumo avatar Nov 10 '23 16:11 makigumo

Partially works on my machine.

mpv --no-config --fs-screen=0 --fs launches directly to fullscreen on my primary display.

mpv --no-config --fs-screen=1 --fs launches on the secondary display, but not in fullscreen. Instead, mpv opens up behind Firefox, which is the only window I have open on the secondary screen, and an alert bong is heard. Selecting the window and hitting the fullscreen hotkey does make it fullscreen on the secondary display though.

Apple M1 Max Mac Studio, macOS 13.6, mpv v0.35.0-1399-ga54cc02341.

Hamuko avatar Nov 10 '23 16:11 Hamuko