aboutsummaryrefslogtreecommitdiff
path: root/selection.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-09-10 05:36:19 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-09-10 05:36:19 +0000
commitfc510d423b1acf0b4c75f53b36edef9d0b135216 (patch)
treed0574e4830bccff656ad8153070e100d154768ad /selection.c
parentconfig: spelling: mosue -> mouse (diff)
parentosc52: use first source that actually *has* data (diff)
Merge branch 'osc52-clear-selection-on-invalid-payload' into master
Diffstat (limited to 'selection.c')
-rw-r--r--selection.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/selection.c b/selection.c
index ed8d061b..f1129b03 100644
--- a/selection.c
+++ b/selection.c
@@ -661,6 +661,59 @@ 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)
+{
+ 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)