Menu

#2227 Mouse middle button copy not working on Wayland

Bug
closed-fixed
nobody
5
2021-06-02
2021-01-04
Chris Mayo
No

Text selected in SciTE 4.4.6 is not pasted into another application (including gnome-terminal) when the middle button is pressed.

Running:

WAYLAND_DEBUG=1 scite README 2>&1 | grep -i primary_selection_offer

Then selecting some text in SciTE does not generate any new terminal output.

Contrast this by replacing scite with gedit.

Gentoo Linux
GTK 3.24.24
Mutter 3.38.2
wayland 1.18.0
wayland-protocols 1.2
gnome-terminal 3.36.2

Related

Bugs: #2287

Discussion

  • Neil Hodgson

    Neil Hodgson - 2021-01-04
    • labels: --> scintilla, wayland, gtk
    • status: open --> open-accepted
     
  • Neil Hodgson

    Neil Hodgson - 2021-01-04

    Reproduced on Ubuntu 20.10. It does however work when SciTE is built for GTK 2.x.

     
    • Colomban Wendling

      FWIW, GTK2 does not support Wayland, so it'll be using XWayland, which I guess will be bridging the primary selection behavior itself.

       
  • Dag

    Dag - 2021-01-12

    Seeing the same problem with geany, which employs scintilla as its editor component. Adding this here for the benefit of other new wayland users. Thank you for scintilla!

     
  • Neil Hodgson

    Neil Hodgson - 2021-04-23

    GTK was using a private protocol for primary selection on Wayland but moved to the standard with 3.24.24. It does not look like there will be much work don on this area of GTK 3.x as 4.x is now the focus.

    https://gitlab.gnome.org/GNOME/gtk/-/issues/2591

    While I haven't read much of the GTK sources, it appears that on Wayland, it makes simple primary selection setting gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), s, -1); work but not the more complex gtk_selection_owner_set with callbacks to provide the data.

    Scintilla could gtk_clipboard_set_text each time the selection changes but that seems expensive as the user may drag the mouse over hundreds of characters per second. It also doesn't provide a signal for when another application has claimed the primary selection which is used to change the selection colour to show it is no longer primary.

    Instead, gtk_clipboard_set_with_data can be used as this allows lazily allocating and providing the selection text. It also receives a signal through its clear function when another application claims primary.

    Attached is a patch that does this and which is working OK on Ubuntu 21.04 with GTK 3.24.25. There's also code that would be removed for this change but this is not included in the patch as it makes it more complex to understand.

    Its potentially a bit slower than needed as it calls gtk_clipboard_clear and gtk_clipboard_get for every change in selection. Keeping a single gtk_clipboard_get open led to stale text after another application had retrieved the primary selection from Scintilla. It would be possible to set a flag in the get function that then started a new gtk_clipboard_get on the next ClaimSelection.

     
  • Chris Mayo

    Chris Mayo - 2021-04-26

    That works for me, added to SciTE 5.0.2 on Gentoo Linux, GTK 3.24.28, GNOME 40. Thanks!

     
  • Neil Hodgson

    Neil Hodgson - 2021-04-28
    • status: open-accepted --> open-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2021-04-28

    Committed fix as [921cb3] . This goes beyond the earlier patch by removing the old primary selection code.

    This revision worked well for me on Ubuntu 21.04 with gedit and GNOME Terminal. It worked mostly with LibreOffice Writer but, if some text is selected in Writer; then some text is selected in SciTE; then middle click in Writer (without otherwise focusing it) the result is that the text that was selected earlier in Writer is pasted rather than the text from SciTE.

    As this change may do more work, slow downs, possibly with rapidly changing selections, should be reported. There could be a flag to turn off primary selection if it is too expensive in some situations.

     

    Related

    Commit: [921cb3]

  • Neil Hodgson

    Neil Hodgson - 2021-06-02
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.