[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 7a709b36ef: Fix `gui-backend-selection-owner-p' on Haiku
From: |
Po Lu |
Subject: |
master 7a709b36ef: Fix `gui-backend-selection-owner-p' on Haiku |
Date: |
Sun, 22 May 2022 21:58:04 -0400 (EDT) |
branch: master
commit 7a709b36ef1a2b184fd1b3e2f1ddf2b98b6f3bcc
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
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.
---
src/haiku_select.cc | 63 ++++++++++++++++++++++++++++++++++++++++++++++++-----
src/haikuselect.c | 13 +++++------
src/haikuselect.h | 7 +++---
3 files changed, 65 insertions(+), 18 deletions(-)
diff --git a/src/haiku_select.cc b/src/haiku_select.cc
index 43b71138b3..764001f62b 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/>. */
#include "haikuselect.h"
+/* The clipboard object representing the primary selection. */
static BClipboard *primary = NULL;
+
+/* The clipboard object representing the secondary selection. */
static BClipboard *secondary = NULL;
+
+/* The clipboard object used by other programs, representing the
+ clipboard. */
static BClipboard *system_clipboard = NULL;
+
+/* The number of times the system clipboard has changed. */
static int64 count_clipboard = -1;
+
+/* The number of times the primary selection has changed. */
static int64 count_primary = -1;
+
+/* The number of times the secondary selection has changed. */
static int64 count_secondary = -1;
static BClipboard *
@@ -178,6 +190,25 @@ be_set_clipboard_data_1 (BClipboard *cb, const char *type,
const char *data,
cb->Unlock ();
}
+void
+be_update_clipboard_count (enum haiku_clipboard id)
+{
+ switch (id)
+ {
+ case CLIPBOARD_CLIPBOARD:
+ count_clipboard = system_clipboard->SystemCount ();
+ break;
+
+ case CLIPBOARD_PRIMARY:
+ count_primary = primary->SystemCount ();
+ break;
+
+ case CLIPBOARD_SECONDARY:
+ count_secondary = secondary->SystemCount ();
+ break;
+ }
+}
+
char *
be_find_clipboard_data (enum haiku_clipboard id, const char *type,
ssize_t *len)
@@ -190,6 +221,8 @@ void
be_set_clipboard_data (enum haiku_clipboard id, const char *type,
const char *data, ssize_t len, bool clear)
{
+ be_update_clipboard_count (id);
+
be_set_clipboard_data_1 (get_clipboard_object (id), type,
data, len, clear);
}
@@ -202,30 +235,48 @@ be_get_clipboard_targets (enum haiku_clipboard id, char
**targets,
len);
}
-bool
-BClipboard_owns_clipboard (void)
+static bool
+clipboard_owner_p (void)
{
return (count_clipboard >= 0
&& (count_clipboard + 1
== system_clipboard->SystemCount ()));
}
-bool
-BClipboard_owns_primary (void)
+static bool
+primary_owner_p (void)
{
return (count_primary >= 0
&& (count_primary + 1
== primary->SystemCount ()));
}
-bool
-BClipboard_owns_secondary (void)
+static bool
+secondary_owner_p (void)
{
return (count_secondary >= 0
&& (count_secondary + 1
== secondary->SystemCount ()));
}
+bool
+be_clipboard_owner_p (enum haiku_clipboard clipboard)
+{
+ switch (clipboard)
+ {
+ case CLIPBOARD_PRIMARY:
+ return primary_owner_p ();
+
+ case CLIPBOARD_SECONDARY:
+ return secondary_owner_p ();
+
+ case CLIPBOARD_CLIPBOARD:
+ return clipboard_owner_p ();
+ }
+
+ abort ();
+}
+
void
init_haiku_select (void)
{
diff --git a/src/haikuselect.c b/src/haikuselect.c
index 6d03d6eb68..80604252cb 100644
--- a/src/haikuselect.c
+++ b/src/haikuselect.c
@@ -145,6 +145,8 @@ In that case, the arguments after NAME are ignored. */)
if (CONSP (name) || NILP (name))
{
+ be_update_clipboard_count (clipboard_name);
+
rc = be_lock_clipboard_message (clipboard_name,
&message, true);
@@ -179,16 +181,11 @@ of the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
*/)
(Lisp_Object selection)
{
bool value;
+ enum haiku_clipboard name;
block_input ();
- if (EQ (selection, QPRIMARY))
- value = BClipboard_owns_primary ();
- else if (EQ (selection, QSECONDARY))
- value = BClipboard_owns_secondary ();
- else if (EQ (selection, QCLIPBOARD))
- value = BClipboard_owns_clipboard ();
- else
- value = false;
+ name = haiku_get_clipboard_name (selection);
+ value = be_clipboard_owner_p (name);
unblock_input ();
return value ? Qt : Qnil;
diff --git a/src/haikuselect.h b/src/haikuselect.h
index b63d3c3653..e9a2f2dd77 100644
--- a/src/haikuselect.h
+++ b/src/haikuselect.h
@@ -37,6 +37,7 @@ enum haiku_clipboard
#ifdef __cplusplus
extern "C"
{
+/* Also declared in haikuterm.h for use in emacs.c. */
extern void init_haiku_select (void);
#endif
/* 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
extern void be_set_clipboard_data (enum haiku_clipboard, const char *, const
char *,
ssize_t, bool);
extern void be_get_clipboard_targets (enum haiku_clipboard, char **, int);
-
-extern bool BClipboard_owns_clipboard (void);
-extern bool BClipboard_owns_primary (void);
-extern bool BClipboard_owns_secondary (void);
+extern bool be_clipboard_owner_p (enum haiku_clipboard);
+extern void be_update_clipboard_count (enum haiku_clipboard);
extern int be_enum_message (void *, int32 *, int32, int32 *, const char **);
extern int be_get_message_data (void *, const char *, int32, int32,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 7a709b36ef: Fix `gui-backend-selection-owner-p' on Haiku,
Po Lu <=