libdockapp supports shaped dockapps with the DASetShape() function, but this
function requires as input a bitmap. Previously, there was no support for
creating such a bitmap from XBM data without using Xlib directly.
We add two functions, DAMakeShapeFromData(), which is a wrapper around
XCreateBitmapFromData and allows developers to #include XBM data, and
DAMakeShapeFromFile(), which is a wrapper around XReadBitmapfile and
lets developers specify the path to an XBM file.
---
libdockapp/src/dapixmap.c | 35 +++++++++++++++++++++++++++++++++++
libdockapp/src/dockapp.h | 12 ++++++++++++
2 files changed, 47 insertions(+)
diff --git a/libdockapp/src/dapixmap.c b/libdockapp/src/dapixmap.c
index 58733b2..7b37f65 100644
--- a/libdockapp/src/dapixmap.c
+++ b/libdockapp/src/dapixmap.c
@@ -88,6 +88,41 @@ DAMakeShape(void)
1));
}
+Pixmap
+DAMakeShapeFromData(char *data, unsigned int width, unsigned int height)
+{
+ return (XCreateBitmapFromData(DADisplay, DAWindow, data,
+ width, height));
+}
+
+Pixmap
+DAMakeShapeFromFile(char *filename)
+{
+ Pixmap shape;
+ unsigned int width, height;
+ int result, x_hot, y_hot;
+
+ result = XReadBitmapFile(DADisplay, DAWindow, filename, &width, &height,
+ &shape, &x_hot, &y_hot);
+
+ switch (result) {
+ case BitmapOpenFailed:
+ DAWarning("bitmap file %s cannot be opened.", filename);
+ break;
+
+ case BitmapFileInvalid:
+ DAWarning("bitmap file %s not valid.", filename);
+ break;
+
+ case BitmapNoMemory:
+ DAWarning("insufficient memory to open bitmap file %s.",
+ filename);
+ break;
+ }
+
+ return shape;
+}
+
Bool
DAMakePixmapFromData(char **data, Pixmap *pixmap, Pixmap *mask,
unsigned short *width, unsigned short *height)
diff --git a/libdockapp/src/dockapp.h b/libdockapp/src/dockapp.h
index 18442b1..a16ee1d 100644
--- a/libdockapp/src/dockapp.h
+++ b/libdockapp/src/dockapp.h
@@ -264,6 +264,18 @@ Pixmap DAMakePixmap(void);
*/
Pixmap DAMakeShape(void);
+/*
+ * DAMakeShapeFromData-
+ * Creates a shape pixmap suitable for use with DASetShape() from XBM data.
+ */
+Pixmap DAMakeShapeFromData(char *data, unsigned int width, unsigned int
height);
+
+/*
+ * DAMakeShapeFromFile-
+ * Creates a shape pixmap suitable for use with DASetShape() from an
+ * XBM file.
+ */
+Pixmap DAMakeShapeFromFile(char *filename);
/*
* DAMakePixmapFromData-
--
2.11.0
--
To unsubscribe, send mail to [email protected].