data-device: Use a listener list to decouple the x11 selection bridge

dev
Kristian Høgsberg 14 years ago
parent f9b0844e59
commit a33d0c38d2
  1. 1
      src/compositor.c
  2. 7
      src/compositor.h
  3. 5
      src/data-device.c
  4. 22
      src/xserver-launcher.c

@ -1681,6 +1681,7 @@ weston_input_device_init(struct weston_input_device *device,
wl_list_insert(ec->input_device_list.prev, &device->link); wl_list_insert(ec->input_device_list.prev, &device->link);
device->selection_data_source = NULL; device->selection_data_source = NULL;
wl_list_init(&device->selection_listener_list);
} }
WL_EXPORT void WL_EXPORT void

@ -96,6 +96,12 @@ struct weston_output {
void (*destroy)(struct weston_output *output); void (*destroy)(struct weston_output *output);
}; };
struct weston_selection_listener {
void (*func)(struct weston_selection_listener *listener,
struct weston_input_device *device);
struct wl_list link;
};
struct weston_input_device { struct weston_input_device {
struct wl_input_device input_device; struct wl_input_device input_device;
struct weston_compositor *compositor; struct weston_compositor *compositor;
@ -113,6 +119,7 @@ struct weston_input_device {
struct weston_data_source *selection_data_source; struct weston_data_source *selection_data_source;
struct wl_listener selection_data_source_listener; struct wl_listener selection_data_source_listener;
struct wl_grab grab; struct wl_grab grab;
struct wl_list selection_listener_list;
uint32_t num_tp; uint32_t num_tp;
struct wl_surface *touch_focus; struct wl_surface *touch_focus;

@ -317,6 +317,7 @@ weston_input_device_set_selection(struct weston_input_device *device,
struct weston_data_source *source, uint32_t time) struct weston_data_source *source, uint32_t time)
{ {
struct wl_resource *data_device, *focus, *offer; struct wl_resource *data_device, *focus, *offer;
struct weston_selection_listener *listener, *next;
if (device->selection_data_source) { if (device->selection_data_source) {
device->selection_data_source->cancel(device->selection_data_source); device->selection_data_source->cancel(device->selection_data_source);
@ -339,7 +340,9 @@ weston_input_device_set_selection(struct weston_input_device *device,
} }
} }
weston_xserver_set_selection(device); wl_list_for_each_safe(listener, next,
&device->selection_listener_list, link)
listener->func(listener, device);
device->selection_data_source_listener.func = device->selection_data_source_listener.func =
destroy_selection_data_source; destroy_selection_data_source;

@ -81,6 +81,7 @@ struct weston_wm {
xcb_timestamp_t selection_timestamp; xcb_timestamp_t selection_timestamp;
int selection_property_set; int selection_property_set;
int flush_property_on_delete; int flush_property_on_delete;
struct weston_selection_listener selection_listener;
struct { struct {
xcb_atom_t wm_protocols; xcb_atom_t wm_protocols;
@ -446,22 +447,21 @@ weston_wm_get_incr_chunk(struct weston_wm *wm)
} }
} }
void static void
weston_xserver_set_selection(struct weston_input_device *device) weston_wm_set_selection(struct weston_selection_listener *listener,
struct weston_input_device *device)
{ {
struct weston_xserver *wxs = device->compositor->wxs; struct weston_wm *wm =
struct weston_wm *wm = wxs->wm; container_of(listener, struct weston_wm, selection_listener);
struct weston_data_source *source; struct weston_data_source *source = device->selection_data_source;
const char **p, **end; const char **p, **end;
int has_text_plain = 0; int has_text_plain = 0;
fprintf(stderr, "set selection\n"); fprintf(stderr, "set selection\n");
source = device->selection_data_source;
p = source->mime_types.data; p = source->mime_types.data;
end = (const char **) end = (const char **)
((char *) source->mime_types.data + source->mime_types.size); ((char *) source->mime_types.data + source->mime_types.size);
while (p < end) { while (p < end) {
fprintf(stderr, " %s\n", *p); fprintf(stderr, " %s\n", *p);
if (strcmp(*p, "text/plain") == 0 || if (strcmp(*p, "text/plain") == 0 ||
@ -1186,6 +1186,7 @@ wxs_wm_get_resources(struct weston_wm *wm)
static struct weston_wm * static struct weston_wm *
weston_wm_create(struct weston_xserver *wxs) weston_wm_create(struct weston_xserver *wxs)
{ {
struct weston_input_device *device;
struct weston_wm *wm; struct weston_wm *wm;
struct wl_event_loop *loop; struct wl_event_loop *loop;
xcb_screen_iterator_t s; xcb_screen_iterator_t s;
@ -1268,6 +1269,12 @@ weston_wm_create(struct weston_xserver *wxs)
wm->atom.clipboard, mask); wm->atom.clipboard, mask);
xcb_flush(wm->conn); xcb_flush(wm->conn);
device = (struct weston_input_device *) wxs->compositor->input_device;
wm->selection_listener.func = weston_wm_set_selection;
wl_list_insert(&device->selection_listener_list,
&wm->selection_listener.link);
fprintf(stderr, "created wm\n"); fprintf(stderr, "created wm\n");
return wm; return wm;
@ -1280,6 +1287,7 @@ weston_wm_destroy(struct weston_wm *wm)
hash_table_destroy(wm->window_hash); hash_table_destroy(wm->window_hash);
xcb_disconnect(wm->conn); xcb_disconnect(wm->conn);
wl_event_source_remove(wm->source); wl_event_source_remove(wm->source);
wl_list_remove(&wm->selection_listener.link);
free(wm); free(wm);
} }

Loading…
Cancel
Save