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,
MetaWaylandSurface *surface)
{
struct wl_resource *resource;
uint32_t serial;
if (keyboard->focus_surface == surface && keyboard->focus_resource != NULL)
return;
resource = keyboard->focus_resource;
if (resource)
if (keyboard->focus_surface != NULL)
{
wl_list_remove (&keyboard->focus_surface_listener.link);
keyboard->focus_surface = NULL;
if (keyboard->focus_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);
serial = wl_display_next_serial (display);
wl_keyboard_send_leave (resource, serial, keyboard->focus_surface->resource);
uint32_t serial = wl_display_next_serial (display);
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_surface_listener.link);
keyboard->focus_resource = NULL;
keyboard->focus_surface = NULL;
}
}
resource = find_resource_for_surface (&keyboard->resource_list, surface);
if (resource)
if (surface != NULL)
{
struct wl_client *client = wl_resource_get_client (resource);
struct wl_display *display = wl_client_get_display (client);
keyboard->focus_surface = surface;
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
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;
wl_array_init (&empty);
wl_keyboard_send_modifiers (resource, serial,
0, 0, 0, 0);
wl_keyboard_send_enter (resource, serial, surface->resource,
&empty);
wl_keyboard_send_modifiers (keyboard->focus_resource, serial, 0, 0, 0, 0);
wl_keyboard_send_enter (keyboard->focus_resource, serial, keyboard->focus_surface->resource, &empty);
}
else
{
wl_keyboard_send_modifiers (resource, serial,
wl_keyboard_send_modifiers (keyboard->focus_resource, serial,
keyboard->modifier_state.mods_depressed,
keyboard->modifier_state.mods_latched,
keyboard->modifier_state.mods_locked,
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->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_surface->resource, &keyboard->focus_surface_listener);
keyboard->focus_serial = serial;
}
}
}
void

View File

@ -333,42 +333,49 @@ meta_wayland_pointer_set_focus (MetaWaylandPointer *pointer,
{
MetaWaylandSeat *seat = meta_wayland_pointer_get_seat (pointer);
MetaWaylandKeyboard *kbd = &seat->keyboard;
struct wl_resource *resource, *kr;
uint32_t serial;
if (pointer->focus_surface == surface && pointer->focus_resource != NULL)
return;
resource = pointer->focus_resource;
if (resource)
if (pointer->focus_surface)
{
wl_list_remove (&pointer->focus_surface_listener.link);
pointer->focus_surface = NULL;
if (pointer->focus_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);
serial = wl_display_next_serial (display);
wl_pointer_send_leave (resource, serial, pointer->focus_surface->resource);
uint32_t serial = wl_display_next_serial (display);
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);
pointer->focus_surface = NULL;
pointer->focus_resource = NULL;
}
}
resource = find_resource_for_surface (&pointer->resource_list, surface);
if (resource)
if (surface != NULL)
{
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);
wl_fixed_t sx, sy;
serial = wl_display_next_serial (display);
uint32_t serial = wl_display_next_serial (display);
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)
{
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_window_handle_enter (surface->window,
meta_wayland_pointer_get_relative_coordinates (pointer, pointer->focus_surface, &sx, &sy);
meta_window_handle_enter (pointer->focus_surface->window,
/* XXX -- can we reliably get a timestamp for setting focus? */
clutter_get_current_event_time (),
wl_fixed_to_int (pointer->x),
wl_fixed_to_int (pointer->y));
wl_pointer_send_enter (resource, serial, surface->resource, sx, sy);
pointer->focus_resource = resource;
pointer->focus_surface = surface;
wl_pointer_send_enter (pointer->focus_resource, serial, pointer->focus_surface->resource, sx, sy);
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;
}
}
}
void