Revert "linux(x11): Add support for pasting images from clipboard (#29387)" (#31033)

Closes: #30523

Release Notes:

- linux: Reverted the ability to paste images on X11, as the change
broke pasting from some external applications
This commit is contained in:
Ben Kunkle 2025-05-20 12:05:24 -05:00 committed by GitHub
parent 5e5a124ae1
commit eb318c1626
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 28 deletions

View file

@ -1,5 +1,4 @@
mod client; mod client;
mod clipboard;
mod display; mod display;
mod event; mod event;
mod window; mod window;

View file

@ -1,3 +1,4 @@
use crate::platform::scap_screen_capture::scap_screen_sources;
use core::str; use core::str;
use std::{ use std::{
cell::RefCell, cell::RefCell,
@ -40,9 +41,8 @@ use xkbc::x11::ffi::{XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSIO
use xkbcommon::xkb::{self as xkbc, LayoutIndex, ModMask, STATE_LAYOUT_EFFECTIVE}; use xkbcommon::xkb::{self as xkbc, LayoutIndex, ModMask, STATE_LAYOUT_EFFECTIVE};
use super::{ use super::{
ButtonOrScroll, ScrollDirection, button_or_scroll_from_event_detail, ButtonOrScroll, ScrollDirection, button_or_scroll_from_event_detail, get_valuator_axis_index,
clipboard::{self, Clipboard}, modifiers_from_state, pressed_button_from_mask,
get_valuator_axis_index, modifiers_from_state, pressed_button_from_mask,
}; };
use super::{X11Display, X11WindowStatePtr, XcbAtoms}; use super::{X11Display, X11WindowStatePtr, XcbAtoms};
use super::{XimCallbackEvent, XimHandler}; use super::{XimCallbackEvent, XimHandler};
@ -56,7 +56,6 @@ use crate::platform::{
reveal_path_internal, reveal_path_internal,
xdg_desktop_portal::{Event as XDPEvent, XDPEventSource}, xdg_desktop_portal::{Event as XDPEvent, XDPEventSource},
}, },
scap_screen_capture::scap_screen_sources,
}; };
use crate::{ use crate::{
AnyWindowHandle, Bounds, ClipboardItem, CursorStyle, DisplayId, FileDropEvent, Keystroke, AnyWindowHandle, Bounds, ClipboardItem, CursorStyle, DisplayId, FileDropEvent, Keystroke,
@ -202,7 +201,7 @@ pub struct X11ClientState {
pointer_device_states: BTreeMap<xinput::DeviceId, PointerDeviceState>, pointer_device_states: BTreeMap<xinput::DeviceId, PointerDeviceState>,
pub(crate) common: LinuxCommon, pub(crate) common: LinuxCommon,
pub(crate) clipboard: Clipboard, pub(crate) clipboard: x11_clipboard::Clipboard,
pub(crate) clipboard_item: Option<ClipboardItem>, pub(crate) clipboard_item: Option<ClipboardItem>,
pub(crate) xdnd_state: Xdnd, pub(crate) xdnd_state: Xdnd,
} }
@ -389,7 +388,7 @@ impl X11Client {
.reply() .reply()
.unwrap(); .unwrap();
let clipboard = Clipboard::new().unwrap(); let clipboard = x11_clipboard::Clipboard::new().unwrap();
let xcb_connection = Rc::new(xcb_connection); let xcb_connection = Rc::new(xcb_connection);
@ -1497,36 +1496,39 @@ impl LinuxClient for X11Client {
let state = self.0.borrow_mut(); let state = self.0.borrow_mut();
state state
.clipboard .clipboard
.set_text( .store(
std::borrow::Cow::Owned(item.text().unwrap_or_default()), state.clipboard.setter.atoms.primary,
clipboard::ClipboardKind::Primary, state.clipboard.setter.atoms.utf8_string,
clipboard::WaitConfig::None, item.text().unwrap_or_default().as_bytes(),
) )
.context("Failed to write to clipboard (primary)") .ok();
.log_with_level(log::Level::Debug);
} }
fn write_to_clipboard(&self, item: crate::ClipboardItem) { fn write_to_clipboard(&self, item: crate::ClipboardItem) {
let mut state = self.0.borrow_mut(); let mut state = self.0.borrow_mut();
state state
.clipboard .clipboard
.set_text( .store(
std::borrow::Cow::Owned(item.text().unwrap_or_default()), state.clipboard.setter.atoms.clipboard,
clipboard::ClipboardKind::Clipboard, state.clipboard.setter.atoms.utf8_string,
clipboard::WaitConfig::None, item.text().unwrap_or_default().as_bytes(),
) )
.context("Failed to write to clipboard (clipboard)") .ok();
.log_with_level(log::Level::Debug);
state.clipboard_item.replace(item); state.clipboard_item.replace(item);
} }
fn read_from_primary(&self) -> Option<crate::ClipboardItem> { fn read_from_primary(&self) -> Option<crate::ClipboardItem> {
let state = self.0.borrow_mut(); let state = self.0.borrow_mut();
return state state
.clipboard .clipboard
.get_any(clipboard::ClipboardKind::Primary) .load(
.context("Failed to read from clipboard (primary)") state.clipboard.getter.atoms.primary,
.log_with_level(log::Level::Debug); state.clipboard.getter.atoms.utf8_string,
state.clipboard.getter.atoms.property,
Duration::from_secs(3),
)
.map(|text| crate::ClipboardItem::new_string(String::from_utf8(text).unwrap()))
.ok()
} }
fn read_from_clipboard(&self) -> Option<crate::ClipboardItem> { fn read_from_clipboard(&self) -> Option<crate::ClipboardItem> {
@ -1535,15 +1537,26 @@ impl LinuxClient for X11Client {
// which has metadata attached. // which has metadata attached.
if state if state
.clipboard .clipboard
.is_owner(clipboard::ClipboardKind::Clipboard) .setter
.connection
.get_selection_owner(state.clipboard.setter.atoms.clipboard)
.ok()
.and_then(|r| r.reply().ok())
.map(|reply| reply.owner == state.clipboard.setter.window)
.unwrap_or(false)
{ {
return state.clipboard_item.clone(); return state.clipboard_item.clone();
} }
return state state
.clipboard .clipboard
.get_any(clipboard::ClipboardKind::Clipboard) .load(
.context("Failed to read from clipboard (clipboard)") state.clipboard.getter.atoms.clipboard,
.log_with_level(log::Level::Debug); state.clipboard.getter.atoms.utf8_string,
state.clipboard.getter.atoms.property,
Duration::from_secs(3),
)
.map(|text| crate::ClipboardItem::new_string(String::from_utf8(text).unwrap()))
.ok()
} }
fn run(&self) { fn run(&self) {