[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master d2a23c7441: Implement selection ownership on Haiku
From: |
Po Lu |
Subject: |
master d2a23c7441: Implement selection ownership on Haiku |
Date: |
Wed, 19 Jan 2022 20:08:42 -0500 (EST) |
branch: master
commit d2a23c7441dda2f0650b78d4bb9e2340a02b66bc
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
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.
---
lisp/term/haiku-win.el | 6 +++---
src/haiku_select.cc | 27 +++++++++++++++++++++++++++
src/haikuselect.c | 31 +++++++++++++++++++++++++++++++
src/haikuselect.h | 9 +++++++++
4 files changed, 70 insertions(+), 3 deletions(-)
diff --git a/lisp/term/haiku-win.el b/lisp/term/haiku-win.el
index 739ea9fdfc..a5cde929f9 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 041e244f3e..d39000d8bb 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 2e619c69f7..e65ab827c5 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 80f33c6ed2..566aae596f 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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master d2a23c7441: Implement selection ownership on Haiku,
Po Lu <=