~eliasnaur/gio

2 2

question about how to use io/clipboard in gio v0.0.7

Details
Message ID
<bd5a0dde0626dfb7e5e30d4d54b5b294@riseup.net>
DKIM signature
pass
Download raw message
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!
Details
Message ID
<CAMAFT9UX2eBWH2yM8czcTN4D3p5PW39RUvZef=HDV9trxErpBw@mail.gmail.com>
In-Reply-To
<bd5a0dde0626dfb7e5e30d4d54b5b294@riseup.net> (view parent)
DKIM signature
pass
Download raw message
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
Details
Message ID
<908683a20a1371b265794fe2bd1d7242@riseup.net>
In-Reply-To
<CAMAFT9UX2eBWH2yM8czcTN4D3p5PW39RUvZef=HDV9trxErpBw@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
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.
Reply to thread Export thread (mbox)