aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-19 09:12:14 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-19 09:12:14 +0000
commit167036ccbea9af961c2635226a7c9746f2f8cbf5 (patch)
treef958fe403e7b321bd7880e4fe2a228ab18e2461e
parentinput: store last seen wayland input serial (diff)
selection: add text_to_clipboard()
This function takes a string and makes it available to the clipboard.
-rw-r--r--selection.c21
-rw-r--r--selection.h2
2 files changed, 17 insertions, 6 deletions
diff --git a/selection.c b/selection.c
index 73a20b40..024e7f37 100644
--- a/selection.c
+++ b/selection.c
@@ -405,8 +405,8 @@ static const struct zwp_primary_selection_source_v1_listener primary_selection_s
.cancelled = &primary_cancelled,
};
-void
-selection_to_clipboard(struct terminal *term, uint32_t serial)
+bool
+text_to_clipboard(struct terminal *term, char *text, uint32_t serial)
{
if (term->selection.clipboard.data_source != NULL) {
/* Kill previous data source */
@@ -423,17 +423,16 @@ selection_to_clipboard(struct terminal *term, uint32_t serial)
struct clipboard *clipboard = &term->selection.clipboard;
- /* Get selection as a string */
- clipboard->text = extract_selection(term);
-
clipboard->data_source
= wl_data_device_manager_create_data_source(term->wl.data_device_manager);
if (clipboard->data_source == NULL) {
LOG_ERR("failed to create clipboard data source");
- return;
+ return false;
}
+ clipboard->text = text;
+
/* Configure source */
wl_data_source_offer(clipboard->data_source, "text/plain;charset=utf-8");
wl_data_source_add_listener(clipboard->data_source, &data_source_listener, term);
@@ -442,6 +441,16 @@ selection_to_clipboard(struct terminal *term, uint32_t serial)
/* Needed when sending the selection to other client */
clipboard->serial = serial;
+ return true;
+}
+
+void
+selection_to_clipboard(struct terminal *term, uint32_t serial)
+{
+ /* Get selection as a string */
+ char *text = extract_selection(term);
+ if (!text_to_clipboard(term, text, serial))
+ free(text);
}
void
diff --git a/selection.h b/selection.h
index 772f5a73..a98a0327 100644
--- a/selection.h
+++ b/selection.h
@@ -16,3 +16,5 @@ void selection_mark_word(struct terminal *term, int col, int row, uint32_t seria
void selection_to_clipboard(struct terminal *term, uint32_t serial);
void selection_from_clipboard(struct terminal *term, uint32_t serial);
void selection_from_primary(struct terminal *term);
+
+bool text_to_clipboard(struct terminal *term, char *text, uint32_t serial);