xstate: refactor clipboard selections

Before, every time the clipboard selection changed, satellite would copy
everything on it and force itself to be the clipboard owner, regardless
of X11 or Wayland. Now, satellite is only the owner when the clipboard
owner comes from Wayland, and uses the XFixes extension to watch for
changes in clipboard ownership X11 side. Satellite also now avoids
copying all of the clipboard contents into memory every time, instead
copying directly on request. This is a pretty big change, but should
hopefully help make the clipboard more stable.

Also added some misc test cleanup/using helper functions where possible.
Using the XFixes extension may also end up being necessary for
implementing drag and drop, so it's good the infrastructure is there
now.
This commit is contained in:
Shawn Wallace 2025-01-08 23:57:22 -05:00
parent 42ffd06d1e
commit 47e7357eab
7 changed files with 755 additions and 777 deletions

View file

@ -7,6 +7,7 @@ use crate::server::{PendingSurfaceState, ServerState};
use crate::xstate::{RealConnection, XState};
use log::{error, info};
use rustix::event::{poll, PollFd, PollFlags};
use smithay_client_toolkit::data_device_manager::WritePipe;
use std::io::{BufRead, BufReader, Read, Write};
use std::os::fd::{AsFd, AsRawFd, BorrowedFd};
use std::os::unix::net::UnixStream;
@ -16,7 +17,7 @@ use xcb::x;
pub trait XConnection: Sized + 'static {
type ExtraData: FromServerState<Self>;
type MimeTypeData: MimeTypeData;
type X11Selection: X11Selection;
fn root_window(&self) -> x::Window;
fn set_window_dims(&mut self, window: x::Window, dims: PendingSurfaceState);
@ -35,9 +36,9 @@ pub trait FromServerState<C: XConnection> {
fn create(state: &ServerState<C>) -> Self;
}
pub trait MimeTypeData {
fn name(&self) -> &str;
fn data(&self) -> &[u8];
pub trait X11Selection {
fn mime_types(&self) -> Vec<&str>;
fn write_to(&self, mime: &str, pipe: WritePipe);
}
type RealServerState = ServerState<RealConnection>;