-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
win32, wayland: add clipboard support #15355
Conversation
This completely freezes mpv on startup on sway for me. If compiling with ASan, I get
On dwl + wlroots-git I can use mpv and read the clipboard, but writing to clipboard/text fails. Same behavior on Mesa and Nvidia. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this version is more scalable than #13837 with clipboard backend definitions. Though notably is missing image support, which for me is not a deal breaker for first implementation, but the other PR did have it implemented, so we should align on a way forward how to merge those two implementations, probably #13837 would be rebased as clipboard backend in this architecture.
static void handle_clipboard_updates(struct MPContext *mpctx) | ||
{ | ||
if (mp_clipboard_data_changed(mpctx->clipboard)) | ||
mp_notify_property(mpctx, "clipboard"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remind me what would be the use-case for monitoring the clipboard in mpv? I always though it would rather be used to past text / image data on demand by user, rather than monitoring it constantly and acting. I would even argue that I don't want my media player to act depending on my clipboard content automatically. That's in no means rejecting the idea, but I would like to know when would that be useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's implemented in the other PR, and properties are generally expected to be observable. Clipboard polling is also disabled by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remind me what would be the use-case for monitoring the clipboard in mpv?
Could be used for auto playing Links(like YouTube) while copying links or so, some other programs do that too I think
Never personally used it but nice to have I guess. And: and > "properties are generally expected to be observable."
d190cd3
to
fe5676b
Compare
player/lua/console.lua
Outdated
}) | ||
if not res.error then | ||
return res.stdout | ||
if clip and mp.get_property('current-vo') and mp.get_property_native('video-osd') then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is those checks required? Wouldn't it be better to check mp.get_property('clipboard/text', nil) ~= nil
and fallback to wl-paste?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Wayland clipboard is only updated when the VO window is focused. If the user only focuses on the terminal window while the VO window exists, the clipboard can contain outdated data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. And it cannot be detected on clipboard side? Well, it seems bit tricky for script users to know this detail.
Also would focused
property work in this case? It is implemented by wayland.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clipboard property still works with a VO and just --video-osd=no.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use focused
property instead.
And it cannot be detected on clipboard side? Well, it seems bit tricky for script users to know this detail.
This is a Wayland limitation, nothing I can do about it. I can document this detail if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please. It should be noted in docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to check current-vo
if focused
is true, it can't be true in the terminal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
I can confirm it no longer freezes on sway. Also I saw that the docs say that writing is not supported on Wayland. |
c3b9457
to
29b75ef
Compare
This adds a clipboard API with multiple backend and format support. --clipboard-enable option can be toggled at runtime to turn native clipboard on and off.
This adds clipboard property which uses the clipboard API to get and set clipboard contents. Currently only clipboard text is implemented, but this can be extended in the future to cover primary selection and other formats.
This adds VOCTRLs needed for VO-based clipboard backend.
This adds a generic VO clipboard backend based on VOCTRLs to get and set clipboard data.
Clipboard contents are available as selection data offers under Wayland. The offer can become invalid at any time, so request the text format content immediately when an offer is received, and cache the content for later use.
This adds support for VOCTRL_GET_CLIPBOARD which makes the VO clipboard backend be able to get clipboard content for Wayland.
This adds a Windows clipboard backend. This doesn't depend on VO, so it can be used even when no video window is created.
This adds a clipboard monitoring API for backends which use polling to monitor clipboard updates. --clipboard-monitor option can turn clipboard monitoring on and off at runtime.
This uses GetClipboardSequenceNumber() to detect clipboard content changes. Clipboard Format Listener is a better way to do this according to MS docs, but sequence number works and the listener requires creating a dedicated thread and HWND for monitoring, so I will save it for a later time.
Since VOCTRL is not suitable for frequent data query (see 477a0f8 for details), it's not suitable to be used by the VO clipboard backend. Instead, since the VO does the clipboard monitoring by itself, it can notify the player when the clipboard is updated. This adds an internal notify-property command so that VOs can notify player when the clipboard is updated, so that clipboard monitoring works.
Works by notifying property update when clipboard content is updated.
Since native clipboard is implemented on win32 and wayland, use the clipboard property instead. This fixes the problems with commandline implementations of clipboard: - On win32, the powershell implementation is complex, and it can take several seconds to run for the first time. - On wayland, it requires wl-paste to be installed, which isn't always available. It also works poorly on GNOME.
Thanks, I hope this will be extended in the future. |
Alternative to #13837.
This adds a general internal clipboard API with support for different formats, targets, and autoprobing backends, and implements 2 clipboard backends (win32and VO) and Wayland support for the VO backend. The clipboard can be interacted publicly with the
clipboard
property, with change notification support. The internal API provides a polling interface for clipboard backends which use polling for notification. Other backends monitors changes in the backgrounds and notify the property when changes are detected.Currently, only text format and clipboard target is implemented, but image formats and primary selection target can be added later.
console.lua
is changed to use the clipboard property when supported.Fixes: #14373
Partially fixes (currently Windows, other platforms can be added later): #7361