wlt: toolkit: add helpers to create/manage selections
authorDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 7 Oct 2012 13:08:03 +0000 (15:08 +0200)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 7 Oct 2012 13:08:03 +0000 (15:08 +0200)
Two new helpers which are needed to implement copy-support. They create
data-sources and set the current selection-source. This allows widgets to
copy data for others to paste.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/wlt_toolkit.c
src/wlt_toolkit.h

index bd66ddd..e23fc33 100644 (file)
@@ -894,6 +894,32 @@ int wlt_display_get_selection_fd(struct wlt_display *disp, const char *mime)
        return p[0];
 }
 
+int wlt_display_new_data_source(struct wlt_display *disp,
+                               struct wl_data_source **out)
+{
+       struct wl_data_source *src;
+
+       if (!disp)
+               return -EINVAL;
+
+       src = wl_data_device_manager_create_data_source(disp->w_manager);
+       if (!src)
+               return -EFAULT;
+
+       *out = src;
+       return 0;
+}
+
+void wlt_display_set_selection(struct wlt_display *disp,
+                              struct wl_data_source *selection)
+{
+       if (!disp)
+               return;
+
+       wl_data_device_set_selection(disp->w_data_dev, selection,
+                                    disp->last_serial);
+}
+
 static const struct wl_data_device_listener data_dev_listener = {
        .data_offer = data_dev_data_offer,
        .enter = data_dev_enter,
index c6e171f..df2edc1 100644 (file)
@@ -137,6 +137,10 @@ void wlt_display_unregister_cb(struct wlt_display *disp,
 int wlt_display_get_selection_fd(struct wlt_display *disp, const char *mime);
 int wlt_display_get_selection_to_fd(struct wlt_display *disp, const char *mime,
                                    int output_fd);
+int wlt_display_new_data_source(struct wlt_display *disp,
+                               struct wl_data_source **out);
+void wlt_display_set_selection(struct wlt_display *disp,
+                              struct wl_data_source *selection);
 
 void wlt_window_ref(struct wlt_window *wnd);
 void wlt_window_unref(struct wlt_window *wnd);