[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master defe6cf2d9: Implement TIMESTAMP target for Haiku selections
From: |
Po Lu |
Subject: |
master defe6cf2d9: Implement TIMESTAMP target for Haiku selections |
Date: |
Wed, 13 Jul 2022 01:45:44 -0400 (EDT) |
branch: master
commit defe6cf2d941ceee2d7e11cc991da6a62fd52398
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
Implement TIMESTAMP target for Haiku selections
* lisp/term/haiku-win.el (haiku-selection-targets): Fix return
values.
(gui-backend-get-selection): Handle TIMESTAMP specially.
* src/haiku_select.cc (be_get_clipboard_count): New function.
* src/haikuselect.c (Fhaiku_selection_timestamp): New function.
(syms_of_haikuselect): Add new defsubr.
* src/haikuselect.h: Update prototypes.
---
lisp/term/haiku-win.el | 21 ++++++++++++++-------
src/haiku_select.cc | 9 +++++++++
src/haikuselect.c | 18 ++++++++++++++++++
src/haikuselect.h | 1 +
4 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/lisp/term/haiku-win.el b/lisp/term/haiku-win.el
index f6e4829cad..bbc263df68 100644
--- a/lisp/term/haiku-win.el
+++ b/lisp/term/haiku-win.el
@@ -249,7 +249,7 @@ If TYPE is nil, return \"text/plain\"."
"Find the types of data available from CLIPBOARD.
CLIPBOARD should be the symbol `PRIMARY', `SECONDARY' or
`CLIPBOARD'. Return the available types as a list of strings."
- (mapcar #'car (haiku-selection-data clipboard nil)))
+ (delq 'type (mapcar #'car (haiku-selection-data clipboard nil))))
(defun haiku-select-encode-xstring (_selection value)
"Convert VALUE to a system message association.
@@ -288,12 +288,19 @@ or a pair of markers) and turns it into a file system
reference."
(cl-defmethod gui-backend-get-selection (type data-type
&context (window-system haiku))
- (if (eq data-type 'TARGETS)
- (apply #'vector (mapcar #'intern
- (haiku-selection-targets type)))
- (if (eq type 'XdndSelection)
- haiku-dnd-selection-value
- (haiku-selection-data type (haiku--selection-type-to-mime data-type)))))
+ (cond
+ ((eq data-type 'TARGETS)
+ (apply #'vector (mapcar #'intern
+ (haiku-selection-targets type))))
+ ;; The timestamp here is really the number of times a program has
+ ;; put data into the selection. But it always increases, so it
+ ;; makes sense if one imagines that time is frozen until
+ ;; immediately before that happens.
+ ((eq data-type 'TIMESTAMP)
+ (haiku-selection-timestamp type))
+ ((eq type 'XdndSelection) haiku-dnd-selection-value)
+ (t (haiku-selection-data type
+ (haiku--selection-type-to-mime data-type)))))
(cl-defmethod gui-backend-set-selection (type value
&context (window-system haiku))
diff --git a/src/haiku_select.cc b/src/haiku_select.cc
index e1f2a81524..872da1d6c4 100644
--- a/src/haiku_select.cc
+++ b/src/haiku_select.cc
@@ -508,3 +508,12 @@ be_selection_outdated_p (enum haiku_clipboard id, int64
count)
return false;
}
+
+int64
+be_get_clipboard_count (enum haiku_clipboard id)
+{
+ BClipboard *clipboard;
+
+ clipboard = get_clipboard_object (id);
+ return clipboard->SystemCount ();
+}
diff --git a/src/haikuselect.c b/src/haikuselect.c
index 9d8c4a2cd1..dc0a7edf43 100644
--- a/src/haikuselect.c
+++ b/src/haikuselect.c
@@ -54,6 +54,23 @@ haiku_get_clipboard_name (Lisp_Object clipboard)
signal_error ("Invalid clipboard", clipboard);
}
+DEFUN ("haiku-selection-timestamp", Fhaiku_selection_timestamp,
+ Shaiku_selection_timestamp, 1, 1, 0,
+ doc: /* Retrieve the "timestamp" of the clipboard CLIPBOARD.
+CLIPBOARD can either be the symbol `PRIMARY', `SECONDARY' or
+`CLIPBOARD'. The timestamp is returned as a number describing the
+number of times programs have put data into CLIPBOARD. */)
+ (Lisp_Object clipboard)
+{
+ enum haiku_clipboard clipboard_name;
+ int64 timestamp;
+
+ clipboard_name = haiku_get_clipboard_name (clipboard);
+ timestamp = be_get_clipboard_count (clipboard_name);
+
+ return INT_TO_INTEGER (timestamp);
+}
+
DEFUN ("haiku-selection-data", Fhaiku_selection_data, Shaiku_selection_data,
2, 2, 0,
doc: /* Retrieve content typed as NAME from the clipboard
@@ -1122,6 +1139,7 @@ These are only called if a connection to the Haiku
display was opened. */);
DEFSYM (Qalready_running, "already-running");
defsubr (&Shaiku_selection_data);
+ defsubr (&Shaiku_selection_timestamp);
defsubr (&Shaiku_selection_put);
defsubr (&Shaiku_selection_owner_p);
defsubr (&Shaiku_drag_message);
diff --git a/src/haikuselect.h b/src/haikuselect.h
index 61efeb9cd9..42e9c93f7e 100644
--- a/src/haikuselect.h
+++ b/src/haikuselect.h
@@ -67,6 +67,7 @@ extern void be_unlock_clipboard (enum haiku_clipboard, bool);
extern void be_handle_clipboard_changed_message (void);
extern void be_start_watching_selection (enum haiku_clipboard);
extern bool be_selection_outdated_p (enum haiku_clipboard, int64);
+extern int64 be_get_clipboard_count (enum haiku_clipboard);
#ifdef __cplusplus
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master defe6cf2d9: Implement TIMESTAMP target for Haiku selections,
Po Lu <=