From: Po Lu Date: Wed, 13 Jul 2022 05:44:31 +0000 (+0000) Subject: Implement TIMESTAMP target for Haiku selections X-Git-Tag: archive/raspbian/1%29.2+1-2+rpi1^2~5^2~16^2~1886^2~970 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=defe6cf2d941ceee2d7e11cc991da6a62fd52398;p=emacs.git 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. --- diff --git a/lisp/term/haiku-win.el b/lisp/term/haiku-win.el index f6e4829cad4..bbc263df68f 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 e1f2a815241..872da1d6c44 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 9d8c4a2cd16..dc0a7edf430 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 61efeb9cd93..42e9c93f7e9 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 };