File indexing completed on 2024-05-19 04:24:50
0001 /* 0002 * SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org> 0003 * 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "KoInputDevice.h" 0008 0009 class Q_DECL_HIDDEN KoInputDevice::Private 0010 { 0011 public: 0012 Private(QTabletEvent::TabletDevice d, QTabletEvent::PointerType p, qint64 id, bool m) 0013 : device(d), 0014 pointer(p), 0015 uniqueTabletId(id), 0016 mouse(m) { 0017 } 0018 QTabletEvent::TabletDevice device; 0019 QTabletEvent::PointerType pointer; 0020 qint64 uniqueTabletId; 0021 bool mouse; 0022 }; 0023 0024 KoInputDevice::KoInputDevice(QTabletEvent::TabletDevice device, QTabletEvent::PointerType pointer, qint64 uniqueTabletId) 0025 : d(new Private(device, pointer, uniqueTabletId, false)) 0026 { 0027 } 0028 0029 KoInputDevice::KoInputDevice() 0030 : d(new Private(QTabletEvent::NoDevice, QTabletEvent::UnknownPointer, -1, true)) 0031 { 0032 } 0033 0034 KoInputDevice::KoInputDevice(const KoInputDevice &other) 0035 : d(new Private(other.d->device, other.d->pointer, other.d->uniqueTabletId, other.d->mouse)) 0036 { 0037 } 0038 0039 0040 KoInputDevice::~KoInputDevice() 0041 { 0042 delete d; 0043 } 0044 0045 QTabletEvent::TabletDevice KoInputDevice::device() const 0046 { 0047 return d->device; 0048 } 0049 0050 QTabletEvent::PointerType KoInputDevice::pointer() const 0051 { 0052 return d->pointer; 0053 } 0054 0055 qint64 KoInputDevice::uniqueTabletId() const 0056 { 0057 return d->uniqueTabletId; 0058 } 0059 0060 bool KoInputDevice::isMouse() const 0061 { 0062 // sometimes, the system gives us tablet events with NoDevice or UnknownPointer. This is 0063 // likely an XInput2 bug. However, assuming that if cannot identify the tablet device we've 0064 // actually got a mouse is reasonable. See https://bugs.kde.org/show_bug.cgi?id=283130. 0065 return d->mouse || d->device == QTabletEvent::NoDevice || d->pointer == QTabletEvent::UnknownPointer; 0066 } 0067 0068 0069 bool KoInputDevice::operator==(const KoInputDevice &other) const 0070 { 0071 return d->device == other.d->device && d->pointer == other.d->pointer && 0072 d->uniqueTabletId == other.d->uniqueTabletId && d->mouse == other.d->mouse; 0073 } 0074 0075 KoInputDevice & KoInputDevice::operator=(const KoInputDevice & other) 0076 { 0077 d->device = other.d->device; 0078 d->pointer = other.d->pointer; 0079 d->uniqueTabletId = other.d->uniqueTabletId; 0080 d->mouse = other.d->mouse; 0081 return *this; 0082 } 0083 0084 // static 0085 KoInputDevice KoInputDevice::invalid() 0086 { 0087 KoInputDevice id(QTabletEvent::NoDevice, QTabletEvent::UnknownPointer); 0088 return id; 0089 } 0090 0091 0092 0093 KoInputDevice KoInputDevice::mouse() 0094 { 0095 KoInputDevice id; 0096 return id; 0097 } 0098 0099 // static 0100 KoInputDevice KoInputDevice::stylus() 0101 { 0102 KoInputDevice id(QTabletEvent::Stylus, QTabletEvent::Pen); 0103 return id; 0104 } 0105 0106 // static 0107 KoInputDevice KoInputDevice::eraser() 0108 { 0109 KoInputDevice id(QTabletEvent::Stylus, QTabletEvent::Eraser); 0110 return id; 0111 } 0112 0113 QDebug operator<<(QDebug dbg, const KoInputDevice &device) 0114 { 0115 if (device.isMouse()) 0116 dbg.nospace() << "mouse"; 0117 else { 0118 switch (device.pointer()) { 0119 case QTabletEvent::UnknownPointer: 0120 dbg.nospace() << "unknown pointer"; 0121 break; 0122 case QTabletEvent::Pen: 0123 dbg.nospace() << "pen"; 0124 break; 0125 case QTabletEvent::Cursor: 0126 dbg.nospace() << "cursor"; 0127 break; 0128 case QTabletEvent::Eraser: 0129 dbg.nospace() << "eraser"; 0130 break; 0131 } 0132 switch(device.device()) { 0133 case QTabletEvent::NoDevice: 0134 dbg.space() << "no device"; 0135 break; 0136 case QTabletEvent::Puck: 0137 dbg.space() << "puck"; 0138 break; 0139 case QTabletEvent::Stylus: 0140 dbg.space() << "stylus"; 0141 break; 0142 case QTabletEvent::Airbrush: 0143 dbg.space() << "airbrush"; 0144 break; 0145 case QTabletEvent::FourDMouse: 0146 dbg.space() << "four2mouse"; 0147 break; 0148 case QTabletEvent::RotationStylus: 0149 dbg.space() << "rotationstylus"; 0150 break; 0151 case QTabletEvent::XFreeEraser: 0152 dbg.space() << "XFreeEraser"; 0153 break; 0154 } 0155 dbg.space() << "(id: " << device.uniqueTabletId() << ")"; 0156 } 0157 return dbg.space(); 0158 }