~lioploum/offpunk-devel

6 2

Support for Wayland clipboard in offpunk-trunk

Details
Message ID
<171723278886.8.15803366681356242221.344510622@ploum.eu>
DKIM signature
pass
Download raw message
Hi everyone,

I’ve implemented support for both X11 clipboard (xsel) and Wayland 
clipboard (wl-clipboard) in trunk.

This is used by two functions in offpunk:

1. Copy : which adds URL/cache path/content/title of page to the 
clipboard

2. Go : when used without argument, go, will try to find an URL in one 
of the available clipboard.


I welcome any testing in both X11 and Wayland to ensure I didn’t break 
anything. I also welcome suggestions to support clipboard in other 
systems.


For packagers, this also means that "wl-clipboard" is a new dependency 
suggestion.


Cheers,

Ploum

-- 
Ploum - Lionel Dricot
Blog: https://www.ploum.net
Livres: https://ploum.net/livres.html
Details
Message ID
<qo7ed42wvmwyokmsigxbfg5ipdrgniozzcxnkcq5i3u42p3qya@jx4eqsfmo5f4>
In-Reply-To
<171723278886.8.15803366681356242221.344510622@ploum.eu> (view parent)
DKIM signature
pass
Download raw message
Ploum wrote:

> I’ve implemented support for both X11 clipboard (xsel) and Wayland 
> clipboard (wl-clipboard) in trunk.

Looks good.

The fish shell's `fish_clipboard_copy` and `fish_clipboard_paste` are using these heuristics to include Wayland, MacOS and Windows:

Copy:

```
if type -q pbcopy
  printf '%s' $cmdline | pbcopy
else if set -q WAYLAND_DISPLAY; and type -q wl-copy
  printf '%s' $cmdline | wl-copy
else if set -q DISPLAY; and type -q xsel
  printf '%s' $cmdline | xsel --clipboard
else if set -q DISPLAY; and type -q xclip
  printf '%s' $cmdline | xclip -selection clipboard
else if type -q clip.exe
  printf '%s' $cmdline | clip.exe
end
```

Paste:

```
if type -q pbpaste
  set data (pbpaste 2>/dev/null | string collect -N)
else if set -q WAYLAND_DISPLAY; and type -q wl-paste
  set data (wl-paste -n 2>/dev/null | string collect -N)
else if set -q DISPLAY; and type -q xsel
  set data (xsel --clipboard | string collect -N)
else if set -q DISPLAY; and type -q xclip
  set data (xclip -selection clipboard -o 2>/dev/null | string collect -N)
else if type -q powershell.exe
  set data (powershell.exe Get-Clipboard | string trim -r -c \r | string collect -N)
end
```

> For packagers, this also means that "wl-clipboard" is a new
> dependency suggestion.

Thanks!

Cheers,

-- 
Kʟᴀᴜꜱ Aʟᴇxᴀɴᴅᴇʀ Sᴇɪꜱᴛʀᴜᴘ
https://kas.bio.link/ 🇩🇰
Details
Message ID
<171725141864.7.7934091137388191802.344684231@ploum.eu>
In-Reply-To
<qo7ed42wvmwyokmsigxbfg5ipdrgniozzcxnkcq5i3u42p3qya@jx4eqsfmo5f4> (view parent)
DKIM signature
pass
Download raw message
On 24 jun 01 12:27, Klaus Alexander Seistrup wrote:
>Ploum wrote:
>
>> I’ve implemented support for both X11 clipboard (xsel) and Wayland
>> clipboard (wl-clipboard) in trunk.
>
>Looks good.
>
>The fish shell's `fish_clipboard_copy` and `fish_clipboard_paste` are using these heuristics to include Wayland, MacOS and Windows:


Wow, that’s very interesting. Do you think we should do the same in 
offpunk? With the refactorisation, this would be relatively easy to do.

As fort the paste, a particular thing we do is to get the value of all 
the clipboards in order to get an URL from both the primary or the 
normal clipboar under Linux. But I guess this should not be a problem.

Should it still be marked as a dependency or can we safely assume that 
at least one solution would work and throws a message in the rare case 
none of those work?
>
>Copy:
>
>```
>if type -q pbcopy
>  printf '%s' $cmdline | pbcopy
>else if set -q WAYLAND_DISPLAY; and type -q wl-copy
>  printf '%s' $cmdline | wl-copy
>else if set -q DISPLAY; and type -q xsel
>  printf '%s' $cmdline | xsel --clipboard
>else if set -q DISPLAY; and type -q xclip
>  printf '%s' $cmdline | xclip -selection clipboard
>else if type -q clip.exe
>  printf '%s' $cmdline | clip.exe
>end
>```
>
>Paste:
>
>```
>if type -q pbpaste
>  set data (pbpaste 2>/dev/null | string collect -N)
>else if set -q WAYLAND_DISPLAY; and type -q wl-paste
>  set data (wl-paste -n 2>/dev/null | string collect -N)
>else if set -q DISPLAY; and type -q xsel
>  set data (xsel --clipboard | string collect -N)
>else if set -q DISPLAY; and type -q xclip
>  set data (xclip -selection clipboard -o 2>/dev/null | string collect -N)
>else if type -q powershell.exe
>  set data (powershell.exe Get-Clipboard | string trim -r -c \r | string collect -N)
>end
>```
>
>> For packagers, this also means that "wl-clipboard" is a new
>> dependency suggestion.
>
>Thanks!
>
>Cheers,
>
>--
>Kʟᴀᴜꜱ Aʟᴇxᴀɴᴅᴇʀ Sᴇɪꜱᴛʀᴜᴘ
>https://kas.bio.link/ 🇩🇰
>

-- 
Ploum - Lionel Dricot
Blog: https://www.ploum.net
Livres: https://ploum.net/livres.html
Details
Message ID
<idvk3qmjaihrnigwqlu2ytv7vztwv3vfenr6brpnizkrrhrisx@hptbvtr3byov>
In-Reply-To
<171725141864.7.7934091137388191802.344684231@ploum.eu> (view parent)
DKIM signature
pass
Download raw message
Ploum wrote:

>> [`fish_clipboard_(copy|paste)`]
>
> Do you think we should do the same in offpunk?

It seems like lightweight checks to do, so why not. It could even be implemented as two functions (e.g. `get_clipboard_copy()`) that is called upon first invocation and then memoized so that subsequent invocations already know what to do.

> Should it still be marked as a dependency or can we safely
> assume that at least one solution would work and throws a
> message in the rare case none of those work?

On AUR I have set these as optional dependencies: if people want e.g. image support, they should install this, if the want … they should install … and so on. And it should be visible in the version command if it works.

But now that you mention it:

```
ON> version
Traceback (most recent call last):
  File "/usr/bin/offpunk", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/lib/python3.12/site-packages/offpunk.py", line 1927, in main
    gc.cmdloop()
  File "/usr/lib/python3.12/cmd.py", line 138, in cmdloop
    stop = self.onecmd(line)
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/cmd.py", line 217, in onecmd
    return func(arg)
           ^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/offpunk.py", line 887, in do_version
    output += " - wl-clipboard (for Wayland): " + shutil.which("wl-copy")
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str
```

I don't have wl-clipboard installed because I don't use Wayland. It shouldn't be a hard dependency, IMHO.

Cheers,

-- 
Kʟᴀᴜꜱ Aʟᴇxᴀɴᴅᴇʀ Sᴇɪꜱᴛʀᴜᴘ
https://kas.bio.link/ 🇩🇰
Details
Message ID
<171727223162.7.904576334414392397.344873899@ploum.eu>
In-Reply-To
<idvk3qmjaihrnigwqlu2ytv7vztwv3vfenr6brpnizkrrhrisx@hptbvtr3byov> (view parent)
DKIM signature
pass
Download raw message
On 24 jun 01 04:49, Klaus Alexander Seistrup wrote:
>Ploum wrote:
>
>>> [`fish_clipboard_(copy|paste)`]
>>
>> Do you think we should do the same in offpunk?
>
>It seems like lightweight checks to do, so why not. It could even be implemented as two functions (e.g. `get_clipboard_copy()`) that is called upon first invocation and then memoized so that subsequent invocations already know what to do.

I’ve added support for xclip as it was cheap enough. I would gladly 
accept support for MacOS or Windows if anybody use one of those and 
could test it.

>
>But now that you mention it:
>
>```
>ON> version
>Traceback (most recent call last):
>  File "/usr/bin/offpunk", line 8, in <module>
>    sys.exit(main())
>             ^^^^^^
>  File "/usr/lib/python3.12/site-packages/offpunk.py", line 1927, in main
>    gc.cmdloop()
>  File "/usr/lib/python3.12/cmd.py", line 138, in cmdloop
>    stop = self.onecmd(line)
>           ^^^^^^^^^^^^^^^^^
>  File "/usr/lib/python3.12/cmd.py", line 217, in onecmd
>    return func(arg)
>           ^^^^^^^^^
>  File "/usr/lib/python3.12/site-packages/offpunk.py", line 887, in do_version
>    output += " - wl-clipboard (for Wayland): " + shutil.which("wl-copy")
>              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
>TypeError: can only concatenate str (not "NoneType") to str
>```

Good catch. That’s exactly the kind of crash I was hoping to find when 
asking for feedbacks :-)
>
>I don't have wl-clipboard installed because I don't use Wayland. It shouldn't be a hard dependency, IMHO.

I just added xclip in parallel to xsel. Could you please try if 
everything works fine in X11?

Thanks a lot for your help!
Details
Message ID
<r3a7vgdgdmotuw4dbhbkqf427ypxzh5arhy2wftcbd4f335f6b@xusxggizsxkt>
In-Reply-To
<171727223162.7.904576334414392397.344873899@ploum.eu> (view parent)
DKIM signature
pass
Download raw message
Ploum wrote:

> I just added xclip in parallel to xsel. Could you please
> try if everything works fine in X11?

The `version` command says:

```
Nice to have:
- python-setproctitle       : Installed
- X11 clipboard (xsel or xclip)   : Installed
- Wayland clipboard (wl-clipboard): Not Installed
```

and the `copy` command works as expected. :)

-- 
Kʟᴀᴜꜱ Aʟᴇxᴀɴᴅᴇʀ Sᴇɪꜱᴛʀᴜᴘ 🇩🇰
https://kas.bio.link/
Details
Message ID
<171740371997.7.10747569595413548464.345738539@ploum.eu>
In-Reply-To
<r3a7vgdgdmotuw4dbhbkqf427ypxzh5arhy2wftcbd4f335f6b@xusxggizsxkt> (view parent)
DKIM signature
pass
Download raw message
On 24 jun 02 05:24, Klaus Alexander Seistrup wrote:
>Ploum wrote:
>
>> I just added xclip in parallel to xsel. Could you please
>> try if everything works fine in X11?
>
>The `version` command says:
>
>```
>Nice to have:
>- python-setproctitle       : Installed
>- X11 clipboard (xsel or xclip)   : Installed
>- Wayland clipboard (wl-clipboard): Not Installed
>```
>
>and the `copy` command works as expected. :)

Thanks for the confirmation, it looks like it’s fine!
Reply to thread Export thread (mbox)