From a6d6b14306727692bffdadd09bca239aebc867c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Thu, 25 Jul 2019 02:02:21 +0200
Subject: [PATCH 25/28] compositor: Use meta_window_actor_from_window to get
the actor
Use this utility function instead of repeating the cast all the time.
Also in some case, warn if the returned value isn't valid.
https://gitlab.gnome.org/GNOME/mutter/merge_requests/682
---
src/compositor/compositor.c | 58 +++++++++++++++++++++++++++----------
1 file changed, 42 insertions(+), 16 deletions(-)
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index 799bcddf5..d02926171 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -116,61 +116,64 @@ meta_finish_workspace_switch (MetaCompositor *compositor)
void
meta_switch_workspace_completed (MetaCompositor *compositor)
{
/* FIXME -- must redo stacking order */
compositor->switch_workspace_in_progress--;
if (compositor->switch_workspace_in_progress < 0)
{
g_warning ("Error in workspace_switch accounting!");
compositor->switch_workspace_in_progress = 0;
}
if (!compositor->switch_workspace_in_progress)
meta_finish_workspace_switch (compositor);
}
void
meta_compositor_destroy (MetaCompositor *compositor)
{
clutter_threads_remove_repaint_func (compositor->pre_paint_func_id);
clutter_threads_remove_repaint_func (compositor->post_paint_func_id);
if (compositor->have_x11_sync_object)
meta_sync_ring_destroy ();
}
static void
process_damage (MetaCompositor *compositor,
XDamageNotifyEvent *event,
MetaWindow *window)
{
- MetaWindowActor *window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
+ MetaWindowActor *window_actor = meta_window_actor_from_window (window);
+
+ g_return_if_fail (window_actor);
+
meta_window_actor_process_x11_damage (window_actor, event);
compositor->frame_has_updated_xsurfaces = TRUE;
}
/* compat helper */
static MetaCompositor *
get_compositor_for_screen (MetaScreen *screen)
{
return screen->display->compositor;
}
/**
* meta_get_stage_for_screen:
* @screen: a #MetaScreen
*
* Returns: (transfer none): The #ClutterStage for the screen
*/
ClutterActor *
meta_get_stage_for_screen (MetaScreen *screen)
{
MetaCompositor *compositor = get_compositor_for_screen (screen);
return compositor->stage;
}
/**
* meta_get_window_group_for_screen:
* @screen: a #MetaScreen
*
* Returns: (transfer none): The window group corresponding to @screen
@@ -707,135 +710,146 @@ meta_shape_cow_for_window (MetaCompositor *compositor,
meta_window_get_frame_rect (window, &rect);
window_bounds.x = rect.x;
window_bounds.y = rect.y;
window_bounds.width = rect.width;
window_bounds.height = rect.height;
meta_screen_get_size (display->screen, &width, &height);
screen_rect.x = 0;
screen_rect.y = 0;
screen_rect.width = width;
screen_rect.height = height;
output_region = XFixesCreateRegion (xdisplay, &window_bounds, 1);
XFixesInvertRegion (xdisplay, output_region, &screen_rect, output_region);
XFixesSetWindowShapeRegion (xdisplay, compositor->output, ShapeBounding, 0, 0, output_region);
XFixesDestroyRegion (xdisplay, output_region);
}
}
static void
set_unredirected_window (MetaCompositor *compositor,
MetaWindow *window)
{
if (compositor->unredirected_window == window)
return;
if (compositor->unredirected_window != NULL)
{
- MetaWindowActor *window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (compositor->unredirected_window));
+ MetaWindowActor *window_actor =
+ meta_window_actor_from_window (compositor->unredirected_window);
meta_window_actor_set_unredirected (window_actor, FALSE);
}
meta_shape_cow_for_window (compositor, window);
compositor->unredirected_window = window;
if (compositor->unredirected_window != NULL)
{
- MetaWindowActor *window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (compositor->unredirected_window));
+ MetaWindowActor *window_actor =
+ meta_window_actor_from_window (compositor->unredirected_window);
meta_window_actor_set_unredirected (window_actor, TRUE);
}
}
void
meta_compositor_add_window (MetaCompositor *compositor,
MetaWindow *window)
{
MetaDisplay *display = compositor->display;
meta_error_trap_push (display);
meta_window_actor_new (window);
sync_actor_stacking (compositor);
meta_error_trap_pop (display);
}
void
meta_compositor_remove_window (MetaCompositor *compositor,
MetaWindow *window)
{
- MetaWindowActor *window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
+ MetaWindowActor *window_actor = meta_window_actor_from_window (window);
+
+ if (!window_actor)
+ return;
if (compositor->unredirected_window == window)
set_unredirected_window (compositor, NULL);
meta_window_actor_queue_destroy (window_actor);
}
void
meta_compositor_sync_updates_frozen (MetaCompositor *compositor,
MetaWindow *window)
{
- MetaWindowActor *window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
+ MetaWindowActor *window_actor = meta_window_actor_from_window (window);
+
+ g_return_if_fail (window_actor);
+
meta_window_actor_sync_updates_frozen (window_actor);
}
void
meta_compositor_queue_frame_drawn (MetaCompositor *compositor,
MetaWindow *window,
gboolean no_delay_frame)
{
- MetaWindowActor *window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
+ MetaWindowActor *window_actor = meta_window_actor_from_window (window);
+
+ g_return_if_fail (window_actor);
+
meta_window_actor_queue_frame_drawn (window_actor, no_delay_frame);
}
void
meta_compositor_window_shape_changed (MetaCompositor *compositor,
MetaWindow *window)
{
- MetaWindowActor *window_actor;
- window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
+ MetaWindowActor *window_actor = meta_window_actor_from_window (window);
+
if (!window_actor)
return;
meta_window_actor_update_shape (window_actor);
}
void
meta_compositor_window_opacity_changed (MetaCompositor *compositor,
MetaWindow *window)
{
- MetaWindowActor *window_actor;
- window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
+ MetaWindowActor *window_actor = meta_window_actor_from_window (window);
+
if (!window_actor)
return;
meta_window_actor_update_opacity (window_actor);
}
void
meta_compositor_window_surface_changed (MetaCompositor *compositor,
MetaWindow *window)
{
MetaWindowActor *window_actor;
window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
if (!window_actor)
return;
meta_window_actor_update_surface (window_actor);
}
/**
* meta_compositor_process_event: (skip)
* @compositor:
* @event:
* @window:
*
*/
gboolean
meta_compositor_process_event (MetaCompositor *compositor,
XEvent *event,
MetaWindow *window)
{
@@ -872,81 +886,91 @@ meta_compositor_process_event (MetaCompositor *compositor,
}
}
if (compositor->have_x11_sync_object)
meta_sync_ring_handle_event (event);
/* Clutter needs to know about MapNotify events otherwise it will
think the stage is invisible */
if (!meta_is_wayland_compositor () && event->type == MapNotify)
clutter_x11_handle_event (event);
/* The above handling is basically just "observing" the events, so we return
* FALSE to indicate that the event should not be filtered out; if we have
* GTK+ windows in the same process, GTK+ needs the ConfigureNotify event, for example.
*/
return FALSE;
}
gboolean
meta_compositor_filter_keybinding (MetaCompositor *compositor,
MetaKeyBinding *binding)
{
return meta_plugin_manager_filter_keybinding (compositor->plugin_mgr, binding);
}
void
meta_compositor_show_window (MetaCompositor *compositor,
MetaWindow *window,
MetaCompEffect effect)
{
- MetaWindowActor *window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
+ MetaWindowActor *window_actor = meta_window_actor_from_window (window);
+
+ g_return_if_fail (window_actor);
+
meta_window_actor_show (window_actor, effect);
}
void
meta_compositor_hide_window (MetaCompositor *compositor,
MetaWindow *window,
MetaCompEffect effect)
{
- MetaWindowActor *window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
+ MetaWindowActor *window_actor = meta_window_actor_from_window (window);
+
+ if (!window_actor)
+ return;
+
meta_window_actor_hide (window_actor, effect);
}
void
meta_compositor_size_change_window (MetaCompositor *compositor,
MetaWindow *window,
MetaSizeChange which_change,
MetaRectangle *old_frame_rect,
MetaRectangle *old_buffer_rect)
{
- MetaWindowActor *window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
+ MetaWindowActor *window_actor = meta_window_actor_from_window (window);
+
+ g_return_if_fail (window_actor);
+
meta_window_actor_size_change (window_actor, which_change, old_frame_rect, old_buffer_rect);
}
void
meta_compositor_switch_workspace (MetaCompositor *compositor,
MetaWorkspace *from,
MetaWorkspace *to,
MetaMotionDirection direction)
{
gint to_indx, from_indx;
to_indx = meta_workspace_index (to);
from_indx = meta_workspace_index (from);
compositor->switch_workspace_in_progress++;
if (!meta_plugin_manager_switch_workspace (compositor->plugin_mgr,
from_indx,
to_indx,
direction))
{
compositor->switch_workspace_in_progress--;
/* We have to explicitely call this to fix up stacking order of the
* actors; this is because the abs stacking position of actors does not
* necessarily change during the window hiding/unhiding, only their
* relative position toward the destkop window.
*/
meta_finish_workspace_switch (compositor);
}
@@ -1093,61 +1117,61 @@ meta_compositor_sync_stack (MetaCompositor *compositor,
stack = g_list_copy (stack); /* The new stack of MetaWindow */
old_stack = g_list_reverse (compositor->windows); /* The old stack of MetaWindowActor */
compositor->windows = NULL;
while (TRUE)
{
MetaWindowActor *old_actor = NULL, *stack_actor = NULL, *actor;
MetaWindow *old_window = NULL, *stack_window = NULL, *window;
/* Find the remaining top actor in our existing stack (ignoring
* windows that have been hidden and are no longer animating) */
while (old_stack)
{
old_actor = old_stack->data;
old_window = meta_window_actor_get_meta_window (old_actor);
if ((old_window->hidden || old_window->unmanaging) &&
!meta_window_actor_effect_in_progress (old_actor))
{
old_stack = g_list_delete_link (old_stack, old_stack);
old_actor = NULL;
}
else
break;
}
/* And the remaining top actor in the new stack */
while (stack)
{
stack_window = stack->data;
- stack_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (stack_window));
+ stack_actor = meta_window_actor_from_window (stack_window);
if (!stack_actor)
{
meta_verbose ("Failed to find corresponding MetaWindowActor "
"for window %s\n", meta_window_get_description (stack_window));
stack = g_list_delete_link (stack, stack);
}
else
break;
}
if (!old_actor && !stack_actor) /* Nothing more to stack */
break;
/* We usually prefer the window in the new stack, but if if we
* found a hidden window in the process of being animated out
* of existence in the old stack we use that instead. We've
* filtered out non-animating hidden windows above.
*/
if (old_actor &&
(!stack_actor || old_window->hidden || old_window->unmanaging))
{
actor = old_actor;
window = old_window;
}
else
{
actor = stack_actor;
window = stack_window;
}
@@ -1159,63 +1183,65 @@ meta_compositor_sync_stack (MetaCompositor *compositor,
compositor->windows = g_list_prepend (compositor->windows, actor);
if (meta_window_actor_is_stereo (actor))
stereo_window_count++;
stack = g_list_remove (stack, window);
old_stack = g_list_remove (old_stack, actor);
}
sync_actor_stacking (compositor);
meta_stereo_set_have_stereo_windows (stereo_window_count > 0);
if (compositor->top_window_actor)
g_signal_handlers_disconnect_by_func (compositor->top_window_actor,
on_top_window_actor_destroyed,
compositor);
compositor->top_window_actor = get_top_visible_window_actor (compositor);
if (compositor->top_window_actor)
g_signal_connect (compositor->top_window_actor, "destroy",
G_CALLBACK (on_top_window_actor_destroyed),
compositor);
}
void
meta_compositor_sync_window_geometry (MetaCompositor *compositor,
MetaWindow *window,
gboolean did_placement)
{
- MetaWindowActor *window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
+ MetaWindowActor *window_actor = meta_window_actor_from_window (window);
MetaWindowActorChanges changes;
+ g_return_if_fail (window_actor);
+
changes = meta_window_actor_sync_actor_geometry (window_actor, did_placement);
if (changes & META_WINDOW_ACTOR_CHANGE_SIZE)
meta_plugin_manager_event_size_changed (compositor->plugin_mgr, window_actor);
}
static void
on_presented (ClutterStage *stage,
CoglFrameEvent event,
ClutterFrameInfo *frame_info,
MetaCompositor *compositor)
{
GList *l;
if (event == COGL_FRAME_EVENT_COMPLETE)
{
gint64 presentation_time_cogl = frame_info->presentation_time;
gint64 presentation_time;
if (presentation_time_cogl != 0)
{
/* Cogl reports presentation in terms of its own clock, which is
* guaranteed to be in nanoseconds but with no specified base. The
* normal case with the open source GPU drivers on Linux 3.8 and
* newer is that the base of cogl_get_clock_time() is that of
* clock_gettime(CLOCK_MONOTONIC), so the same as g_get_monotonic_time),
* but there's no exposure of that through the API. clock_gettime()
* is fairly fast, so calling it twice and subtracting to get a
* nearly-zero number is acceptable, if a litle ugly.
*/
@@ -1469,61 +1495,61 @@ meta_compositor_flash_screen (MetaCompositor *compositor,
clutter_actor_save_easing_state (flash);
clutter_actor_set_easing_mode (flash, CLUTTER_EASE_IN_QUAD);
clutter_actor_set_easing_duration (flash, FLASH_TIME_MS);
clutter_actor_set_opacity (flash, 192);
transition = clutter_actor_get_transition (flash, "opacity");
clutter_timeline_set_auto_reverse (CLUTTER_TIMELINE (transition), TRUE);
clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), 2);
g_signal_connect (transition, "stopped",
G_CALLBACK (flash_out_completed), flash);
clutter_actor_restore_easing_state (flash);
}
static void
window_flash_out_completed (ClutterTimeline *timeline,
gboolean is_finished,
gpointer user_data)
{
ClutterActor *flash = CLUTTER_ACTOR (user_data);
clutter_actor_destroy (flash);
}
void
meta_compositor_flash_window (MetaCompositor *compositor,
MetaWindow *window)
{
ClutterActor *window_actor =
- CLUTTER_ACTOR (meta_window_get_compositor_private (window));
+ CLUTTER_ACTOR (meta_window_actor_from_window (window));
ClutterActor *flash;
ClutterTransition *transition;
flash = clutter_actor_new ();
clutter_actor_set_background_color (flash, CLUTTER_COLOR_Black);
clutter_actor_set_size (flash, window->rect.width, window->rect.height);
clutter_actor_set_position (flash,
window->custom_frame_extents.left,
window->custom_frame_extents.top);
clutter_actor_set_opacity (flash, 0);
clutter_actor_add_child (window_actor, flash);
clutter_actor_save_easing_state (flash);
clutter_actor_set_easing_mode (flash, CLUTTER_EASE_IN_QUAD);
clutter_actor_set_easing_duration (flash, FLASH_TIME_MS);
clutter_actor_set_opacity (flash, 192);
transition = clutter_actor_get_transition (flash, "opacity");
clutter_timeline_set_auto_reverse (CLUTTER_TIMELINE (transition), TRUE);
clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), 2);
g_signal_connect (transition, "stopped",
G_CALLBACK (window_flash_out_completed), flash);
clutter_actor_restore_easing_state (flash);
}
/**
* meta_compositor_monotonic_time_to_server_time:
* @display: a #MetaDisplay
--
2.26.2