~shnatsel/+junk/cairo-compmgr

« back to all changes in this revision

Viewing changes to plugins/clone/ccm-clone.c

  • Committer: Sergey "Shnatsel" Davidoff
  • Date: 2012-03-04 22:53:22 UTC
  • Revision ID: shnatsel@gmail.com-20120304225322-q2hz82j51yxv1qqw
fixed up build dependencies

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ccm-clone.c generated by valac, the Vala compiler
 
2
 * generated from ccm-clone.vala, do not modify */
 
3
 
 
4
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*- */
 
5
/*
 
6
 * cairo-compmgr
 
7
 * Copyright (C) Nicolas Bruguier 2007-2010 <gandalfn@club-internet.fr>
 
8
 * 
 
9
 * cairo-compmgr is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU Lesser General Public
 
11
 * License as published by the Free Software Foundation; either
 
12
 * version 2.1 of the License, or (at your option) any later version.
 
13
 * 
 
14
 * cairo-compmgr is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
 * Lesser General Public License for more details.
 
18
 * 
 
19
 * You should have received a copy of the GNU Lesser General Public
 
20
 * License along with cairo-compmgr.  If not, write to:
 
21
 *      The Free Software Foundation, Inc.,
 
22
 *      51 Franklin Street, Fifth Floor
 
23
 *      Boston, MA  02110-1301, USA.
 
24
 */
 
25
 
 
26
#include <glib.h>
 
27
#include <glib-object.h>
 
28
#include <ccm.h>
 
29
#include <ccm-window.h>
 
30
#include <ccm-window-plugin.h>
 
31
#include <ccm-pixmap.h>
 
32
#include <ccm-screen.h>
 
33
#include <X11/Xlib.h>
 
34
#include <X11/Xatom.h>
 
35
#include <X11/Xutil.h>
 
36
#include <X11/Xregion.h>
 
37
#include <ccm-plugin.h>
 
38
#include <ccm-screen-plugin.h>
 
39
#include <valagee.h>
 
40
#include <ccm-debug.h>
 
41
#include <ccm-drawable.h>
 
42
#include <ccm-display.h>
 
43
#include <cairo.h>
 
44
#include <string.h>
 
45
#include <float.h>
 
46
#include <math.h>
 
47
#include <gobject/gvaluecollector.h>
 
48
 
 
49
 
 
50
#define CCM_TYPE_OUTPUT (ccm_output_get_type ())
 
51
#define CCM_OUTPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CCM_TYPE_OUTPUT, CCMOutput))
 
52
#define CCM_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CCM_TYPE_OUTPUT, CCMOutputClass))
 
53
#define CCM_IS_OUTPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CCM_TYPE_OUTPUT))
 
54
#define CCM_IS_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CCM_TYPE_OUTPUT))
 
55
#define CCM_OUTPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CCM_TYPE_OUTPUT, CCMOutputClass))
 
56
 
 
57
typedef struct _CCMOutput CCMOutput;
 
58
typedef struct _CCMOutputClass CCMOutputClass;
 
59
typedef struct _CCMOutputPrivate CCMOutputPrivate;
 
60
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
 
61
typedef struct _CCMParamSpecOutput CCMParamSpecOutput;
 
62
 
 
63
#define CCM_TYPE_CLONE (ccm_clone_get_type ())
 
64
#define CCM_CLONE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CCM_TYPE_CLONE, CCMClone))
 
65
#define CCM_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CCM_TYPE_CLONE, CCMCloneClass))
 
66
#define CCM_IS_CLONE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CCM_TYPE_CLONE))
 
67
#define CCM_IS_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CCM_TYPE_CLONE))
 
68
#define CCM_CLONE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CCM_TYPE_CLONE, CCMCloneClass))
 
69
 
 
70
typedef struct _CCMClone CCMClone;
 
71
typedef struct _CCMCloneClass CCMCloneClass;
 
72
typedef struct _CCMClonePrivate CCMClonePrivate;
 
73
typedef struct _CCMCloneClassPrivate CCMCloneClassPrivate;
 
74
static GQuark _vala_ccm_clone_class_private_quark = 0;
 
75
#define _vala_collection_object_unref0(var) ((var == NULL) ? NULL : (var = (vala_collection_object_unref (var), NULL)))
 
76
#define _ccm_output_unref0(var) ((var == NULL) ? NULL : (var = (ccm_output_unref (var), NULL)))
 
77
#define _cairo_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_destroy (var), NULL)))
 
78
 
 
79
struct _CCMOutput {
 
80
        GTypeInstance parent_instance;
 
81
        volatile int ref_count;
 
82
        CCMOutputPrivate * priv;
 
83
        CCMWindow* window;
 
84
        CCMPixmap* pixmap;
 
85
};
 
86
 
 
87
struct _CCMOutputClass {
 
88
        GTypeClass parent_class;
 
89
        void (*finalize) (CCMOutput *self);
 
90
};
 
91
 
 
92
struct _CCMParamSpecOutput {
 
93
        GParamSpec parent_instance;
 
94
};
 
95
 
 
96
struct _CCMClone {
 
97
        CCMPlugin parent_instance;
 
98
        CCMClonePrivate * priv;
 
99
};
 
100
 
 
101
struct _CCMCloneClass {
 
102
        CCMPluginClass parent_class;
 
103
};
 
104
 
 
105
struct _CCMClonePrivate {
 
106
        CCMScreen* screen;
 
107
        ValaArrayList* screen_outputs;
 
108
        ValaArrayList* window_outputs;
 
109
};
 
110
 
 
111
 
 
112
static gpointer ccm_output_parent_class = NULL;
 
113
static GType ccm_output_type_id = 0;
 
114
static gpointer ccm_clone_parent_class = NULL;
 
115
static CCMScreenPluginIface* ccm_clone_ccm_screen_plugin_parent_iface = NULL;
 
116
static CCMWindowPluginIface* ccm_clone_ccm_window_plugin_parent_iface = NULL;
 
117
static GType ccm_clone_type_id = 0;
 
118
 
 
119
gpointer ccm_output_ref (gpointer instance);
 
120
void ccm_output_unref (gpointer instance);
 
121
GParamSpec* ccm_param_spec_output (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
 
122
void ccm_value_set_output (GValue* value, gpointer v_object);
 
123
gpointer ccm_value_get_output (const GValue* value);
 
124
GType ccm_output_get_type (void);
 
125
GType ccm_output_register_type (GTypeModule * module);
 
126
enum  {
 
127
        CCM_OUTPUT_DUMMY_PROPERTY
 
128
};
 
129
CCMOutput* ccm_output_new (CCMScreen* screen, CCMWindow* window, Pixmap xpixmap, gint depth);
 
130
CCMOutput* ccm_output_construct (GType object_type, CCMScreen* screen, CCMWindow* window, Pixmap xpixmap, gint depth);
 
131
static void ccm_output_finalize (CCMOutput* obj);
 
132
GType ccm_clone_get_type (void);
 
133
GType ccm_clone_register_type (GTypeModule * module);
 
134
#define CCM_CLONE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CCM_TYPE_CLONE, CCMClonePrivate))
 
135
struct _CCMCloneClassPrivate {
 
136
        Atom screen_enable_atom;
 
137
        Atom screen_disable_atom;
 
138
        Atom enable_atom;
 
139
        Atom disable_atom;
 
140
};
 
141
 
 
142
#define CCM_CLONE_GET_CLASS_PRIVATE(type) ((CCMCloneClassPrivate *) g_type_get_qdata (type, _vala_ccm_clone_class_private_quark))
 
143
enum  {
 
144
        CCM_CLONE_DUMMY_PROPERTY
 
145
};
 
146
static void ccm_clone_add_screen_output (CCMClone* self, CCMOutput* output);
 
147
static void ccm_clone_remove_screen_output (CCMClone* self, CCMOutput* output);
 
148
static void ccm_clone_on_composite_message (CCMClone* self, CCMWindow* client, CCMWindow* window, glong l1, glong l2, glong l3);
 
149
static void _ccm_clone_on_composite_message_ccm_screen_composite_message (CCMScreen* _sender, CCMWindow* client, CCMWindow* window, glong l1, glong l2, glong l3, gpointer self);
 
150
static void ccm_clone_real_screen_load_options (CCMScreenPlugin* base, CCMScreen* screen);
 
151
static gboolean ccm_clone_real_window_paint (CCMWindowPlugin* base, CCMWindow* window, cairo_t* context, cairo_surface_t* surface, gboolean y_invert);
 
152
CCMClone* ccm_clone_new (void);
 
153
CCMClone* ccm_clone_construct (GType object_type);
 
154
static void ccm_clone_base_finalize (CCMCloneClass * klass);
 
155
static void ccm_clone_finalize (GObject* obj);
 
156
GType ccm_clone_get_plugin_type (GTypeModule* module);
 
157
 
 
158
 
 
159
 
 
160
CCMOutput* ccm_output_construct (GType object_type, CCMScreen* screen, CCMWindow* window, Pixmap xpixmap, gint depth) {
 
161
        CCMOutput* self;
 
162
        Visual* visual;
 
163
        CCMPixmap* _tmp0_;
 
164
        g_return_val_if_fail (screen != NULL, NULL);
 
165
        g_return_val_if_fail (window != NULL, NULL);
 
166
        self = (CCMOutput*) g_type_create_instance (object_type);
 
167
        visual = ccm_screen_get_visual_for_depth (screen, depth);
 
168
        self->window = window;
 
169
        self->pixmap = (_tmp0_ = ccm_pixmap_new_from_visual (screen, visual, xpixmap), _g_object_unref0 (self->pixmap), _tmp0_);
 
170
        ccm_pixmap_set_foreign (self->pixmap, TRUE);
 
171
        return self;
 
172
}
 
173
 
 
174
 
 
175
CCMOutput* ccm_output_new (CCMScreen* screen, CCMWindow* window, Pixmap xpixmap, gint depth) {
 
176
        return ccm_output_construct (CCM_TYPE_OUTPUT, screen, window, xpixmap, depth);
 
177
}
 
178
 
 
179
 
 
180
static void ccm_value_output_init (GValue* value) {
 
181
        value->data[0].v_pointer = NULL;
 
182
}
 
183
 
 
184
 
 
185
static void ccm_value_output_free_value (GValue* value) {
 
186
        if (value->data[0].v_pointer) {
 
187
                ccm_output_unref (value->data[0].v_pointer);
 
188
        }
 
189
}
 
190
 
 
191
 
 
192
static void ccm_value_output_copy_value (const GValue* src_value, GValue* dest_value) {
 
193
        if (src_value->data[0].v_pointer) {
 
194
                dest_value->data[0].v_pointer = ccm_output_ref (src_value->data[0].v_pointer);
 
195
        } else {
 
196
                dest_value->data[0].v_pointer = NULL;
 
197
        }
 
198
}
 
199
 
 
200
 
 
201
static gpointer ccm_value_output_peek_pointer (const GValue* value) {
 
202
        return value->data[0].v_pointer;
 
203
}
 
204
 
 
205
 
 
206
static gchar* ccm_value_output_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
 
207
        if (collect_values[0].v_pointer) {
 
208
                CCMOutput* object;
 
209
                object = collect_values[0].v_pointer;
 
210
                if (object->parent_instance.g_class == NULL) {
 
211
                        return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
 
212
                } else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
 
213
                        return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
 
214
                }
 
215
                value->data[0].v_pointer = ccm_output_ref (object);
 
216
        } else {
 
217
                value->data[0].v_pointer = NULL;
 
218
        }
 
219
        return NULL;
 
220
}
 
221
 
 
222
 
 
223
static gchar* ccm_value_output_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
 
224
        CCMOutput** object_p;
 
225
        object_p = collect_values[0].v_pointer;
 
226
        if (!object_p) {
 
227
                return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
 
228
        }
 
229
        if (!value->data[0].v_pointer) {
 
230
                *object_p = NULL;
 
231
        } else if (collect_flags && G_VALUE_NOCOPY_CONTENTS) {
 
232
                *object_p = value->data[0].v_pointer;
 
233
        } else {
 
234
                *object_p = ccm_output_ref (value->data[0].v_pointer);
 
235
        }
 
236
        return NULL;
 
237
}
 
238
 
 
239
 
 
240
GParamSpec* ccm_param_spec_output (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
 
241
        CCMParamSpecOutput* spec;
 
242
        g_return_val_if_fail (g_type_is_a (object_type, CCM_TYPE_OUTPUT), NULL);
 
243
        spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
 
244
        G_PARAM_SPEC (spec)->value_type = object_type;
 
245
        return G_PARAM_SPEC (spec);
 
246
}
 
247
 
 
248
 
 
249
gpointer ccm_value_get_output (const GValue* value) {
 
250
        g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, CCM_TYPE_OUTPUT), NULL);
 
251
        return value->data[0].v_pointer;
 
252
}
 
253
 
 
254
 
 
255
void ccm_value_set_output (GValue* value, gpointer v_object) {
 
256
        CCMOutput* old;
 
257
        g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, CCM_TYPE_OUTPUT));
 
258
        old = value->data[0].v_pointer;
 
259
        if (v_object) {
 
260
                g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, CCM_TYPE_OUTPUT));
 
261
                g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
 
262
                value->data[0].v_pointer = v_object;
 
263
                ccm_output_ref (value->data[0].v_pointer);
 
264
        } else {
 
265
                value->data[0].v_pointer = NULL;
 
266
        }
 
267
        if (old) {
 
268
                ccm_output_unref (old);
 
269
        }
 
270
}
 
271
 
 
272
 
 
273
static void ccm_output_class_init (CCMOutputClass * klass) {
 
274
        ccm_output_parent_class = g_type_class_peek_parent (klass);
 
275
        CCM_OUTPUT_CLASS (klass)->finalize = ccm_output_finalize;
 
276
}
 
277
 
 
278
 
 
279
static void ccm_output_instance_init (CCMOutput * self) {
 
280
        self->ref_count = 1;
 
281
}
 
282
 
 
283
 
 
284
static void ccm_output_finalize (CCMOutput* obj) {
 
285
        CCMOutput * self;
 
286
        self = CCM_OUTPUT (obj);
 
287
        _g_object_unref0 (self->pixmap);
 
288
}
 
289
 
 
290
 
 
291
GType ccm_output_get_type (void) {
 
292
        return ccm_output_type_id;
 
293
}
 
294
 
 
295
 
 
296
GType ccm_output_register_type (GTypeModule * module) {
 
297
        static const GTypeValueTable g_define_type_value_table = { ccm_value_output_init, ccm_value_output_free_value, ccm_value_output_copy_value, ccm_value_output_peek_pointer, "p", ccm_value_output_collect_value, "p", ccm_value_output_lcopy_value };
 
298
        static const GTypeInfo g_define_type_info = { sizeof (CCMOutputClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ccm_output_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CCMOutput), 0, (GInstanceInitFunc) ccm_output_instance_init, &g_define_type_value_table };
 
299
        static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
 
300
        ccm_output_type_id = g_type_register_fundamental (g_type_fundamental_next (), "CCMOutput", &g_define_type_info, &g_define_type_fundamental_info, 0);
 
301
        return ccm_output_type_id;
 
302
}
 
303
 
 
304
 
 
305
gpointer ccm_output_ref (gpointer instance) {
 
306
        CCMOutput* self;
 
307
        self = instance;
 
308
        g_atomic_int_inc (&self->ref_count);
 
309
        return instance;
 
310
}
 
311
 
 
312
 
 
313
void ccm_output_unref (gpointer instance) {
 
314
        CCMOutput* self;
 
315
        self = instance;
 
316
        if (g_atomic_int_dec_and_test (&self->ref_count)) {
 
317
                CCM_OUTPUT_GET_CLASS (self)->finalize (self);
 
318
                g_type_free_instance ((GTypeInstance *) self);
 
319
        }
 
320
}
 
321
 
 
322
 
 
323
static gpointer _g_object_ref0 (gpointer self) {
 
324
        return self ? g_object_ref (self) : NULL;
 
325
}
 
326
 
 
327
 
 
328
static void ccm_clone_add_screen_output (CCMClone* self, CCMOutput* output) {
 
329
        g_return_if_fail (self != NULL);
 
330
        g_return_if_fail (output != NULL);
 
331
        if (self->priv->screen_outputs == NULL) {
 
332
                ValaArrayList* _tmp0_;
 
333
                self->priv->screen_outputs = (_tmp0_ = vala_array_list_new (CCM_TYPE_OUTPUT, (GBoxedCopyFunc) ccm_output_ref, ccm_output_unref, g_direct_equal), _vala_collection_object_unref0 (self->priv->screen_outputs), _tmp0_);
 
334
        }
 
335
        vala_collection_add ((ValaCollection*) self->priv->screen_outputs, output);
 
336
        {
 
337
                GList* window_collection;
 
338
                GList* window_it;
 
339
                window_collection = ccm_screen_get_windows (self->priv->screen);
 
340
                for (window_it = window_collection; window_it != NULL; window_it = window_it->next) {
 
341
                        CCMWindow* window;
 
342
                        window = _g_object_ref0 ((CCMWindow*) window_it->data);
 
343
                        {
 
344
                                if (window != output->window) {
 
345
                                        CCMClone* clone;
 
346
                                        clone = _g_object_ref0 (CCM_CLONE (_ccm_window_get_plugin (window, CCM_TYPE_CLONE)));
 
347
                                        if (clone->priv->screen_outputs == NULL) {
 
348
                                                ValaArrayList* _tmp1_;
 
349
                                                clone->priv->screen_outputs = (_tmp1_ = vala_array_list_new (CCM_TYPE_OUTPUT, (GBoxedCopyFunc) ccm_output_ref, ccm_output_unref, g_direct_equal), _vala_collection_object_unref0 (clone->priv->screen_outputs), _tmp1_);
 
350
                                        }
 
351
                                        vala_collection_add ((ValaCollection*) clone->priv->screen_outputs, output);
 
352
                                        _g_object_unref0 (clone);
 
353
                                }
 
354
                                _g_object_unref0 (window);
 
355
                        }
 
356
                }
 
357
        }
 
358
}
 
359
 
 
360
 
 
361
static void ccm_clone_remove_screen_output (CCMClone* self, CCMOutput* output) {
 
362
        g_return_if_fail (self != NULL);
 
363
        g_return_if_fail (output != NULL);
 
364
        vala_collection_remove ((ValaCollection*) self->priv->screen_outputs, output);
 
365
        {
 
366
                GList* window_collection;
 
367
                GList* window_it;
 
368
                window_collection = ccm_screen_get_windows (self->priv->screen);
 
369
                for (window_it = window_collection; window_it != NULL; window_it = window_it->next) {
 
370
                        CCMWindow* window;
 
371
                        window = _g_object_ref0 ((CCMWindow*) window_it->data);
 
372
                        {
 
373
                                CCMClone* clone;
 
374
                                clone = _g_object_ref0 (CCM_CLONE (_ccm_window_get_plugin (window, CCM_TYPE_CLONE)));
 
375
                                vala_collection_remove ((ValaCollection*) clone->priv->screen_outputs, output);
 
376
                                _g_object_unref0 (window);
 
377
                                _g_object_unref0 (clone);
 
378
                        }
 
379
                }
 
380
        }
 
381
}
 
382
 
 
383
 
 
384
static void ccm_clone_on_composite_message (CCMClone* self, CCMWindow* client, CCMWindow* window, glong l1, glong l2, glong l3) {
 
385
        Atom atom;
 
386
        Pixmap xpixmap;
 
387
        gint depth;
 
388
        g_return_if_fail (self != NULL);
 
389
        g_return_if_fail (client != NULL);
 
390
        g_return_if_fail (window != NULL);
 
391
        atom = (Atom) l1;
 
392
        xpixmap = (Pixmap) l2;
 
393
        depth = (gint) l3;
 
394
        if (atom == CCM_CLONE_GET_CLASS_PRIVATE (G_TYPE_FROM_CLASS (CCM_CLONE_CLASS (G_OBJECT_GET_CLASS (self))))->enable_atom) {
 
395
                CCMClone* clone;
 
396
                CCMOutput* output;
 
397
                ccm_log ("ENABLE CLONE", NULL);
 
398
                clone = _g_object_ref0 (CCM_CLONE (_ccm_window_get_plugin (window, CCM_TYPE_CLONE)));
 
399
                output = ccm_output_new (ccm_drawable_get_screen ((CCMDrawable*) window), window, xpixmap, depth);
 
400
                if (clone->priv->window_outputs == NULL) {
 
401
                        ValaArrayList* _tmp0_;
 
402
                        clone->priv->window_outputs = (_tmp0_ = vala_array_list_new (CCM_TYPE_OUTPUT, (GBoxedCopyFunc) ccm_output_ref, ccm_output_unref, g_direct_equal), _vala_collection_object_unref0 (clone->priv->window_outputs), _tmp0_);
 
403
                }
 
404
                vala_collection_add ((ValaCollection*) clone->priv->window_outputs, output);
 
405
                ccm_window_set_no_undamage_sibling (client, TRUE);
 
406
                ccm_drawable_damage ((CCMDrawable*) window);
 
407
                _g_object_unref0 (clone);
 
408
                _ccm_output_unref0 (output);
 
409
        } else {
 
410
                if (atom == CCM_CLONE_GET_CLASS_PRIVATE (G_TYPE_FROM_CLASS (CCM_CLONE_CLASS (G_OBJECT_GET_CLASS (self))))->disable_atom) {
 
411
                        CCMClone* clone;
 
412
                        ccm_log ("DISABLE CLONE", NULL);
 
413
                        clone = _g_object_ref0 (CCM_CLONE (_ccm_window_get_plugin (window, CCM_TYPE_CLONE)));
 
414
                        ccm_window_set_no_undamage_sibling (client, FALSE);
 
415
                        {
 
416
                                ValaIterator* _output_it;
 
417
                                _output_it = vala_iterable_iterator ((ValaIterable*) clone->priv->window_outputs);
 
418
                                while (TRUE) {
 
419
                                        CCMOutput* output;
 
420
                                        if (!vala_iterator_next (_output_it)) {
 
421
                                                break;
 
422
                                        }
 
423
                                        output = (CCMOutput*) vala_iterator_get (_output_it);
 
424
                                        if (ccm_drawable_get_xid ((CCMDrawable*) output->pixmap) == ((XID) xpixmap)) {
 
425
                                                vala_collection_remove ((ValaCollection*) clone->priv->window_outputs, output);
 
426
                                                _ccm_output_unref0 (output);
 
427
                                                break;
 
428
                                        }
 
429
                                        _ccm_output_unref0 (output);
 
430
                                }
 
431
                                _vala_collection_object_unref0 (_output_it);
 
432
                        }
 
433
                        _g_object_unref0 (clone);
 
434
                } else {
 
435
                        if (atom == CCM_CLONE_GET_CLASS_PRIVATE (G_TYPE_FROM_CLASS (CCM_CLONE_CLASS (G_OBJECT_GET_CLASS (self))))->screen_enable_atom) {
 
436
                                CCMOutput* output;
 
437
                                ccm_log ("ENABLE SCREEN CLONE", NULL);
 
438
                                output = ccm_output_new (ccm_drawable_get_screen ((CCMDrawable*) window), window, xpixmap, depth);
 
439
                                ccm_window_set_no_undamage_sibling (window, TRUE);
 
440
                                ccm_clone_add_screen_output (self, output);
 
441
                                _ccm_output_unref0 (output);
 
442
                        } else {
 
443
                                if (atom == CCM_CLONE_GET_CLASS_PRIVATE (G_TYPE_FROM_CLASS (CCM_CLONE_CLASS (G_OBJECT_GET_CLASS (self))))->screen_disable_atom) {
 
444
                                        ccm_log ("DISABLE SCREEN CLONE", NULL);
 
445
                                        {
 
446
                                                ValaIterator* _output_it;
 
447
                                                _output_it = vala_iterable_iterator ((ValaIterable*) self->priv->screen_outputs);
 
448
                                                while (TRUE) {
 
449
                                                        CCMOutput* output;
 
450
                                                        if (!vala_iterator_next (_output_it)) {
 
451
                                                                break;
 
452
                                                        }
 
453
                                                        output = (CCMOutput*) vala_iterator_get (_output_it);
 
454
                                                        if (ccm_drawable_get_xid ((CCMDrawable*) output->pixmap) == ((XID) xpixmap)) {
 
455
                                                                ccm_window_set_no_undamage_sibling (output->window, FALSE);
 
456
                                                                ccm_clone_remove_screen_output (self, output);
 
457
                                                                _ccm_output_unref0 (output);
 
458
                                                                break;
 
459
                                                        }
 
460
                                                        _ccm_output_unref0 (output);
 
461
                                                }
 
462
                                                _vala_collection_object_unref0 (_output_it);
 
463
                                        }
 
464
                                }
 
465
                        }
 
466
                }
 
467
        }
 
468
}
 
469
 
 
470
 
 
471
static void _ccm_clone_on_composite_message_ccm_screen_composite_message (CCMScreen* _sender, CCMWindow* client, CCMWindow* window, glong l1, glong l2, glong l3, gpointer self) {
 
472
        ccm_clone_on_composite_message (self, client, window, l1, l2, l3);
 
473
}
 
474
 
 
475
 
 
476
static void ccm_clone_real_screen_load_options (CCMScreenPlugin* base, CCMScreen* screen) {
 
477
        CCMClone * self;
 
478
        self = (CCMClone*) base;
 
479
        g_return_if_fail (screen != NULL);
 
480
        self->priv->screen = screen;
 
481
        g_signal_connect_object (self->priv->screen, "composite-message", (GCallback) _ccm_clone_on_composite_message_ccm_screen_composite_message, self, 0);
 
482
        if (CCM_CLONE_GET_CLASS_PRIVATE (G_TYPE_FROM_CLASS (CCM_CLONE_CLASS (G_OBJECT_GET_CLASS (self))))->screen_enable_atom == 0) {
 
483
                CCM_CLONE_GET_CLASS_PRIVATE (G_TYPE_FROM_CLASS (CCM_CLONE_CLASS (G_OBJECT_GET_CLASS (self))))->screen_enable_atom = XInternAtom (ccm_display_get_xdisplay (ccm_screen_get_display (screen)), "_CCM_CLONE_SCREEN_ENABLE", FALSE);
 
484
                CCM_CLONE_GET_CLASS_PRIVATE (G_TYPE_FROM_CLASS (CCM_CLONE_CLASS (G_OBJECT_GET_CLASS (self))))->screen_disable_atom = XInternAtom (ccm_display_get_xdisplay (ccm_screen_get_display (screen)), "_CCM_CLONE_SCREEN_DISABLE", FALSE);
 
485
                CCM_CLONE_GET_CLASS_PRIVATE (G_TYPE_FROM_CLASS (CCM_CLONE_CLASS (G_OBJECT_GET_CLASS (self))))->enable_atom = XInternAtom (ccm_display_get_xdisplay (ccm_screen_get_display (screen)), "_CCM_CLONE_ENABLE", FALSE);
 
486
                CCM_CLONE_GET_CLASS_PRIVATE (G_TYPE_FROM_CLASS (CCM_CLONE_CLASS (G_OBJECT_GET_CLASS (self))))->disable_atom = XInternAtom (ccm_display_get_xdisplay (ccm_screen_get_display (screen)), "_CCM_CLONE_DISABLE", FALSE);
 
487
        }
 
488
        ccm_screen_plugin_load_options (CCM_SCREEN_PLUGIN (ccm_plugin_get_parent ((CCMPlugin*) self)), screen);
 
489
}
 
490
 
 
491
 
 
492
static gboolean ccm_clone_real_window_paint (CCMWindowPlugin* base, CCMWindow* window, cairo_t* context, cairo_surface_t* surface, gboolean y_invert) {
 
493
        CCMClone * self;
 
494
        gboolean result;
 
495
        gboolean ret;
 
496
        gboolean _tmp0_ = FALSE;
 
497
        gboolean _tmp1_ = FALSE;
 
498
        gboolean _tmp2_ = FALSE;
 
499
        self = (CCMClone*) base;
 
500
        g_return_val_if_fail (window != NULL, FALSE);
 
501
        g_return_val_if_fail (context != NULL, FALSE);
 
502
        g_return_val_if_fail (surface != NULL, FALSE);
 
503
        ret = FALSE;
 
504
        ret = ccm_window_plugin_paint (CCM_WINDOW_PLUGIN (ccm_plugin_get_parent ((CCMPlugin*) self)), window, context, surface, y_invert);
 
505
        if (self->priv->window_outputs != NULL) {
 
506
                _tmp2_ = vala_collection_get_size ((ValaCollection*) self->priv->window_outputs) > 0;
 
507
        } else {
 
508
                _tmp2_ = FALSE;
 
509
        }
 
510
        if (_tmp2_) {
 
511
                _tmp1_ = TRUE;
 
512
        } else {
 
513
                gboolean _tmp3_ = FALSE;
 
514
                if (self->priv->screen_outputs != NULL) {
 
515
                        _tmp3_ = vala_collection_get_size ((ValaCollection*) self->priv->screen_outputs) > 0;
 
516
                } else {
 
517
                        _tmp3_ = FALSE;
 
518
                }
 
519
                _tmp1_ = _tmp3_;
 
520
        }
 
521
        if (_tmp1_) {
 
522
                _tmp0_ = ret;
 
523
        } else {
 
524
                _tmp0_ = FALSE;
 
525
        }
 
526
        if (_tmp0_) {
 
527
                cairo_rectangle_t* area;
 
528
                cairo_rectangle_t _tmp4_ = {0};
 
529
                cairo_rectangle_t geometry;
 
530
                gboolean _tmp5_ = FALSE;
 
531
                area = ccm_window_get_area (window);
 
532
                geometry = (memset (&_tmp4_, 0, sizeof (cairo_rectangle_t)), _tmp4_);
 
533
                if (area != NULL) {
 
534
                        _tmp5_ = ccm_drawable_get_device_geometry_clipbox ((CCMDrawable*) window, &geometry);
 
535
                } else {
 
536
                        _tmp5_ = FALSE;
 
537
                }
 
538
                if (_tmp5_) {
 
539
                        if (self->priv->window_outputs != NULL) {
 
540
                                {
 
541
                                        ValaIterator* _output_it;
 
542
                                        _output_it = vala_iterable_iterator ((ValaIterable*) self->priv->window_outputs);
 
543
                                        while (TRUE) {
 
544
                                                CCMOutput* output;
 
545
                                                cairo_rectangle_t _tmp6_ = {0};
 
546
                                                cairo_rectangle_t clipbox;
 
547
                                                if (!vala_iterator_next (_output_it)) {
 
548
                                                        break;
 
549
                                                }
 
550
                                                output = (CCMOutput*) vala_iterator_get (_output_it);
 
551
                                                clipbox = (memset (&_tmp6_, 0, sizeof (cairo_rectangle_t)), _tmp6_);
 
552
                                                if (ccm_drawable_get_device_geometry_clipbox ((CCMDrawable*) output->pixmap, &clipbox)) {
 
553
                                                        cairo_t* ctx;
 
554
                                                        ctx = ccm_drawable_create_context ((CCMDrawable*) output->pixmap);
 
555
                                                        if (ctx != NULL) {
 
556
                                                                cairo_scale (ctx, clipbox.width / (*area).width, clipbox.height / (*area).height);
 
557
                                                                cairo_translate (ctx, -(*area).x, -(*area).y);
 
558
                                                                ccm_drawable_get_damage_path ((CCMDrawable*) window, ctx);
 
559
                                                                cairo_clip (ctx);
 
560
                                                                cairo_translate (ctx, (*area).x, (*area).y);
 
561
                                                                cairo_set_source_surface (ctx, surface, (-(geometry.width - (*area).width)) / 2.0, (-(geometry.height - (*area).height)) / 2.0);
 
562
                                                                cairo_paint (ctx);
 
563
                                                        }
 
564
                                                        _cairo_destroy0 (ctx);
 
565
                                                }
 
566
                                                _ccm_output_unref0 (output);
 
567
                                        }
 
568
                                        _vala_collection_object_unref0 (_output_it);
 
569
                                }
 
570
                        }
 
571
                        if (self->priv->screen_outputs != NULL) {
 
572
                                {
 
573
                                        ValaIterator* _output_it;
 
574
                                        _output_it = vala_iterable_iterator ((ValaIterable*) self->priv->screen_outputs);
 
575
                                        while (TRUE) {
 
576
                                                CCMOutput* output;
 
577
                                                cairo_rectangle_t _tmp7_ = {0};
 
578
                                                cairo_rectangle_t clipbox;
 
579
                                                gint width;
 
580
                                                gint height;
 
581
                                                gboolean _tmp8_ = FALSE;
 
582
                                                if (!vala_iterator_next (_output_it)) {
 
583
                                                        break;
 
584
                                                }
 
585
                                                output = (CCMOutput*) vala_iterator_get (_output_it);
 
586
                                                clipbox = (memset (&_tmp7_, 0, sizeof (cairo_rectangle_t)), _tmp7_);
 
587
                                                width = ccm_screen_get_xscreen (ccm_drawable_get_screen ((CCMDrawable*) window))->width;
 
588
                                                height = ccm_screen_get_xscreen (ccm_drawable_get_screen ((CCMDrawable*) window))->height;
 
589
                                                if (output->window != window) {
 
590
                                                        _tmp8_ = ccm_drawable_get_device_geometry_clipbox ((CCMDrawable*) output->pixmap, &clipbox);
 
591
                                                } else {
 
592
                                                        _tmp8_ = FALSE;
 
593
                                                }
 
594
                                                if (_tmp8_) {
 
595
                                                        cairo_t* ctx;
 
596
                                                        ctx = ccm_drawable_create_context ((CCMDrawable*) output->pixmap);
 
597
                                                        if (ctx != NULL) {
 
598
                                                                cairo_matrix_t matrix = {0};
 
599
                                                                cairo_matrix_t _tmp9_ = {0};
 
600
                                                                matrix = (cairo_matrix_init (&_tmp9_, clipbox.width / width, (double) 0, (double) 0, clipbox.height / height, (-geometry.x) * (1 - (clipbox.width / width)), (-geometry.y) * (1 - (clipbox.height / height))), _tmp9_);
 
601
                                                                cairo_set_matrix (ctx, &matrix);
 
602
                                                                ccm_drawable_get_damage_path ((CCMDrawable*) window, ctx);
 
603
                                                                cairo_clip (ctx);
 
604
                                                                cairo_identity_matrix (ctx);
 
605
                                                                ccm_drawable_push_matrix ((CCMDrawable*) window, "CCMClone", &matrix);
 
606
                                                                ccm_window_plugin_paint (CCM_WINDOW_PLUGIN (ccm_plugin_get_parent ((CCMPlugin*) self)), window, ctx, surface, y_invert);
 
607
                                                                ccm_drawable_pop_matrix ((CCMDrawable*) window, "CCMClone");
 
608
                                                        }
 
609
                                                        _cairo_destroy0 (ctx);
 
610
                                                }
 
611
                                                _ccm_output_unref0 (output);
 
612
                                        }
 
613
                                        _vala_collection_object_unref0 (_output_it);
 
614
                                }
 
615
                        }
 
616
                }
 
617
        }
 
618
        result = ret;
 
619
        return result;
 
620
}
 
621
 
 
622
 
 
623
CCMClone* ccm_clone_construct (GType object_type) {
 
624
        CCMClone * self;
 
625
        self = g_object_newv (object_type, 0, NULL);
 
626
        return self;
 
627
}
 
628
 
 
629
 
 
630
CCMClone* ccm_clone_new (void) {
 
631
        return ccm_clone_construct (CCM_TYPE_CLONE);
 
632
}
 
633
 
 
634
 
 
635
static void ccm_clone_base_init (CCMCloneClass * klass) {
 
636
        {
 
637
                CCMCloneClassPrivate * priv;
 
638
                CCMCloneClassPrivate * parent_priv;
 
639
                GType parent_type;
 
640
                parent_priv = NULL;
 
641
                parent_type = g_type_parent (G_TYPE_FROM_CLASS (klass));
 
642
                if (parent_type) {
 
643
                        parent_priv = CCM_CLONE_GET_CLASS_PRIVATE (parent_type);
 
644
                }
 
645
                priv = g_slice_new0 (CCMCloneClassPrivate);
 
646
                if (parent_priv) {
 
647
                        memcpy (priv, parent_priv, sizeof (CCMCloneClassPrivate));
 
648
                }
 
649
                g_type_set_qdata (G_TYPE_FROM_CLASS (klass), _vala_ccm_clone_class_private_quark, priv);
 
650
        }
 
651
}
 
652
 
 
653
 
 
654
static void ccm_clone_class_init (CCMCloneClass * klass) {
 
655
        ccm_clone_parent_class = g_type_class_peek_parent (klass);
 
656
        g_type_class_add_private (klass, sizeof (CCMClonePrivate));
 
657
        G_OBJECT_CLASS (klass)->finalize = ccm_clone_finalize;
 
658
}
 
659
 
 
660
 
 
661
static void ccm_clone_base_finalize (CCMCloneClass * klass) {
 
662
        {
 
663
                CCMCloneClassPrivate * priv;
 
664
                priv = CCM_CLONE_GET_CLASS_PRIVATE (G_TYPE_FROM_CLASS (klass));
 
665
                g_slice_free (CCMCloneClassPrivate, priv);
 
666
        }
 
667
}
 
668
 
 
669
 
 
670
static void ccm_clone_ccm_screen_plugin_interface_init (CCMScreenPluginIface * iface) {
 
671
        ccm_clone_ccm_screen_plugin_parent_iface = g_type_interface_peek_parent (iface);
 
672
        iface->load_options = ccm_clone_real_screen_load_options;
 
673
}
 
674
 
 
675
 
 
676
static void ccm_clone_ccm_window_plugin_interface_init (CCMWindowPluginIface * iface) {
 
677
        ccm_clone_ccm_window_plugin_parent_iface = g_type_interface_peek_parent (iface);
 
678
        iface->paint = ccm_clone_real_window_paint;
 
679
}
 
680
 
 
681
 
 
682
static void ccm_clone_instance_init (CCMClone * self) {
 
683
        self->priv = CCM_CLONE_GET_PRIVATE (self);
 
684
        self->priv->screen_outputs = NULL;
 
685
        self->priv->window_outputs = NULL;
 
686
}
 
687
 
 
688
 
 
689
static void ccm_clone_finalize (GObject* obj) {
 
690
        CCMClone * self;
 
691
        self = CCM_CLONE (obj);
 
692
        _vala_collection_object_unref0 (self->priv->screen_outputs);
 
693
        _vala_collection_object_unref0 (self->priv->window_outputs);
 
694
        G_OBJECT_CLASS (ccm_clone_parent_class)->finalize (obj);
 
695
}
 
696
 
 
697
 
 
698
GType ccm_clone_get_type (void) {
 
699
        return ccm_clone_type_id;
 
700
}
 
701
 
 
702
 
 
703
GType ccm_clone_register_type (GTypeModule * module) {
 
704
        static const GTypeInfo g_define_type_info = { sizeof (CCMCloneClass), (GBaseInitFunc) ccm_clone_base_init, (GBaseFinalizeFunc) ccm_clone_base_finalize, (GClassInitFunc) ccm_clone_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CCMClone), 0, (GInstanceInitFunc) ccm_clone_instance_init, NULL };
 
705
        static const GInterfaceInfo ccm_screen_plugin_info = { (GInterfaceInitFunc) ccm_clone_ccm_screen_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
 
706
        static const GInterfaceInfo ccm_window_plugin_info = { (GInterfaceInitFunc) ccm_clone_ccm_window_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
 
707
        _vala_ccm_clone_class_private_quark = g_quark_from_string ("ValaCCMCloneClassPrivate");
 
708
        ccm_clone_type_id = g_type_module_register_type (module, CCM_TYPE_PLUGIN, "CCMClone", &g_define_type_info, 0);
 
709
        g_type_module_add_interface (module, ccm_clone_type_id, CCM_TYPE_SCREEN_PLUGIN, &ccm_screen_plugin_info);
 
710
        g_type_module_add_interface (module, ccm_clone_type_id, CCM_TYPE_WINDOW_PLUGIN, &ccm_window_plugin_info);
 
711
        return ccm_clone_type_id;
 
712
}
 
713
 
 
714
 
 
715
GType ccm_clone_get_plugin_type (GTypeModule* module) {
 
716
        GType result;
 
717
        g_return_val_if_fail (module != NULL, 0UL);
 
718
        ccm_output_register_type (module);
 
719
        ccm_clone_register_type (module);
 
720
        result = CCM_TYPE_CLONE;
 
721
        return result;
 
722
}
 
723
 
 
724
 
 
725
 
 
726