Results 1 to 3 of 3

Thread: X11 clipboard trouble

  1. #1
    Lesser Knight
    Join Date
    Jan 2011
    Location
    Vienna, Austria
    Posts
    30

    Default X11 clipboard trouble

    Hi,

    I'm having some trouble with the clipboard on Linux, using the latest clanlib 2.3 SVN.
    I think there are two issues in Display/X11/clipboard_x11.cpp:

    -) In CL_Clipboard_X11::get_clipboard_text, shouldn't there be a check like
    Code:
    if (clipboard_available)
    {
    	return clipboard_current;
    }
    at the beginning of the function? Both variables are set throughout the file, but never actually used. This might be especially important since selection requests from the same window are ignored (line 127).
    I tested this modification, works fine. A patch containing the above mentioned lines is attached.

    -) It appears to me that the get_clipboard_text function is not "waiting long enough" for the SelectionNotify event. When I execute the program normally, I can't copy text from other windows. However, when I step through the code with a debugger, copying from other windows works. Out of curiosity, I also tested with a sleep(1) before XCheckTypedWindowEvent - works as well.
    So my impression is that clanlib (or my computer) is a bit too fast here. But I do not really know how to fix this properly. Waiting in a while loop for the event can be problematic if other applications do not produce the correct events. Maybe an asynchronous callback would be the proper way to fix this, but that would require bigger modifications.

    Do you have any other ideas how to fix issue #2?
    Does the clipboard work on your computers?

    Thanks,
    spin
    Attached Files Attached Files

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I haven't had a chance to look at your patch.

    Ref issue #2

    Your bug description does seem to make sense.

    It might have occured during the http://clanlib.org/wiki/ClanLib_2.3.4_Release_Notes release

    For example...
    Linux - Window events are fired straight away, instead of queuing them. This ensures xlib and the application are synchronized
    ... and others.

    I don't think I ever tested the clipboard after the change.

    I have some ideas to fix it. I'll have a look, but it maybe in a couple of weeks time.

    Thanks

  3. #3
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I had a quick (2 hour) look at the problem.

    "clipboard_available" is not actually required

    It is a flag to determine if the X window supports the clipboard.

    The same check can be made by using "if (atom_CLIPBOARD == None ) "

    CL_Clipboard_X11::set_clipboard_text() "clipboard_current = text;" should be set, even if the X11 clipboard is not available
    CL_Clipboard_X11::get_clipboard_text() should return clipboard_current, not CL_String when the X11 clipboard is not available

    The XCheckTypedWindowEvent issue can be fixed by replacing the code as follows:

    Code:
    	XConvertSelection(disp, atom_CLIPBOARD, XA_STRING, None, window, CurrentTime);
    	XFlush(disp);
    
    	int retry_count = 500;	// Waiting for half second
    	while(true)
    	{
    		XEvent event;
    		if (XCheckTypedWindowEvent(x11_window->get_display(), x11_window->get_window(), SelectionNotify, &event))
    			break;
    
    		retry_count--;
    		if (retry_count < 0)
    			return CL_String();
    			
    		usleep(1000);
    	}
    But when testing by copying and pasting from the Terminal to a ClanLib application, the terminal and the ClanLib application both vanished!

    That is as far as I got.

    Notice, that I also changed XConvertSelection, from "XConvertSelection(disp, atom_CLIPBOARD, XA_STRING, atom_CLIPBOARD, window, CurrentTime);", which I believe was incorrect.

    If interested, have a look at the Wine source code: dlls/winex11.drv/clipboard.c .It is a more complete working implementation. Unfortunately, we cannot copy the entire code, due to it having a conflicting license.
    But we can still follow the same method, implementing it, in our way.

Similar Threads

  1. clipboard linux
    By sphair in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 05-25-2009, 07:42 PM
  2. Trouble with CL_InputBox
    By silekey in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 07-11-2007, 08:25 AM
  3. Trouble with CL_SoundBuffer_Session
    By somar in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 06-30-2007, 01:30 PM
  4. Trouble
    By FQ101 in forum Funeral Quest
    Replies: 1
    Last Post: 02-09-2007, 05:05 AM
  5. anyone else having trouble getting
    By jimbobbucky in forum Funeral Quest
    Replies: 4
    Last Post: 07-16-2003, 04:41 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •