data-device: Don't poke into MetaWaylandKeyboard

It needs to know the wl_client that has keyboard focus, so add a simple
getter for that.
This commit is contained in:
Jasper St. Pierre 2014-04-16 15:20:07 -04:00
parent 86100936d9
commit 2bcd4ab159
3 changed files with 24 additions and 19 deletions

View File

@ -360,17 +360,14 @@ destroy_selection_data_source (struct wl_listener *listener, void *data)
MetaWaylandSeat *seat = MetaWaylandSeat *seat =
wl_container_of (listener, seat, selection_data_source_listener); wl_container_of (listener, seat, selection_data_source_listener);
struct wl_resource *data_device; struct wl_resource *data_device;
struct wl_resource *focus = NULL; struct wl_client *focus_client = NULL;
seat->selection_data_source = NULL; seat->selection_data_source = NULL;
focus = seat->keyboard.focus_resource; focus_client = meta_wayland_keyboard_get_focus_client (&seat->keyboard);
if (focus_client)
if (focus)
{ {
data_device = data_device = wl_resource_find_for_client (&seat->data_device_resource_list, focus_client);
wl_resource_find_for_client (&seat->data_device_resource_list,
wl_resource_get_client (focus));
if (data_device) if (data_device)
wl_data_device_send_selection (data_device, NULL); wl_data_device_send_selection (data_device, NULL);
} }
@ -382,7 +379,7 @@ meta_wayland_seat_set_selection (MetaWaylandSeat *seat,
guint32 serial) guint32 serial)
{ {
struct wl_resource *data_device, *offer; struct wl_resource *data_device, *offer;
struct wl_resource *focus = NULL; struct wl_client *focus_client;
if (seat->selection_data_source && if (seat->selection_data_source &&
seat->selection_serial - serial < UINT32_MAX / 2) seat->selection_serial - serial < UINT32_MAX / 2)
@ -398,13 +395,10 @@ meta_wayland_seat_set_selection (MetaWaylandSeat *seat,
seat->selection_data_source = source; seat->selection_data_source = source;
seat->selection_serial = serial; seat->selection_serial = serial;
focus = seat->keyboard.focus_resource; focus_client = meta_wayland_keyboard_get_focus_client (&seat->keyboard);
if (focus_client)
if (focus)
{ {
data_device = data_device = wl_resource_find_for_client (&seat->data_device_resource_list, focus_client);
wl_resource_find_for_client (&seat->data_device_resource_list,
wl_resource_get_client (focus));
if (data_device && source) if (data_device && source)
{ {
offer = offer =
@ -515,15 +509,15 @@ bind_manager (struct wl_client *client,
void void
meta_wayland_data_device_set_keyboard_focus (MetaWaylandSeat *seat) meta_wayland_data_device_set_keyboard_focus (MetaWaylandSeat *seat)
{ {
struct wl_resource *data_device, *focus, *offer; struct wl_client *focus_client;
struct wl_resource *data_device, *offer;
MetaWaylandDataSource *source; MetaWaylandDataSource *source;
focus = seat->keyboard.focus_resource; focus_client = meta_wayland_keyboard_get_focus_client (&seat->keyboard);
if (!focus) if (!focus_client)
return; return;
data_device = wl_resource_find_for_client (&seat->data_device_resource_list, data_device = wl_resource_find_for_client (&seat->data_device_resource_list, focus_client);
wl_resource_get_client (focus));
if (!data_device) if (!data_device)
return; return;

View File

@ -532,3 +532,11 @@ meta_wayland_keyboard_set_keymap_names (MetaWaylandKeyboard *keyboard,
flags); flags);
} }
struct wl_client *
meta_wayland_keyboard_get_focus_client (MetaWaylandKeyboard *keyboard)
{
if (keyboard->focus_surface)
return wl_resource_get_client (keyboard->focus_surface->resource);
else
return NULL;
}

View File

@ -140,4 +140,7 @@ void
meta_wayland_keyboard_update (MetaWaylandKeyboard *keyboard, meta_wayland_keyboard_update (MetaWaylandKeyboard *keyboard,
const ClutterKeyEvent *event); const ClutterKeyEvent *event);
struct wl_client *
meta_wayland_keyboard_get_focus_client (MetaWaylandKeyboard *keyboard);
#endif /* __META_WAYLAND_KEYBOARD_H__ */ #endif /* __META_WAYLAND_KEYBOARD_H__ */