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.
This commit is contained in:
parent
9396b7d0b4
commit
d2a23c7441
4 changed files with 70 additions and 3 deletions
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue