diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c index 8c11f74dc..92732c635 100644 --- a/src/compositor/compositor.c +++ b/src/compositor/compositor.c @@ -61,6 +61,7 @@ #include "backends/x11/meta-stage-x11.h" #include "clutter/clutter-mutter.h" #include "cogl/cogl.h" +#include "compositor/meta-compositor-view.h" #include "compositor/meta-later-private.h" #include "compositor/meta-window-actor-x11.h" #include "compositor/meta-window-actor-private.h" @@ -108,6 +109,7 @@ typedef struct _MetaCompositorPrivate gulong before_paint_handler_id; gulong after_paint_handler_id; gulong window_visibility_updated_id; + gulong monitors_changed_internal_id; int64_t server_time_query_time; int64_t server_time_offset; @@ -137,6 +139,8 @@ typedef struct _MetaCompositorPrivate G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaCompositor, meta_compositor, G_TYPE_OBJECT) +static GQuark quark_compositor_view; + static void on_presented (ClutterStage *stage, ClutterStageView *stage_view, @@ -926,6 +930,35 @@ meta_compositor_sync_window_geometry (MetaCompositor *compositor, meta_plugin_manager_event_size_changed (priv->plugin_mgr, window_actor); } +static void +meta_compositor_ensure_compositor_views (MetaCompositor *compositor) +{ + MetaCompositorPrivate *priv = + meta_compositor_get_instance_private (compositor); + ClutterStage *stage = + CLUTTER_STAGE (meta_backend_get_stage (priv->backend)); + GList *l; + + for (l = clutter_stage_peek_stage_views (stage); l; l = l->next) + { + ClutterStageView *stage_view = l->data; + MetaCompositorView *compositor_view; + + compositor_view = g_object_get_qdata (G_OBJECT (stage_view), + quark_compositor_view); + + if (compositor_view) + continue; + + compositor_view = meta_compositor_view_new (stage_view); + + g_object_set_qdata_full (G_OBJECT (stage_view), + quark_compositor_view, + compositor_view, + g_object_unref); + } +} + static void on_presented (ClutterStage *stage, ClutterStageView *stage_view, @@ -1053,6 +1086,13 @@ on_window_visibility_updated (MetaDisplay *display, update_top_window_actor (compositor); } +static void +on_monitors_changed_internal (MetaMonitorManager *monitor_manager, + MetaCompositor *compositor) +{ + meta_compositor_ensure_compositor_views (compositor); +} + static void meta_compositor_set_property (GObject *object, guint prop_id, @@ -1113,6 +1153,8 @@ meta_compositor_constructed (GObject *object) ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (priv->backend); ClutterActor *stage = meta_backend_get_stage (priv->backend); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (priv->backend); priv->context = clutter_backend->cogl_context; @@ -1133,9 +1175,17 @@ meta_compositor_constructed (GObject *object) G_CALLBACK (on_window_visibility_updated), compositor); + priv->monitors_changed_internal_id = + g_signal_connect (monitor_manager, + "monitors-changed-internal", + G_CALLBACK (on_monitors_changed_internal), + compositor); + priv->laters = meta_laters_new (compositor); G_OBJECT_CLASS (meta_compositor_parent_class)->constructed (object); + + meta_compositor_ensure_compositor_views (compositor); } static void @@ -1190,6 +1240,9 @@ meta_compositor_class_init (MetaCompositorClass *klass) G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, N_PROPS, obj_props); + + quark_compositor_view = + g_quark_from_static_string ("-meta-compositor-view"); } /** diff --git a/src/compositor/meta-compositor-view.c b/src/compositor/meta-compositor-view.c new file mode 100644 index 000000000..5bc16de3b --- /dev/null +++ b/src/compositor/meta-compositor-view.c @@ -0,0 +1,129 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* + * Copyright (C) 2022 Dor Askayo + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by: + * Dor Askayo + */ + +#include "config.h" + +#include "compositor/meta-compositor-view.h" + +enum +{ + PROP_0, + + PROP_STAGE_VIEW, + + N_PROPS +}; + +static GParamSpec *obj_props[N_PROPS]; + +typedef struct _MetaCompositorViewPrivate +{ + ClutterStageView *stage_view; +} MetaCompositorViewPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE (MetaCompositorView, meta_compositor_view, + G_TYPE_OBJECT) + +MetaCompositorView * +meta_compositor_view_new (ClutterStageView *stage_view) +{ + g_assert (stage_view); + + return g_object_new (META_TYPE_COMPOSITOR_VIEW, + "stage-view", stage_view, + NULL); +} + +ClutterStageView * +meta_compositor_view_get_stage_view (MetaCompositorView *compositor_view) +{ + MetaCompositorViewPrivate *priv = + meta_compositor_view_get_instance_private (compositor_view); + + return priv->stage_view; +} + +static void +meta_compositor_view_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MetaCompositorView *compositor_view = META_COMPOSITOR_VIEW (object); + MetaCompositorViewPrivate *priv = + meta_compositor_view_get_instance_private (compositor_view); + + switch (prop_id) + { + case PROP_STAGE_VIEW: + priv->stage_view = g_value_get_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +meta_compositor_view_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MetaCompositorView *compositor_view = META_COMPOSITOR_VIEW (object); + MetaCompositorViewPrivate *priv = + meta_compositor_view_get_instance_private (compositor_view); + + switch (prop_id) + { + case PROP_STAGE_VIEW: + g_value_set_object (value, priv->stage_view); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +meta_compositor_view_class_init (MetaCompositorViewClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = meta_compositor_view_set_property; + object_class->get_property = meta_compositor_view_get_property; + + obj_props[PROP_STAGE_VIEW] = + g_param_spec_object ("stage-view", + "stage-view", + "ClutterStageView", + CLUTTER_TYPE_STAGE_VIEW, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, N_PROPS, obj_props); +} + +static void +meta_compositor_view_init (MetaCompositorView *compositor_view) +{ +} diff --git a/src/compositor/meta-compositor-view.h b/src/compositor/meta-compositor-view.h new file mode 100644 index 000000000..bed3404f7 --- /dev/null +++ b/src/compositor/meta-compositor-view.h @@ -0,0 +1,45 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* + * Copyright (C) 2022 Dor Askayo + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by: + * Dor Askayo + */ + +#ifndef META_COMPOSITOR_VIEW_H +#define META_COMPOSITOR_VIEW_H + +#include + +#include "clutter/clutter-mutter.h" + +struct _MetaCompositorViewClass +{ + GObjectClass parent_class; +}; + +#define META_TYPE_COMPOSITOR_VIEW (meta_compositor_view_get_type ()) +G_DECLARE_FINAL_TYPE (MetaCompositorView, meta_compositor_view, + META, COMPOSITOR_VIEW, GObject) + +MetaCompositorView *meta_compositor_view_new (ClutterStageView *stage_view); + +ClutterStageView *meta_compositor_view_get_stage_view (MetaCompositorView *compositor_view); + +#endif /* META_COMPOSITOR_VIEW_H */ diff --git a/src/meson.build b/src/meson.build index 6dda94b69..504dc20ee 100644 --- a/src/meson.build +++ b/src/meson.build @@ -268,6 +268,8 @@ mutter_sources = [ 'compositor/meta-background-private.h', 'compositor/meta-compositor-server.c', 'compositor/meta-compositor-server.h', + 'compositor/meta-compositor-view.c', + 'compositor/meta-compositor-view.h', 'compositor/meta-cullable.c', 'compositor/meta-cullable.h', 'compositor/meta-dnd-actor.c',