[PATCH 4/6] Xi: add XATOM_FLOAT to server-defined properties.
Peter Hutterer
peter.hutterer at who-t.net
Thu Dec 4 22:42:36 PST 2008
This property is used to denote type float for input properties. Such
properties can be accessed easily through the XIPropToFloat() function.
Code originally written by Simon Thum.
Signed-off-by: Peter Hutterer <peter.hutterer at redhat.com>
---
Xi/xiproperty.c | 43 +++++++++++++++++++++++++++++++++++++++++-
include/exevents.h | 5 ++++
include/xserver-properties.h | 3 ++
3 files changed, 50 insertions(+), 1 deletions(-)
diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index 5f435ff..cdfa25f 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -49,7 +49,8 @@ static struct dev_properties
Atom type;
char *name;
} dev_properties[] = {
- {0, XI_PROP_ENABLED}
+ {0, XI_PROP_ENABLED},
+ {0, XATOM_FLOAT}
};
static long XIPropHandlerID = 1;
@@ -126,6 +127,46 @@ XIPropToInt(XIPropertyValuePtr val, int **buf_return)
return Success;
}
+/**
+ * Convert the given property's value(s) into floats and store them in @buf.
+ * If @buf is NULL, memory is allocated automatically and must be freed by the
+ * caller.
+ *
+ * Possible errors returned:
+ * Success
+ * BadMatch ... Wrong atom type, atom is not XA_INTEGER
+ * BadValue ... Wrong format, format is not 32
+ * BadAlloc ... NULL passed as buffer and allocation failed.
+ *
+ * @return Success or the error code if an error occured.
+ */
+_X_EXPORT int
+XIPropToFloat(XIPropertyValuePtr val, float **buf_return)
+{
+ int i;
+ float *buf;
+
+ if (!val->type || val->type != XIGetKnownProperty(XATOM_FLOAT))
+ return BadMatch;
+
+ if (val->format != 32)
+ return BadValue;
+
+ buf = *buf_return;
+ if (!buf)
+ {
+ buf = xcalloc(val->size, sizeof(float));
+ if (!buf)
+ return BadAlloc;
+
+ *buf_return = buf;
+ }
+
+ for (i = 0; i < val->size; i++)
+ buf[i] = (*(float*)val->data);
+
+ return Success;
+}
/**
* Init those properties that are allocated by the server and most likely used
diff --git a/include/exevents.h b/include/exevents.h
index d5c8c01..936a0d2 100644
--- a/include/exevents.h
+++ b/include/exevents.h
@@ -256,4 +256,9 @@ extern _X_EXPORT int XIPropToInt(
int **buf_return
);
+extern _X_EXPORT int XIPropToFloat(
+ XIPropertyValuePtr val,
+ float **buf_return
+);
+
#endif /* EXEVENTS_H */
diff --git a/include/xserver-properties.h b/include/xserver-properties.h
index 4d602b5..0a0e849 100644
--- a/include/xserver-properties.h
+++ b/include/xserver-properties.h
@@ -26,6 +26,9 @@
#ifndef _XSERVER_PROPERTIES_H_
#define _XSERVER_PROPERTIES_H_
+/* Type for a 4 byte float number */
+#define XATOM_FLOAT "FLOAT"
+
/* BOOL. 0 - device disabled, 1 - device enabled */
#define XI_PROP_ENABLED "Device Enabled"
--
1.6.0.4
More information about the xorg
mailing list