Use wl-copy for clipboard on Wayland, Qt fallback on X11/Windows
Qt's clipboard doesn't work reliably on Wayland. Pipes the file directly to wl-copy with correct MIME type. Falls back to QApplication.clipboard().setPixmap() on other platforms.
This commit is contained in:
parent
81d7a0c5d0
commit
84b1e738ab
@ -1896,20 +1896,7 @@ class BooruApp(QMainWindow):
|
|||||||
super().keyPressEvent(event)
|
super().keyPressEvent(event)
|
||||||
|
|
||||||
def _copy_preview_to_clipboard(self) -> None:
|
def _copy_preview_to_clipboard(self) -> None:
|
||||||
# Try preview pixmap
|
# Find the file path to copy
|
||||||
pix = self._preview._image_viewer._pixmap
|
|
||||||
if pix and not pix.isNull():
|
|
||||||
QApplication.clipboard().setPixmap(pix)
|
|
||||||
self._status.showMessage(f"{len(self._posts)} results — Copied to clipboard")
|
|
||||||
return
|
|
||||||
# Try slideshow pixmap
|
|
||||||
if self._fullscreen_window and self._fullscreen_window._viewer._pixmap:
|
|
||||||
pix = self._fullscreen_window._viewer._pixmap
|
|
||||||
if not pix.isNull():
|
|
||||||
QApplication.clipboard().setPixmap(pix)
|
|
||||||
self._status.showMessage(f"{len(self._posts)} results — Copied to clipboard")
|
|
||||||
return
|
|
||||||
# Try loading from preview path or selected post's cached file
|
|
||||||
path = self._preview._current_path
|
path = self._preview._current_path
|
||||||
if not path:
|
if not path:
|
||||||
idx = self._grid.selected_index
|
idx = self._grid.selected_index
|
||||||
@ -1918,12 +1905,36 @@ class BooruApp(QMainWindow):
|
|||||||
cp = cached_path_for(self._posts[idx].file_url)
|
cp = cached_path_for(self._posts[idx].file_url)
|
||||||
if cp.exists():
|
if cp.exists():
|
||||||
path = str(cp)
|
path = str(cp)
|
||||||
if path:
|
if not path or not Path(path).exists():
|
||||||
|
self._status.showMessage(f"{len(self._posts)} results — Nothing to copy")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Try wl-copy on Wayland, fall back to Qt clipboard
|
||||||
|
import shutil
|
||||||
|
if shutil.which("wl-copy"):
|
||||||
|
import subprocess
|
||||||
|
mime = "image/png"
|
||||||
|
ext = Path(path).suffix.lower()
|
||||||
|
if ext in (".jpg", ".jpeg"):
|
||||||
|
mime = "image/jpeg"
|
||||||
|
elif ext == ".gif":
|
||||||
|
mime = "image/gif"
|
||||||
|
elif ext == ".webp":
|
||||||
|
mime = "image/webp"
|
||||||
|
try:
|
||||||
|
with open(path, "rb") as f:
|
||||||
|
subprocess.run(["wl-copy", "--type", mime], stdin=f, timeout=5)
|
||||||
|
self._status.showMessage(f"{len(self._posts)} results — Copied to clipboard")
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
log.warning(f"wl-copy failed: {e}")
|
||||||
|
|
||||||
|
# Qt fallback
|
||||||
pix = QPixmap(path)
|
pix = QPixmap(path)
|
||||||
if not pix.isNull():
|
if not pix.isNull():
|
||||||
QApplication.clipboard().setPixmap(pix)
|
QApplication.clipboard().setPixmap(pix)
|
||||||
self._status.showMessage(f"{len(self._posts)} results — Copied to clipboard")
|
self._status.showMessage(f"{len(self._posts)} results — Copied to clipboard")
|
||||||
return
|
else:
|
||||||
self._status.showMessage(f"{len(self._posts)} results — Nothing to copy")
|
self._status.showMessage(f"{len(self._posts)} results — Nothing to copy")
|
||||||
|
|
||||||
# -- Bookmarks --
|
# -- Bookmarks --
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user