summaryrefslogtreecommitdiff
path: root/example.h
blob: c49e2bbd2592c5d6ed5af51835ad4906d007273e (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/* Compiz example plugin
 * example.h
 *
 * 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.
 */

#include <composite/composite.h>

/* OpenGL support is now no longer built in by-default as well. You have to use the
 * interface of the opengl plugin if you want to do anything with that. */

#include <opengl/opengl.h>

/* This is the options class header created for us automatically on build with BCOP */

#include "example_options.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,
    /* And opengl plugin */
    public GLScreenInterface,
    /* 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 (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 ();

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

	/* And some member variables */
	int foo;

	/* 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
	 */

	/* This is the function that is called before the screen is 're-painted'. It is used for animation
	 * and such because it gives you a time difference between when the last time the screen was repainted
	 * and the current time of the execution of the functions in milliseconds). It's part of the composite
	 * plugin's interface
	 */

	void
	preparePaint (int);

	/* This is the guts of the paint function. You can transform the way the entire output is painted
	 * or you can just draw things on screen with openGL. The unsigned int here is a mask for painting
	 * the screen, see opengl/opengl.h on how you can change it */

	bool
	glPaintOutput (const GLScreenPaintAttrib &,
		       const GLMatrix &, const CompRegion &,
		       CompOutput *, unsigned int);

	/* This is called when the output is transformed by a matrix. Basically the same, but core has
	 * done a few things for us like clip planes etc */

	void
	glPaintTransformedOutput (const GLScreenPaintAttrib &,
		       		  const GLMatrix &, const CompRegion &,
		       		  CompOutput *, unsigned int);


	/* This is called after screen painting is finished. It gives you a chance to do any cleanup and or
	 * call another repaint with screen->damageScreen (). It's also part of the composite plugin's
	 * interface.
	 */

	void
	donePaint ();

	/* This is our event handler. It directly hooks into the screen's X Event handler and allows us to handle
	 * our raw X Events
	 */

	void
	handleEvent (XEvent *);

	/* Actions, these are called on keypresses, buttonpress, edges etc by compiz */

	static bool
	exampleInitiate (CompAction         *action,
	  		 CompAction::State  state,
	  		 CompOption::Vector &options);

	/* Initiate / Terminate action pair */

	static bool
	specialInitiate (CompAction         *action,
		         CompAction::State  state,
		         CompOption::Vector &options);

	static bool
	specialTerminate (CompAction         *action,
			  CompAction::State  state,
			  CompOption::Vector &options);

	/* Actions with additional args through boost::bind */

	static bool
	customInitiate (CompAction	   *action,
		        CompAction::State  state,
		        CompOption::Vector options,
		        int                theMeaningOfLife);
};

class ExampleWindow :
    /* Same for Example Screen, inherit interfaces, private handlers, options */
    public WindowInterface,
    public CompositeWindowInterface,
    public GLWindowInterface,
    public PrivateHandler <ExampleWindow, CompWindow>
{

    public:

        /* Constructors, destructors etc */

	ExampleWindow (CompWindow *);
	~ExampleWindow ();

	/* We store CompositeWindow, GLWindow, and CompWindow to avoid unecessary calls to ::get */
	CompWindow      *window;
	CompositeWindow *cWindow;
        GLWindow        *gWindow;

	/* This gets called whenever the window needs to be repainted. WindowPaintAttrib gives you some
	 * attributes like brightness/saturation etc to play around with. GLMatrix is the window's
	 * transformation matrix. the unsigned int is the mask, have a look at opengl.h on what you can do
	 * with it */

	bool
	glPaint (const GLWindowPaintAttrib &, const GLMatrix &,
		 const CompRegion &, unsigned int);

	/* This get's called whenever a window's rect is damaged. You can do stuff here or you can adjust the damage
	 * rectangle so that the window will update properly. Part of the CompositeWindowInterface.
	 */

	bool
	damageRect (bool, const CompRect &);

	/* This is called whenever the window is focussed */
	bool
	focus ();

	/* This is called whenever the window is activated */
	void
	activate ();

	/* This is called whenever the window must be placed. You can alter the placement position by altering
	 * the CompPoint & */
	bool
	place (CompPoint &);

	/* This is called whenever the window is moved. It tells you how far it's been moved and whether that
	 * move should be immediate or animated. (Immediate is usually for a sudden move, false for that
	 * usually means the user moved the window */
	void
	moveNotify (int, int, bool);

	/* This is called whenever the window is resized. It tells you how much the window has been resized */
	void
	resizeNotify (int, int, int, int);

	/* This is called when another plugin deems a window to be 'grabbed'. You can't actually 'grab' a
	 * window in X, but it is useful in case you need to know when a user has grabbed a window for some reason */
	void
	grabNotify (int, int, unsigned int, unsigned int);

	/* This is called when a window in released from a grab. See above */
	void
	ungrabNotify ();

	/* This is called when another misc notification arises, such as Map/Unmap etc */
	void
	windowNotify (CompWindowNotify);

};

/* Most plugins set up macros to access their Screen and Window classes based on a CompScreen * or CompWindow * */

#define EX_SCREEN (screen) \
ExampleScreen *es = ExampleScreen::get (screen);

#define EX_WINDOW (window) \
ExampleWindow *ew = ExampleWindow::get (window);

/* Your vTable class is some basic info about the plugin that core uses.
 */

class ExamplePluginVTable :
    /* Inheriting CompPlugin::VTableForScreenAndWindow <ScreenClass, WindowClass>
     * automatically does most of the vTable setup for you */
    public CompPlugin::VTableForScreenAndWindow<ExampleScreen, ExampleWindow>
{
    public:

	/* You MUST have this function. Compiz calls this function first off and that
	 * is what kick-starts your initialization procedure. It must be named
	 * _exactly_ init too */

	bool init ();

	/* This implements ::getOption and ::setOption in your screen class for you. Yay */
			
	PLUGIN_OPTION_HELPER (ExampleScreen);
};