diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-07-19 09:12:14 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-07-19 09:12:14 +0000 |
| commit | 167036ccbea9af961c2635226a7c9746f2f8cbf5 (patch) | |
| tree | f958fe403e7b321bd7880e4fe2a228ab18e2461e /selection.c | |
| parent | input: store last seen wayland input serial (diff) | |
selection: add text_to_clipboard()
This function takes a string and makes it available to the clipboard.
Diffstat (limited to 'selection.c')
| -rw-r--r-- | selection.c | 21 |
1 files changed, 15 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 |
