pointer/keyboard: Fix focus setting once again

Yet another large-scale restructuring... this is some messy code.
This commit is contained in:
Jasper St. Pierre 2014-02-18 23:16:54 -05:00
parent 7615d17293
commit a5d950f453
2 changed files with 99 additions and 99 deletions

View File

@ -527,37 +527,40 @@ void
meta_wayland_keyboard_set_focus (MetaWaylandKeyboard *keyboard, meta_wayland_keyboard_set_focus (MetaWaylandKeyboard *keyboard,
MetaWaylandSurface *surface) MetaWaylandSurface *surface)
{ {
struct wl_resource *resource;
uint32_t serial;
if (keyboard->focus_surface == surface && keyboard->focus_resource != NULL) if (keyboard->focus_surface == surface && keyboard->focus_resource != NULL)
return; return;
resource = keyboard->focus_resource; if (keyboard->focus_surface != NULL)
if (resource) {
wl_list_remove (&keyboard->focus_surface_listener.link);
keyboard->focus_surface = NULL;
if (keyboard->focus_resource)
{ {
if (keyboard->focus_surface->resource) if (keyboard->focus_surface->resource)
{ {
struct wl_client *client = wl_resource_get_client (resource); struct wl_client *client = wl_resource_get_client (keyboard->focus_resource);
struct wl_display *display = wl_client_get_display (client); struct wl_display *display = wl_client_get_display (client);
serial = wl_display_next_serial (display); uint32_t serial = wl_display_next_serial (display);
wl_keyboard_send_leave (resource, serial, keyboard->focus_surface->resource); wl_keyboard_send_leave (keyboard->focus_resource, serial, keyboard->focus_surface->resource);
} }
wl_list_remove (&keyboard->focus_resource_listener.link); wl_list_remove (&keyboard->focus_resource_listener.link);
wl_list_remove (&keyboard->focus_surface_listener.link);
keyboard->focus_resource = NULL; keyboard->focus_resource = NULL;
keyboard->focus_surface = NULL; }
} }
resource = find_resource_for_surface (&keyboard->resource_list, surface); if (surface != NULL)
if (resource)
{ {
struct wl_client *client = wl_resource_get_client (resource); keyboard->focus_surface = surface;
struct wl_display *display = wl_client_get_display (client); wl_resource_add_destroy_listener (keyboard->focus_surface->resource, &keyboard->focus_surface_listener);
serial = wl_display_next_serial (display); keyboard->focus_resource = find_resource_for_surface (&keyboard->resource_list, surface);
if (keyboard->focus_resource)
{
struct wl_client *client = wl_resource_get_client (keyboard->focus_resource);
struct wl_display *display = wl_client_get_display (client);
uint32_t serial = wl_display_next_serial (display);
/* If we're in a modal grab, the client is focused but doesn't see /* If we're in a modal grab, the client is focused but doesn't see
modifiers or pressed keys (and fix that up when we exit the modal) */ modifiers or pressed keys (and fix that up when we exit the modal) */
@ -566,30 +569,24 @@ meta_wayland_keyboard_set_focus (MetaWaylandKeyboard *keyboard,
struct wl_array empty; struct wl_array empty;
wl_array_init (&empty); wl_array_init (&empty);
wl_keyboard_send_modifiers (resource, serial, wl_keyboard_send_modifiers (keyboard->focus_resource, serial, 0, 0, 0, 0);
0, 0, 0, 0); wl_keyboard_send_enter (keyboard->focus_resource, serial, keyboard->focus_surface->resource, &empty);
wl_keyboard_send_enter (resource, serial, surface->resource,
&empty);
} }
else else
{ {
wl_keyboard_send_modifiers (resource, serial, wl_keyboard_send_modifiers (keyboard->focus_resource, serial,
keyboard->modifier_state.mods_depressed, keyboard->modifier_state.mods_depressed,
keyboard->modifier_state.mods_latched, keyboard->modifier_state.mods_latched,
keyboard->modifier_state.mods_locked, keyboard->modifier_state.mods_locked,
keyboard->modifier_state.group); keyboard->modifier_state.group);
wl_keyboard_send_enter (resource, serial, surface->resource, wl_keyboard_send_enter (keyboard->focus_resource, serial, keyboard->focus_surface->resource,
&keyboard->keys); &keyboard->keys);
} }
keyboard->focus_resource = resource;
keyboard->focus_surface = surface;
wl_resource_add_destroy_listener (keyboard->focus_resource, &keyboard->focus_resource_listener); wl_resource_add_destroy_listener (keyboard->focus_resource, &keyboard->focus_resource_listener);
wl_resource_add_destroy_listener (keyboard->focus_surface->resource, &keyboard->focus_surface_listener);
keyboard->focus_serial = serial; keyboard->focus_serial = serial;
} }
}
} }
void void

View File

@ -333,42 +333,49 @@ meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer,
{ {
MetaWaylandSeat *seat = meta_wayland_pointer_get_seat (pointer); MetaWaylandSeat *seat = meta_wayland_pointer_get_seat (pointer);
MetaWaylandKeyboard *kbd = &seat->keyboard; MetaWaylandKeyboard *kbd = &seat->keyboard;
struct wl_resource *resource, *kr;
uint32_t serial;
if (pointer->focus_surface == surface && pointer->focus_resource != NULL) if (pointer->focus_surface == surface && pointer->focus_resource != NULL)
return; return;
resource = pointer->focus_resource; if (pointer->focus_surface)
if (resource) {
wl_list_remove (&pointer->focus_surface_listener.link);
pointer->focus_surface = NULL;
if (pointer->focus_resource)
{ {
if (pointer->focus_surface->resource) if (pointer->focus_surface->resource)
{ {
struct wl_client *client = wl_resource_get_client (resource); struct wl_client *client = wl_resource_get_client (pointer->focus_resource);
struct wl_display *display = wl_client_get_display (client); struct wl_display *display = wl_client_get_display (client);
serial = wl_display_next_serial (display); uint32_t serial = wl_display_next_serial (display);
wl_pointer_send_leave (resource, serial, pointer->focus_surface->resource); wl_pointer_send_leave (pointer->focus_resource, serial, pointer->focus_surface->resource);
} }
wl_list_remove (&pointer->focus_surface_listener.link);
wl_list_remove (&pointer->focus_resource_listener.link); wl_list_remove (&pointer->focus_resource_listener.link);
pointer->focus_surface = NULL; pointer->focus_surface = NULL;
pointer->focus_resource = NULL; pointer->focus_resource = NULL;
} }
}
resource = find_resource_for_surface (&pointer->resource_list, surface); if (surface != NULL)
if (resource)
{ {
struct wl_client *client = wl_resource_get_client (resource); pointer->focus_surface = surface;
wl_resource_add_destroy_listener (pointer->focus_surface->resource, &pointer->focus_surface_listener);
pointer->focus_resource = find_resource_for_surface (&pointer->resource_list, surface);
if (pointer->focus_resource)
{
struct wl_client *client = wl_resource_get_client (pointer->focus_resource);
struct wl_display *display = wl_client_get_display (client); struct wl_display *display = wl_client_get_display (client);
wl_fixed_t sx, sy; wl_fixed_t sx, sy;
serial = wl_display_next_serial (display); uint32_t serial = wl_display_next_serial (display);
if (kbd) if (kbd)
{ {
kr = find_resource_for_surface (&kbd->resource_list, surface); struct wl_resource *kr = find_resource_for_surface (&kbd->resource_list, pointer->focus_surface);
if (kr) if (kr)
{ {
wl_keyboard_send_modifiers (kr, wl_keyboard_send_modifiers (kr,
@ -380,22 +387,18 @@ meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer,
} }
} }
meta_wayland_pointer_get_relative_coordinates (pointer, surface, &sx, &sy); meta_wayland_pointer_get_relative_coordinates (pointer, pointer->focus_surface, &sx, &sy);
meta_window_handle_enter (surface->window, meta_window_handle_enter (pointer->focus_surface->window,
/* XXX -- can we reliably get a timestamp for setting focus? */ /* XXX -- can we reliably get a timestamp for setting focus? */
clutter_get_current_event_time (), clutter_get_current_event_time (),
wl_fixed_to_int (pointer->x), wl_fixed_to_int (pointer->x),
wl_fixed_to_int (pointer->y)); wl_fixed_to_int (pointer->y));
wl_pointer_send_enter (resource, serial, surface->resource, sx, sy); wl_pointer_send_enter (pointer->focus_resource, serial, pointer->focus_surface->resource, sx, sy);
pointer->focus_resource = resource;
pointer->focus_surface = surface;
wl_resource_add_destroy_listener (pointer->focus_resource, &pointer->focus_resource_listener); wl_resource_add_destroy_listener (pointer->focus_resource, &pointer->focus_resource_listener);
wl_resource_add_destroy_listener (pointer->focus_surface->resource, &pointer->focus_surface_listener);
pointer->focus_serial = serial; pointer->focus_serial = serial;
} }
}
} }
void void