godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.95k stars 20.17k forks source link

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

Closed TierraDelFuego closed 2 years ago

TierraDelFuego commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

punto- commented 8 years ago

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 https://github.com/godotengine/godot/issues/3030#issuecomment-164204494.

est31 commented 8 years ago

@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 commented 8 years ago

@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 commented 7 years ago

+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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 :smiley:

thejacer87 commented 4 years ago

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

larpon commented 4 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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

ConteZero commented 2 years ago

@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 commented 2 years ago

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:

larpon commented 2 years ago

@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 commented 2 years ago

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:

ConteZero commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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

Calinou commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

Same story here 🙁

ConteZero commented 2 years ago

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

Calinou commented 2 years ago

Closing in favor of https://github.com/godotengine/godot-proposals/issues/3440, as feature proposals are now tracked on the Godot proposals repository.

FeralBytes commented 2 years ago

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

ConteZero commented 2 years ago

@FeralBytes I've already done a pull request to backport it to 3.x three weeks ago, is awaiting review https://github.com/godotengine/godot/pull/54026