I'm updating my project that uses gio to v0.0.7 and trying to figure out
how to get the contents of the clipboard (on wayland); here's a
simplified example of what I'm doing:
```
func (p *Page) Layout(gtx layout.Context) layout.Dimensions {
... snip ...
if p.foo.Clicked(gtx) {
gtx.Execute(clipboard.ReadCmd{Tag: p})
}
// not getting any events
if ev, ok := gtx.Event(transfer.TargetFilter{Target: p}); ok {
switch ev.(type) {
case transfer.InitiateEvent, transfer.CancelEvent:
panic("notreached")
case transfer.DataEvent:
panic("notreached")
default:
panic("notreached")
}
}
```
I've spent a bit of time trying to figure out how this works internally
and it does seem that the transfer.DataEvent does reach
app/window.processEvent and io/input/router.processEvent (so it
shouldn't be a wayland specific bug as far as I can see). I guess I'm
probably making a mistake here but couldn't find any example of
clipboard.ReadCmd being used in gio-example. Any tips?
Thanks!
On Tue, 30 Jul 2024 at 08:33, <masala@riseup.net> wrote:
>> I'm updating my project that uses gio to v0.0.7 and trying to figure out> how to get the contents of the clipboard (on wayland); here's a> simplified example of what I'm doing:>> ```> func (p *Page) Layout(gtx layout.Context) layout.Dimensions {> ... snip ...> if p.foo.Clicked(gtx) {> gtx.Execute(clipboard.ReadCmd{Tag: p})> }>> // not getting any events> if ev, ok := gtx.Event(transfer.TargetFilter{Target: p}); ok {> switch ev.(type) {> case transfer.InitiateEvent, transfer.CancelEvent:> panic("notreached")> case transfer.DataEvent:> panic("notreached")> default:> panic("notreached")> }> }> ```> I've spent a bit of time trying to figure out how this works internally> and it does seem that the transfer.DataEvent does reach> app/window.processEvent and io/input/router.processEvent (so it> shouldn't be a wayland specific bug as far as I can see). I guess I'm> probably making a mistake here but couldn't find any example of> clipboard.ReadCmd being used in gio-example. Any tips?>
An example would be nice, but in the meantime take a look at the
widget.Editor. It uses both ReadCmd and transfer.TargetFilter. From
a glance, you may need to set TargetFilter.Type.
Thanks,
Elias
On 2024-07-30 09:06, Elias Naur wrote:
> On Tue, 30 Jul 2024 at 08:33, <masala@riseup.net> wrote:>>>> I'm updating my project that uses gio to v0.0.7 and trying to figure out>> how to get the contents of the clipboard (on wayland); here's a>> simplified example of what I'm doing:>>>> ```>> func (p *Page) Layout(gtx layout.Context) layout.Dimensions {>> ... snip ...>> if p.foo.Clicked(gtx) {>> gtx.Execute(clipboard.ReadCmd{Tag: p})>> }>>>> // not getting any events>> if ev, ok := gtx.Event(transfer.TargetFilter{Target: p}); ok {>> switch ev.(type) {>> case transfer.InitiateEvent, transfer.CancelEvent:>> panic("notreached")>> case transfer.DataEvent:>> panic("notreached")>> default:>> panic("notreached")>> }>> }>> ```>> I've spent a bit of time trying to figure out how this works internally>> and it does seem that the transfer.DataEvent does reach>> app/window.processEvent and io/input/router.processEvent (so it>> shouldn't be a wayland specific bug as far as I can see). I guess I'm>> probably making a mistake here but couldn't find any example of>> clipboard.ReadCmd being used in gio-example. Any tips?>>> > An example would be nice, but in the meantime take a look at the> widget.Editor. It uses both ReadCmd and transfer.TargetFilter. From> a glance, you may need to set TargetFilter.Type.> > Thanks,> Elias
Yes, this was it. Thank you so much!
So, all I did was add Type: "application/text" e.g.
```
if ev, ok := gtx.Event(transfer.TargetFilter{Target: p, Type:
"application/text"}); ok {
```
And now the event is received. Phew.