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/haiku_select.cc | |
| 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/haiku_select.cc')
| -rw-r--r-- | src/haiku_select.cc | 92 |
1 files changed, 83 insertions, 9 deletions
diff --git a/src/haiku_select.cc b/src/haiku_select.cc index 8d345ca6617..6cd6ee879e5 100644 --- a/src/haiku_select.cc +++ b/src/haiku_select.cc | |||
| @@ -64,12 +64,62 @@ BClipboard_find_data (BClipboard *cb, const char *type, ssize_t *len) | |||
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | static void | 66 | static void |
| 67 | BClipboard_get_targets (BClipboard *cb, char **buf, int buf_size) | ||
| 68 | { | ||
| 69 | BMessage *data; | ||
| 70 | char *name; | ||
| 71 | int32 count_found; | ||
| 72 | type_code type; | ||
| 73 | int32 i; | ||
| 74 | int index; | ||
| 75 | |||
| 76 | if (!cb->Lock ()) | ||
| 77 | { | ||
| 78 | buf[0] = NULL; | ||
| 79 | return; | ||
| 80 | } | ||
| 81 | |||
| 82 | data = cb->Data (); | ||
| 83 | index = 0; | ||
| 84 | |||
| 85 | if (!data) | ||
| 86 | { | ||
| 87 | buf[0] = NULL; | ||
| 88 | cb->Unlock (); | ||
| 89 | return; | ||
| 90 | } | ||
| 91 | |||
| 92 | for (i = 0; (data->GetInfo (B_ANY_TYPE, i, &name, | ||
| 93 | &type, &count_found) | ||
| 94 | == B_OK); ++i) | ||
| 95 | { | ||
| 96 | if (type == B_MIME_TYPE) | ||
| 97 | { | ||
| 98 | if (index < (buf_size - 1)) | ||
| 99 | { | ||
| 100 | buf[index++] = strdup (name); | ||
| 101 | |||
| 102 | if (!buf[index - 1]) | ||
| 103 | break; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | buf[index] = NULL; | ||
| 109 | |||
| 110 | cb->Unlock (); | ||
| 111 | } | ||
| 112 | |||
| 113 | static void | ||
| 67 | BClipboard_set_data (BClipboard *cb, const char *type, const char *dat, | 114 | BClipboard_set_data (BClipboard *cb, const char *type, const char *dat, |
| 68 | ssize_t len) | 115 | ssize_t len, bool clear) |
| 69 | { | 116 | { |
| 70 | if (!cb->Lock ()) | 117 | if (!cb->Lock ()) |
| 71 | return; | 118 | return; |
| 72 | cb->Clear (); | 119 | |
| 120 | if (clear) | ||
| 121 | cb->Clear (); | ||
| 122 | |||
| 73 | BMessage *mdat = cb->Data (); | 123 | BMessage *mdat = cb->Data (); |
| 74 | if (!mdat) | 124 | if (!mdat) |
| 75 | { | 125 | { |
| @@ -78,7 +128,13 @@ BClipboard_set_data (BClipboard *cb, const char *type, const char *dat, | |||
| 78 | } | 128 | } |
| 79 | 129 | ||
| 80 | if (dat) | 130 | if (dat) |
| 81 | mdat->AddData (type, B_MIME_TYPE, dat, len); | 131 | { |
| 132 | if (mdat->ReplaceData (type, B_MIME_TYPE, dat, len) | ||
| 133 | == B_NAME_NOT_FOUND) | ||
| 134 | mdat->AddData (type, B_MIME_TYPE, dat, len); | ||
| 135 | } | ||
| 136 | else | ||
| 137 | mdat->RemoveName (type); | ||
| 82 | cb->Commit (); | 138 | cb->Commit (); |
| 83 | cb->Unlock (); | 139 | cb->Unlock (); |
| 84 | } | 140 | } |
| @@ -112,32 +168,32 @@ BClipboard_find_secondary_selection_data (const char *type, ssize_t *len) | |||
| 112 | 168 | ||
| 113 | void | 169 | void |
| 114 | BClipboard_set_system_data (const char *type, const char *data, | 170 | BClipboard_set_system_data (const char *type, const char *data, |
| 115 | ssize_t len) | 171 | ssize_t len, bool clear) |
| 116 | { | 172 | { |
| 117 | if (!system_clipboard) | 173 | if (!system_clipboard) |
| 118 | return; | 174 | return; |
| 119 | 175 | ||
| 120 | BClipboard_set_data (system_clipboard, type, data, len); | 176 | BClipboard_set_data (system_clipboard, type, data, len, clear); |
| 121 | } | 177 | } |
| 122 | 178 | ||
| 123 | void | 179 | void |
| 124 | BClipboard_set_primary_selection_data (const char *type, const char *data, | 180 | BClipboard_set_primary_selection_data (const char *type, const char *data, |
| 125 | ssize_t len) | 181 | ssize_t len, bool clear) |
| 126 | { | 182 | { |
| 127 | if (!primary) | 183 | if (!primary) |
| 128 | return; | 184 | return; |
| 129 | 185 | ||
| 130 | BClipboard_set_data (primary, type, data, len); | 186 | BClipboard_set_data (primary, type, data, len, clear); |
| 131 | } | 187 | } |
| 132 | 188 | ||
| 133 | void | 189 | void |
| 134 | BClipboard_set_secondary_selection_data (const char *type, const char *data, | 190 | BClipboard_set_secondary_selection_data (const char *type, const char *data, |
| 135 | ssize_t len) | 191 | ssize_t len, bool clear) |
| 136 | { | 192 | { |
| 137 | if (!secondary) | 193 | if (!secondary) |
| 138 | return; | 194 | return; |
| 139 | 195 | ||
| 140 | BClipboard_set_data (secondary, type, data, len); | 196 | BClipboard_set_data (secondary, type, data, len, clear); |
| 141 | } | 197 | } |
| 142 | 198 | ||
| 143 | void | 199 | void |
| @@ -147,6 +203,24 @@ BClipboard_free_data (void *ptr) | |||
| 147 | } | 203 | } |
| 148 | 204 | ||
| 149 | void | 205 | void |
| 206 | BClipboard_system_targets (char **buf, int len) | ||
| 207 | { | ||
| 208 | BClipboard_get_targets (system_clipboard, buf, len); | ||
| 209 | } | ||
| 210 | |||
| 211 | void | ||
| 212 | BClipboard_primary_targets (char **buf, int len) | ||
| 213 | { | ||
| 214 | BClipboard_get_targets (primary, buf, len); | ||
| 215 | } | ||
| 216 | |||
| 217 | void | ||
| 218 | BClipboard_secondary_targets (char **buf, int len) | ||
| 219 | { | ||
| 220 | BClipboard_get_targets (secondary, buf, len); | ||
| 221 | } | ||
| 222 | |||
| 223 | void | ||
| 150 | init_haiku_select (void) | 224 | init_haiku_select (void) |
| 151 | { | 225 | { |
| 152 | system_clipboard = new BClipboard ("system"); | 226 | system_clipboard = new BClipboard ("system"); |