]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix `gui-backend-selection-owner-p' on Haiku
authorPo Lu <luangruo@yahoo.com>
Mon, 23 May 2022 01:57:19 +0000 (01:57 +0000)
committerPo Lu <luangruo@yahoo.com>
Mon, 23 May 2022 01:57:19 +0000 (01:57 +0000)
* 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
src/haikuselect.c
src/haikuselect.h

index 43b71138b33a5fdf29ef827bb8644ce8d26bc961..764001f62b05d6b994763c3e204ec2f243d871c8 100644 (file)
@@ -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)
 {
index 6d03d6eb6818fb07d1a345417ee8463521f79fb1..80604252cb90c47a87553b646b6d0e3ceb5e18b2 100644 (file)
@@ -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;
index b63d3c36536fb05dd40491c23f496d2c76b2b3f2..e9a2f2dd77d930d860ae4755f8e6c0a0f13d531c 100644 (file)
@@ -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,