Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X copy/paste buffers, inability to paste with middle-mouse button in gd editor #3030

Closed
TierraDelFuego opened this issue Dec 9, 2015 · 29 comments

Comments

@TierraDelFuego
Copy link

I am no X expert but I think there are two copy/paste buffers under X.
When I am writing gd code in Godot I cannot copy (via highlighting from xterm) into my gd script by using the middle-mouse button. I looked around and did not see any settings for Godot regarding this.

Did I miss this or is this a feature? I can copy/paste from X apps that use ctrl-c,ctrl-v but I cannot use the other X buffer accessed via highlighting and middle-mouse click.

I tried with git version and 1.1-stable.

@reduz
Copy link
Member

reduz commented Dec 12, 2015

should this work on Linux? I can understand for the editor, but for Godot to work like this may make some games work odd on linux..

@ghost
Copy link

ghost commented Dec 13, 2015

This is X' fault and a very special use case, waiting for Wayland.

@punto-
Copy link
Contributor

punto- commented Dec 13, 2015

If I remember correctly, the clipboard code doesn't really deal with the "2
clipboards" problem of X11, we copy to both clipboards, but I don't
remember where we paste from. I think my intention was to paste from the
latest modified (ie whatever you did last, "copy" or "selection" ends up
pasted when you press ctrl+v in godot), but I don't remember if I
succeeded, in that case I might have picked one of the 2.

Having 2 clipboards is pretty stupid anyway, and in X11 they're not even
"clipboards", it's some kind of IPC system where you communicate with the
last window that claimed the particular global variable called "CLIPBOARD"
or "SELECTION" or whatever, and ask for the contents.

On 12 December 2015 at 21:30, Stian Furu Øverbye notifications@github.com
wrote:

This is X' fault and a very special use case, waiting for Wayland.


Reply to this email directly or view it on GitHub
#3030 (comment).

@est31
Copy link
Contributor

est31 commented Dec 15, 2015

@punto- The IPC system is smarter than copying the whole clipboard to the window manager. This way there is no overhead when you do ctrl+c or when you select text. The overhead only happens when you do ctrl+v or when you press the middle button. Its no big issue to copy stuff if you copy a small piece of text, but sometimes you want to copy whole files or stuff.

@StianTheDark Wayland has currently no support for middle click paste buffers. In fact, it (as protocol) makes the life for wm's and applications even very hard, e.g. you have to think of your own custom MIME type in order to be able to distinguish the selection buffer from the ctrl+c/ctrl+v buffer. And neither weston nor the kde or gnome efforts support middle click pasting, as of now. Or you think of your own custom IPC method to do this, but as long as neither kde nor gnome nor weston support it (nor the toolkits!), one is without hope.

@TierraDelFuego
Copy link
Author

@reduz, this should work in linux, this is just in the GD editor. @punto- this is a basic X feature that's existed for as long as I can remember, there are many, many stupid things in X. This feature is very useful.

@danboid
Copy link

danboid commented Mar 5, 2017

+1

My fave feature of X is the ability to copy text by highlighting it and paste it with middle click. I find it much more efficient than other methods so I was very disappointed when I discovered this doesn't work under the gd script editor as I use that feature constantly under every other X app.

@nbanks
Copy link

nbanks commented Mar 6, 2019

Has there been any progress on this? I'm still not able to center-click to paste with Godot 3.1-beta. It's difficult to copy from an urxvt terminal to the Godot editor because it uses Ctrl-C to terminate the running process. Apparently Ctrl+Alt+C or Ctrl+Shift+C will copy to the clipboard, but I only use the keystroke every few years whereas I use the center click dozens of times a day.

@larpon
Copy link
Contributor

larpon commented May 30, 2019

I use this feature everywhere in GNU/Linux where there's a text/edit area.
This includes browser textareas, all text editors I've tried so far (Kate, KWrite, Atom, QtCreator + many more), in all terminals (Konsole, XTerm), on the plasma desktop (pastes a new note with copy buffer text). Basically everywhere you have text input this feature is enabled. In short this is something people are used to when working in Linux (X) environments.

I'd vote for it to be enabled, as a minimum, in the Godot main editor.
Pasting with middle-mouse click into game windows should be optional.

It's quite a show-stopper when you're used to this.

@larpon
Copy link
Contributor

larpon commented Aug 26, 2019

The Qt implementation of clipboard has some clarifying notes on the global mouse Selection
https://github.com/qt/qtbase/blob/53d62b8fcbb639bd625777c8f1c01764445fb1c4/src/gui/kernel/qclipboard.cpp#L94-L117

I've been thinking it could be possible to support in text input fields in editor mode. It doesn't have to touch Godot's clipboard system. Some applications under X11 implement clipboard indexes (also known as Clipboard History) for convenience which is the "real" (Ctrl+c) clipboard - but the middle-mouse uses the X11 global "Selection" buffer which is specifically dedicated to hold selected text from your application - and get pasted into another application window with middle-mouse.

So it shouldn't touch the normal system wide clipboard - it's a separate buffer (or "feature") available in X11.

Would it be a solution to have code in text input fields in Godot that send the text to the X11 selection buffer upon a selection end - and then (optionally) have them looking for content in said buffer when clicking with middle-mouse in a text input field, only enabled in editor mode to ensure it doesn't break any existing games relying on middle-mouse events?

The implementation could sit as a detectable feature of the current clipboard system in Godot (drawing inspiration from the Qt implementation)

EDIT
It seems the clipboard "system" is just two virtual methods in OS

@larpon
Copy link
Contributor

larpon commented Sep 2, 2019

If anyone care, I now have a working implementation at https://github.com/Larpon/godot/tree/feature/multi-clipboards

Selections in TextEdit and LineEdit fields now get reflected in X11 PRIMARY clipboard (middle mouse button) - and likewise middle-mouse clicks in those input fields will result in a paste at the cursor position. So selection and MMB paste are now possible both in Godot and between Godot and other X11 applications.

IMPORTANT
Be advised that the code is NOT production ready yet - and I'm waiting to discuss a better architecture and more features with the maintainers. Current version is not platform and editor/game aware yet so the functionality will work inside the editor and in any games using aforementioned fields on other platforms.

I thought I'd link it here to let people test it and provide feedback if they want 😃

@thejacer87
Copy link

@larpon any updates? do we know if this is coming soon

@larpon
Copy link
Contributor

larpon commented Apr 13, 2020

@thejacer87 - I'm a bit out of the loop currently. I spoke to "TMM" (irc nick) on IRC a while back and we concluded that he (or someone) had to rewrite the X server integration after 3.2 - and then I could start working on proper support on top of that. The current code need to be rewritten according to TMM. So maybe ask around on IRC?

@ConteZero
Copy link
Contributor

@larpon I have updated your patches to make them work with the latest stable branch (3.3.4)
I fixed some bugs and added small improvements, for those who want to do some tests, the code can be found at
https://github.com/ConteZero/godot/tree/3.3

For openSUSE Tumbleweed users there is a package available at
https://build.opensuse.org/package/show/home:alucardx:godot/godot

I've been using it for a few days and it seems to work fine, now the clipboard on Godot behaves like any other application on Linux

@thejacer87
Copy link

this is in 3.3.4...? i swear i just updated yesterday and it still didn't work. will check again tonight

@ConteZero
Copy link
Contributor

@thejacer87 the patches are not merged in official 3.3.4 build, I've only posted my forked repository that contain the clipboard patches

@Calinou
Copy link
Member

Calinou commented Oct 8, 2021

Note that if you want this feature to be merged, it has to be redone for the master branch first (which uses an entirely different platform layer known as DisplayServer). Then you can open a pull request against the master branch. The existing version can be opened as a pull request against the 3.x branch after the master PR was opened 🙂

@larpon
Copy link
Contributor

larpon commented Oct 8, 2021

@larpon I have updated your patches to make them work with the latest stable branch (3.3.4) I fixed some bugs and added small improvements.

@ConteZero awesome! Good job 💪 my comment above from April last year is still valid though. I'm unsure if it'll ever reach master in this condition. I hope it will since this is a major UX improvement for users that use the select copy /MM paste all the time.

@ConteZero
Copy link
Contributor

Note that if you want this feature to be merged, it has to be redone for the master branch first (which uses an entirely different platform layer known as DisplayServer). Then you can open a pull request against the master branch. The existing version can be opened as a pull request against the 3.x branch after the master PR was opened slightly_smiling_face

Porting the patches to master branch is not straight forward for me:

  • as you noted master branch uses DisplayServer so I need to understand how it handles the clipboard first
  • vulkan does not works well with my igpu so I cannot run the code in master
  • I do not know if the current code if the right way to go, if the devs do not like how the feature is implemented then it will be only a waste of time

@ConteZero
Copy link
Contributor

@larpon I have updated your patches to make them work with the latest stable branch (3.3.4) I fixed some bugs and added small improvements.

@ConteZero awesome! Good job muscle my comment above from April last year is still valid though. I'm unsure if it'll ever reach master in this condition. I hope it will since this is a major UX improvement for users that use the select copy /MM paste all the time.

I can confirm it's a huge UX improvement, if you use Linux it's a killer feature, you understand how important it is only when it doesn't work.
As for your April comment I don't know how the developers want the code to be rewritten, I can only say that the current code works fine.
I added some #ifdef so that the code in scene/gui/ only compiles on Linux.
I also thought about adding a parameter in case you need to disable the primary clipboard in game, but would it really be useful?

@larpon
Copy link
Contributor

larpon commented Oct 9, 2021

I also thought about adding a parameter in case you need to disable the primary clipboard in game, but would it really be useful?

Yes definitely. Many games use MM and Ctrl+C/P for different action input. I can vaguely remember that it'd had to be implemented as a setting for sure, for cases like the mentioned.

@ConteZero
Copy link
Contributor

A new property in line_edit and text_edit similar to shortcut_keys_enabled but for the middle mouse button will be enough?

@Calinou
Copy link
Member

Calinou commented Oct 9, 2021

I'm not sure if this needs to be made optional. People generally expect X11 middle-mouse paste to work in every text field, everywhere. It should also use a clipboard separate from the main (Ctrl + C) clipboard.

@larpon
Copy link
Contributor

larpon commented Oct 10, 2021

But what about in-game text fields? If you're using the UI in-game, you might not want that behaviour or am I missing something?

@ConteZero
Copy link
Contributor

ConteZero commented Oct 10, 2021

I've ported the patches to master branch
https://github.com/ConteZero/godot/tree/primary_clipboard_linux
but I cannot test it because vulkan does not work with my igpu, so I need some volunteer to try if it works.

@larpon
Copy link
Contributor

larpon commented Oct 11, 2021

but I cannot test it because vulkan does not work with my igpu.

Same story here 🙁

@ConteZero
Copy link
Contributor

I used a friend's pc to test it and it works so I've done a pull request for master

@Calinou Calinou added enhancement and removed bug labels Oct 12, 2021
@Calinou
Copy link
Member

Calinou commented Oct 16, 2021

Closing in favor of godotengine/godot-proposals#3440, as feature proposals are now tracked on the Godot proposals repository.

@FeralBytes
Copy link
Contributor

@ConteZero now that this is merged for master, can we please get a 3.4 port, if you have the time. Thank you.

@ConteZero
Copy link
Contributor

@FeralBytes I've already done a pull request to backport it to 3.x three weeks ago, is awaiting review
#54026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests