aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-05-23 01:57:19 +0000
committerPo Lu2022-05-23 01:57:19 +0000
commit7a709b36ef1a2b184fd1b3e2f1ddf2b98b6f3bcc (patch)
tree8b4d2bb1626a26985c40a7e6c6fbf76d7e0c4b2c /src
parent42e48f788ac6c7934466fe75b19644045594e5dd (diff)
downloademacs-7a709b36ef1a2b184fd1b3e2f1ddf2b98b6f3bcc.tar.gz
emacs-7a709b36ef1a2b184fd1b3e2f1ddf2b98b6f3bcc.zip
Fix `gui-backend-selection-owner-p' on Haiku
* src/haiku_select.cc (be_update_clipboard_count): New function. (be_set_clipboard_data): Update clipboard counts. (BClipboard_owns_clipboard, clipboard_owner_p) (BClipboard_owns_primary, primary_owner_p) (BClipboard_owns_secondary, secondary_owner_p): Rename functions somewhat. (be_clipboard_owner_p): New function. * src/haikuselect.c (Fhaiku_selection_put) (Fhaiku_selection_owner_p): Update selection counts as well. * src/haikuselect.h: Update prototypes.
Diffstat (limited to 'src')
-rw-r--r--src/haiku_select.cc63
-rw-r--r--src/haikuselect.c13
-rw-r--r--src/haikuselect.h7
3 files changed, 65 insertions, 18 deletions
diff --git a/src/haiku_select.cc b/src/haiku_select.cc
index 43b71138b33..764001f62b0 100644
--- a/src/haiku_select.cc
+++ b/src/haiku_select.cc
@@ -28,11 +28,23 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
28 28
29#include "haikuselect.h" 29#include "haikuselect.h"
30 30
31/* The clipboard object representing the primary selection. */
31static BClipboard *primary = NULL; 32static BClipboard *primary = NULL;
33
34/* The clipboard object representing the secondary selection. */
32static BClipboard *secondary = NULL; 35static BClipboard *secondary = NULL;
36
37/* The clipboard object used by other programs, representing the
38 clipboard. */
33static BClipboard *system_clipboard = NULL; 39static BClipboard *system_clipboard = NULL;
40
41/* The number of times the system clipboard has changed. */
34static int64 count_clipboard = -1; 42static int64 count_clipboard = -1;
43
44/* The number of times the primary selection has changed. */
35static int64 count_primary = -1; 45static int64 count_primary = -1;
46
47/* The number of times the secondary selection has changed. */
36static int64 count_secondary = -1; 48static int64 count_secondary = -1;
37 49
38static BClipboard * 50static BClipboard *
@@ -178,6 +190,25 @@ be_set_clipboard_data_1 (BClipboard *cb, const char *type, const char *data,
178 cb->Unlock (); 190 cb->Unlock ();
179} 191}
180 192
193void
194be_update_clipboard_count (enum haiku_clipboard id)
195{
196 switch (id)
197 {
198 case CLIPBOARD_CLIPBOARD:
199 count_clipboard = system_clipboard->SystemCount ();
200 break;
201
202 case CLIPBOARD_PRIMARY:
203 count_primary = primary->SystemCount ();
204 break;
205
206 case CLIPBOARD_SECONDARY:
207 count_secondary = secondary->SystemCount ();
208 break;
209 }
210}
211
181char * 212char *
182be_find_clipboard_data (enum haiku_clipboard id, const char *type, 213be_find_clipboard_data (enum haiku_clipboard id, const char *type,
183 ssize_t *len) 214 ssize_t *len)
@@ -190,6 +221,8 @@ void
190be_set_clipboard_data (enum haiku_clipboard id, const char *type, 221be_set_clipboard_data (enum haiku_clipboard id, const char *type,
191 const char *data, ssize_t len, bool clear) 222 const char *data, ssize_t len, bool clear)
192{ 223{
224 be_update_clipboard_count (id);
225
193 be_set_clipboard_data_1 (get_clipboard_object (id), type, 226 be_set_clipboard_data_1 (get_clipboard_object (id), type,
194 data, len, clear); 227 data, len, clear);
195} 228}
@@ -202,30 +235,48 @@ be_get_clipboard_targets (enum haiku_clipboard id, char **targets,
202 len); 235 len);
203} 236}
204 237
205bool 238static bool
206BClipboard_owns_clipboard (void) 239clipboard_owner_p (void)
207{ 240{
208 return (count_clipboard >= 0 241 return (count_clipboard >= 0
209 && (count_clipboard + 1 242 && (count_clipboard + 1
210 == system_clipboard->SystemCount ())); 243 == system_clipboard->SystemCount ()));
211} 244}
212 245
213bool 246static bool
214BClipboard_owns_primary (void) 247primary_owner_p (void)
215{ 248{
216 return (count_primary >= 0 249 return (count_primary >= 0
217 && (count_primary + 1 250 && (count_primary + 1
218 == primary->SystemCount ())); 251 == primary->SystemCount ()));
219} 252}
220 253
221bool 254static bool
222BClipboard_owns_secondary (void) 255secondary_owner_p (void)
223{ 256{
224 return (count_secondary >= 0 257 return (count_secondary >= 0
225 && (count_secondary + 1 258 && (count_secondary + 1
226 == secondary->SystemCount ())); 259 == secondary->SystemCount ()));
227} 260}
228 261
262bool
263be_clipboard_owner_p (enum haiku_clipboard clipboard)
264{
265 switch (clipboard)
266 {
267 case CLIPBOARD_PRIMARY:
268 return primary_owner_p ();
269
270 case CLIPBOARD_SECONDARY:
271 return secondary_owner_p ();
272
273 case CLIPBOARD_CLIPBOARD:
274 return clipboard_owner_p ();
275 }
276
277 abort ();
278}
279
229void 280void
230init_haiku_select (void) 281init_haiku_select (void)
231{ 282{
diff --git a/src/haikuselect.c b/src/haikuselect.c
index 6d03d6eb681..80604252cb9 100644
--- a/src/haikuselect.c
+++ b/src/haikuselect.c
@@ -145,6 +145,8 @@ In that case, the arguments after NAME are ignored. */)
145 145
146 if (CONSP (name) || NILP (name)) 146 if (CONSP (name) || NILP (name))
147 { 147 {
148 be_update_clipboard_count (clipboard_name);
149
148 rc = be_lock_clipboard_message (clipboard_name, 150 rc = be_lock_clipboard_message (clipboard_name,
149 &message, true); 151 &message, true);
150 152
@@ -179,16 +181,11 @@ of the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'. */)
179 (Lisp_Object selection) 181 (Lisp_Object selection)
180{ 182{
181 bool value; 183 bool value;
184 enum haiku_clipboard name;
182 185
183 block_input (); 186 block_input ();
184 if (EQ (selection, QPRIMARY)) 187 name = haiku_get_clipboard_name (selection);
185 value = BClipboard_owns_primary (); 188 value = be_clipboard_owner_p (name);
186 else if (EQ (selection, QSECONDARY))
187 value = BClipboard_owns_secondary ();
188 else if (EQ (selection, QCLIPBOARD))
189 value = BClipboard_owns_clipboard ();
190 else
191 value = false;
192 unblock_input (); 189 unblock_input ();
193 190
194 return value ? Qt : Qnil; 191 return value ? Qt : Qnil;
diff --git a/src/haikuselect.h b/src/haikuselect.h
index b63d3c36536..e9a2f2dd77d 100644
--- a/src/haikuselect.h
+++ b/src/haikuselect.h
@@ -37,6 +37,7 @@ enum haiku_clipboard
37#ifdef __cplusplus 37#ifdef __cplusplus
38extern "C" 38extern "C"
39{ 39{
40/* Also declared in haikuterm.h for use in emacs.c. */
40extern void init_haiku_select (void); 41extern void init_haiku_select (void);
41#endif 42#endif
42/* Whether or not the selection was recently changed. */ 43/* Whether or not the selection was recently changed. */
@@ -45,10 +46,8 @@ extern char *be_find_clipboard_data (enum haiku_clipboard, const char *, ssize_t
45extern void be_set_clipboard_data (enum haiku_clipboard, const char *, const char *, 46extern void be_set_clipboard_data (enum haiku_clipboard, const char *, const char *,
46 ssize_t, bool); 47 ssize_t, bool);
47extern void be_get_clipboard_targets (enum haiku_clipboard, char **, int); 48extern void be_get_clipboard_targets (enum haiku_clipboard, char **, int);
48 49extern bool be_clipboard_owner_p (enum haiku_clipboard);
49extern bool BClipboard_owns_clipboard (void); 50extern void be_update_clipboard_count (enum haiku_clipboard);
50extern bool BClipboard_owns_primary (void);
51extern bool BClipboard_owns_secondary (void);
52 51
53extern int be_enum_message (void *, int32 *, int32, int32 *, const char **); 52extern int be_enum_message (void *, int32 *, int32, int32 *, const char **);
54extern int be_get_message_data (void *, const char *, int32, int32, 53extern int be_get_message_data (void *, const char *, int32, int32,