summaryrefslogtreecommitdiffstats
path: root/src/shell-window-preview.c
blob: 47a11c5240a5c6b0236cf0501989925b5468b37f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "config.h"

#include "shell-window-preview.h"

enum
{
  PROP_0,

  PROP_WINDOW_CONTAINER,

  PROP_LAST
};

static GParamSpec *obj_props[PROP_LAST] = { NULL, };

struct _ShellWindowPreview
{
  /*< private >*/
  StWidget parent_instance;

  ClutterActor *window_container;
};

G_DEFINE_TYPE (ShellWindowPreview, shell_window_preview, ST_TYPE_WIDGET);

static void
shell_window_preview_get_property (GObject      *gobject,
                                   unsigned int  property_id,
                                   GValue       *value,
                                   GParamSpec   *pspec)
{
  ShellWindowPreview *self = SHELL_WINDOW_PREVIEW (gobject);

  switch (property_id)
    {
    case PROP_WINDOW_CONTAINER:
      g_value_set_object (value, self->window_container);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
    }
}

static void
shell_window_preview_set_property (GObject      *gobject,
                                   unsigned int  property_id,
                                   const GValue *value,
                                   GParamSpec   *pspec)
{
  ShellWindowPreview *self = SHELL_WINDOW_PREVIEW (gobject);

  switch (property_id)
    {
    case PROP_WINDOW_CONTAINER:
      if (g_set_object (&self->window_container, g_value_get_object (value)))
        g_object_notify_by_pspec (gobject, obj_props[PROP_WINDOW_CONTAINER]);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
    }
}

static void
shell_window_preview_get_preferred_width (ClutterActor *actor,
                                          float         for_height,
                                          float        *min_width_p,
                                          float        *natural_width_p)
{
  ShellWindowPreview *self = SHELL_WINDOW_PREVIEW (actor);
  StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
  float min_width, nat_width;

  st_theme_node_adjust_for_height (theme_node, &for_height);

  clutter_actor_get_preferred_width (self->window_container, for_height,
                                     &min_width, &nat_width);

  st_theme_node_adjust_preferred_width (theme_node, &min_width, &nat_width);

  if (min_width_p)
    *min_width_p = min_width;

  if (natural_width_p)
    *natural_width_p = nat_width;
}

static void
shell_window_preview_get_preferred_height (ClutterActor *actor,
                                           float         for_width,
                                           float        *min_height_p,
                                           float        *natural_height_p)
{
  ShellWindowPreview *self = SHELL_WINDOW_PREVIEW (actor);
  StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
  float min_height, nat_height;

  st_theme_node_adjust_for_width (theme_node, &for_width);

  clutter_actor_get_preferred_height (self->window_container, for_width,
                                      &min_height, &nat_height);

  st_theme_node_adjust_preferred_height (theme_node, &min_height, &nat_height);

  if (min_height_p)
    *min_height_p = min_height;

  if (natural_height_p)
    *natural_height_p = nat_height;
}

static void
shell_window_preview_allocate (ClutterActor          *actor,
                               const ClutterActorBox *box)
{
  StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
  ClutterActorBox content_box;
  float x, y, max_width, max_height;
  ClutterActorIter iter;
  ClutterActor *child;

  clutter_actor_set_allocation (actor, box);

  st_theme_node_get_content_box (theme_node, box, &content_box);

  clutter_actor_box_get_origin (&content_box, &x, &y);
  clutter_actor_box_get_size (&content_box, &max_width, &max_height);

  clutter_actor_iter_init (&iter, actor);
  while (clutter_actor_iter_next (&iter, &child))
    clutter_actor_allocate_available_size (child, x, y, max_width, max_height);
}

static void
shell_window_preview_dispose (GObject *gobject)
{
  ShellWindowPreview *self = SHELL_WINDOW_PREVIEW (gobject);

  g_clear_object (&self->window_container);

  G_OBJECT_CLASS (shell_window_preview_parent_class)->dispose (gobject);
}

static void
shell_window_preview_init (ShellWindowPreview *self)
{
}

static void
shell_window_preview_class_init (ShellWindowPreviewClass *klass)
{
  ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

  actor_class->get_preferred_width = shell_window_preview_get_preferred_width;
  actor_class->get_preferred_height = shell_window_preview_get_preferred_height;
  actor_class->allocate = shell_window_preview_allocate;

  gobject_class->dispose = shell_window_preview_dispose;
  gobject_class->get_property = shell_window_preview_get_property;
  gobject_class->set_property = shell_window_preview_set_property;

  /**
   * ShellWindowPreview:window-container:
   */
  obj_props[PROP_WINDOW_CONTAINER] =
    g_param_spec_object ("window-container",
                         "window-container",
                         "window-container",
                         CLUTTER_TYPE_ACTOR,
                         G_PARAM_READWRITE |
                         G_PARAM_EXPLICIT_NOTIFY |
                         G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
}