From b47d36f189d067ebf41098021da1d1e160db9d53 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 14 Feb 2022 10:17:58 +0000 Subject: [PATCH] Improve Haiku selection handling * lisp/select.el (gui--selection-value-internal): Use X types on Haiku as well. * lisp/term/haiku-win.el (haiku--selection-type-to-mime): Update types to correspond better with X. * src/haikuselect.c (Fhaiku_selection_data): (Fhaiku_selection_put): Remove a great deal of ad hoc code now handled by the regular selection machinery. --- lisp/select.el | 2 +- lisp/term/haiku-win.el | 3 ++- src/haikuselect.c | 31 +++++++------------------------ 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/lisp/select.el b/lisp/select.el index ca9061c0b03..42b50c44e6c 100644 --- a/lisp/select.el +++ b/lisp/select.el @@ -176,7 +176,7 @@ decoded. If `gui-get-selection' signals an error, return nil." (memq window-system '(x haiku)) (eq type 'CLIPBOARD) (gui-backend-selection-owner-p type)) - (let ((request-type (if (memq window-system '(x pgtk)) + (let ((request-type (if (memq window-system '(x pgtk haiku)) (or x-select-request-type '(UTF8_STRING COMPOUND_TEXT STRING text/plain\;charset=utf-8)) 'STRING)) diff --git a/lisp/term/haiku-win.el b/lisp/term/haiku-win.el index 4c06f7f58aa..c4810f116d2 100644 --- a/lisp/term/haiku-win.el +++ b/lisp/term/haiku-win.el @@ -86,7 +86,8 @@ DISPLAY may be set to the name of a display that will be initialized." "Convert symbolic selection type TYPE to its MIME equivalent. If TYPE is nil, return \"text/plain\"." (cond - ((memq type '(TEXT COMPOUND_TEXT STRING UTF8_STRING)) "text/plain") + ((eq type 'STRING) "text/plain;charset=iso-8859-1") + ((eq type 'UTF8_STRING) "text/plain") ((stringp type) type) ((symbolp type) (symbol-name type)) (t "text/plain"))) diff --git a/src/haikuselect.c b/src/haikuselect.c index e65ab827c51..65dac0e02fa 100644 --- a/src/haikuselect.c +++ b/src/haikuselect.c @@ -97,20 +97,12 @@ fetch. */) return Qnil; Lisp_Object str = make_unibyte_string (dat, len); - Lisp_Object lispy_type = Qnil; - if (!strcmp (SSDATA (name), "text/utf-8") || - !strcmp (SSDATA (name), "text/plain")) - { - if (string_ascii_p (str)) - lispy_type = QSTRING; - else - lispy_type = QUTF8_STRING; - } - - if (!NILP (lispy_type)) - Fput_text_property (make_fixnum (0), make_fixnum (len), - Qforeign_selection, lispy_type, str); + /* `foreign-selection' just means that the selection has to be + decoded by `gui-get-selection'. It has no other meaning, + AFAICT. */ + Fput_text_property (make_fixnum (0), make_fixnum (len), + Qforeign_selection, Qt, str); block_input (); BClipboard_free_data (dat); @@ -125,10 +117,8 @@ DEFUN ("haiku-selection-put", Fhaiku_selection_put, Shaiku_selection_put, CLIPBOARD is the symbol `PRIMARY', `SECONDARY' or `CLIPBOARD'. NAME is a MIME type denoting the type of the data to add. DATA is the string that will be placed in the clipboard, or nil if the content is -to be removed. If NAME is the string "text/utf-8" or the string -"text/plain", encode it as UTF-8 before storing it into the clipboard. -CLEAR, if non-nil, means to erase all the previous contents of the -clipboard. */) +to be removed. CLEAR, if non-nil, means to erase all the previous +contents of the clipboard. */) (Lisp_Object clipboard, Lisp_Object name, Lisp_Object data, Lisp_Object clear) { @@ -138,13 +128,6 @@ clipboard. */) CHECK_STRING (data); block_input (); - /* It seems that Haiku applications counter-intuitively expect - UTF-8 data in both text/utf-8 and text/plain. */ - if (!NILP (data) && STRING_MULTIBYTE (data) && - (!strcmp (SSDATA (name), "text/utf-8") || - !strcmp (SSDATA (name), "text/plain"))) - data = ENCODE_UTF_8 (data); - char *dat = !NILP (data) ? SSDATA (data) : NULL; ptrdiff_t len = !NILP (data) ? SBYTES (data) : 0; -- 2.39.5