/* touchscreen-calibrator Copyright (C) 2019 Enrique Medina Gremaldos This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "x11device.hpp" #include #include #include #include #include using namespace std; X11InputDevice::X11InputDevice(XID id, QString name) { m_id=id; setName(name); } X11InputDevice::~X11InputDevice() { } XID X11InputDevice::xid() { return m_id; } void X11InputDevice::resetMatrix() { QMatrix3x3 identity; setMatrix(identity); } void X11InputDevice::restoreMatrix() { setMatrix(m_oldMatrix); } void X11InputDevice::setMatrix(QMatrix3x3& m) { m_oldMatrix=getMatrix(); Atom propMatrix; Atom reqType; int format; Display* display = XOpenDisplay(0); propMatrix=XInternAtom (display, "Coordinate Transformation Matrix", False); reqType=XInternAtom (display, "FLOAT", False); XIChangeProperty(display, m_id, propMatrix, reqType, 32, PropModeReplace, (unsigned char*)m.data(), 9); XCloseDisplay(display); } QMatrix3x3 X11InputDevice::getMatrix() { QMatrix3x3 matrix; Atom propMatrix; Atom realType; Atom reqType; int realFormat; unsigned long nitems; unsigned long bytesafter; unsigned char* property; Display* display = XOpenDisplay(0); propMatrix=XInternAtom (display, "Coordinate Transformation Matrix", False); reqType=XInternAtom (display, "FLOAT", False); Status status = XIGetProperty(display,m_id, propMatrix, 0,9, False, AnyPropertyType, &realType, &realFormat, &nitems, &bytesafter, &property ); if (status!=Success) { throw runtime_error("Failed to get transformation matrix from device"); } if (realType!=reqType or realFormat!=32) { throw runtime_error("Unexpected read from transformation matrix"); } matrix = QMatrix3x3((float*)property); XFree(property); XCloseDisplay(display); return matrix; } void X11InputDevice::calibrate(QList& points) { if (points.size()<8) { throw runtime_error("No enough calibration points"); } QPolygonF source; QPolygonF dest; source<