From c3cacb470430f3a19db8e2442f1ed61887044373 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 9 Sep 2020 18:44:49 +0200 Subject: selection: add selection__unset() These functions clear the current selection. --- selection.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'selection.c') diff --git a/selection.c b/selection.c index ed8d061b..b423fcca 100644 --- a/selection.c +++ b/selection.c @@ -661,6 +661,47 @@ selection_cancel(struct terminal *term) term->selection.ongoing = false; } +void +selection_clipboard_unset(struct seat *seat) +{ + struct wl_clipboard *clipboard = &seat->clipboard; + + if (clipboard->data_source == NULL) + return; + + /* Kill previous data source */ + assert(clipboard->serial != 0); + wl_data_device_set_selection(seat->data_device, NULL, clipboard->serial); + wl_data_source_destroy(clipboard->data_source); + + clipboard->data_source = NULL; + clipboard->serial = 0; + + free(clipboard->text); + clipboard->text = NULL; +} + +void +selection_primary_unset(struct seat *seat) +{ + struct wl_primary *primary = &seat->primary; + + if (primary->data_source == NULL) + return; + + assert(primary->serial != 0); + zwp_primary_selection_device_v1_set_selection( + seat->primary_selection_device, NULL, primary->serial); + zwp_primary_selection_source_v1_destroy(primary->data_source); + free(primary->text); + + primary->data_source = NULL; + primary->serial = 0; + + free(primary->text); + primary->text = NULL; +} + void selection_mark_word(struct seat *seat, struct terminal *term, int col, int row, bool spaces_only, uint32_t serial) -- cgit v1.3 From dec6f963cbedb093370f8d9559e357e72a31df90 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 9 Sep 2020 18:45:10 +0200 Subject: selection: add selection__has_data() Returns true when there is data available for paste in the clipboard/primary selection. --- selection.c | 12 ++++++++++++ selection.h | 3 +++ 2 files changed, 15 insertions(+) (limited to 'selection.c') diff --git a/selection.c b/selection.c index b423fcca..f1129b03 100644 --- a/selection.c +++ b/selection.c @@ -661,6 +661,18 @@ selection_cancel(struct terminal *term) term->selection.ongoing = false; } +bool +selection_clipboard_has_data(const struct seat *seat) +{ + return seat->clipboard.data_offer != NULL; +} + +bool +selection_primary_has_data(const struct seat *seat) +{ + return seat->primary.data_offer != NULL; +} + void selection_clipboard_unset(struct seat *seat) { diff --git a/selection.h b/selection.h index 178a990b..547da2fc 100644 --- a/selection.h +++ b/selection.h @@ -33,6 +33,9 @@ void selection_mark_row( void selection_clipboard_unset(struct seat *seat); void selection_primary_unset(struct seat *seat); +bool selection_clipboard_has_data(const struct seat *seat); +bool selection_primary_has_data(const struct seat *seat); + char *selection_to_text(const struct terminal *term); void selection_to_clipboard( struct seat *seat, struct terminal *term, uint32_t serial); -- cgit v1.3