wlt: toolkit: add helpers to create/manage selections

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>
This commit is contained in:
David Herrmann 2012-10-07 15:08:03 +02:00
parent 3ecd09ddd3
commit 166dcc5a09
2 changed files with 30 additions and 0 deletions

View 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,

View 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);