File indexing completed on 2024-12-22 05:17:16
0001 /* 0002 * This file is part of the KDE wacomtablet project. For copyright 0003 * information and license terms see the AUTHORS and COPYING files 0004 * in the top-level directory of this distribution. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include "x11input.h" 0021 0022 #include <QList> 0023 0024 #include "private/qtx11extras_p.h" 0025 0026 #include <xorg/wacom-properties.h> 0027 0028 #include <X11/extensions/XInput.h> 0029 0030 using namespace Wacom; 0031 0032 const QString X11Input::PROPERTY_DEVICE_PRODUCT_ID = QLatin1String("Device Product ID"); 0033 const QString X11Input::PROPERTY_DEVICE_NODE = QLatin1String("Device Node"); 0034 const QString X11Input::PROPERTY_TRANSFORM_MATRIX = QLatin1String("Coordinate Transformation Matrix"); 0035 const QString X11Input::PROPERTY_WACOM_SERIAL_IDS = QLatin1String(WACOM_PROP_SERIALIDS); 0036 const QString X11Input::PROPERTY_WACOM_TABLET_AREA = QLatin1String(WACOM_PROP_TABLET_AREA); 0037 const QString X11Input::PROPERTY_WACOM_TOOL_TYPE = QLatin1String(WACOM_PROP_TOOL_TYPE); 0038 0039 bool X11Input::findDevice(const QString &deviceName, X11InputDevice &device) 0040 { 0041 if (deviceName.isEmpty()) { 0042 return false; 0043 } 0044 0045 bool found = false; 0046 int ndevices = 0; 0047 Display *display = QX11Info::display(); 0048 0049 // Don't port this to xcb, not supported yet. 0050 XDeviceInfo *info = XListInputDevices(display, &ndevices); 0051 0052 for (int i = 0; i < ndevices; ++i) { 0053 if (deviceName.compare(QLatin1String(info[i].name), Qt::CaseInsensitive) == 0) { 0054 found = device.open(info[i].id, QLatin1String(info[i].name)); 0055 break; 0056 } 0057 } 0058 0059 if (info) { 0060 XFreeDeviceList(info); 0061 } 0062 0063 return found; 0064 } 0065 0066 void X11Input::scanDevices(X11InputVisitor &visitor) 0067 { 0068 int ndevices = 0; 0069 Display *dpy = QX11Info::display(); 0070 0071 XDeviceInfo *info = XListInputDevices(dpy, &ndevices); 0072 0073 for (int i = 0; i < ndevices; ++i) { 0074 X11InputDevice device(info[i].id, QLatin1String(info[i].name)); 0075 0076 if (visitor.visit(device)) { 0077 break; 0078 } 0079 } 0080 0081 if (info) { 0082 XFreeDeviceList(info); 0083 } 0084 }