summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2014-10-06 16:50:15 +0200
committerJasper St. Pierre <jstpierre@mecheye.net>2014-10-06 19:39:43 -0700
commitb588baf9f5862e9e12c37f93079dfddc8bff214d (patch)
tree9402a168e28c12b2ea52b926d0be0e64446c82b6
parent9a825d9bee5a854f0154c9600e49d1210094a1fc (diff)
downloadmutter-b588baf9f5862e9e12c37f93079dfddc8bff214d.tar.gz
compositor: Add MetaFeedbackActor
This actor is a non-reactive container that autoembeds itself into the feedback window group in the compositor. The API is meant to help on creating things attached to pointer/touchpoints, with an X/Y attachment offset, and following the position of certain events.
-rw-r--r--src/Makefile.am2
-rw-r--r--src/compositor/meta-feedback-actor-private.h74
-rw-r--r--src/compositor/meta-feedback-actor.c249
3 files changed, 325 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 9882d7ebb..7f3418dbe 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -109,6 +109,8 @@ libmutter_la_SOURCES = \
compositor/meta-background-group.c \
compositor/meta-cullable.c \
compositor/meta-cullable.h \
+ compositor/meta-feedback-actor.c \
+ compositor/meta-feedback-actor-private.h \
compositor/meta-module.c \
compositor/meta-module.h \
compositor/meta-plugin.c \
diff --git a/src/compositor/meta-feedback-actor-private.h b/src/compositor/meta-feedback-actor-private.h
new file mode 100644
index 000000000..ee8b6a1f1
--- /dev/null
+++ b/src/compositor/meta-feedback-actor-private.h
@@ -0,0 +1,74 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * meta-feedback-actor-private.h: Actor for painting user interaction feedback
+ *
+ * Copyright 2014 Red Hat, Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Carlos Garnacho <carlosg@gnome.org>
+ */
+
+#ifndef META_FEEDBACK_ACTOR_PRIVATE_H
+#define META_FEEDBACK_ACTOR_PRIVATE_H
+
+#include <clutter/clutter.h>
+
+/**
+ * MetaFeedbackActor:
+ *
+ * This class handles the rendering of user interaction feedback
+ */
+
+#define META_TYPE_FEEDBACK_ACTOR (meta_feedback_actor_get_type ())
+#define META_FEEDBACK_ACTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_FEEDBACK_ACTOR, MetaFeedbackActor))
+#define META_FEEDBACK_ACTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), META_TYPE_FEEDBACK_ACTOR, MetaFeedbackActorClass))
+#define META_IS_FEEDBACK_ACTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_FEEDBACK_ACTOR))
+#define META_IS_FEEDBACK_ACTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), META_TYPE_FEEDBACK_ACTOR))
+#define META_FEEDBACK_ACTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), META_TYPE_FEEDBACK_ACTOR, MetaFeedbackActorClass))
+
+typedef struct _MetaFeedbackActor MetaFeedbackActor;
+typedef struct _MetaFeedbackActorClass MetaFeedbackActorClass;
+
+struct _MetaFeedbackActorClass
+{
+ /*< private >*/
+ ClutterActorClass parent_class;
+};
+
+struct _MetaFeedbackActor
+{
+ ClutterActor parent;
+};
+
+GType meta_feedback_actor_get_type (void);
+
+ClutterActor *meta_feedback_actor_new (int anchor_x,
+ int anchor_y);
+
+void meta_feedback_actor_set_anchor (MetaFeedbackActor *actor,
+ int anchor_x,
+ int anchor_y);
+void meta_feedback_actor_get_anchor (MetaFeedbackActor *actor,
+ int *anchor_x,
+ int *anchor_y);
+
+void meta_feedback_actor_set_position (MetaFeedbackActor *self,
+ int x,
+ int y);
+
+void meta_feedback_actor_update (MetaFeedbackActor *self,
+ const ClutterEvent *event);
+
+#endif /* META_FEEDBACK_ACTOR_PRIVATE_H */
diff --git a/src/compositor/meta-feedback-actor.c b/src/compositor/meta-feedback-actor.c
new file mode 100644
index 000000000..b162584ea
--- /dev/null
+++ b/src/compositor/meta-feedback-actor.c
@@ -0,0 +1,249 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright 2014 Red Hat, Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Carlos Garnacho <carlosg@gnome.org>
+ */
+
+/**
+ * SECTION:meta-feedback-actor
+ * @title: MetaFeedbackActor
+ * @short_description: Actor for painting user interaction feedback
+ */
+
+#include <config.h>
+
+#include "display-private.h"
+#include "compositor-private.h"
+#include "meta-feedback-actor-private.h"
+
+enum {
+ PROP_ANCHOR_X = 1,
+ PROP_ANCHOR_Y
+};
+
+typedef struct _MetaFeedbackActorPrivate MetaFeedbackActorPrivate;
+
+struct _MetaFeedbackActorPrivate
+{
+ int anchor_x;
+ int anchor_y;
+ int pos_x;
+ int pos_y;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (MetaFeedbackActor, meta_feedback_actor, CLUTTER_TYPE_ACTOR)
+
+static void
+meta_feedback_actor_constructed (GObject *object)
+{
+ MetaDisplay *display;
+
+ display = meta_get_display ();
+ clutter_actor_add_child (display->compositor->feedback_group,
+ CLUTTER_ACTOR (object));
+}
+
+static void
+meta_feedback_actor_update_position (MetaFeedbackActor *self)
+{
+ MetaFeedbackActorPrivate *priv = meta_feedback_actor_get_instance_private (self);
+
+ clutter_actor_set_position (CLUTTER_ACTOR (self),
+ priv->pos_x - priv->anchor_x,
+ priv->pos_y - priv->anchor_y);
+}
+
+static void
+meta_feedback_actor_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MetaFeedbackActor *self = META_FEEDBACK_ACTOR (object);
+ MetaFeedbackActorPrivate *priv = meta_feedback_actor_get_instance_private (self);
+
+ switch (prop_id)
+ {
+ case PROP_ANCHOR_X:
+ priv->anchor_x = g_value_get_int (value);
+ meta_feedback_actor_update_position (self);
+ break;
+ case PROP_ANCHOR_Y:
+ priv->anchor_y = g_value_get_int (value);
+ meta_feedback_actor_update_position (self);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+meta_feedback_actor_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MetaFeedbackActor *self = META_FEEDBACK_ACTOR (object);
+ MetaFeedbackActorPrivate *priv = meta_feedback_actor_get_instance_private (self);
+
+ switch (prop_id)
+ {
+ case PROP_ANCHOR_X:
+ g_value_set_int (value, priv->anchor_x);
+ break;
+ case PROP_ANCHOR_Y:
+ g_value_set_int (value, priv->anchor_y);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+meta_feedback_actor_class_init (MetaFeedbackActorClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GParamSpec *pspec;
+
+ object_class->constructed = meta_feedback_actor_constructed;
+ object_class->set_property = meta_feedback_actor_set_property;
+ object_class->get_property = meta_feedback_actor_get_property;
+
+ pspec = g_param_spec_int ("anchor-x",
+ "Anchor X",
+ "The X axis of the anchor point",
+ 0, G_MAXINT, 0,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (object_class,
+ PROP_ANCHOR_X,
+ pspec);
+
+ pspec = g_param_spec_int ("anchor-y",
+ "Anchor Y",
+ "The Y axis of the anchor point",
+ 0, G_MAXINT, 0,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_property (object_class,
+ PROP_ANCHOR_Y,
+ pspec);
+}
+
+static void
+meta_feedback_actor_init (MetaFeedbackActor *self)
+{
+ clutter_actor_set_reactive (CLUTTER_ACTOR (self), FALSE);
+}
+
+/**
+ * meta_feedback_actor_new:
+ *
+ * Creates a new actor to draw the current drag and drop surface.
+ *
+ * Return value: the newly created background actor
+ */
+ClutterActor *
+meta_feedback_actor_new (int anchor_x,
+ int anchor_y)
+{
+ MetaFeedbackActor *self;
+
+ self = g_object_new (META_TYPE_FEEDBACK_ACTOR,
+ "anchor-x", anchor_x,
+ "anchor-y", anchor_y,
+ NULL);
+
+ return CLUTTER_ACTOR (self);
+}
+
+void
+meta_feedback_actor_set_anchor (MetaFeedbackActor *self,
+ int anchor_x,
+ int anchor_y)
+{
+ MetaFeedbackActorPrivate *priv;
+
+ g_return_if_fail (META_IS_FEEDBACK_ACTOR (self));
+
+ priv = meta_feedback_actor_get_instance_private (self);
+
+ if (priv->anchor_x == anchor_x && priv->anchor_y == anchor_y)
+ return;
+
+ if (priv->anchor_x != anchor_y)
+ {
+ priv->anchor_x = anchor_x;
+ g_object_notify (G_OBJECT (self), "anchor-x");
+ }
+
+ if (priv->anchor_y != anchor_y)
+ {
+ priv->anchor_y = anchor_y;
+ g_object_notify (G_OBJECT (self), "anchor-y");
+ }
+
+ meta_feedback_actor_update_position (self);
+}
+
+void
+meta_feedback_actor_get_anchor (MetaFeedbackActor *self,
+ int *anchor_x,
+ int *anchor_y)
+{
+ MetaFeedbackActorPrivate *priv;
+
+ g_return_if_fail (META_IS_FEEDBACK_ACTOR (self));
+
+ priv = meta_feedback_actor_get_instance_private (self);
+
+ if (anchor_x)
+ *anchor_x = priv->anchor_x;
+ if (anchor_y)
+ *anchor_y = priv->anchor_y;
+}
+
+void
+meta_feedback_actor_set_position (MetaFeedbackActor *self,
+ int x,
+ int y)
+{
+ MetaFeedbackActorPrivate *priv;
+
+ g_return_if_fail (META_IS_FEEDBACK_ACTOR (self));
+
+ priv = meta_feedback_actor_get_instance_private (self);
+ priv->pos_x = x;
+ priv->pos_y = y;
+
+ meta_feedback_actor_update_position (self);
+}
+
+void
+meta_feedback_actor_update (MetaFeedbackActor *self,
+ const ClutterEvent *event)
+{
+ ClutterPoint point;
+
+ g_return_if_fail (META_IS_FEEDBACK_ACTOR (self));
+ g_return_if_fail (event != NULL);
+
+ clutter_event_get_position (event, &point);
+ meta_feedback_actor_set_position (self, point.x, point.y);
+}