aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2023-11-06 10:14:09 +0800
committerPo Lu2023-11-06 10:14:09 +0800
commitde380adb64688455ef315ea807622de25e385c44 (patch)
tree3e0b9f62100badb0331d222dbb1eec656f3cf438
parent3dd9750d124b077b2e87e0a253f69cf1f65422d6 (diff)
downloademacs-de380adb64688455ef315ea807622de25e385c44.tar.gz
emacs-de380adb64688455ef315ea807622de25e385c44.zip
Emulate secondary selections on Android
* doc/lispref/frames.texi (Other Selections): Revise documentation to match. * lisp/term/android-win.el (android-secondary-selection): New variable. (android-primary-selection, android-get-clipboard-1) (android-get-primary, gui-backend-get-selection) (gui-backend-selection-exists-p, gui-backend-selection-owner-p) (gui-backend-set-selection): Update doc strings and code as is proper.
-rw-r--r--doc/lispref/frames.texi9
-rw-r--r--lisp/term/android-win.el61
2 files changed, 51 insertions, 19 deletions
diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi
index 6193a4fe1cd..ca8c79395ed 100644
--- a/doc/lispref/frames.texi
+++ b/doc/lispref/frames.texi
@@ -4686,15 +4686,18 @@ of available selection data types, as elsewhere.
4686@cindex Android selections 4686@cindex Android selections
4687 Much like MS-Windows, Android provides a clipboard but no primary or 4687 Much like MS-Windows, Android provides a clipboard but no primary or
4688secondary selection; @code{gui-set-selection} simulates the primary 4688secondary selection; @code{gui-set-selection} simulates the primary
4689selection by saving the value supplied into a variable subsequent 4689and secondary selections by saving the value supplied into a variable
4690calls to @code{gui-get-selection} return. 4690subsequent calls to @code{gui-get-selection} return.
4691 4691
4692 From the clipboard, @code{gui-get-selection} is capable of returning 4692 From the clipboard, @code{gui-get-selection} is capable of returning
4693UTF-8 string data of the type @code{STRING}, the @code{TAREGTS} data 4693UTF-8 string data of the type @code{STRING}, the @code{TAREGTS} data
4694type, or image and application data of any MIME type. 4694type, or image and application data of any MIME type.
4695@code{gui-set-selection} sets only string data, much as under 4695@code{gui-set-selection} sets only string data, much as under
4696MS-Windows, although this data is not affected by the value of 4696MS-Windows, although this data is not affected by the value of
4697@code{selection-coding-system}. 4697@code{selection-coding-system}. By contrast, only string data can be
4698saved to and from the primary and secondary selections; but since this
4699data is not communicated to programs besides Emacs, it is not subject
4700to encoding or decoding by any coding system.
4698 4701
4699@node Yanking Media 4702@node Yanking Media
4700@section Yanking Media 4703@section Yanking Media
diff --git a/lisp/term/android-win.el b/lisp/term/android-win.el
index 70e24f4ccc7..7d9a033d723 100644
--- a/lisp/term/android-win.el
+++ b/lisp/term/android-win.el
@@ -75,19 +75,28 @@ DISPLAY is ignored on Android."
75 75
76(defvar android-primary-selection nil 76(defvar android-primary-selection nil
77 "The last string placed in the primary selection. 77 "The last string placed in the primary selection.
78Nil if there was no such string. 78nil if there was no such string.
79 79
80Android does not have a primary selection of its own, so Emacs 80Android is not equipped with a primary selection of its own, so
81emulates one inside Lisp.") 81Emacs emulates one in Lisp.")
82
83(defvar android-secondary-selection nil
84 "The last string placed in the secondary selection.
85nil if there was no such string.
86
87Android is not equipped with a secondary selection of its own, so
88Emacs emulates one in Lisp.")
82 89
83(defun android-get-clipboard-1 (data-type) 90(defun android-get-clipboard-1 (data-type)
84 "Return the clipboard data. 91 "Return data saved from the clipboard.
85DATA-TYPE is a selection conversion target. `STRING' means to 92DATA-TYPE is a selection conversion target.
86return the contents of the clipboard as a string. `TARGETS'
87means to return supported data types as a vector.
88 93
89Interpret any other symbol as a MIME type, and return its 94`STRING' means return the contents of the clipboard as a string,
90corresponding data." 95while `TARGETS' means return the types of all data present within
96the clipboard as a vector.
97
98Interpret any other symbol as a MIME type for which any clipboard
99data is returned"
91 (or (and (eq data-type 'STRING) 100 (or (and (eq data-type 'STRING)
92 (android-get-clipboard)) 101 (android-get-clipboard))
93 (and (eq data-type 'TARGETS) 102 (and (eq data-type 'TARGETS)
@@ -95,7 +104,8 @@ corresponding data."
95 (vconcat [TARGETS STRING] 104 (vconcat [TARGETS STRING]
96 (let ((i nil)) 105 (let ((i nil))
97 (dolist (type (android-get-clipboard-targets)) 106 (dolist (type (android-get-clipboard-targets))
98 ;; Don't report plain text as a valid target. 107 ;; Don't report plain text as a valid target
108 ;; since it is addressed by STRING.
99 (unless (equal type "text/plain") 109 (unless (equal type "text/plain")
100 (push (intern type) i))) 110 (push (intern type) i)))
101 (nreverse i)))) 111 (nreverse i))))
@@ -109,7 +119,16 @@ Return nil if DATA-TYPE is anything other than STRING or TARGETS."
109 (or (and (eq data-type 'STRING) 119 (or (and (eq data-type 'STRING)
110 android-primary-selection) 120 android-primary-selection)
111 (and (eq data-type 'TARGETS) 121 (and (eq data-type 'TARGETS)
112 [TARGETS])))) 122 [TARGETS STRING]))))
123
124(defun android-get-secondary (data-type)
125 "Return the last string placed in the secondary selection, or nil.
126Return nil if DATA-TYPE is anything other than STRING or TARGETS."
127 (when android-secondary-selection
128 (or (and (eq data-type 'STRING)
129 android-secondary-selection)
130 (and (eq data-type 'TARGETS)
131 [TARGETS STRING]))))
113 132
114(defun android-selection-bounds (value) 133(defun android-selection-bounds (value)
115 "Return bounds of selection value VALUE. 134 "Return bounds of selection value VALUE.
@@ -152,26 +171,34 @@ VALUE should be something suitable for passing to
152 (cond ((eq type 'CLIPBOARD) 171 (cond ((eq type 'CLIPBOARD)
153 (android-get-clipboard-1 data-type)) 172 (android-get-clipboard-1 data-type))
154 ((eq type 'PRIMARY) 173 ((eq type 'PRIMARY)
155 (android-get-primary data-type)))) 174 (android-get-primary data-type))
175 ((eq type 'SECONDARY)
176 (android-get-secondary data-type))))
156 177
157(cl-defmethod gui-backend-selection-exists-p (selection 178(cl-defmethod gui-backend-selection-exists-p (selection
158 &context (window-system android)) 179 &context (window-system android))
159 (cond ((eq selection 'CLIPBOARD) 180 (cond ((eq selection 'CLIPBOARD)
160 (android-clipboard-exists-p)) 181 (android-clipboard-exists-p))
161 ((eq selection 'PRIMARY) 182 ((eq selection 'PRIMARY)
162 (not (null android-primary-selection))))) 183 (not (null android-primary-selection)))
184 ((eq selection 'SECONDARY)
185 (not (null android-secondary-selection)))))
163 186
164(cl-defmethod gui-backend-selection-owner-p (selection 187(cl-defmethod gui-backend-selection-owner-p (selection
165 &context (window-system android)) 188 &context (window-system android))
166 (cond ((eq selection 'CLIPBOARD) 189 (cond ((eq selection 'CLIPBOARD)
167 (let ((ownership (android-clipboard-owner-p))) 190 (let ((ownership (android-clipboard-owner-p)))
168 ;; If ownership is `lambda', then Emacs couldn't determine 191 ;; If ownership is `lambda', then Emacs couldn't establish
169 ;; whether or not it owns the clipboard. 192 ;; whether or not it owns the clipboard.
170 (and (not (eq ownership 'lambda)) ownership))) 193 (and (not (eq ownership 'lambda)) ownership)))
171 ((eq selection 'PRIMARY) 194 ((eq selection 'PRIMARY)
172 ;; Emacs always owns its own primary selection as long as it 195 ;; Emacs always owns its own primary selection as long as it
173 ;; exists. 196 ;; exists.
174 (not (null android-primary-selection))))) 197 (not (null android-primary-selection)))
198 ((eq selection 'SECONDARY)
199 ;; Emacs always owns its own secondary selection as long as
200 ;; it exists.
201 (not (null android-secondary-selection)))))
175 202
176(cl-defmethod gui-backend-set-selection (type value 203(cl-defmethod gui-backend-set-selection (type value
177 &context (window-system android)) 204 &context (window-system android))
@@ -181,7 +208,9 @@ VALUE should be something suitable for passing to
181 (cond ((eq type 'CLIPBOARD) 208 (cond ((eq type 'CLIPBOARD)
182 (android-set-clipboard string)) 209 (android-set-clipboard string))
183 ((eq type 'PRIMARY) 210 ((eq type 'PRIMARY)
184 (setq android-primary-selection string))))) 211 (setq android-primary-selection string))
212 ((eq type 'SECONDARY)
213 (setq android-secondary-selection string)))))
185 214
186;;; Character composition display. 215;;; Character composition display.
187 216