PDA

View Full Version : Triangle plugin (example plugin)


mikedee
December 31st, 2006, 03:24 PM
Here is a very simple plugin which just draws a triangle to the screen.

It is just for learning/template purposes, it could be the base for any head up display style plugin (ie similar to bench).

Its not commented yet, but you can refer to helloworld for comments.

This plugin is part of the example plugins, to check them out from git type this

git-clone git://people.freedesktop.org/~mike/example

gasol
June 11th, 2007, 12:54 AM
In the lastest GIT version of compiz the paintScreen function has been renamed to paintOutput so i have made a patch for the triangle plugin:


tho im a bit new too submitting patches and stuff, i hope this diff file will work and dont break everything ^_^

//Gasol



diff --git a/triangle/triangle.c b/triangle/triangle.c
index 0e6d54e..2d96ece 100644
--- a/triangle/triangle.c
+++ b/triangle/triangle.c
@@ -44,7 +44,7 @@ typedef struct _TriangleDisplay {
} TriangleDisplay;

typedef struct _TriangleScreen {
- PaintScreenProc paintScreen;
+ PaintOutputProc paintOutput;
int grabIndex;
Bool active;
} TriangleScreen;
@@ -81,6 +81,7 @@ triangleToggle (CompDisplay *d,
{
TRIANGLE_SCREEN (s);

+
if (otherScreenGrabExist (s, 0))
return FALSE;

@@ -100,11 +101,11 @@ triangleToggle (CompDisplay *d,


static Bool
-trianglePaintScreen (CompScreen *s,
+trianglePaintOutput (CompScreen *s,
const ScreenPaintAttrib *sAttrib,
const CompTransform *transform,
Region region,
- int output,
+ CompOutput *output,
unsigned int mask)
{
Bool status;
@@ -113,9 +114,10 @@ trianglePaintScreen (CompScreen *s,
TRIANGLE_SCREEN (s);
TRIANGLE_DISPLAY (s->display);

- UNWRAP (as, s, paintScreen);
- status = (*s->paintScreen) (s, sAttrib, transform, region, output, mask);
- WRAP (as, s, paintScreen, trianglePaintScreen);
+ UNWRAP (as, s, paintOutput);
+ status = (*s->paintOutput) (s, sAttrib, transform, region, output, mask);
+ WRAP (as, s, paintOutput, trianglePaintOutput);
+

if (status && as->active && region->numRects)
{
@@ -248,11 +250,11 @@ triangleInitScreen (CompPlugin *p,
return FALSE;

as->grabIndex = 0;
- as->active = FALSE;
+ as->active = FALSE;

addScreenAction (s, &ad->opt[TRIANGLE_DISPLAY_OPTION_INITIATE].value.action);

- WRAP (as, s, paintScreen, trianglePaintScreen);
+ WRAP (as, s, paintOutput, trianglePaintOutput);

s->privates[ad->screenPrivateIndex].ptr = as;

@@ -265,7 +267,7 @@ triangleFiniScreen (CompPlugin *p,
{
TRIANGLE_SCREEN (s);

- UNWRAP (as, s, paintScreen);
+ UNWRAP (as, s, paintOutput);

free (as);
}

mikedee
June 11th, 2007, 01:34 AM
Thanks very much :)

I have pushed those changes out now

SmSpillaz
October 31st, 2007, 11:48 AM
Oops, sorry guys - wrong thread :D

goma
May 25th, 2008, 12:07 AM
Anyone one know how to get these working on master? I have a feeling it needs to be ported, though, is there a simple explanation as to how one ports code to master?

I getandrew@andrew-laptop:~/example/triangle$ make
libtool --mode=compile gcc -Wall -g `pkg-config --cflags compiz cairo` -shared -c -o triangle.lo triangle.c
mkdir .libs
gcc -Wall -g -DPNG_NO_MMX_CODE -I/usr/include/libxml2 -I/usr/include/startup-notification-1.0 -I/usr/local/include/compiz -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/pixman-1 -shared -c triangle.c -fPIC -DPIC -o .libs/triangle.o
triangle.c:43: error: array type has incomplete element type
triangle.c:47: error: expected specifier-qualifier-list before ‘PaintOutputProc’
triangle.c:68: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘triangleToggle’
triangle.c:103: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘trianglePaintOutput’
triangle.c: In function ‘triangleGetDisplayOptions’:
triangle.c:150: error: dereferencing pointer to incomplete type
triangle.c:152: error: invalid application of ‘sizeof’ to incomplete type ‘CompOption’
triangle.c:154: warning: control reaches end of non-void function
triangle.c: At top level:
triangle.c:157: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘triangleSetDisplayOption’
triangle.c:187: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘triangleDisplayOptionInfo’
triangle.c:193: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘triangleInitDisplay’
triangle.c: In function ‘triangleFiniDisplay’:
triangle.c:229: error: dereferencing pointer to incomplete type
triangle.c:231: warning: implicit declaration of function ‘freeScreenPrivateIndex’
triangle.c:233: warning: implicit declaration of function ‘compFiniDisplayOptions’
triangle.c: At top level:
triangle.c:239: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘triangleInitScreen’
triangle.c: In function ‘triangleFiniScreen’:
triangle.c:266: error: dereferencing pointer to incomplete type
triangle.c:266: error: dereferencing pointer to incomplete type
triangle.c:268: warning: implicit declaration of function ‘UNWRAP’
triangle.c:268: error: ‘paintOutput’ undeclared (first use in this function)
triangle.c:268: error: (Each undeclared identifier is reported only once
triangle.c:268: error: for each function it appears in.)
triangle.c: At top level:
triangle.c:274: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘triangleInit’
triangle.c: In function ‘triangleFini’:
triangle.c:299: warning: implicit declaration of function ‘freeDisplayPrivateIndex’
triangle.c: In function ‘triangleGetVersion’:
triangle.c:308: error: ‘ABIVERSION’ undeclared (first use in this function)
triangle.c:309: warning: control reaches end of non-void function
triangle.c: At top level:
triangle.c:317: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘triangleVTable’
triangle.c:335: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
make: *** [triangle.lo] Error 1


Thanks.

SmSpillaz
May 25th, 2008, 02:06 AM
I think porting the plugin to master will be more difficult than learning compiz code ;-)

All that plugin uses is paintOutput to draw some stuff on the screen. All this requires is for you to WRAP into paintOutput, glLoadMatrix() the sTransform (sTransform.m) then do glBegin(GL_TRIANGLES) glLineWidth(2.0) , then glVertex2f(x, y) the points that you want the triangle to go across.

goma
May 25th, 2008, 02:21 AM
Once again thanks for the help SmSpillaz. :)