summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-01-20 01:01:52 +0000
committerPo Lu <luangruo@yahoo.com>2022-01-20 01:05:53 +0000
commitd2a23c7441dda2f0650b78d4bb9e2340a02b66bc (patch)
tree4725c1ffaa5f67a162809d883aded21719f5225d
parent9396b7d0b425a114eb6e8695c439be3d30490f98 (diff)
downloademacs-d2a23c7441dda2f0650b78d4bb9e2340a02b66bc.tar.gz
emacs-d2a23c7441dda2f0650b78d4bb9e2340a02b66bc.tar.bz2
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.
-rw-r--r--lisp/term/haiku-win.el6
-rw-r--r--src/haiku_select.cc27
-rw-r--r--src/haikuselect.c31
-rw-r--r--src/haikuselect.h9
4 files changed, 70 insertions, 3 deletions
diff --git a/lisp/term/haiku-win.el b/lisp/term/haiku-win.el
index 739ea9fdfce..a5cde929f96 100644
--- a/lisp/term/haiku-win.el
+++ b/lisp/term/haiku-win.el
@@ -50,6 +50,7 @@
(declare-function haiku-selection-data "haikuselect.c")
(declare-function haiku-selection-put "haikuselect.c")
(declare-function haiku-selection-targets "haikuselect.c")
+(declare-function haiku-selection-owner-p "haikuselect.c")
(declare-function haiku-put-resource "haikufns.c")
(defun haiku--handle-x-command-line-resources (command-line-resources)
@@ -105,9 +106,8 @@ If TYPE is nil, return \"text/plain\"."
&context (window-system haiku))
(haiku-selection-data selection "text/plain"))
-(cl-defmethod gui-backend-selection-owner-p (_
- &context (window-system haiku))
- t)
+(cl-defmethod gui-backend-selection-owner-p (selection &context (window-system haiku))
+ (haiku-selection-owner-p selection))
(declare-function haiku-read-file-name "haikufns.c")
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/>. */
static BClipboard *primary = NULL;
static BClipboard *secondary = NULL;
static BClipboard *system_clipboard = NULL;
+static unsigned long count_clipboard = 0;
+static unsigned long count_primary = 0;
+static unsigned long count_secondary = 0;
int selection_state_flag;
@@ -174,6 +177,7 @@ BClipboard_set_system_data (const char *type, const char *data,
return;
BClipboard_set_data (system_clipboard, type, data, len, clear);
+ count_clipboard = system_clipboard->SystemCount ();
}
void
@@ -184,6 +188,7 @@ BClipboard_set_primary_selection_data (const char *type, const char *data,
return;
BClipboard_set_data (primary, type, data, len, clear);
+ count_primary = primary->SystemCount ();
}
void
@@ -194,6 +199,7 @@ BClipboard_set_secondary_selection_data (const char *type, const char *data,
return;
BClipboard_set_data (secondary, type, data, len, clear);
+ count_secondary = secondary->SystemCount ();
}
void
@@ -220,6 +226,27 @@ BClipboard_secondary_targets (char **buf, int len)
BClipboard_get_targets (secondary, buf, len);
}
+bool
+BClipboard_owns_clipboard (void)
+{
+ return (count_clipboard
+ == system_clipboard->SystemCount ());
+}
+
+bool
+BClipboard_owns_primary (void)
+{
+ return (count_primary
+ == primary->SystemCount ());
+}
+
+bool
+BClipboard_owns_secondary (void)
+{
+ return (count_secondary
+ == secondary->SystemCount ());
+}
+
void
init_haiku_select (void)
{
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. */)
return Qnil;
}
+DEFUN ("haiku-selection-owner-p", Fhaiku_selection_owner_p, Shaiku_selection_owner_p,
+ 0, 1, 0,
+ doc: /* Whether the current Emacs process owns the given SELECTION.
+The arg should be the name of the selection in question, typically one
+of the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'. For
+convenience, the symbol nil is the same as `PRIMARY', and t is the
+same as `SECONDARY'. */)
+ (Lisp_Object selection)
+{
+ bool value;
+
+ if (NILP (selection))
+ selection = QPRIMARY;
+ else if (EQ (selection, Qt))
+ selection = QSECONDARY;
+
+ 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;
+ unblock_input ();
+
+ return value ? Qt : Qnil;
+}
+
void
syms_of_haikuselect (void)
{
@@ -179,4 +209,5 @@ syms_of_haikuselect (void)
defsubr (&Shaiku_selection_data);
defsubr (&Shaiku_selection_put);
defsubr (&Shaiku_selection_targets);
+ defsubr (&Shaiku_selection_owner_p);
}
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"
extern void
BClipboard_secondary_targets (char **buf, int len);
+ extern bool
+ BClipboard_owns_clipboard (void);
+
+ extern bool
+ BClipboard_owns_primary (void);
+
+ extern bool
+ BClipboard_owns_secondary (void);
+
/* Free the returned data. */
extern void BClipboard_free_data (void *ptr);
#ifdef __cplusplus