Implement TIMESTAMP target for Haiku selections
authorPo Lu <luangruo@yahoo.com>
Wed, 13 Jul 2022 05:44:31 +0000 (05:44 +0000)
committerPo Lu <luangruo@yahoo.com>
Wed, 13 Jul 2022 05:45:30 +0000 (05:45 +0000)
* 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
src/haiku_select.cc
src/haikuselect.c
src/haikuselect.h

index f6e4829cad4fad6327375e8c32e90f6c264b9044..bbc263df68fd8e76e19e360764f0e49400a7f3c2 100644 (file)
@@ -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))
index e1f2a815241fc445fece3a4fc13428274bfc3632..872da1d6c44066d180f802a56e29c7f96e3786d1 100644 (file)
@@ -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 ();
+}
index 9d8c4a2cd162ca938f032e2168429dc36df9d0c8..dc0a7edf4305390a9399677e98cac384feba2294 100644 (file)
@@ -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);
index 61efeb9cd936d3aaf12387cf98dc1bee476375fe..42e9c93f7e9584ca8fc06ab4177084d58d62a312 100644 (file)
@@ -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
 };