[mutter/wayland] pointer/keyboard: Fix focus setting once again



commit a5d950f453cd38a3442cc1ef49c22297a2d6335d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Feb 18 23:16:54 2014 -0500

    pointer/keyboard: Fix focus setting once again
    
    Yet another large-scale restructuring... this is some messy code.

 src/wayland/meta-wayland-keyboard.c |   97 +++++++++++++++++------------------
 src/wayland/meta-wayland-pointer.c  |   93 +++++++++++++++++----------------
 2 files changed, 95 insertions(+), 95 deletions(-)
---
diff --git a/src/wayland/meta-wayland-keyboard.c b/src/wayland/meta-wayland-keyboard.c
index f4ac4d8..9d41f98 100644
--- a/src/wayland/meta-wayland-keyboard.c
+++ b/src/wayland/meta-wayland-keyboard.c
@@ -527,68 +527,65 @@ 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)
     {
-      if (keyboard->focus_surface->resource)
-        {
-          struct wl_client *client = wl_resource_get_client (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);
-        }
-
-      wl_list_remove (&keyboard->focus_resource_listener.link);
       wl_list_remove (&keyboard->focus_surface_listener.link);
-
-      keyboard->focus_resource = NULL;
       keyboard->focus_surface = NULL;
+
+      if (keyboard->focus_resource)
+        {
+          if (keyboard->focus_surface->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);
+              wl_keyboard_send_leave (keyboard->focus_resource, serial, keyboard->focus_surface->resource);
+            }
+
+          wl_list_remove (&keyboard->focus_resource_listener.link);
+          keyboard->focus_resource = 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);
-
-      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) */
-      if (keyboard->grab->interface == &modal_grab)
-       {
-         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);
-       }
-      else
-       {
-         wl_keyboard_send_modifiers (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,
-                                 &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;
+      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) */
+          if (keyboard->grab->interface == &modal_grab)
+            {
+              struct wl_array empty;
+              wl_array_init (&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 (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 (keyboard->focus_resource, serial, keyboard->focus_surface->resource,
+                                      &keyboard->keys);
+            }
+
+          wl_resource_add_destroy_listener (keyboard->focus_resource, &keyboard->focus_resource_listener);
+          keyboard->focus_serial = serial;
+        }
     }
 }
 
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index 30a1e9e..b0030dd 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -333,68 +333,71 @@ 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)
     {
-      if (pointer->focus_surface->resource)
+      wl_list_remove (&pointer->focus_surface_listener.link);
+      pointer->focus_surface = NULL;
+
+      if (pointer->focus_resource)
         {
-          struct wl_client *client = wl_resource_get_client (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);
-        }
+          if (pointer->focus_surface->resource)
+            {
+              struct wl_client *client = wl_resource_get_client (pointer->focus_resource);
+              struct wl_display *display = wl_client_get_display (client);
+              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);
+          wl_list_remove (&pointer->focus_resource_listener.link);
 
-      pointer->focus_surface = NULL;
-      pointer->focus_resource = NULL;
+          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);
-      struct wl_display *display = wl_client_get_display (client);
-      wl_fixed_t sx, sy;
-
-      serial = wl_display_next_serial (display);
+      pointer->focus_surface = surface;
+      wl_resource_add_destroy_listener (pointer->focus_surface->resource, &pointer->focus_surface_listener);
 
-      if (kbd)
+      pointer->focus_resource = find_resource_for_surface (&pointer->resource_list, surface);
+      if (pointer->focus_resource)
         {
-          kr = find_resource_for_surface (&kbd->resource_list, surface);
-          if (kr)
-            {
-              wl_keyboard_send_modifiers (kr,
-                                          serial,
-                                          kbd->modifier_state.mods_depressed,
-                                          kbd->modifier_state.mods_latched,
-                                          kbd->modifier_state.mods_locked,
-                                          kbd->modifier_state.group);
-            }
-        }
+          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;
 
-      meta_wayland_pointer_get_relative_coordinates (pointer, surface, &sx, &sy);
-      meta_window_handle_enter (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);
+          uint32_t serial = wl_display_next_serial (display);
 
-      pointer->focus_resource = resource;
-      pointer->focus_surface = surface;
+          if (kbd)
+            {
+              struct wl_resource *kr = find_resource_for_surface (&kbd->resource_list, 
pointer->focus_surface);
+              if (kr)
+                {
+                  wl_keyboard_send_modifiers (kr,
+                                              serial,
+                                              kbd->modifier_state.mods_depressed,
+                                              kbd->modifier_state.mods_latched,
+                                              kbd->modifier_state.mods_locked,
+                                              kbd->modifier_state.group);
+                }
+            }
 
-      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);
+          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 (pointer->focus_resource, serial, pointer->focus_surface->resource, sx, sy);
 
-      pointer->focus_serial = serial;
+          wl_resource_add_destroy_listener (pointer->focus_resource, &pointer->focus_resource_listener);
+          pointer->focus_serial = serial;
+        }
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]