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

X11 Copy and Paste does not work #17

Open
JetStarBlues opened this issue Dec 5, 2019 · 9 comments
Open

X11 Copy and Paste does not work #17

JetStarBlues opened this issue Dec 5, 2019 · 9 comments

Comments

@JetStarBlues
Copy link

The copy and paste feature of the X11 demo does not work. The code (found in nuklear_xlib.h) that accesses the X11 clipboard seems to have all come from one commit (#371). Since then, there have been no substantial changes to the respective lines of code.

Copy and paste in the gdi equivalent works (nuklear_gdi.h), so the problem seems specific to the xlib implementation.

copy_paste

@dumblob
Copy link
Member

dumblob commented Dec 5, 2019

My observation:

  1. the X11 Nuklear backend uses just X PRIMARY selection
  2. X11 PRIMARY & SECONDARY selections needs the process with data being copied from to run during pasting in another process
  3. X11 CLIPBOARD is not implemented by the X11 Nuklear backend
  4. X11 CLIPBOARD doesn't need the originating process since the moment of copying
  5. X11 doesn't offer any synchronization between any of PRIMARY, SECONDARY, and CLIPBOARD
  6. most X11 graphical environments (KDE, Gnome, ...) do support handling of either PRIMARY or CLIPBOARD and sometimes even both
  7. xterm (and other X11 native apps having no dependencies on bigger frameworks like Qt/GTK/...) uses PRIMARY
  8. most Qt/GTK/... apps use CLIPBOARD

There are tools like xsel and many others offering synchronization of these selection buffers and handling of their content in general.

If you were not aware of the above, could you retest with this new knowledge?

I myself hate this distinction between several selection buffers, so I synchronize them all using 3 instances of autocutsel and thus can use any app and paste into arbitrary another app. There are though people using multiple content records e.g. in CLIPBOARD, so this taste varies a lot I'd say.

@JetStarBlues
Copy link
Author

JetStarBlues commented Dec 5, 2019

Thank you for the reply!

How is the PRIMARY clipboard supposed to be used? I am more familiar with the windows style of using CTRL+C and CTRL+V to copy and paste (as per the gdi demo). From what I am reading online, it seems that to use the PRIMARY clipboard, you select the text to copy, and middle click to paste:

For X11-based systems (ie. Linux and most other UNIX-like systems) there are two clipboards which are independent of each other:

PRIMARY - This is copy-on-select, and can be pasted with the middle mouse button.
CLIPBOARD - This is copied with (usually) ^C, and pasted with ^V (It's like MS Windows).

I opened xedit (the x11-apps version), and successfully copied and pasted text within xedit using this middle mouse button approach. However, when I select text from the nuklear textbox, and then attempt to paste it into xedit by clicking the middle mouse button nothing happens. Similarly the other way around, when I select text from xedit, and attempt to paste it into the nuklear textbox by clicking the middle mouse button, nothing happens...

It seems that NK_KEY_COPY and NK_KEY_PASTE have been associated with the CTRL+C and CTRL+V keys (see these lines). Whereas the only reference to the middle mouse button NK_BUTTON_MIDDLE in the file (nuklear_xlib.h), is the generic handler (see this line). So I am not sure how the middle mouse button is associated with pasting in the nuklear demo... Or how just selecting text is associated with copying...

Edit:
I also tried using CTRL+V in nuklear after selecting text in xedit but no luck this way either. The thought process here was, selecting text in xedit places it in the PRIMARY clipboard. And CTRL+V on nuklear would trigger the paste handler...

Edit2:
I also tried all the above steps mentioned for xedit, using the default Ubuntu terminal (i.e. copying and pasting text on the terminal using the middle mouse button interface) and Vim just in case xedit was not a good test candidate. It still failed... Copy/paste works between apps, but not between nuklear.

@dumblob
Copy link
Member

dumblob commented Dec 9, 2019

Thanks for thorough testing you did. As you experienced, PRIMARY is not necessarily handled (e.g. pasted) just by MMB. Let's try to dig deeper.

  1. Does copy&paste work within your Nuklear app itself in the same text widget instance?
  2. Does copy&paste work within your Nuklear app itself among different text widget instances?

@JetStarBlues
Copy link
Author

Hi
It does not work within the same text widget, or between text widgets. (Using the variety of copy/paste approaches (CTRL+C/V, middle mouse button, combos) described above).

@dumblob
Copy link
Member

dumblob commented Dec 10, 2019

Could you pleasy simulate the two cases from #17 (comment) fully programatically (i.e. just calling the appropriate functions one after another instead of waiting for mouse input etc.)?

@JetStarBlues
Copy link
Author

Hi
My understanding of how Nuklear works isn't good enough at the moment to do so. I can't find any documentation regarding copy/paste let alone how to do it programatically. The copy/paste seems to be handled by nk_do_edit (link) but I'm not sure how to combine that with the nk_edit_string that generates the textbox (link)...

@dumblob
Copy link
Member

dumblob commented Dec 11, 2019

Please post your full code you're using to test the copy & paste behavior (use e.g. pastebin), so that we have a specific starting point.

@JetStarBlues
Copy link
Author

I am using the "overview.c" example that comes with the source code (see picture above).

nk_label(ctx, "Box:", NK_TEXT_LEFT);

@dumblob
Copy link
Member

dumblob commented Dec 28, 2019

A minimal example how to use X11 clipboard/selection capabilities is on https://gist.github.com/vurtun/1c57d1e9e2ee169b90209325e38f0cb7 - might be interesting to compare with the current Nuklear backend implementation.

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

No branches or pull requests

2 participants