~eliasnaur/gio#553: 
middle-click paste

On X11 and Wayland, you can usually select text with the mouse, and then click the middle mouse button to paste it. This doesn't seem to work in Gio apps. Are there plans to implement it?

Status
REPORTED
Submitter
~andybalholm
Assigned to
No-one
Submitted
8 months ago
Updated
8 months ago
Labels
No labels applied.

~whereswaldon 8 months ago

There's a challenge here in that the behavior isn't coherent cross-platform. Windows and macOS desktop users will not expect this to happen. To get this to work in Gio, we'd need to:

  • start notifying the OS of any text selected so that this special clipboard could be updated on supported platforms (maybe this could reuse the existing IME events)
  • develop platform-specific code for reading this special clipboard (I suppose this could return nothing on windows/mac/etc so that it doesn't do unexpected things on those platforms)
  • add some mechanism for text editing widgets to receive from this special clipboard on middle-click if there isn't some other handler in place for the middle-click interaction

It's certainly doable. Are you interested in working on it? We'd be happy to offer guidance on how to approach it.

~andybalholm 8 months ago

I don't really know what I'd be getting into with this low-level GUI plumbing, but I suppose I could try.

I assume one of the first steps would be adding "primary selection" support to gioui.org/io/clipboard. One option would be to add a boolean field to each struct type in that package, indicating whether it applies to the primary selection instead of the clipboard. Maybe it could be called Primary.

On platforms without support for the primary selection, the ops relating to it would just do nothing. A ReadOp would never produce an event there.

Andy

On Tuesday, December 12, 2023 11:41:04 AM PST, ~whereswaldon wrote:

There's a challenge here in that the behavior isn't coherent cross-platform. Windows and macOS desktop users will not expect this to happen. To get this to work in Gio, we'd need to:

  • start notifying the OS of any text selected so that this special clipboard could be updated on supported platforms (maybe this could reuse the existing IME events)
  • develop platform-specific code for reading this special clipboard (I suppose this could return nothing on windows/mac/etc so that it doesn't do unexpected things on those platforms)
  • add some mechanism for text editing widgets to receive from this special clipboard on middle-click if there isn't some other handler in place for the middle-click interaction

It's certainly doable. Are you interested in working on it? We'd be happy to offer guidance on how to approach it.

~eliasnaur 8 months ago

If you've going to take a stab at it please keep in mind that the event system is probably getting an overhaul soon: https://todo.sr.ht/~eliasnaur/gio/550. I haven't thought deeply about the issue itself, but it seems to me that it can be implemented by triggering a transfer.DataEvent when the user middle-presses; widget.Editor listens for DataEvents through transfer.TargetFilter at every frame so it should receive events even when it hasn't explicitly asked for them.

~andybalholm 8 months ago

We should probably wait to work on the implementation till the event system overhaul is done.

I don't think that transfer.DataEvent has enough information; it would need to include the mouse location for the middle-click if we would use it. (With middle-click paste, the text is inserted where the middle button was clicked, not at the current insertion point.)

Andy

On Wednesday, December 13, 2023 7:17:58 AM PST, ~eliasnaur wrote:

If you've going to take a stab at it please keep in mind that the event system is probably getting an overhaul soon: https://todo.sr.ht/~eliasnaur/gio/550. I haven't thought deeply about the issue itself, but it seems to me that it can be implemented by triggering a transfer.DataEvent when the user middle-presses; widget.Editor listens for DataEvents through transfer.TargetFilter at every frame so it should receive events even when it hasn't explicitly asked for them.

~whereswaldon 8 months ago

I don't think that transfer.DataEvent has enough information; it would need to include the mouse location for the middle-click if we would use it. (With middle-click paste, the text is inserted where the middle button was clicked, not at the current insertion point.)

In my brief experiment just now, the middle-click moves the insertion point prior to the insertion. That would be easy to implement without modifying the data event. We could just cause the cursor to move on middle click. Or am I missing something?

~andybalholm 8 months ago

Yes, that would probably work.

I had assumed that the API would be similar to the clipboard API, because they are often thought of together, and the underlying implementation is similar (at least on X11). But they wouldn't have to be the same.

Andy

On Thursday, December 14, 2023 7:16:03 AM PST, ~whereswaldon wrote:

I don't think that transfer.DataEvent has enough information; it would need to include the mouse location for the middle-click if we would use it. (With middle-click paste, the text is inserted where the middle button was clicked, not at the current insertion point.)

In my brief experiment just now, the middle-click moves the insertion point prior to the insertion. That would be easy to implement without modifying the data event. We could just cause the cursor to move on middle click. Or am I missing something?

~whereswaldon 8 months ago

I believe we're considering unifying the clipboard API with the transfer API as well. It would enable some nice things like handling typed clipboard contents other than text (images, etc...) and would make it possible to handle drag-n-drop and clipboard in a uniform way. You'd likely still need to explicitly request a paste (read the clipboard), but the content could come to you in the same format as other data transfer mechanisms. This new clipboard functionality seems like it fits that paradigm too.

~andybalholm 8 months ago

OK. In that case, I suppose we should wait for the dust to settle from that transition.

Andy

On Thursday, December 14, 2023 1:21:29 PM PST, ~whereswaldon wrote:

I believe we're considering unifying the clipboard API with the transfer API as well. It would enable some nice things like handling typed clipboard contents other than text (images, etc...) and would make it possible to handle drag-n-drop and clipboard in a uniform way. You'd likely still need to explicitly request a paste (read the clipboard), but the content could come to you in the same format as other data transfer mechanisms. This new clipboard functionality seems like it fits that paradigm too.

Register here or Log in to comment, or comment via email.