From b33a82eb7cdfdc57ecb9c9369b1d7fbac08f2717 Mon Sep 17 00:00:00 2001
From: "Jasper St. Pierre" <jstpierre@mecheye.net>
Date: Mon, 6 Jul 2015 00:02:13 -0700
Subject: [PATCH] Export the shadow factory

The elementary guys would like this as an API, and I don't see any
reason to refuse -- this is quite nice shadow painting code :)

For some reason, gobject-introspection can't seem to cope with
MetaWindowShape. I'll look into it a bit later, but for now, mark
the function it has trouble with as (skip).
---
 doc/reference/Makefile.am                    |  1 -
 src/Makefile.am                              |  3 +-
 src/compositor/meta-shadow-factory-private.h | 66 --------------------
 src/compositor/meta-shadow-factory.c         |  8 ++-
 src/compositor/meta-window-actor.c           |  2 +-
 src/compositor/meta-window-shape.c           | 10 ++-
 src/meta/meta-shadow-factory.h               | 41 +++++++++++-
 src/{compositor => meta}/meta-window-shape.h |  5 +-
 8 files changed, 60 insertions(+), 76 deletions(-)
 delete mode 100644 src/compositor/meta-shadow-factory-private.h
 rename src/{compositor => meta}/meta-window-shape.h (96%)

diff --git a/doc/reference/Makefile.am b/doc/reference/Makefile.am
index cae0b85c7..52e9ba3c7 100644
--- a/doc/reference/Makefile.am
+++ b/doc/reference/Makefile.am
@@ -84,7 +84,6 @@ IGNORE_HFILES= \
 	meta-dbus-login1.h \
 	meta-module.h \
 	meta-plugin-manager.h \
-	meta-shadow-factory-private.h \
 	meta-texture-rectangle.h \
 	meta-texture-tower.h \
 	meta-window-actor-private.h \
diff --git a/src/Makefile.am b/src/Makefile.am
index af8ae87a9..592d858e9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -132,7 +132,6 @@ libmutter_la_SOURCES =				\
 	compositor/meta-plugin-manager.c	\
 	compositor/meta-plugin-manager.h	\
 	compositor/meta-shadow-factory.c	\
-	compositor/meta-shadow-factory-private.h	\
 	compositor/meta-shaped-texture.c	\
 	compositor/meta-shaped-texture-private.h 	\
 	compositor/meta-surface-actor.c		\
@@ -148,7 +147,6 @@ libmutter_la_SOURCES =				\
 	compositor/meta-window-group.c		\
 	compositor/meta-window-group.h		\
 	compositor/meta-window-shape.c		\
-	compositor/meta-window-shape.h		\
 	compositor/region-utils.c		\
 	compositor/region-utils.h		\
 	meta/compositor.h			\
@@ -159,6 +157,7 @@ libmutter_la_SOURCES =				\
 	meta/meta-plugin.h			\
 	meta/meta-shadow-factory.h		\
 	meta/meta-window-actor.h		\
+	meta/meta-window-shape.h		\
 	meta/compositor-mutter.h 		\
 	core/constraints.c			\
 	core/constraints.h			\
diff --git a/src/compositor/meta-shadow-factory-private.h b/src/compositor/meta-shadow-factory-private.h
deleted file mode 100644
index 8a24b5fd1..000000000
--- a/src/compositor/meta-shadow-factory-private.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/*
- * MetaShadowFactory:
- *
- * Create and cache shadow textures for arbitrary window shapes
- *
- * Copyright (C) 2010 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/>.
- */
-
-#ifndef __META_SHADOW_FACTORY_PRIVATE_H__
-#define __META_SHADOW_FACTORY_PRIVATE_H__
-
-#include <cairo.h>
-#include <clutter/clutter.h>
-#include "meta-window-shape.h"
-#include <meta/meta-shadow-factory.h>
-
-/**
- * MetaShadow:
- * #MetaShadow holds a shadow texture along with information about how to
- * apply that texture to draw a window texture. (E.g., it knows how big the
- * unscaled borders are on each side of the shadow texture.)
- */
-typedef struct _MetaShadow MetaShadow;
-
-MetaShadow *meta_shadow_ref         (MetaShadow            *shadow);
-void        meta_shadow_unref       (MetaShadow            *shadow);
-CoglTexture*meta_shadow_get_texture (MetaShadow            *shadow);
-void        meta_shadow_paint       (MetaShadow            *shadow,
-                                     int                    window_x,
-                                     int                    window_y,
-                                     int                    window_width,
-                                     int                    window_height,
-                                     guint8                 opacity,
-                                     cairo_region_t        *clip,
-                                     gboolean               clip_strictly);
-void        meta_shadow_get_bounds  (MetaShadow            *shadow,
-                                     int                    window_x,
-                                     int                    window_y,
-                                     int                    window_width,
-                                     int                    window_height,
-                                     cairo_rectangle_int_t *bounds);
-
-MetaShadowFactory *meta_shadow_factory_new (void);
-
-MetaShadow *meta_shadow_factory_get_shadow (MetaShadowFactory *factory,
-                                            MetaWindowShape   *shape,
-                                            int                width,
-                                            int                height,
-                                            const char        *class_name,
-                                            gboolean           focused);
-
-#endif /* __META_SHADOW_FACTORY_PRIVATE_H__ */
diff --git a/src/compositor/meta-shadow-factory.c b/src/compositor/meta-shadow-factory.c
index 0a6039899..a72c91dd4 100644
--- a/src/compositor/meta-shadow-factory.c
+++ b/src/compositor/meta-shadow-factory.c
@@ -26,8 +26,9 @@
 #include <math.h>
 #include <string.h>
 
+#include <meta/meta-shadow-factory.h>
+
 #include "cogl-utils.h"
-#include "meta-shadow-factory-private.h"
 #include "region-utils.h"
 
 /* This file implements blurring the shape of a window to produce a
@@ -844,7 +845,7 @@ get_shadow_params (MetaShadowFactory *factory,
 }
 
 /**
- * meta_shadow_factory_get_shadow:
+ * meta_shadow_factory_get_shadow: (skip)
  * @factory: a #MetaShadowFactory
  * @shape: the size-invariant shape of the window's region
  * @width: the actual width of the window's region
@@ -1048,3 +1049,6 @@ meta_shadow_factory_get_params (MetaShadowFactory *factory,
   if (params)
     *params = *stored_params;
 }
+
+G_DEFINE_BOXED_TYPE (MetaShadow, meta_shadow,
+                     meta_shadow_ref, meta_shadow_unref)
diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c
index fefd5d8be..a6aebc9da 100644
--- a/src/compositor/meta-window-actor.c
+++ b/src/compositor/meta-window-actor.c
@@ -21,10 +21,10 @@
 #include <meta/window.h>
 #include <meta/meta-shaped-texture.h>
 #include <meta/meta-enum-types.h>
+#include <meta/meta-shadow-factory.h>
 
 #include "compositor-private.h"
 #include "meta-shaped-texture-private.h"
-#include "meta-shadow-factory-private.h"
 #include "meta-window-actor-private.h"
 #include "meta-texture-rectangle.h"
 #include "region-utils.h"
diff --git a/src/compositor/meta-window-shape.c b/src/compositor/meta-window-shape.c
index a41ed6ad1..0b2b351bd 100644
--- a/src/compositor/meta-window-shape.c
+++ b/src/compositor/meta-window-shape.c
@@ -1,4 +1,5 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
 /*
  * MetaWindowShape
  *
@@ -19,9 +20,12 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
-#include <string.h>
 
-#include "meta-window-shape.h"
+#include "config.h"
+
+#include <meta/meta-window-shape.h>
+
+#include <string.h>
 #include "region-utils.h"
 
 struct _MetaWindowShape
@@ -250,3 +254,5 @@ meta_window_shape_to_region (MetaWindowShape *shape,
   return region;
 }
 
+G_DEFINE_BOXED_TYPE (MetaWindowShape, meta_window_shape,
+                     meta_window_shape_ref, meta_window_shape_unref)
diff --git a/src/meta/meta-shadow-factory.h b/src/meta/meta-shadow-factory.h
index 466264e93..2109c04ca 100644
--- a/src/meta/meta-shadow-factory.h
+++ b/src/meta/meta-shadow-factory.h
@@ -23,7 +23,12 @@
 #ifndef __META_SHADOW_FACTORY_H__
 #define __META_SHADOW_FACTORY_H__
 
-#include <glib-object.h>
+#include <cairo.h>
+#include <clutter/clutter.h>
+#include <meta/meta-window-shape.h>
+
+G_GNUC_CONST
+GType meta_shadow_get_type (void);
 
 /**
  * MetaShadowParams:
@@ -81,4 +86,38 @@ void meta_shadow_factory_get_params (MetaShadowFactory *factory,
                                      gboolean           focused,
                                      MetaShadowParams  *params);
 
+/**
+ * MetaShadow:
+ * #MetaShadow holds a shadow texture along with information about how to
+ * apply that texture to draw a window texture. (E.g., it knows how big the
+ * unscaled borders are on each side of the shadow texture.)
+ */
+typedef struct _MetaShadow MetaShadow;
+
+MetaShadow *meta_shadow_ref         (MetaShadow            *shadow);
+void        meta_shadow_unref       (MetaShadow            *shadow);
+void        meta_shadow_paint       (MetaShadow            *shadow,
+                                     int                    window_x,
+                                     int                    window_y,
+                                     int                    window_width,
+                                     int                    window_height,
+                                     guint8                 opacity,
+                                     cairo_region_t        *clip,
+                                     gboolean               clip_strictly);
+void        meta_shadow_get_bounds  (MetaShadow            *shadow,
+                                     int                    window_x,
+                                     int                    window_y,
+                                     int                    window_width,
+                                     int                    window_height,
+                                     cairo_rectangle_int_t *bounds);
+
+MetaShadowFactory *meta_shadow_factory_new (void);
+
+MetaShadow *meta_shadow_factory_get_shadow (MetaShadowFactory *factory,
+                                            MetaWindowShape   *shape,
+                                            int                width,
+                                            int                height,
+                                            const char        *class_name,
+                                            gboolean           focused);
+
 #endif /* __META_SHADOW_FACTORY_H__ */
diff --git a/src/compositor/meta-window-shape.h b/src/meta/meta-window-shape.h
similarity index 96%
rename from src/compositor/meta-window-shape.h
rename to src/meta/meta-window-shape.h
index da23e5e9d..ddf638a8d 100644
--- a/src/compositor/meta-window-shape.h
+++ b/src/meta/meta-window-shape.h
@@ -24,7 +24,10 @@
 #define __META_WINDOW_SHAPE_H__
 
 #include <cairo.h>
-#include <glib.h>
+#include <glib-object.h>
+
+G_GNUC_CONST
+GType meta_window_shape_get_type (void);
 
 /**
  * MetaWindowShape: