hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
11.12k stars 664 forks source link

a new API to read and write a clipboard content #2726

Open hajimehoshi opened 1 year ago

hajimehoshi commented 1 year ago

Operating System

What feature would you like to be added?

I want a new API to read and write a clipboard content. I have not determined the API yet, but the API should match with Ebitengine's semantics. For example, we might have to restrict reading and writing the content only in Update (https://github.com/hajimehoshi/ebiten/issues/2658).

Why is this needed?

This is useful especially for GUI applications.

There are some existing libraries like https://github.com/golang-design/clipboard, but I'm worried that this uses its own threads and might cause impedance mismatch with Ebitengine's threads. The new API would have to use Ebitengine's internal UI (main) thread.

hajimehoshi commented 8 months ago

Probably I'll add github.com/hajimehoshi/ebitengine/v2/exp/clipboard as an expeirmental package:

package clipboard

func Set([]byte)
func Get() []byte

What about other mime type like images?

EDIT: https://w3c.github.io/clipboard-apis/#mandatory-data-types-x

erexo commented 4 months ago

I'm currently using the library mentioned in the issue (namely golang.design/x/clipboard) mainly because of it's Watch() feature. In my game I need to be notified and do action whenever the text stored in the clipboard changes, if we implement the clipboard functionalities to the Ebitengine, can we also move this feature?

hajimehoshi commented 4 months ago

In my game I need to be notified and do action whenever the text stored in the clipboard changes,

Interesting. I'll take a look at the implementation later.

hajimehoshi commented 4 months ago

Unfortunately it would not be possible to implement the 'watch' feature in a portable way if we want to include browsers https://developer.mozilla.org/en-US/docs/Web/API/Clipboard

erexo commented 4 months ago

then what about throwing error on browsers?

hajimehoshi commented 4 months ago

I don't think this is a good solution. What about looking at the content of the clipboard every tick?