2009-05-03 13:05:15 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2009-11-24 09:07:40 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-05-03 13:05:15 -04:00
|
|
|
#include "shell-embedded-window-private.h"
|
2013-02-12 17:31:38 -05:00
|
|
|
#include "shell-global.h"
|
2019-02-15 11:04:10 -05:00
|
|
|
#include "shell-util.h"
|
2009-05-03 13:05:15 -04:00
|
|
|
|
|
|
|
#include <gdk/gdkx.h>
|
2013-02-12 17:31:38 -05:00
|
|
|
#include <meta/display.h>
|
|
|
|
#include <meta/window.h>
|
2009-05-03 13:05:15 -04:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_WINDOW
|
|
|
|
};
|
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
typedef struct _ShellGtkEmbedPrivate ShellGtkEmbedPrivate;
|
|
|
|
|
2009-05-03 13:05:15 -04:00
|
|
|
struct _ShellGtkEmbedPrivate
|
|
|
|
{
|
|
|
|
ShellEmbeddedWindow *window;
|
2013-02-12 17:31:38 -05:00
|
|
|
|
|
|
|
ClutterActor *window_actor;
|
2019-11-21 17:00:53 -05:00
|
|
|
gulong window_actor_destroyed_handler;
|
2013-02-12 17:31:38 -05:00
|
|
|
|
2019-11-21 17:00:53 -05:00
|
|
|
gulong window_created_handler;
|
2009-05-03 13:05:15 -04:00
|
|
|
};
|
|
|
|
|
2015-09-24 12:56:13 -04:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (ShellGtkEmbed, shell_gtk_embed, CLUTTER_TYPE_CLONE);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
|
|
|
static void shell_gtk_embed_set_window (ShellGtkEmbed *embed,
|
|
|
|
ShellEmbeddedWindow *window);
|
|
|
|
|
|
|
|
static void
|
2010-09-27 06:36:43 -04:00
|
|
|
shell_gtk_embed_on_window_destroy (GtkWidget *object,
|
2009-05-03 13:05:15 -04:00
|
|
|
ShellGtkEmbed *embed)
|
|
|
|
{
|
|
|
|
shell_gtk_embed_set_window (embed, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-02-12 17:31:38 -05:00
|
|
|
shell_gtk_embed_remove_window_actor (ShellGtkEmbed *embed)
|
|
|
|
{
|
2015-09-24 14:07:44 -04:00
|
|
|
ShellGtkEmbedPrivate *priv = shell_gtk_embed_get_instance_private (embed);
|
2013-02-12 17:31:38 -05:00
|
|
|
|
|
|
|
if (priv->window_actor)
|
|
|
|
{
|
2019-11-21 17:00:53 -05:00
|
|
|
g_clear_signal_handler (&priv->window_actor_destroyed_handler,
|
|
|
|
priv->window_actor);
|
2013-02-12 17:31:38 -05:00
|
|
|
|
|
|
|
g_object_unref (priv->window_actor);
|
|
|
|
priv->window_actor = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_clone_set_source (CLUTTER_CLONE (embed), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_gtk_embed_window_created_cb (MetaDisplay *display,
|
|
|
|
MetaWindow *window,
|
2009-05-03 13:05:15 -04:00
|
|
|
ShellGtkEmbed *embed)
|
|
|
|
{
|
2015-09-24 14:07:44 -04:00
|
|
|
ShellGtkEmbedPrivate *priv = shell_gtk_embed_get_instance_private (embed);
|
2013-02-12 17:31:38 -05:00
|
|
|
Window xwindow = meta_window_get_xwindow (window);
|
|
|
|
GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (priv->window));
|
|
|
|
|
2016-12-15 06:34:10 -05:00
|
|
|
if (gdk_window && xwindow == gdk_x11_window_get_xid (gdk_window))
|
2013-02-12 17:31:38 -05:00
|
|
|
{
|
|
|
|
ClutterActor *window_actor =
|
|
|
|
CLUTTER_ACTOR (meta_window_get_compositor_private (window));
|
|
|
|
GCallback remove_cb = G_CALLBACK (shell_gtk_embed_remove_window_actor);
|
|
|
|
cairo_region_t *empty_region;
|
|
|
|
|
|
|
|
clutter_clone_set_source (CLUTTER_CLONE (embed), window_actor);
|
|
|
|
|
|
|
|
/* We want to explicitly clear the clone source when the window
|
|
|
|
actor is destroyed because otherwise we might end up keeping
|
|
|
|
it alive after it has been disposed. Otherwise this can cause
|
|
|
|
a crash if there is a paint after mutter notices that the top
|
|
|
|
level window has been destroyed, which causes it to dispose
|
|
|
|
the window, and before the tray manager notices that the
|
|
|
|
window is gone which would otherwise reset the window and
|
|
|
|
unref the clone */
|
|
|
|
priv->window_actor = g_object_ref (window_actor);
|
|
|
|
priv->window_actor_destroyed_handler =
|
|
|
|
g_signal_connect_swapped (window_actor,
|
|
|
|
"destroy",
|
|
|
|
remove_cb,
|
|
|
|
embed);
|
|
|
|
|
|
|
|
/* Hide the original actor otherwise it will appear in the scene
|
|
|
|
as a normal window */
|
|
|
|
clutter_actor_set_opacity (window_actor, 0);
|
|
|
|
|
2019-02-15 11:04:10 -05:00
|
|
|
/* Also make sure it (or any of its children) doesn't block
|
|
|
|
events on wayland */
|
|
|
|
shell_util_set_hidden_from_pick (window_actor, TRUE);
|
|
|
|
|
2013-02-12 17:31:38 -05:00
|
|
|
/* Set an empty input shape on the window so that it can't get
|
2015-03-19 21:27:07 -04:00
|
|
|
any input. This probably isn't the ideal way to achieve this.
|
2013-02-12 17:31:38 -05:00
|
|
|
It would probably be better to force the window to go behind
|
|
|
|
Mutter's guard window, but this is quite difficult to do as
|
|
|
|
Mutter doesn't manage the stacking for override redirect
|
|
|
|
windows and the guard window is repeatedly lowered to the
|
|
|
|
bottom of the stack. */
|
|
|
|
empty_region = cairo_region_create ();
|
|
|
|
gdk_window_input_shape_combine_region (gdk_window,
|
|
|
|
empty_region,
|
|
|
|
0, 0 /* offset x/y */);
|
|
|
|
cairo_region_destroy (empty_region);
|
|
|
|
|
2013-05-29 18:53:37 -04:00
|
|
|
gdk_window_lower (gdk_window);
|
|
|
|
|
2013-02-12 17:31:38 -05:00
|
|
|
/* Now that we've found the window we don't need to listen for
|
|
|
|
new windows anymore */
|
2019-11-21 17:00:53 -05:00
|
|
|
g_clear_signal_handler (&priv->window_created_handler,
|
|
|
|
display);
|
2013-02-12 17:31:38 -05:00
|
|
|
}
|
2009-05-03 13:05:15 -04:00
|
|
|
}
|
|
|
|
|
2015-03-19 19:06:34 -04:00
|
|
|
static void
|
|
|
|
shell_gtk_embed_on_window_mapped (GtkWidget *object,
|
|
|
|
ShellGtkEmbed *embed)
|
|
|
|
{
|
2015-09-24 14:07:44 -04:00
|
|
|
ShellGtkEmbedPrivate *priv = shell_gtk_embed_get_instance_private (embed);
|
2015-03-19 19:06:34 -04:00
|
|
|
MetaDisplay *display = shell_global_get_display (shell_global_get ());
|
|
|
|
|
2017-09-14 14:46:13 -04:00
|
|
|
if (priv->window_created_handler == 0 && priv->window_actor == NULL)
|
|
|
|
/* Listen for new windows so we can detect when Mutter has
|
|
|
|
created a MutterWindow for this window */
|
|
|
|
priv->window_created_handler =
|
|
|
|
g_signal_connect (display,
|
|
|
|
"window-created",
|
|
|
|
G_CALLBACK (shell_gtk_embed_window_created_cb),
|
|
|
|
embed);
|
2015-03-19 19:06:34 -04:00
|
|
|
}
|
|
|
|
|
2009-05-03 13:05:15 -04:00
|
|
|
static void
|
|
|
|
shell_gtk_embed_set_window (ShellGtkEmbed *embed,
|
|
|
|
ShellEmbeddedWindow *window)
|
|
|
|
{
|
2015-09-24 14:07:44 -04:00
|
|
|
ShellGtkEmbedPrivate *priv = shell_gtk_embed_get_instance_private (embed);
|
2013-02-12 17:31:38 -05:00
|
|
|
MetaDisplay *display = shell_global_get_display (shell_global_get ());
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
if (priv->window)
|
2009-05-03 13:05:15 -04:00
|
|
|
{
|
2019-11-21 17:00:53 -05:00
|
|
|
g_clear_signal_handler (&priv->window_created_handler, display);
|
2013-02-12 17:31:38 -05:00
|
|
|
|
|
|
|
shell_gtk_embed_remove_window_actor (embed);
|
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
_shell_embedded_window_set_actor (priv->window, NULL);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
g_object_unref (priv->window);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
g_signal_handlers_disconnect_by_func (priv->window,
|
2009-05-03 13:05:15 -04:00
|
|
|
(gpointer)shell_gtk_embed_on_window_destroy,
|
|
|
|
embed);
|
2015-03-19 19:06:34 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
g_signal_handlers_disconnect_by_func (priv->window,
|
2015-03-19 19:06:34 -04:00
|
|
|
(gpointer)shell_gtk_embed_on_window_mapped,
|
|
|
|
embed);
|
2009-05-03 13:05:15 -04:00
|
|
|
}
|
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
priv->window = window;
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
if (priv->window)
|
2009-05-03 13:05:15 -04:00
|
|
|
{
|
2015-09-24 14:07:44 -04:00
|
|
|
g_object_ref (priv->window);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
_shell_embedded_window_set_actor (priv->window, embed);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
g_signal_connect (priv->window, "destroy",
|
2009-05-03 13:05:15 -04:00
|
|
|
G_CALLBACK (shell_gtk_embed_on_window_destroy), embed);
|
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
g_signal_connect (priv->window, "map",
|
2015-03-19 19:06:34 -04:00
|
|
|
G_CALLBACK (shell_gtk_embed_on_window_mapped), embed);
|
2009-05-03 13:05:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (embed));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_gtk_embed_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ShellGtkEmbed *embed = SHELL_GTK_EMBED (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_WINDOW:
|
|
|
|
shell_gtk_embed_set_window (embed, (ShellEmbeddedWindow *)g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_gtk_embed_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ShellGtkEmbed *embed = SHELL_GTK_EMBED (object);
|
2015-09-24 14:07:44 -04:00
|
|
|
ShellGtkEmbedPrivate *priv = shell_gtk_embed_get_instance_private (embed);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_WINDOW:
|
2015-09-24 14:07:44 -04:00
|
|
|
g_value_set_object (value, priv->window);
|
2009-05-03 13:05:15 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_gtk_embed_get_preferred_width (ClutterActor *actor,
|
2009-06-06 13:07:41 -04:00
|
|
|
float for_height,
|
|
|
|
float *min_width_p,
|
|
|
|
float *natural_width_p)
|
2009-05-03 13:05:15 -04:00
|
|
|
{
|
|
|
|
ShellGtkEmbed *embed = SHELL_GTK_EMBED (actor);
|
2015-09-24 14:07:44 -04:00
|
|
|
ShellGtkEmbedPrivate *priv = shell_gtk_embed_get_instance_private (embed);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
if (priv->window
|
|
|
|
&& gtk_widget_get_visible (GTK_WIDGET (priv->window)))
|
2009-05-03 13:05:15 -04:00
|
|
|
{
|
2011-11-11 03:50:18 -05:00
|
|
|
GtkRequisition min_req, natural_req;
|
2015-09-24 14:07:44 -04:00
|
|
|
gtk_widget_get_preferred_size (GTK_WIDGET (priv->window), &min_req, &natural_req);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2011-11-11 03:50:18 -05:00
|
|
|
*min_width_p = min_req.width;
|
|
|
|
*natural_width_p = natural_req.width;
|
2009-05-03 13:05:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*min_width_p = *natural_width_p = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_gtk_embed_get_preferred_height (ClutterActor *actor,
|
2009-06-06 13:07:41 -04:00
|
|
|
float for_width,
|
|
|
|
float *min_height_p,
|
|
|
|
float *natural_height_p)
|
2009-05-03 13:05:15 -04:00
|
|
|
{
|
|
|
|
ShellGtkEmbed *embed = SHELL_GTK_EMBED (actor);
|
2015-09-24 14:07:44 -04:00
|
|
|
ShellGtkEmbedPrivate *priv = shell_gtk_embed_get_instance_private (embed);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
if (priv->window
|
|
|
|
&& gtk_widget_get_visible (GTK_WIDGET (priv->window)))
|
2009-05-03 13:05:15 -04:00
|
|
|
{
|
2011-11-11 03:50:18 -05:00
|
|
|
GtkRequisition min_req, natural_req;
|
2015-09-24 14:07:44 -04:00
|
|
|
gtk_widget_get_preferred_size (GTK_WIDGET (priv->window), &min_req, &natural_req);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2011-11-11 03:50:18 -05:00
|
|
|
*min_height_p = min_req.height;
|
|
|
|
*natural_height_p = natural_req.height;
|
2009-05-03 13:05:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*min_height_p = *natural_height_p = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-01-06 17:07:51 -05:00
|
|
|
shell_gtk_embed_allocate (ClutterActor *actor,
|
2020-05-09 15:30:26 -04:00
|
|
|
const ClutterActorBox *box)
|
2009-05-03 13:05:15 -04:00
|
|
|
{
|
|
|
|
ShellGtkEmbed *embed = SHELL_GTK_EMBED (actor);
|
2015-09-24 14:07:44 -04:00
|
|
|
ShellGtkEmbedPrivate *priv = shell_gtk_embed_get_instance_private (embed);
|
2019-06-05 10:46:35 -04:00
|
|
|
float wx, wy;
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2011-01-06 17:07:51 -05:00
|
|
|
CLUTTER_ACTOR_CLASS (shell_gtk_embed_parent_class)->
|
2020-05-09 15:30:26 -04:00
|
|
|
allocate (actor, box);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2011-01-06 17:07:51 -05:00
|
|
|
/* Find the actor's new coordinates in terms of the stage (which is
|
|
|
|
* priv->window's parent window.
|
2009-05-03 13:05:15 -04:00
|
|
|
*/
|
2019-06-05 10:46:35 -04:00
|
|
|
clutter_actor_get_transformed_position (actor, &wx, &wy);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
_shell_embedded_window_allocate (priv->window,
|
2009-06-06 13:07:41 -04:00
|
|
|
(int)(0.5 + wx), (int)(0.5 + wy),
|
2011-01-06 17:07:51 -05:00
|
|
|
box->x2 - box->x1,
|
|
|
|
box->y2 - box->y1);
|
2009-05-03 13:05:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-25 06:02:17 -04:00
|
|
|
shell_gtk_embed_map (ClutterActor *actor)
|
2009-05-03 13:05:15 -04:00
|
|
|
{
|
|
|
|
ShellGtkEmbed *embed = SHELL_GTK_EMBED (actor);
|
2015-09-24 14:07:44 -04:00
|
|
|
ShellGtkEmbedPrivate *priv = shell_gtk_embed_get_instance_private (embed);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
_shell_embedded_window_map (priv->window);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2012-03-25 06:02:17 -04:00
|
|
|
CLUTTER_ACTOR_CLASS (shell_gtk_embed_parent_class)->map (actor);
|
2009-05-03 13:05:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-25 06:02:17 -04:00
|
|
|
shell_gtk_embed_unmap (ClutterActor *actor)
|
2009-05-03 13:05:15 -04:00
|
|
|
{
|
|
|
|
ShellGtkEmbed *embed = SHELL_GTK_EMBED (actor);
|
2015-09-24 14:07:44 -04:00
|
|
|
ShellGtkEmbedPrivate *priv = shell_gtk_embed_get_instance_private (embed);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
_shell_embedded_window_unmap (priv->window);
|
2009-05-03 13:05:15 -04:00
|
|
|
|
2012-03-25 06:02:17 -04:00
|
|
|
CLUTTER_ACTOR_CLASS (shell_gtk_embed_parent_class)->unmap (actor);
|
2009-05-03 13:05:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_gtk_embed_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
ShellGtkEmbed *embed = SHELL_GTK_EMBED (object);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (shell_gtk_embed_parent_class)->dispose (object);
|
2012-03-25 06:07:15 -04:00
|
|
|
|
|
|
|
shell_gtk_embed_set_window (embed, NULL);
|
2009-05-03 13:05:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_gtk_embed_class_init (ShellGtkEmbedClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->get_property = shell_gtk_embed_get_property;
|
|
|
|
object_class->set_property = shell_gtk_embed_set_property;
|
|
|
|
object_class->dispose = shell_gtk_embed_dispose;
|
|
|
|
|
|
|
|
actor_class->get_preferred_width = shell_gtk_embed_get_preferred_width;
|
|
|
|
actor_class->get_preferred_height = shell_gtk_embed_get_preferred_height;
|
2011-01-06 17:07:51 -05:00
|
|
|
actor_class->allocate = shell_gtk_embed_allocate;
|
2012-03-25 06:02:17 -04:00
|
|
|
actor_class->map = shell_gtk_embed_map;
|
|
|
|
actor_class->unmap = shell_gtk_embed_unmap;
|
2009-05-03 13:05:15 -04:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_WINDOW,
|
|
|
|
g_param_spec_object ("window",
|
|
|
|
"Window",
|
|
|
|
"ShellEmbeddedWindow to embed",
|
|
|
|
SHELL_TYPE_EMBEDDED_WINDOW,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_gtk_embed_init (ShellGtkEmbed *embed)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public API
|
|
|
|
*/
|
|
|
|
ClutterActor *
|
|
|
|
shell_gtk_embed_new (ShellEmbeddedWindow *window)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (SHELL_IS_EMBEDDED_WINDOW (window), NULL);
|
|
|
|
|
|
|
|
return g_object_new (SHELL_TYPE_GTK_EMBED,
|
|
|
|
"window", window,
|
|
|
|
NULL);
|
|
|
|
}
|