diff --git a/autotests/faketablet/setmapping.cpp b/autotests/faketablet/setmapping.cpp index a0d3175..66c3988 100644 --- a/autotests/faketablet/setmapping.cpp +++ b/autotests/faketablet/setmapping.cpp @@ -1,62 +1,81 @@ +/* + * This file is part of the KDE wacomtablet project. For copyright + * information and license terms see the AUTHORS and COPYING files + * in the top-level directory of this distribution. + * + * 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 2 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 #include "kded/xinputadaptor.h" #include "kded/xsetwacomadaptor.h" #include "common/screenspace.h" #include "common/property.h" #include #include #include #include using namespace Wacom; class Task : public QObject { Q_OBJECT public: Task(QObject *parent = 0) : QObject(parent) {} public slots: void run() { QString device = QString::fromLatin1("Wacom Bamboo One S Pen stylus"); Wacom::XinputAdaptor xi(device); XsetwacomAdaptor xsetwacom(device); auto defmode = xsetwacom.getProperty(Property::Mode); //auto defmapping = xi.getProperty(Property::ScreenSpace); Wacom::ScreenSpace space(QLatin1String("speedx0.5x0.5")); xsetwacom.setProperty(Property::Mode, QString::fromLatin1("relative")); xi.setProperty(Property::ScreenSpace, space.toString()); std::cout << "Mapping set\n"; QThread::sleep(10); xsetwacom.setProperty(Property::Mode, defmode); std::cout << "Mapping reset\n"; emit finished(); } signals: void finished(); }; int main( int argc, char **argv ) { QApplication a(argc, argv); Task *task = new Task(&a); QObject::connect(task, SIGNAL(finished()), &a, SLOT(quit())); QTimer::singleShot(0, task, SLOT(run())); return a.exec(); } #include "setmapping.moc" diff --git a/src/common/screenspace.cpp b/src/common/screenspace.cpp index 6974c48..f1c2160 100644 --- a/src/common/screenspace.cpp +++ b/src/common/screenspace.cpp @@ -1,175 +1,168 @@ /* * This file is part of the KDE wacomtablet project. For copyright * information and license terms see the AUTHORS and COPYING files * in the top-level directory of this distribution. * * 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 2 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 "screenspace.h" #include "logging.h" #include "x11info.h" using namespace Wacom; namespace Wacom { static const QString DESKTOP_STRING = QLatin1String("desktop"); static const QString AREA_STRING = QLatin1String("area"); static const QString SPEED_STRING = QLatin1String("speed"); } ScreenSpace::ScreenSpace() { } ScreenSpace::ScreenSpace(const QString &screenSpaceString) { if (screenSpaceString == DESKTOP_STRING) { _type = ScreenSpaceType::Desktop; return; } QStringList tokens = screenSpaceString.split(QChar::fromLatin1('x')); if (tokens.size() == 5 && tokens.at(0) == AREA_STRING) { _type = ScreenSpaceType::Area; _area = QRect( tokens.at(1).toInt(), tokens.at(2).toInt(), tokens.at(3).toInt(), tokens.at(4).toInt() ); return; } if (tokens.size() == 3 && tokens.at(0) == SPEED_STRING) { _type = ScreenSpaceType::ArbitraryTranslationMatrix; _speed = QPointF( tokens.at(1).toDouble(), tokens.at(2).toDouble() ); return; } _type = ScreenSpaceType::Output; _output = screenSpaceString; } ScreenSpace::~ScreenSpace() { } bool ScreenSpace::operator==(const ScreenSpace& screenSpace) const { if (getType() != screenSpace.getType()) return false; switch (getType()) { case Wacom::ScreenSpace::ScreenSpaceType::Output: return _output == screenSpace._output; case Wacom::ScreenSpace::ScreenSpaceType::Area: return _area == screenSpace._area; case Wacom::ScreenSpace::ScreenSpaceType::ArbitraryTranslationMatrix: return _speed == screenSpace._speed; case Wacom::ScreenSpace::ScreenSpaceType::Desktop: default: return true; } } - -bool ScreenSpace::operator!=(const ScreenSpace& screenSpace) const -{ - return (!operator==(screenSpace)); -} - - const ScreenSpace ScreenSpace::desktop() { return ScreenSpace(DESKTOP_STRING); } bool ScreenSpace::isDesktop() const { return _type == ScreenSpaceType::Desktop; } bool ScreenSpace::isMonitor() const { return _type == ScreenSpaceType::Output; } const ScreenSpace ScreenSpace::monitor(QString output) { return ScreenSpace(output); } const QString ScreenSpace::toString() const { switch (getType()) { case ScreenSpaceType::Desktop: return DESKTOP_STRING; case ScreenSpaceType::Output: return _output; case ScreenSpaceType::Area: return QString::fromLatin1("%1x%2x%3x%4x%5") .arg(AREA_STRING).arg(_area.left()).arg(_area.top()).arg(_area.width()).arg(_area.height()); case ScreenSpaceType::ArbitraryTranslationMatrix: return QString::fromLatin1("%1x%2x%3") .arg(SPEED_STRING).arg(_speed.x()).arg(_speed.y()); default: qCDebug(COMMON) << "Broken ScreenSpace serialized"; return DESKTOP_STRING; } } ScreenSpace ScreenSpace::next() const { ScreenSpace nextScreen = ScreenSpace::desktop(); if (getType() != ScreenSpaceType::Output) { nextScreen = ScreenSpace::monitor(X11Info::getPrimaryScreenName()); } else { auto nextScreenName = X11Info::getNextScreenName(toString()); if (nextScreenName == X11Info::getPrimaryScreenName()) { nextScreen = ScreenSpace::desktop(); } else { nextScreen = ScreenSpace::monitor(nextScreenName); } } return nextScreen; } ScreenSpace::ScreenSpaceType ScreenSpace::getType() const { return _type; } QPointF ScreenSpace::getSpeed() const { return _speed; } QRect ScreenSpace::getArea() const { return _area; } diff --git a/src/common/screenspace.h b/src/common/screenspace.h index 81749b9..c5fa1c3 100644 --- a/src/common/screenspace.h +++ b/src/common/screenspace.h @@ -1,89 +1,85 @@ /* * This file is part of the KDE wacomtablet project. For copyright * information and license terms see the AUTHORS and COPYING files * in the top-level directory of this distribution. * * 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 2 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 . */ #ifndef SCREENSPACE_H #define SCREENSPACE_H #include #include namespace Wacom { -class ScreenSpacePrivate; - /** * @brief Specifies screen area that is used for mapping * * Stores either "desktop", specific output, arbitrary area * or translation matrix (for relative mode). * When set as a device property, is converted into translation matrix. */ class ScreenSpace { public: enum class ScreenSpaceType { Desktop, Output, Area, ArbitraryTranslationMatrix, }; ScreenSpace(); ScreenSpace(const QString& screenSpaceString); virtual ~ScreenSpace(); bool operator== (const ScreenSpace& screenSpace) const; - bool operator!= (const ScreenSpace& screenSpace) const; - static const ScreenSpace desktop(); bool isDesktop() const; bool isMonitor() const; static const ScreenSpace monitor(QString output); const QString toString() const; /** * This function allows to cycle through all existing screen spaces in a loop, * which means every individual connected screen and "desktop" (whole screen) * * @return Next ScreenSpace after this */ ScreenSpace next() const; ScreenSpaceType getType() const; QPointF getSpeed() const; QRect getArea() const; private: ScreenSpaceType _type = ScreenSpaceType::Desktop; QString _output; QRect _area; QPointF _speed; }; // CLASS } // NAMESPACE #endif // HEADER PROTECTION