aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-03-27 13:36:45 +0000
committerPo Lu2022-03-27 13:36:45 +0000
commitbe21c95842f37e164606a6b392f5396d91506f61 (patch)
tree5d25c80461c213a2c683565233e7016782fba8ee /src
parent46863b7dfa210e73244af9bc790222dd66d5051d (diff)
downloademacs-be21c95842f37e164606a6b392f5396d91506f61.tar.gz
emacs-be21c95842f37e164606a6b392f5396d91506f61.zip
Store latin-1 content into the Haiku clipboard as well
* lisp/term/haiku-win.el (haiku-normal-selection-encoders): New variable. (haiku-select-encode-utf-8-string, haiku-select-encode-xstring): New functions. (gui-backend-set-selection): Use new selection encoder functions instead of hard-coding UTF-8. (haiku-dnd-handle-drag-n-drop-event): Rename to `haiku-drag-and-drop'. * src/haiku_select.cc (be_lock_clipboard_message): Accept new argument `clear'. (be_unlock_clipboard): Accept new argument `discard'. * src/haikuselect.c (Fhaiku_selection_data): Change calls to `be_lock_clipboard_message' and `be_unlock_clipboard'. (haiku_unwind_clipboard_lock): New function. (Fhaiku_selection_put): Accept new meaning of `name' which means to set the selection message. * src/haikuselect.h: Update prototypes.
Diffstat (limited to 'src')
-rw-r--r--src/haiku_select.cc12
-rw-r--r--src/haikuselect.c56
-rw-r--r--src/haikuselect.h6
3 files changed, 63 insertions, 11 deletions
diff --git a/src/haiku_select.cc b/src/haiku_select.cc
index 373ad321c4b..e047b9b5139 100644
--- a/src/haiku_select.cc
+++ b/src/haiku_select.cc
@@ -413,7 +413,7 @@ be_add_message_message (void *message, const char *name,
413 413
414int 414int
415be_lock_clipboard_message (enum haiku_clipboard clipboard, 415be_lock_clipboard_message (enum haiku_clipboard clipboard,
416 void **message_return) 416 void **message_return, bool clear)
417{ 417{
418 BClipboard *board; 418 BClipboard *board;
419 419
@@ -427,12 +427,15 @@ be_lock_clipboard_message (enum haiku_clipboard clipboard,
427 if (!board->Lock ()) 427 if (!board->Lock ())
428 return 1; 428 return 1;
429 429
430 if (clear)
431 board->Clear ();
432
430 *message_return = board->Data (); 433 *message_return = board->Data ();
431 return 0; 434 return 0;
432} 435}
433 436
434void 437void
435be_unlock_clipboard (enum haiku_clipboard clipboard) 438be_unlock_clipboard (enum haiku_clipboard clipboard, bool discard)
436{ 439{
437 BClipboard *board; 440 BClipboard *board;
438 441
@@ -443,5 +446,10 @@ be_unlock_clipboard (enum haiku_clipboard clipboard)
443 else 446 else
444 board = system_clipboard; 447 board = system_clipboard;
445 448
449 if (discard)
450 board->Revert ();
451 else
452 board->Commit ();
453
446 board->Unlock (); 454 board->Unlock ();
447} 455}
diff --git a/src/haikuselect.c b/src/haikuselect.c
index f1aa4f20d96..461482fea18 100644
--- a/src/haikuselect.c
+++ b/src/haikuselect.c
@@ -27,6 +27,8 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
27 27
28#include <stdlib.h> 28#include <stdlib.h>
29 29
30static void haiku_lisp_to_message (Lisp_Object, void *);
31
30DEFUN ("haiku-selection-data", Fhaiku_selection_data, Shaiku_selection_data, 32DEFUN ("haiku-selection-data", Fhaiku_selection_data, Shaiku_selection_data,
31 2, 2, 0, 33 2, 2, 0,
32 doc: /* Retrieve content typed as NAME from the clipboard 34 doc: /* Retrieve content typed as NAME from the clipboard
@@ -88,7 +90,7 @@ message in the format accepted by `haiku-drag-message', which see. */)
88 clipboard_name = CLIPBOARD_CLIPBOARD; 90 clipboard_name = CLIPBOARD_CLIPBOARD;
89 91
90 block_input (); 92 block_input ();
91 rc = be_lock_clipboard_message (clipboard_name, &message); 93 rc = be_lock_clipboard_message (clipboard_name, &message, false);
92 unblock_input (); 94 unblock_input ();
93 95
94 if (rc) 96 if (rc)
@@ -96,13 +98,19 @@ message in the format accepted by `haiku-drag-message', which see. */)
96 98
97 block_input (); 99 block_input ();
98 str = haiku_message_to_lisp (message); 100 str = haiku_message_to_lisp (message);
99 be_unlock_clipboard (clipboard_name); 101 be_unlock_clipboard (clipboard_name, true);
100 unblock_input (); 102 unblock_input ();
101 } 103 }
102 104
103 return str; 105 return str;
104} 106}
105 107
108static void
109haiku_unwind_clipboard_lock (int clipboard)
110{
111 be_unlock_clipboard (clipboard, false);
112}
113
106DEFUN ("haiku-selection-put", Fhaiku_selection_put, Shaiku_selection_put, 114DEFUN ("haiku-selection-put", Fhaiku_selection_put, Shaiku_selection_put,
107 3, 4, 0, 115 3, 4, 0,
108 doc: /* Add or remove content from the clipboard CLIPBOARD. 116 doc: /* Add or remove content from the clipboard CLIPBOARD.
@@ -110,18 +118,53 @@ CLIPBOARD is the symbol `PRIMARY', `SECONDARY' or `CLIPBOARD'. NAME
110is a MIME type denoting the type of the data to add. DATA is the 118is a MIME type denoting the type of the data to add. DATA is the
111string that will be placed in the clipboard, or nil if the content is 119string that will be placed in the clipboard, or nil if the content is
112to be removed. CLEAR, if non-nil, means to erase all the previous 120to be removed. CLEAR, if non-nil, means to erase all the previous
113contents of the clipboard. */) 121contents of the clipboard.
122
123Alternatively, NAME can be a system message in the format accepted by
124`haiku-drag-message', which will replace the contents of CLIPBOARD.
125In that case, the arguments after NAME are ignored. */)
114 (Lisp_Object clipboard, Lisp_Object name, Lisp_Object data, 126 (Lisp_Object clipboard, Lisp_Object name, Lisp_Object data,
115 Lisp_Object clear) 127 Lisp_Object clear)
116{ 128{
129 enum haiku_clipboard clipboard_name;
130 specpdl_ref ref;
131 char *dat;
132 ptrdiff_t len;
133 int rc;
134 void *message;
135
136 if (CONSP (name) || NILP (name))
137 {
138 if (EQ (clipboard, QPRIMARY))
139 clipboard_name = CLIPBOARD_PRIMARY;
140 else if (EQ (clipboard, QSECONDARY))
141 clipboard_name = CLIPBOARD_SECONDARY;
142 else if (EQ (clipboard, QCLIPBOARD))
143 clipboard_name = CLIPBOARD_CLIPBOARD;
144 else
145 signal_error ("Invalid clipboard", clipboard);
146
147 rc = be_lock_clipboard_message (clipboard_name,
148 &message, true);
149
150 if (rc)
151 signal_error ("Couldn't open clipboard", clipboard);
152
153 ref = SPECPDL_INDEX ();
154 record_unwind_protect_int (haiku_unwind_clipboard_lock,
155 clipboard_name);
156 haiku_lisp_to_message (name, message);
157
158 return unbind_to (ref, Qnil);
159 }
160
117 CHECK_SYMBOL (clipboard); 161 CHECK_SYMBOL (clipboard);
118 CHECK_STRING (name); 162 CHECK_STRING (name);
119 if (!NILP (data)) 163 if (!NILP (data))
120 CHECK_STRING (data); 164 CHECK_STRING (data);
121 165
122 block_input (); 166 dat = !NILP (data) ? SSDATA (data) : NULL;
123 char *dat = !NILP (data) ? SSDATA (data) : NULL; 167 len = !NILP (data) ? SBYTES (data) : 0;
124 ptrdiff_t len = !NILP (data) ? SBYTES (data) : 0;
125 168
126 if (EQ (clipboard, QPRIMARY)) 169 if (EQ (clipboard, QPRIMARY))
127 BClipboard_set_primary_selection_data (SSDATA (name), dat, len, 170 BClipboard_set_primary_selection_data (SSDATA (name), dat, len,
@@ -136,7 +179,6 @@ contents of the clipboard. */)
136 unblock_input (); 179 unblock_input ();
137 signal_error ("Bad clipboard", clipboard); 180 signal_error ("Bad clipboard", clipboard);
138 } 181 }
139 unblock_input ();
140 182
141 return Qnil; 183 return Qnil;
142} 184}
diff --git a/src/haikuselect.h b/src/haikuselect.h
index 01e4ca327da..5d1dd33c8c4 100644
--- a/src/haikuselect.h
+++ b/src/haikuselect.h
@@ -107,8 +107,10 @@ extern "C"
107 extern int be_add_message_message (void *message, const char *name, 107 extern int be_add_message_message (void *message, const char *name,
108 void *data); 108 void *data);
109 extern int be_lock_clipboard_message (enum haiku_clipboard clipboard, 109 extern int be_lock_clipboard_message (enum haiku_clipboard clipboard,
110 void **message_return); 110 void **message_return,
111 extern void be_unlock_clipboard (enum haiku_clipboard clipboard); 111 bool clear);
112 extern void be_unlock_clipboard (enum haiku_clipboard clipboard,
113 bool discard);
112#ifdef __cplusplus 114#ifdef __cplusplus
113}; 115};
114#endif 116#endif