[ஞாயிறு பிப்ரவரி 09, 2025] Ihor Radchenko wrote:

> Visuwesh <visuwe...@gmail.com> writes:
>
>>> One way to check for pgtk is checking the result of
>>> (window-system). Or checking whether `pgtk-backend-display-class' is
>>> `fboundp'.
>>
>> I don't think we should use (window-system) since the return value is
>> FRAME dependent: if Someone™ opens a terminal frame first and loads Org
>> while it is focused, they won't get this fix even if their build is a
>> pgtk build.  C:
>> [ I think this will definitely break for daemon processes.  ]
>>
>> We could rely on (fboundp 'pgtk-backend-display-class) but I somehow
>> don't like it as compared to just leaving this extra check out.
>
> We can use (foundp 'pgtk-get-selection-internal).
> And we kind of need to. At least, to pacify the byte-compiler.

Now done.

> Also, please check that the method is not yet defined. We do not want to
> overwrite an existing method if it is defined by user/other package.

I am using an undocumented (autoloaded) function to do so.  Please note
that I know less than nothing about cl-defgeneric/cl-defmethod and the
solution I found was from trial-and-error.
[ The test returns non-nil once I C-x C-e the cl-defmethod so that is at
  least something.  ]

>From cc1b303f28d8bfdbfe240753cf5f37456bec0ae5 Mon Sep 17 00:00:00 2001
From: Visuwesh <visuwe...@gmail.com>
Date: Fri, 24 Jan 2025 10:32:15 +0530
Subject: [PATCH] Add workaround to make yank-media work under GNOME for Emacs
 29
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/org-compat.el: Add workaround proposed by Robert Pluim
<rpl...@gmail.com> to make yank-media work under GNOME reliably for
Emacs 29.

Link: https://list.orgmode.org/orgmode/87ed7kttoa....@k-7.ch
Reported-by: Sébastien Gendre <s...@k-7.ch>
---
 lisp/org-compat.el | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 91192629a..cfcb831d1 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -1992,6 +1992,26 @@ (make-obsolete-variable 'org-speed-commands-user
                         "configure `org-speed-commands' instead." "9.5")
 (provide 'org-compat)
 
+;;;; yank-media
+;; Emacs 29's pgtk port has a bug where it might fail to return the
+;; right TARGET.  Install a workaround for Emacs <=29 since the fix
+;; went to Emacs 30.  See bug#72254.
+;; Org bug report link: https://list.orgmode.org/orgmode/87ed7kttoa....@k-7.ch
+;; This should be removed once we drop Emacs 29 support.
+(when (and (fboundp 'pgtk-get-selection-internal)
+           (<= emacs-major-version 29))
+  ;; Only define the method if it hasn't been previously defined.
+  (unless (cl-find-method 'gui-backend-get-selection nil
+                          '((eql 'CLIPBOARD) (eql 'TARGETS)
+                            ((&context . window-system) eql 'pgtk)))
+    (cl-defmethod gui-backend-get-selection ((selection-symbol (eql 'CLIPBOARD))
+                                             (target-type (eql 'TARGETS))
+                                             &context (window-system pgtk))
+      (let ((sel (pgtk-get-selection-internal selection-symbol target-type)))
+        (if (vectorp sel)
+            sel
+          (vector sel))))))
+
 ;; Local variables:
 ;; generated-autoload-file: "org-loaddefs.el"
 ;; End:
-- 
2.47.2

Reply via email to