/* Create a new shaped pixmap using specified method */ DAShapedPixmap* _daMakeShapedPixmap(daShapeSource source, char **data) { Bool success; DAShapedPixmap *dasp = malloc(sizeof(DAShapedPixmap)); if (dasp == NULL) return NULL; memset(dasp, 0, sizeof(DAShapedPixmap)); if (source == daShapeSourceData) success = DAMakePixmapFromData(data, &dasp->pixmap, &dasp->shape, &dasp->geometry.width, &dasp->geometry.height); else success = DAMakePixmapFromFile((char*)data, &dasp->pixmap, &dasp->shape, &dasp->geometry.width, &dasp->geometry.height); if (!success) return NULL; setGCs(dasp); return dasp; }
/* 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) { /* 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; }