MetaWaylandPointerConstraint: Use own 'appears-focused' signal handler

Instead of having MetaWindowWayland having hooks into pointer
constraints subsystem, have the pointer constraints subsystem listen
for the signal itself and enable/disable itself.

https://bugzilla.gnome.org/show_bug.cgi?id=762661
This commit is contained in:
Jonas Ådahl 2016-02-24 19:55:58 +08:00
parent 20908b9c2c
commit 6396974eae
3 changed files with 61 additions and 14 deletions

View File

@ -68,6 +68,8 @@ struct _MetaWaylandPointerConstraint
typedef struct _MetaWaylandSurfacePointerConstraintsData typedef struct _MetaWaylandSurfacePointerConstraintsData
{ {
GList *pointer_constraints; GList *pointer_constraints;
MetaWindow *window;
gulong appears_changed_handler_id;
} MetaWaylandSurfacePointerConstraintsData; } MetaWaylandSurfacePointerConstraintsData;
typedef struct typedef struct
@ -93,6 +95,13 @@ static const MetaWaylandPointerGrabInterface confined_pointer_grab_interface;
static void static void
meta_wayland_pointer_constraint_destroy (MetaWaylandPointerConstraint *constraint); meta_wayland_pointer_constraint_destroy (MetaWaylandPointerConstraint *constraint);
static void
meta_wayland_pointer_constraint_maybe_enable_for_window (MetaWindow *window);
static void
meta_wayland_pointer_constraint_maybe_remove_for_seat (MetaWaylandSeat *seat,
MetaWindow *focus_window);
static MetaWaylandSurfacePointerConstraintsData * static MetaWaylandSurfacePointerConstraintsData *
get_surface_constraints_data (MetaWaylandSurface *surface) get_surface_constraints_data (MetaWaylandSurface *surface)
{ {
@ -100,9 +109,59 @@ get_surface_constraints_data (MetaWaylandSurface *surface)
quark_surface_pointer_constraints_data); quark_surface_pointer_constraints_data);
} }
static void
appears_focused_changed (MetaWindow *window,
GParamSpec *pspec,
gpointer user_data)
{
MetaWaylandCompositor *wayland_compositor;
wayland_compositor = meta_wayland_compositor_get_default ();
meta_wayland_pointer_constraint_maybe_remove_for_seat (wayland_compositor->seat,
window);
if (window->unmanaging)
return;
meta_wayland_pointer_constraint_maybe_enable_for_window (window);
}
static MetaWaylandSurfacePointerConstraintsData *
surface_constraint_data_new (MetaWaylandSurface *surface)
{
MetaWaylandSurfacePointerConstraintsData *data;
data = g_new0 (MetaWaylandSurfacePointerConstraintsData, 1);
if (surface->window)
{
data->window = surface->window;
g_object_add_weak_pointer (G_OBJECT (data->window),
(gpointer *) &data->window);
data->appears_changed_handler_id =
g_signal_connect (data->window, "notify::appears-focused",
G_CALLBACK (appears_focused_changed), NULL);
}
else
{
/* TODO: Support constraints on non-toplevel windows, such as subsurfaces.
*/
g_warn_if_reached ();
}
return data;
}
static void static void
surface_constraint_data_free (MetaWaylandSurfacePointerConstraintsData *data) surface_constraint_data_free (MetaWaylandSurfacePointerConstraintsData *data)
{ {
if (data->window)
{
g_signal_handler_disconnect (data->window,
data->appears_changed_handler_id);
g_object_remove_weak_pointer (G_OBJECT (data->window),
(gpointer *) &data->window);
}
g_list_free_full (data->pointer_constraints, g_list_free_full (data->pointer_constraints,
(GDestroyNotify) meta_wayland_pointer_constraint_destroy); (GDestroyNotify) meta_wayland_pointer_constraint_destroy);
g_free (data); g_free (data);
@ -116,7 +175,7 @@ ensure_surface_constraints_data (MetaWaylandSurface *surface)
data = get_surface_constraints_data (surface); data = get_surface_constraints_data (surface);
if (!data) if (!data)
{ {
data = g_new0 (MetaWaylandSurfacePointerConstraintsData, 1); data = surface_constraint_data_new (surface);
g_object_set_qdata_full (G_OBJECT (surface), g_object_set_qdata_full (G_OBJECT (surface),
quark_surface_pointer_constraints_data, quark_surface_pointer_constraints_data,
data, data,
@ -365,7 +424,7 @@ meta_wayland_pointer_constraint_maybe_remove_for_seat (MetaWaylandSeat *seat,
} }
} }
void static void
meta_wayland_pointer_constraint_maybe_enable_for_window (MetaWindow *window) meta_wayland_pointer_constraint_maybe_enable_for_window (MetaWindow *window)
{ {
MetaWaylandSurface *surface = window->surface; MetaWaylandSurface *surface = window->surface;

View File

@ -44,9 +44,4 @@ cairo_region_t * meta_wayland_pointer_constraint_calculate_effective_region (Met
MetaWaylandSurface * meta_wayland_pointer_constraint_get_surface (MetaWaylandPointerConstraint *constraint); MetaWaylandSurface * meta_wayland_pointer_constraint_get_surface (MetaWaylandPointerConstraint *constraint);
void meta_wayland_pointer_constraint_maybe_remove_for_seat (MetaWaylandSeat *seat,
MetaWindow *focus_window);
void meta_wayland_pointer_constraint_maybe_enable_for_window (MetaWindow *window);
#endif /* META_WAYLAND_POINTER_CONSTRAINTS_H */ #endif /* META_WAYLAND_POINTER_CONSTRAINTS_H */

View File

@ -403,11 +403,6 @@ appears_focused_changed (GObject *object,
gpointer user_data) gpointer user_data)
{ {
MetaWindow *window = META_WINDOW (object); MetaWindow *window = META_WINDOW (object);
MetaWaylandCompositor *wayland_compositor;
wayland_compositor = meta_wayland_compositor_get_default ();
meta_wayland_pointer_constraint_maybe_remove_for_seat (wayland_compositor->seat,
window);
/* When we're unmanaging, we remove focus from the window, /* When we're unmanaging, we remove focus from the window,
* causing this to fire. Don't do anything in that case. */ * causing this to fire. Don't do anything in that case. */
@ -415,8 +410,6 @@ appears_focused_changed (GObject *object,
return; return;
surface_state_changed (window); surface_state_changed (window);
meta_wayland_pointer_constraint_maybe_enable_for_window (window);
} }
static void static void