All pastes #147519 Raw Edit

C

public c v1 · immutable
#147519 ·published 2006-08-24 12:47 UTC
rendered paste body
#include <stdlib.h>#include <stdio.h>#include <unistd.h>#include <X11/Xlib.h>#include <X11/keysymdef.h>#include <X11/extensions/Xrender.h>intmain (int argc,	  char** argv){	Display* pDisplay = NULL;	XEvent event;	Bool bKeepGoing = True;	Bool bGotEvent = False;	int iEventBase;	int iErrorBase;	int iMajorVersion;	int iMinorVersion;	XSetWindowAttributes values;	Window window;	XRenderPictFormat* pPictFormat = NULL;	XRenderPictureAttributes pictAttribs;	XRenderColor colorRed = {0xffff, 0x000, 0x000, 0x7fff};	XRenderColor colorGreen = {0x000, 0xffff, 0x000, 0x7fff};	XRenderColor colorBlue = {0x000, 0x000, 0xffff, 0x7fff};	Picture redFillPict;	Picture greenFillPict;	Picture blueFillPict;	Picture destPict;	int iWindowAttribsMask;	XTrapezoid trapezoid;	trapezoid.top = 20;	trapezoid.bottom = 100;	trapezoid.left.p1.x = 40;	trapezoid.left.p1.y = 20;	trapezoid.left.p2.x = 20;	trapezoid.left.p2.y = 100;	trapezoid.right.p1.x = 60;	trapezoid.right.p1.y = 20;	trapezoid.right.p2.x = 200;	trapezoid.right.p2.y = 200;	/* connect to display */	pDisplay = XOpenDisplay (NULL);	if (!pDisplay)	{		printf ("Could not open display\n");		return 1;	}	/* check for Xrender-extension */	if (!XRenderQueryExtension (pDisplay, &iEventBase, &iErrorBase))	{		XCloseDisplay (pDisplay);		printf ("Xrender-extension not found\n");		return 2;	}	/* see which version is available */	XRenderQueryVersion (pDisplay, &iMajorVersion, &iMinorVersion);	printf ("Found Xrender %d.%d\n", iMajorVersion, iMinorVersion);	/* make behaviour synchronous */	XSynchronize (pDisplay, True);	/* create and open window */	values.background_pixel = WhitePixel (pDisplay, 0);	values.event_mask = KeyPressMask;	iWindowAttribsMask = CWEventMask | CWBackPixel;	window = XCreateWindow (pDisplay,							RootWindow (pDisplay, 0),							50, 50, 400, 400, 0,							DefaultDepth (pDisplay, 0),							InputOutput,							DefaultVisual (pDisplay, 0),							iWindowAttribsMask,							&values);	XMapWindow (pDisplay, window);	/* now the guessing work starts,	** because Xrender is so "thoroughly" documented :-( */	pPictFormat = XRenderFindVisualFormat (pDisplay,										   DefaultVisual (pDisplay, 0));	printf ("depth %d\n", pPictFormat->depth);	/* as far as I get it this should give	** me three colored "infinite pictures" */	redFillPict = XRenderCreateSolidFill (pDisplay, &colorRed);	greenFillPict = XRenderCreateSolidFill (pDisplay, &colorGreen);	blueFillPict = XRenderCreateSolidFill (pDisplay, &colorBlue);	/* this is my target- or destination-drawable derived from the window...	** at least I think so */	/*pictAttribs.repeat = True;*/	destPict = XRenderCreatePicture (pDisplay,									 window,									 pPictFormat,									 0,									 &pictAttribs);	/* the rectangles show up */	XRenderFillRectangle (pDisplay,						  PictOpOver,						  destPict,						  &colorRed,						  50,						  120,						  325,						  200);	XRenderFillRectangle (pDisplay,						  PictOpOver,						  destPict,						  &colorGreen,						  150,						  20,						  200,						  150);	XRenderFillRectangle (pDisplay,						  PictOpOver,						  destPict,						  &colorBlue,						  5,						  10,						  250,						  50);	/* but this trapezoid does not */	XRenderCompositeTrapezoids (pDisplay,								PictOpOver,								blueFillPict,								destPict,								pPictFormat,								0,								0,								&trapezoid,								1);	while (bKeepGoing)	{		bGotEvent = XCheckWindowEvent (pDisplay,									   window,									   KeyPressMask,									   &event);		if (bGotEvent)		{			switch (event.type)			{				case KeyPress :					if (XLookupKeysym (&event.xkey, 0) == XK_Escape)						bKeepGoing = False;				break;			}		}		else			usleep (10000);	}	XRenderFreePicture (pDisplay, redFillPict);	XRenderFreePicture (pDisplay, greenFillPict);	XRenderFreePicture (pDisplay, blueFillPict);	XRenderFreePicture (pDisplay, destPict);	XUnmapWindow (pDisplay, window);	XDestroyWindow (pDisplay, window);	XCloseDisplay (pDisplay);	return 0;}