Changeset View
Changeset View
Standalone View
Standalone View
kcms/touchpadx/src/backends/x11/propertyinfo.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2013 Alexander Mezin <mezin.alexander@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #include "propertyinfo.h" | ||||
20 | | ||||
21 | #include <QVariant> | ||||
22 | | ||||
23 | #include <X11/Xlib.h> | ||||
24 | #include <X11/Xatom.h> | ||||
25 | #include <X11/extensions/XInput2.h> | ||||
26 | | ||||
27 | void XDeleter(void* p) | ||||
28 | { | ||||
29 | if (p) { | ||||
30 | XFree(p); | ||||
31 | } | ||||
32 | } | ||||
33 | | ||||
34 | PropertyInfo::PropertyInfo() : | ||||
35 | type(0), format(0), nitems(0), f(0), i(0), b(0), | ||||
36 | display(0), device(0), prop(0) | ||||
37 | { | ||||
38 | } | ||||
39 | | ||||
40 | PropertyInfo::PropertyInfo(Display *display, int device, Atom prop, Atom floatType) | ||||
41 | : type(0), format(0), nitems(0), f(0), i(0), b(0), | ||||
42 | display(display), device(device), prop(prop) | ||||
43 | { | ||||
44 | unsigned char *dataPtr = 0; | ||||
45 | unsigned long bytes_after; | ||||
46 | XIGetProperty(display, device, prop, 0, 1000, False, | ||||
47 | AnyPropertyType, &type, &format, &nitems, | ||||
48 | &bytes_after, &dataPtr); | ||||
49 | data = QSharedPointer<unsigned char>(dataPtr, XDeleter); | ||||
50 | | ||||
51 | if (format == CHAR_BIT && type == XA_INTEGER) { | ||||
52 | b = reinterpret_cast<char *>(dataPtr); | ||||
53 | } | ||||
54 | if (format == sizeof(int) * CHAR_BIT && | ||||
55 | (type == XA_INTEGER || type == XA_CARDINAL)) | ||||
56 | { | ||||
57 | i = reinterpret_cast<int *>(dataPtr); | ||||
58 | } | ||||
59 | if (format == sizeof(float) * CHAR_BIT && | ||||
60 | floatType && type == floatType) | ||||
61 | { | ||||
62 | f = reinterpret_cast<float *>(dataPtr); | ||||
63 | } | ||||
64 | } | ||||
65 | | ||||
66 | QVariant PropertyInfo::value(unsigned offset) const | ||||
67 | { | ||||
68 | QVariant v; | ||||
69 | if (offset >= nitems) { | ||||
70 | return v; | ||||
71 | } | ||||
72 | | ||||
73 | if (b) { | ||||
74 | v = QVariant(static_cast<int>(b[offset])); | ||||
75 | } | ||||
76 | if (i) { | ||||
77 | v = QVariant(i[offset]); | ||||
78 | } | ||||
79 | if (f) { | ||||
80 | v = QVariant(f[offset]); | ||||
81 | } | ||||
82 | | ||||
83 | return v; | ||||
84 | } | ||||
85 | | ||||
86 | void PropertyInfo::set() | ||||
87 | { | ||||
88 | XIChangeProperty(display, device, prop, type, format, | ||||
89 | XIPropModeReplace, data.data(), nitems); | ||||
90 | } |