diff options
| author | Po Lu | 2022-01-20 01:01:52 +0000 |
|---|---|---|
| committer | Po Lu | 2022-01-20 01:05:53 +0000 |
| commit | d2a23c7441dda2f0650b78d4bb9e2340a02b66bc (patch) | |
| tree | 4725c1ffaa5f67a162809d883aded21719f5225d /src | |
| parent | 9396b7d0b425a114eb6e8695c439be3d30490f98 (diff) | |
| download | emacs-d2a23c7441dda2f0650b78d4bb9e2340a02b66bc.tar.gz emacs-d2a23c7441dda2f0650b78d4bb9e2340a02b66bc.zip | |
Implement selection ownership on Haiku
* lisp/term/haiku-win.el (haiku-selection-owner-p): New
declaration.
(gui-backend-selection-owner-p): Implement using newly exposed
primitive.
* src/haiku_select.cc
(count_clipboard, count_primary, count_secondary): New
variables for tracking selection ownership.
(BClipboard_set_system_data):
(BClipboard_set_primary_selection_data):
(BClipboard_set_secondary_selection_data): Set ownership
variables.
(BClipboard_owns_clipboard):
(BClipboard_owns_primary):
(BClipboard_owns_secondary): New functions.
* src/haikuselect.c (Fhaiku_selection_owner_p): New function.
(syms_of_haikuselect): Define new subr.
* src/haikuselect.h: New prototypes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/haiku_select.cc | 27 | ||||
| -rw-r--r-- | src/haikuselect.c | 31 | ||||
| -rw-r--r-- | src/haikuselect.h | 9 |
3 files changed, 67 insertions, 0 deletions
diff --git a/src/haiku_select.cc b/src/haiku_select.cc index 041e244f3ea..d39000d8bbe 100644 --- a/src/haiku_select.cc +++ b/src/haiku_select.cc | |||
| @@ -29,6 +29,9 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 29 | static BClipboard *primary = NULL; | 29 | static BClipboard *primary = NULL; |
| 30 | static BClipboard *secondary = NULL; | 30 | static BClipboard *secondary = NULL; |
| 31 | static BClipboard *system_clipboard = NULL; | 31 | static BClipboard *system_clipboard = NULL; |
| 32 | static unsigned long count_clipboard = 0; | ||
| 33 | static unsigned long count_primary = 0; | ||
| 34 | static unsigned long count_secondary = 0; | ||
| 32 | 35 | ||
| 33 | int selection_state_flag; | 36 | int selection_state_flag; |
| 34 | 37 | ||
| @@ -174,6 +177,7 @@ BClipboard_set_system_data (const char *type, const char *data, | |||
| 174 | return; | 177 | return; |
| 175 | 178 | ||
| 176 | BClipboard_set_data (system_clipboard, type, data, len, clear); | 179 | BClipboard_set_data (system_clipboard, type, data, len, clear); |
| 180 | count_clipboard = system_clipboard->SystemCount (); | ||
| 177 | } | 181 | } |
| 178 | 182 | ||
| 179 | void | 183 | void |
| @@ -184,6 +188,7 @@ BClipboard_set_primary_selection_data (const char *type, const char *data, | |||
| 184 | return; | 188 | return; |
| 185 | 189 | ||
| 186 | BClipboard_set_data (primary, type, data, len, clear); | 190 | BClipboard_set_data (primary, type, data, len, clear); |
| 191 | count_primary = primary->SystemCount (); | ||
| 187 | } | 192 | } |
| 188 | 193 | ||
| 189 | void | 194 | void |
| @@ -194,6 +199,7 @@ BClipboard_set_secondary_selection_data (const char *type, const char *data, | |||
| 194 | return; | 199 | return; |
| 195 | 200 | ||
| 196 | BClipboard_set_data (secondary, type, data, len, clear); | 201 | BClipboard_set_data (secondary, type, data, len, clear); |
| 202 | count_secondary = secondary->SystemCount (); | ||
| 197 | } | 203 | } |
| 198 | 204 | ||
| 199 | void | 205 | void |
| @@ -220,6 +226,27 @@ BClipboard_secondary_targets (char **buf, int len) | |||
| 220 | BClipboard_get_targets (secondary, buf, len); | 226 | BClipboard_get_targets (secondary, buf, len); |
| 221 | } | 227 | } |
| 222 | 228 | ||
| 229 | bool | ||
| 230 | BClipboard_owns_clipboard (void) | ||
| 231 | { | ||
| 232 | return (count_clipboard | ||
| 233 | == system_clipboard->SystemCount ()); | ||
| 234 | } | ||
| 235 | |||
| 236 | bool | ||
| 237 | BClipboard_owns_primary (void) | ||
| 238 | { | ||
| 239 | return (count_primary | ||
| 240 | == primary->SystemCount ()); | ||
| 241 | } | ||
| 242 | |||
| 243 | bool | ||
| 244 | BClipboard_owns_secondary (void) | ||
| 245 | { | ||
| 246 | return (count_secondary | ||
| 247 | == secondary->SystemCount ()); | ||
| 248 | } | ||
| 249 | |||
| 223 | void | 250 | void |
| 224 | init_haiku_select (void) | 251 | init_haiku_select (void) |
| 225 | { | 252 | { |
diff --git a/src/haikuselect.c b/src/haikuselect.c index 2e619c69f7a..e65ab827c51 100644 --- a/src/haikuselect.c +++ b/src/haikuselect.c | |||
| @@ -166,6 +166,36 @@ clipboard. */) | |||
| 166 | return Qnil; | 166 | return Qnil; |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | DEFUN ("haiku-selection-owner-p", Fhaiku_selection_owner_p, Shaiku_selection_owner_p, | ||
| 170 | 0, 1, 0, | ||
| 171 | doc: /* Whether the current Emacs process owns the given SELECTION. | ||
| 172 | The arg should be the name of the selection in question, typically one | ||
| 173 | of the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'. For | ||
| 174 | convenience, the symbol nil is the same as `PRIMARY', and t is the | ||
| 175 | same as `SECONDARY'. */) | ||
| 176 | (Lisp_Object selection) | ||
| 177 | { | ||
| 178 | bool value; | ||
| 179 | |||
| 180 | if (NILP (selection)) | ||
| 181 | selection = QPRIMARY; | ||
| 182 | else if (EQ (selection, Qt)) | ||
| 183 | selection = QSECONDARY; | ||
| 184 | |||
| 185 | block_input (); | ||
| 186 | if (EQ (selection, QPRIMARY)) | ||
| 187 | value = BClipboard_owns_primary (); | ||
| 188 | else if (EQ (selection, QSECONDARY)) | ||
| 189 | value = BClipboard_owns_secondary (); | ||
| 190 | else if (EQ (selection, QCLIPBOARD)) | ||
| 191 | value = BClipboard_owns_clipboard (); | ||
| 192 | else | ||
| 193 | value = false; | ||
| 194 | unblock_input (); | ||
| 195 | |||
| 196 | return value ? Qt : Qnil; | ||
| 197 | } | ||
| 198 | |||
| 169 | void | 199 | void |
| 170 | syms_of_haikuselect (void) | 200 | syms_of_haikuselect (void) |
| 171 | { | 201 | { |
| @@ -179,4 +209,5 @@ syms_of_haikuselect (void) | |||
| 179 | defsubr (&Shaiku_selection_data); | 209 | defsubr (&Shaiku_selection_data); |
| 180 | defsubr (&Shaiku_selection_put); | 210 | defsubr (&Shaiku_selection_put); |
| 181 | defsubr (&Shaiku_selection_targets); | 211 | defsubr (&Shaiku_selection_targets); |
| 212 | defsubr (&Shaiku_selection_owner_p); | ||
| 182 | } | 213 | } |
diff --git a/src/haikuselect.h b/src/haikuselect.h index 80f33c6ed25..566aae596f6 100644 --- a/src/haikuselect.h +++ b/src/haikuselect.h | |||
| @@ -66,6 +66,15 @@ extern "C" | |||
| 66 | extern void | 66 | extern void |
| 67 | BClipboard_secondary_targets (char **buf, int len); | 67 | BClipboard_secondary_targets (char **buf, int len); |
| 68 | 68 | ||
| 69 | extern bool | ||
| 70 | BClipboard_owns_clipboard (void); | ||
| 71 | |||
| 72 | extern bool | ||
| 73 | BClipboard_owns_primary (void); | ||
| 74 | |||
| 75 | extern bool | ||
| 76 | BClipboard_owns_secondary (void); | ||
| 77 | |||
| 69 | /* Free the returned data. */ | 78 | /* Free the returned data. */ |
| 70 | extern void BClipboard_free_data (void *ptr); | 79 | extern void BClipboard_free_data (void *ptr); |
| 71 | #ifdef __cplusplus | 80 | #ifdef __cplusplus |