Skip to content

Fix possible race conditions with XSetSelection()

Carlos Garnacho requested to merge wip/carlosg/x11-selection-timestamps into master

From the main commit:

    x11: Fix race conditions in XSetSelection
    
    Some clients like X11 LibreOffice clear the selection prior to copying
    some content there. This selection clear is correctly seen by our clipboard
    manager as a hint to take ownership and preserve the last copied content,
    all while LO is issuing other XSetSelection with the new clipboard content.
    
    Our use of META_CURRENT_TIME turns this into a race condition, as there's
    both LO and our clipboard manager trying to do XSetSelection(), from our
    side it's all up to the order in which the requests arrive to the X server.
    
    In order to break the tie, keep the selection timestamp from the XFixes
    event (i.e. the timestamp set by the XSetSelection external call that is
    unsetting the clipboard) and ensure it is used for our own XSetSelection
    call replacing the selection. In this same situation, it will make the
    X server deem the request too old, and let LO win.
    
    If the compositor-side XSetSelection event does not happen in result to
    a XFixes selection notify event, the current event time will be used, and
    META_CURRENT_TIME as a last resort.
    
    Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1113

Merge request reports