mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-13 08:21:03 -04:00
selection: add text_to_clipboard()
This function takes a string and makes it available to the clipboard.
This commit is contained in:
parent
32f397d9b0
commit
167036ccbe
2 changed files with 17 additions and 6 deletions
21
selection.c
21
selection.c
|
|
@ -405,8 +405,8 @@ static const struct zwp_primary_selection_source_v1_listener primary_selection_s
|
||||||
.cancelled = &primary_cancelled,
|
.cancelled = &primary_cancelled,
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
bool
|
||||||
selection_to_clipboard(struct terminal *term, uint32_t serial)
|
text_to_clipboard(struct terminal *term, char *text, uint32_t serial)
|
||||||
{
|
{
|
||||||
if (term->selection.clipboard.data_source != NULL) {
|
if (term->selection.clipboard.data_source != NULL) {
|
||||||
/* Kill previous data source */
|
/* Kill previous data source */
|
||||||
|
|
@ -423,17 +423,16 @@ selection_to_clipboard(struct terminal *term, uint32_t serial)
|
||||||
|
|
||||||
struct clipboard *clipboard = &term->selection.clipboard;
|
struct clipboard *clipboard = &term->selection.clipboard;
|
||||||
|
|
||||||
/* Get selection as a string */
|
|
||||||
clipboard->text = extract_selection(term);
|
|
||||||
|
|
||||||
clipboard->data_source
|
clipboard->data_source
|
||||||
= wl_data_device_manager_create_data_source(term->wl.data_device_manager);
|
= wl_data_device_manager_create_data_source(term->wl.data_device_manager);
|
||||||
|
|
||||||
if (clipboard->data_source == NULL) {
|
if (clipboard->data_source == NULL) {
|
||||||
LOG_ERR("failed to create clipboard data source");
|
LOG_ERR("failed to create clipboard data source");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clipboard->text = text;
|
||||||
|
|
||||||
/* Configure source */
|
/* Configure source */
|
||||||
wl_data_source_offer(clipboard->data_source, "text/plain;charset=utf-8");
|
wl_data_source_offer(clipboard->data_source, "text/plain;charset=utf-8");
|
||||||
wl_data_source_add_listener(clipboard->data_source, &data_source_listener, term);
|
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 */
|
/* Needed when sending the selection to other client */
|
||||||
clipboard->serial = serial;
|
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
|
void
|
||||||
|
|
|
||||||
|
|
@ -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_to_clipboard(struct terminal *term, uint32_t serial);
|
||||||
void selection_from_clipboard(struct terminal *term, uint32_t serial);
|
void selection_from_clipboard(struct terminal *term, uint32_t serial);
|
||||||
void selection_from_primary(struct terminal *term);
|
void selection_from_primary(struct terminal *term);
|
||||||
|
|
||||||
|
bool text_to_clipboard(struct terminal *term, char *text, uint32_t serial);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue