]>
Commit | Line | Data |
---|---|---|
ae2945da AM |
1 | From a48c81dcdf569a3f634ac23e08d2491354de6a36 Mon Sep 17 00:00:00 2001 |
2 | From: Peter Hutterer <peter.hutterer@who-t.net> | |
3 | Date: Fri, 5 Dec 2008 16:24:57 +1000 | |
4 | Subject: [PATCH] Xi: add XATOM_FLOAT to server-defined properties. | |
5 | ||
6 | This property is used to denote type float for input properties. Such | |
7 | properties can be accessed easily through the XIPropToFloat() function. | |
8 | ||
9 | Code originally written by Simon Thum. | |
10 | ||
11 | Signed-off-by: Peter Hutterer <peter.hutterer@redhat.com> | |
12 | --- | |
13 | Xi/xiproperty.c | 55 +++++++++++++++++++++++++++++++++++++++++- | |
14 | include/exevents.h | 6 ++++ | |
15 | include/xserver-properties.h | 4 +++ | |
16 | 3 files changed, 64 insertions(+), 1 deletions(-) | |
17 | ||
18 | diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c | |
19 | index cd9805a..6da8424 100644 | |
20 | --- a/Xi/xiproperty.c | |
21 | +++ b/Xi/xiproperty.c | |
22 | @@ -49,7 +49,8 @@ static struct dev_properties | |
23 | Atom type; | |
24 | char *name; | |
25 | } dev_properties[] = { | |
26 | - {0, XI_PROP_ENABLED} | |
27 | + {0, XI_PROP_ENABLED}, | |
28 | + {0, XATOM_FLOAT} | |
29 | }; | |
30 | ||
31 | static long XIPropHandlerID = 1; | |
32 | @@ -137,6 +138,58 @@ XIPropToInt(XIPropertyValuePtr val, int *nelem_return, int **buf_return) | |
33 | return Success; | |
34 | } | |
35 | ||
36 | +/** | |
37 | + * Convert the given property's value(s) into @nelem_return float values and | |
38 | + * store them in @buf_return. If @nelem_return is larger than the number of | |
39 | + * values in the property, @nelem_return is set to the number of values in the | |
40 | + * property. | |
41 | + * | |
42 | + * If *@buf_return is NULL and @nelem_return is 0, memory is allocated | |
43 | + * automatically and must be freed by the caller. | |
44 | + * | |
45 | + * Possible errors returned: | |
46 | + * Success | |
47 | + * BadMatch ... Wrong atom type, atom is not XA_FLOAT | |
48 | + * BadValue ... Wrong format, format is not 32 | |
49 | + * BadAlloc ... NULL passed as buffer and allocation failed. | |
50 | + * BadLength ... @buff is NULL but @nelem_return is non-zero. | |
51 | + * | |
52 | + * @param val The property value | |
53 | + * @param nelem_return The maximum number of elements to return. | |
54 | + * @param buf_return Pointer to an array of at least @nelem_return values. | |
55 | + * @return Success or the error code if an error occured. | |
56 | + */ | |
57 | +_X_EXPORT int | |
58 | +XIPropToFloat(XIPropertyValuePtr val, int *nelem_return, float **buf_return) | |
59 | +{ | |
60 | + int i; | |
61 | + float *buf; | |
62 | + | |
63 | + if (!val->type || val->type != XIGetKnownProperty(XATOM_FLOAT)) | |
64 | + return BadMatch; | |
65 | + | |
66 | + if (val->format != 32) | |
67 | + return BadValue; | |
68 | + if (!*buf_return && *nelem_return) | |
69 | + return BadLength; | |
70 | + | |
71 | + buf = *buf_return; | |
72 | + | |
73 | + if (!buf && !(*nelem_return)) | |
74 | + { | |
75 | + buf = xcalloc(val->size, sizeof(float)); | |
76 | + if (!buf) | |
77 | + return BadAlloc; | |
78 | + *buf_return = buf; | |
79 | + *nelem_return = val->size; | |
80 | + } else if (val->size < *nelem_return) | |
81 | + *nelem_return = val->size; | |
82 | + | |
83 | + for (i = 0; i < val->size && i < *nelem_return; i++) | |
84 | + buf[i] = ((float*)val->data)[i]; | |
85 | + | |
86 | + return Success; | |
87 | +} | |
88 | ||
89 | /** | |
90 | * Init those properties that are allocated by the server and most likely used | |
91 | diff --git a/include/exevents.h b/include/exevents.h | |
92 | index 485347b..2504baf 100644 | |
93 | --- a/include/exevents.h | |
94 | +++ b/include/exevents.h | |
95 | @@ -257,4 +257,10 @@ extern _X_EXPORT int XIPropToInt( | |
96 | int **buf_return | |
97 | ); | |
98 | ||
99 | +extern _X_EXPORT int XIPropToFloat( | |
100 | + XIPropertyValuePtr val, | |
101 | + int *nelem_return, | |
102 | + float **buf_return | |
103 | +); | |
104 | + | |
105 | #endif /* EXEVENTS_H */ | |
106 | diff --git a/include/xserver-properties.h b/include/xserver-properties.h | |
107 | index 4d602b5..f8aeab6 100644 | |
108 | --- a/include/xserver-properties.h | |
109 | +++ b/include/xserver-properties.h | |
110 | @@ -26,6 +26,10 @@ | |
111 | #ifndef _XSERVER_PROPERTIES_H_ | |
112 | #define _XSERVER_PROPERTIES_H_ | |
113 | ||
114 | +/* Type for a 4 byte float. Storage format IEEE 754 in client's default | |
115 | + * byte-ordering. */ | |
116 | +#define XATOM_FLOAT "FLOAT" | |
117 | + | |
118 | /* BOOL. 0 - device disabled, 1 - device enabled */ | |
119 | #define XI_PROP_ENABLED "Device Enabled" | |
120 | ||
121 | -- | |
122 | 1.6.0.6 | |
123 |