meta-background-actor.c 6.24 KB
Newer Older
1 2 3
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/*
 * Copyright 2009 Sander Dijkhuis
Owen W. Taylor's avatar
Owen W. Taylor committed
4
 * Copyright 2014 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 19 20 21
 *
 * Portions adapted from gnome-shell/src/shell-global.c
 */

Jonas Ådahl's avatar
Jonas Ådahl committed
22
#include "config.h"
23

Jonas Ådahl's avatar
Jonas Ådahl committed
24
#include "compositor/meta-background-actor-private.h"
25
#include "compositor/meta-background-content-private.h"
26

Jonas Ådahl's avatar
Jonas Ådahl committed
27
#include "compositor/meta-cullable.h"
28

Owen W. Taylor's avatar
Owen W. Taylor committed
29 30
enum
{
31
  PROP_META_DISPLAY = 1,
Owen W. Taylor's avatar
Owen W. Taylor committed
32 33 34
  PROP_MONITOR,
};

35
struct _MetaBackgroundActor
36
{
37 38
  ClutterActor parent;

39
  MetaDisplay *display;
Owen W. Taylor's avatar
Owen W. Taylor committed
40 41
  int monitor;

42
  MetaBackgroundContent *content;
43 44
};

45 46 47 48 49 50
static void cullable_iface_init (MetaCullableInterface *iface);

G_DEFINE_TYPE_WITH_CODE (MetaBackgroundActor, meta_background_actor, CLUTTER_TYPE_ACTOR,
                         G_IMPLEMENT_INTERFACE (META_TYPE_CULLABLE, cullable_iface_init));

static void
51
maybe_create_content (MetaBackgroundActor *self)
52
{
53
  g_autoptr (ClutterContent) content = NULL;
54

55
  if (self->content || !self->display || self->monitor == -1)
56
      return;
57

58 59 60
  content = meta_background_content_new (self->display, self->monitor);
  self->content = META_BACKGROUND_CONTENT (content);
  clutter_actor_set_content (CLUTTER_ACTOR (self), content);
Owen W. Taylor's avatar
Owen W. Taylor committed
61 62 63 64 65 66 67 68 69 70 71 72
}

static void
meta_background_actor_set_property (GObject      *object,
                                    guint         prop_id,
                                    const GValue *value,
                                    GParamSpec   *pspec)
{
  MetaBackgroundActor *self = META_BACKGROUND_ACTOR (object);

  switch (prop_id)
    {
73
    case PROP_META_DISPLAY:
74
      self->display = g_value_get_object (value);
75
      maybe_create_content (self);
Owen W. Taylor's avatar
Owen W. Taylor committed
76 77
      break;
    case PROP_MONITOR:
78 79
      self->monitor = g_value_get_int (value);
      maybe_create_content (self);
80
      break;
Owen W. Taylor's avatar
Owen W. Taylor committed
81 82 83 84 85 86 87 88 89 90 91 92
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
meta_background_actor_get_property (GObject      *object,
                                    guint         prop_id,
                                    GValue       *value,
                                    GParamSpec   *pspec)
{
93
  MetaBackgroundActor *self = META_BACKGROUND_ACTOR (object);
Owen W. Taylor's avatar
Owen W. Taylor committed
94 95 96

  switch (prop_id)
    {
97
    case PROP_META_DISPLAY:
98
      g_value_set_object (value, self->display);
Owen W. Taylor's avatar
Owen W. Taylor committed
99 100
      break;
    case PROP_MONITOR:
101
      g_value_set_int (value, self->monitor);
Owen W. Taylor's avatar
Owen W. Taylor committed
102 103 104 105 106 107 108
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

109 110 111 112
static void
meta_background_actor_class_init (MetaBackgroundActorClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
Owen W. Taylor's avatar
Owen W. Taylor committed
113
  GParamSpec *param_spec;
114

Owen W. Taylor's avatar
Owen W. Taylor committed
115 116
  object_class->set_property = meta_background_actor_set_property;
  object_class->get_property = meta_background_actor_get_property;
117

118 119 120 121
  param_spec = g_param_spec_object ("meta-display",
                                    "MetaDisplay",
                                    "MetaDisplay",
                                    META_TYPE_DISPLAY,
Owen W. Taylor's avatar
Owen W. Taylor committed
122 123 124
                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);

  g_object_class_install_property (object_class,
125
                                   PROP_META_DISPLAY,
Owen W. Taylor's avatar
Owen W. Taylor committed
126 127 128 129 130 131 132 133 134 135 136
                                   param_spec);

  param_spec = g_param_spec_int ("monitor",
                                 "monitor",
                                 "monitor",
                                 0, G_MAXINT, 0,
                                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);

  g_object_class_install_property (object_class,
                                   PROP_MONITOR,
                                   param_spec);
137 138 139
}

static void
140
meta_background_actor_init (MetaBackgroundActor *self)
141
{
142
  self->monitor = -1;
143

144 145
  clutter_actor_set_request_mode (CLUTTER_ACTOR (self),
                                  CLUTTER_REQUEST_CONTENT_SIZE);
146 147 148 149
}

/**
 * meta_background_actor_new:
Owen W. Taylor's avatar
Owen W. Taylor committed
150
 * @monitor: Index of the monitor for which to draw the background
151
 *
152
 * Creates a new actor to draw the background for the given monitor.
153
 *
154
 * Return value: the newly created background actor
155 156
 */
ClutterActor *
157 158
meta_background_actor_new (MetaDisplay *display,
                           int          monitor)
159 160 161
{
  MetaBackgroundActor *self;

Owen W. Taylor's avatar
Owen W. Taylor committed
162
  self = g_object_new (META_TYPE_BACKGROUND_ACTOR,
163
                       "meta-display", display,
Owen W. Taylor's avatar
Owen W. Taylor committed
164 165
                       "monitor", monitor,
                       NULL);
166 167 168 169

  return CLUTTER_ACTOR (self);
}

170 171 172 173
static void
meta_background_actor_cull_out (MetaCullable   *cullable,
                                cairo_region_t *unobscured_region,
                                cairo_region_t *clip_region)
174
{
175
  MetaBackgroundActor *self = META_BACKGROUND_ACTOR (cullable);
176

177 178 179 180 181 182
  if (!self->content)
    return;

  meta_background_content_cull_out (self->content,
                                    unobscured_region,
                                    clip_region);
183
}
184

185 186 187 188
static void
meta_background_actor_reset_culling (MetaCullable *cullable)
{
  MetaBackgroundActor *self = META_BACKGROUND_ACTOR (cullable);
189

190 191 192 193
  if (!self->content)
    return;

  meta_background_content_reset_culling (self->content);
194
}
195

196 197 198 199 200
static void
cullable_iface_init (MetaCullableInterface *iface)
{
  iface->cull_out = meta_background_actor_cull_out;
  iface->reset_culling = meta_background_actor_reset_culling;
201
}
202 203

/**
204
 * meta_background_actor_get_clip_region:
205
 * @self: a #MetaBackgroundActor
206
 *
207
 * Return value (transfer none): a #cairo_region_t that represents the part of
208 209
 * the background not obscured by other #MetaBackgroundActor or
 * #MetaWindowActor objects.
210
 */
211
cairo_region_t *
212
meta_background_actor_get_clip_region (MetaBackgroundActor *self)
213
{
214 215
  if (!self->content)
    return NULL;
Owen W. Taylor's avatar
Owen W. Taylor committed
216

217
  return meta_background_content_get_clip_region (self->content);
Owen W. Taylor's avatar
Owen W. Taylor committed
218
}