summaryrefslogtreecommitdiff
path: root/example.h
blob: e2db2a8bbd343f3b5e5faa5112381e4e8a69e525 (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
/* Compiz example plugin
 * example.c
 *
 * Copyright (c) 2008 Sam Spilsbury <smspillaz@gmail.com>
 *
 * 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.
 *
 * Your own copyright notice would go above. You are free to choose whatever
 * licence you want, just take note that some compiz code is GPL and you will
 * not be able to re-use it if you want to use a different licence.
 */

/* The include path is set to /PREFIX/include/compiz in the Makefile, so you
 * don't need to worry about not being able to find compiz headers */

#include <core/core.h>

/* You need to include this in order to get access to the CompPrivate templates */

#include <core/privatehandler.h>

/* Compositing is no longer built in by-default, so you need to include the interface
 * of the composite plugin. You also need to do the same with opengl.h if you plan to
 * use opengl functions
 */

#include <composite/composite.h>

/* This is your base screen class. This class definition can be considered the top most
 * as there is no multi-screen or multi-display support in compiz++, only one compiz
 * instance per screen.
 */

class ExampleScreen :
    /* You should inherit the ScreenInterface class if you want to dynamically hook
     * screen-level core functions. */
    public ScreenInterface,
    /* Same goes for screen functions in the composite plugin */
    public CompositeScreenInterface,
    /* This sets up a privates handler, where you can access an instance of your class for
     * every CompScreen object (same goes for ExampleWindow and CompWindow). It adds the 
     * member function ::get, which will allow you get an instance of this class from a
     * CompScreen * object. Oh, and the memory management is done for you now ^_^
     */
    public PrivateHandler <ExampleScreen, CompScreen>,
    /* And finally, because we are using BCOP to generate our options, it creates a class
     * with a bunch of getters and setters that are added to out class when we inherit it. Yay.
     */
    public ExampleOptions
{

    public:

	/* Lets get into buisness. This is the constructor, it replaces the initScreen, initEtc
         * things that used to be in compiz and is called automatically when an instance of this
         * class is created. Notice how it is the same name as the class name. It has to be that way.
         */

	ExampleScreen::ExampleScreen (CompScreen *s);

	/* This is the destructor. It is called when the class is destroyed. If you allocated any
	 * memory or need to do some cleanup, here is where you do it. Note the tilde (~)?
	 */

	ExampleScreen::~ExampleScreen ();

	/* We store CompositeScreen and CompScreen to avoid unecessary calls to ::get */
	CompScreen *screen;
	CompositeScreen *cScreen;

	/* And some member variables */
	int foo;
	char *foobar;

	/* Now. Because we imported ScreenInterface and CompositeScreenInterface, we get all the
	 * core functions in there for free. Here's the twist. Those functions are stored as 'virtual',
	 * so they can be overridden. That is what we do here. So instead of a core function being called,
	 * our own is
	 */

	bool
	preparePaint (int)

	bool
	donePaint ();

	bool
	handleEvent (XEvent *);
};