diff options
| author | Po Lu | 2021-11-24 12:48:01 +0000 |
|---|---|---|
| committer | Po Lu | 2021-11-24 12:58:39 +0000 |
| commit | fc35928ec2b3be40ff7323515f948fc82ca487ca (patch) | |
| tree | 0882f12fdad3aab03d56e923905d8c25582ad282 /src/haikuselect.c | |
| parent | 7878c7f596d69efb68501503da391ed645ae151e (diff) | |
| download | emacs-fc35928ec2b3be40ff7323515f948fc82ca487ca.tar.gz emacs-fc35928ec2b3be40ff7323515f948fc82ca487ca.zip | |
Make `yank-media' work on Haiku
This works with what WebPositive does with images, at least. I don't
know about other programs, but Haiku doesn't seem to standardize this
very well.
* lisp/term/haiku-win.el (haiku--selection-type-to-mime): Handle
regular symbols.
(gui-backend-get-selection): Handle special type `TARGETS'.
(gui-backend-set-selection): Always clear clipboard.
* src/haiku_select.cc (BClipboard_get_targets): New function.
(BClipboard_set_data): New argument `clear'. All callers
changed.
(BClipboard_set_system_data)
(BClipboard_set_primary_selection_data)
(BClipboard_set_secondary_selection_data): New argument `clear'.
(BClipboard_system_targets, BClipboard_primary_targets)
(BClipboard_secondary_targets): New functions.
* src/haikuselect.c (haiku_selection_data_1): New function.
(Fhaiku_selection_targets): New function.
(Fhaiku_selection_put): Allow controlling if the clipboard is
cleared.
(syms_of_haikuselect): New symbols and subrs.
* src/haikuselect.h (BClipboard_set_system_data)
(BClipboard_set_primary_selection_data)
(BClipboard_set_secondary_selection_data): New argument `clear'.
(BClipboard_system_targets, BClipboard_primary_targets)
(BClipboard_secondary_targets): New functions.
Diffstat (limited to 'src/haikuselect.c')
| -rw-r--r-- | src/haikuselect.c | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/src/haikuselect.c b/src/haikuselect.c index 3f0441e0779..38cceb1de74 100644 --- a/src/haikuselect.c +++ b/src/haikuselect.c | |||
| @@ -24,6 +24,46 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 24 | #include "haikuselect.h" | 24 | #include "haikuselect.h" |
| 25 | #include "haikuterm.h" | 25 | #include "haikuterm.h" |
| 26 | 26 | ||
| 27 | static Lisp_Object | ||
| 28 | haiku_selection_data_1 (Lisp_Object clipboard) | ||
| 29 | { | ||
| 30 | Lisp_Object result = Qnil; | ||
| 31 | char *targets[256]; | ||
| 32 | |||
| 33 | block_input (); | ||
| 34 | if (EQ (clipboard, QPRIMARY)) | ||
| 35 | BClipboard_primary_targets ((char **) &targets, 256); | ||
| 36 | else if (EQ (clipboard, QSECONDARY)) | ||
| 37 | BClipboard_secondary_targets ((char **) &targets, 256); | ||
| 38 | else if (EQ (clipboard, QCLIPBOARD)) | ||
| 39 | BClipboard_system_targets ((char **) &targets, 256); | ||
| 40 | else | ||
| 41 | { | ||
| 42 | unblock_input (); | ||
| 43 | signal_error ("Bad clipboard", clipboard); | ||
| 44 | } | ||
| 45 | |||
| 46 | for (int i = 0; targets[i]; ++i) | ||
| 47 | { | ||
| 48 | result = Fcons (build_unibyte_string (targets[i]), | ||
| 49 | result); | ||
| 50 | free (targets[i]); | ||
| 51 | } | ||
| 52 | unblock_input (); | ||
| 53 | |||
| 54 | return result; | ||
| 55 | } | ||
| 56 | |||
| 57 | DEFUN ("haiku-selection-targets", Fhaiku_selection_targets, | ||
| 58 | Shaiku_selection_targets, 1, 1, 0, | ||
| 59 | doc: /* Find the types of data available from CLIPBOARD. | ||
| 60 | CLIPBOARD should be the symbol `PRIMARY', `SECONDARY' or `CLIPBOARD'. | ||
| 61 | Return the available types as a list of strings. */) | ||
| 62 | (Lisp_Object clipboard) | ||
| 63 | { | ||
| 64 | return haiku_selection_data_1 (clipboard); | ||
| 65 | } | ||
| 66 | |||
| 27 | DEFUN ("haiku-selection-data", Fhaiku_selection_data, Shaiku_selection_data, | 67 | DEFUN ("haiku-selection-data", Fhaiku_selection_data, Shaiku_selection_data, |
| 28 | 2, 2, 0, | 68 | 2, 2, 0, |
| 29 | doc: /* Retrieve content typed as NAME from the clipboard | 69 | doc: /* Retrieve content typed as NAME from the clipboard |
| @@ -78,15 +118,17 @@ fetch. */) | |||
| 78 | } | 118 | } |
| 79 | 119 | ||
| 80 | DEFUN ("haiku-selection-put", Fhaiku_selection_put, Shaiku_selection_put, | 120 | DEFUN ("haiku-selection-put", Fhaiku_selection_put, Shaiku_selection_put, |
| 81 | 3, 3, 0, | 121 | 3, 4, 0, |
| 82 | doc: /* Add or remove content from the clipboard CLIPBOARD. | 122 | doc: /* Add or remove content from the clipboard CLIPBOARD. |
| 83 | CLIPBOARD is the symbol `PRIMARY', `SECONDARY' or `CLIPBOARD'. NAME | 123 | CLIPBOARD is the symbol `PRIMARY', `SECONDARY' or `CLIPBOARD'. NAME |
| 84 | is a MIME type denoting the type of the data to add. DATA is the | 124 | is a MIME type denoting the type of the data to add. DATA is the |
| 85 | string that will be placed in the clipboard, or nil if the content is | 125 | string that will be placed in the clipboard, or nil if the content is |
| 86 | to be removed. If NAME is the string `text/utf-8' or the string | 126 | to be removed. If NAME is the string "text/utf-8" or the string |
| 87 | `text/plain', encode it as UTF-8 before storing it into the | 127 | "text/plain", encode it as UTF-8 before storing it into the clipboard. |
| 128 | CLEAR, if non-nil, means to erase all the previous contents of the | ||
| 88 | clipboard. */) | 129 | clipboard. */) |
| 89 | (Lisp_Object clipboard, Lisp_Object name, Lisp_Object data) | 130 | (Lisp_Object clipboard, Lisp_Object name, Lisp_Object data, |
| 131 | Lisp_Object clear) | ||
| 90 | { | 132 | { |
| 91 | CHECK_SYMBOL (clipboard); | 133 | CHECK_SYMBOL (clipboard); |
| 92 | CHECK_STRING (name); | 134 | CHECK_STRING (name); |
| @@ -105,11 +147,13 @@ clipboard. */) | |||
| 105 | ptrdiff_t len = !NILP (data) ? SBYTES (data) : 0; | 147 | ptrdiff_t len = !NILP (data) ? SBYTES (data) : 0; |
| 106 | 148 | ||
| 107 | if (EQ (clipboard, QPRIMARY)) | 149 | if (EQ (clipboard, QPRIMARY)) |
| 108 | BClipboard_set_primary_selection_data (SSDATA (name), dat, len); | 150 | BClipboard_set_primary_selection_data (SSDATA (name), dat, len, |
| 151 | !NILP (clear)); | ||
| 109 | else if (EQ (clipboard, QSECONDARY)) | 152 | else if (EQ (clipboard, QSECONDARY)) |
| 110 | BClipboard_set_secondary_selection_data (SSDATA (name), dat, len); | 153 | BClipboard_set_secondary_selection_data (SSDATA (name), dat, len, |
| 154 | !NILP (clear)); | ||
| 111 | else if (EQ (clipboard, QCLIPBOARD)) | 155 | else if (EQ (clipboard, QCLIPBOARD)) |
| 112 | BClipboard_set_system_data (SSDATA (name), dat, len); | 156 | BClipboard_set_system_data (SSDATA (name), dat, len, !NILP (clear)); |
| 113 | else | 157 | else |
| 114 | { | 158 | { |
| 115 | unblock_input (); | 159 | unblock_input (); |
| @@ -128,7 +172,9 @@ syms_of_haikuselect (void) | |||
| 128 | DEFSYM (QSTRING, "STRING"); | 172 | DEFSYM (QSTRING, "STRING"); |
| 129 | DEFSYM (QUTF8_STRING, "UTF8_STRING"); | 173 | DEFSYM (QUTF8_STRING, "UTF8_STRING"); |
| 130 | DEFSYM (Qforeign_selection, "foreign-selection"); | 174 | DEFSYM (Qforeign_selection, "foreign-selection"); |
| 175 | DEFSYM (QTARGETS, "TARGETS"); | ||
| 131 | 176 | ||
| 132 | defsubr (&Shaiku_selection_data); | 177 | defsubr (&Shaiku_selection_data); |
| 133 | defsubr (&Shaiku_selection_put); | 178 | defsubr (&Shaiku_selection_put); |
| 179 | defsubr (&Shaiku_selection_targets); | ||
| 134 | } | 180 | } |