/* Create a new shaped pixmap with width & height of dockapp window */ DAShapedPixmap* DAMakeShapedPixmap() { DAShapedPixmap *dasp = malloc(sizeof(DAShapedPixmap)); if (dasp == NULL) return NULL; memset(dasp, 0, sizeof(DAShapedPixmap)); dasp->pixmap = DAMakePixmap(); dasp->shape = DAMakeShape(); dasp->geometry.width = _daContext->width; dasp->geometry.height = _daContext->height; setGCs(dasp); DASPClear(dasp); return dasp; }
int main(int argc, char **argv) { unsigned int x = 1, y = 1; Pixmap back; DACallbacks eventCallbacks = { destroy, /* destroy */ NULL, /* buttonPress */ NULL, /* buttonRelease */ NULL, /* motion (mouse) */ NULL, /* mouse enters window */ NULL, /* mouse leaves window */ moveBall /* timeout */ }; /* provide standard command-line options */ DAParseArguments( argc, argv, /* Where the options come from */ NULL, 0, /* Our list with options - none as you can see */ "This is the help text for the basic example of how to " "use libDockapp.\n", "Basic example version 1.1"); /* Tell libdockapp what version we expect it to be (a date from * NEWS should do). */ DASetExpectedVersion(20020126); DAOpenDisplay( NULL /* default display */, argc, argv /* needed by libdockapp */ ); DACreateIcon( "daBasicExample" /* WM_CLASS hint; don't use chars in [.?*: ] */, 48, 48 /* geometry of dockapp internals */, argc, argv /* needed by libdockapp */ ); /* The pixmap that makes up the background of the dockapp */ back = DAMakePixmap(); drawRelief(back); DASetPixmap(back); XFreePixmap(DADisplay, back); /* A window(!) for the ball pixmap. * Moving a window is a lot easier then erasing/copying the pixmap all * the time. * * I use a DAShapedPixmap here, which contains all the information * related to the pixmap: pixmap, mask and geometry. */ ballPix = DAMakeShapedPixmapFromData(ball_red_xpm); ballWin = XCreateSimpleWindow(DADisplay, DAWindow, x, y, /* Use the geometry of the shaped pixmap */ ballPix->geometry.width, ballPix->geometry.height, 0, 0, 0); DASPSetPixmapForWindow(ballWin, ballPix); /* Respond to destroy and timeout events (the ones not NULL in the * eventCallbacks variable. */ DASetCallbacks(&eventCallbacks); /* Set the time for timeout events (in msec) */ DASetTimeout(SPEED); /* Randomize movement variation. * Run multiple versions of the dockapp simultaneously to see the effect * best. * (which function to use is set from the Imakefile) */ #ifdef HAS_RANDOMDEV srandomdev(); #else srandom(time(NULL)); #endif DAShow(); /* Show the dockapp window. */ /* Process events and keep the dockapp running */ DAEventLoop(); /* not reached */ exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { /* define the event handlers for the events */ DACallbacks eventCallbacks = { destroy, /* destroy */ buttonPress, /* buttonPress */ buttonRelease, /* buttonRelease */ mouseMove, /* motion (mouse) */ mouseEnter, /* mouse enters window */ mouseLeave, /* mouse leaves window */ NULL /* timeout */ }; /* define regions (x, y, width, height) that need event-handling */ Region clipRegion = XCreateRegion(); DARect btn = {0, 0, 16, 16}, square = {0, 25, 22, 22}, slider = {24, 0, 23, 48}; /* define what to do if an event occurs in a rectangle */ DAActionRect *buttonPressRects, *buttonReleaseRects, *mouseMoveRects, *mouseEnterRects, *mouseLeaveRects; buttonPressRects = malloc(3 * sizeof(DAActionRect)); buttonPressRects[0] = setRectAction(btn, btnDown); buttonPressRects[1] = setRectAction(square, squareDown); buttonPressRects[2] = setRectAction(slider, sliderDown); buttonReleaseRects = malloc(2 * sizeof(DAActionRect)); buttonReleaseRects[0] = setRectAction(btn, btnUp); buttonReleaseRects[1] = setRectAction(slider, sliderUp); mouseMoveRects = malloc(sizeof(DAActionRect)); mouseMoveRects[0] = setRectAction(slider, sliderMove); mouseEnterRects = malloc(sizeof(DAActionRect)); mouseEnterRects[0] = setRectAction(slider, sliderEnter); mouseLeaveRects = malloc(2 * sizeof(DAActionRect)); mouseLeaveRects[0] = setRectAction(btn, btnLeave); mouseLeaveRects[1] = setRectAction(slider, sliderLeave); /* XXX: make action rectangles available outside main() * ...libDockapp should be able to do this... (reminder) */ actionRects = malloc(6 * sizeof(DAActionRect *)); actionRects[0] = buttonPressRects; actionRects[1] = buttonReleaseRects; actionRects[2] = mouseMoveRects; actionRects[3] = mouseEnterRects; actionRects[4] = mouseLeaveRects; actionRects[5] = NULL; /* provide standard command-line options */ DAParseArguments( argc, argv, /* Where the options come from */ NULL, 0, /* Our list with options - none as you can see */ "This is the help text for the rectangle example of how to " "use libDockapp.\n", "Rectangle example version 1.0"); /* Tell libdockapp what version we expect it to be, so that you can use * older programs with newer versions of libdockapp with less risc for * compatibility problems. */ DASetExpectedVersion(20030126); /* Initialize a dockapp */ DAInitialize( "", /* Use default display */ "daRectangleExample", /* WM_CLASS hint; don't use chars in [.?*: ] */ 48, 48, /* geometry of dockapp internals */ argc, argv /* (needed internally) */ ); /* Create a pixmap to draw on, and to display */ pixmap = DAMakePixmap(); /* size == dockapp geometry (48,48) */ colors = setGCs(pixmap); XFillRectangle(DADisplay, pixmap, DAClearGC, 0, 0, 48, 48); XClearWindow(DADisplay, DAWindow); /* Make a "Region" from the shapes we have */ XUnionRectWithRegion(&btn, clipRegion, clipRegion); XUnionRectWithRegion(&square, clipRegion, clipRegion); XUnionRectWithRegion(&slider, clipRegion, clipRegion); /* Make this region a window shape mask */ XShapeCombineRegion(DADisplay, DAWindow, ShapeBounding, 0, 0, clipRegion, ShapeSet); /* We don't need the region anymore (it is copied by XShapeCombineRegion). * XXX: That's not certain, it is not documented. XSetRegion does so, * though, so it is a likely assumption that it does copy. */ XDestroyRegion(clipRegion); /* The cursor we want to use. * Specify 'None' for the default, * or one from X11/cursorfont.h */ pointer = XCreateFontCursor(DADisplay, XC_based_arrow_up); XDefineCursor(DADisplay, DAWindow, pointer); /* a square with an image that changes when clicked (A button). */ createBtn(btn); /* a square that shows the number of the mouse-button pressed on click. */ createSquare(square); /* a slider a using two dashed line GC's. */ createSlider(slider); /* Tell libdockapp this is the pixmap that we want to show */ DASetPixmap(pixmap); /* Process events every 100ms */ DASetTimeout(100); /* set event callbacks */ DASetCallbacks(&eventCallbacks); /* Display the pixmap we said it to show */ DAShow(); /* Process events and keep the dockapp running */ DAEventLoop(); return 0; }