aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lead.cpp160
-rw-r--r--src/lead.h67
-rw-r--r--src/main.cpp37
-rw-r--r--src/sensor.cpp65
-rw-r--r--src/sensor.h54
5 files changed, 383 insertions, 0 deletions
diff --git a/src/lead.cpp b/src/lead.cpp
new file mode 100644
index 0000000..cd47b19
--- /dev/null
+++ b/src/lead.cpp
@@ -0,0 +1,160 @@
+/*
+MIT License
+
+Copyright (c) 2017 Noah Andreas
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+
+#include "lead.h"
+#include "sensor.h"
+#include <QDebug>
+#include <QScreen>
+#include <QFileSystemWatcher>
+
+
+namespace kernladung {
+
+
+Lead::Lead(int &argc, char** argv) :
+ QApplication(argc, argv),
+ settings("kernladung", "lead"),
+ watcher()
+{
+ loadScreens();
+ watchSettings();
+}
+
+
+Lead::~Lead()
+{
+ qDeleteAll(sensors);
+}
+
+
+void
+Lead::watchSettings()
+{
+ watcher.addPath(settings.fileName());
+
+ connect(&watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString)));
+}
+
+
+void
+Lead::fileChanged(QString fileName)
+{
+ qDebug() << "kernladung::Lead::fileChanged() fileName: " << fileName;
+
+ // this reloads the settings from the file
+ settings.sync();
+
+ // some editors dont update but delete/create the config file, in this
+ // case our watcher loses the file so we have to add it again
+ watcher.addPath( fileName );
+
+ // simply reload everything
+ reloadScreens();
+}
+
+
+void
+Lead::screenAdded(QScreen* screen)
+{
+ loadScreen(screen);
+}
+
+
+void
+Lead::screenRemoved(QScreen* screen)
+{
+ // thats the easiest way
+ reloadScreens();
+}
+
+
+void
+Lead::reloadScreens()
+{
+ qDeleteAll(sensors);
+ sensors.clear();
+
+ loadScreens();
+}
+
+
+void
+Lead::loadScreens()
+{
+ foreach (QScreen* screen, screens())
+ {
+ loadScreen(screen);
+ }
+}
+
+
+void
+Lead::loadScreen(QScreen* screen)
+{
+ qDebug() << "kernladung::Lead::loadScreen() " << screen->name();
+
+ QRect rec = screen->geometry();
+
+ loadSensor(screen, "top", rec.width() / 3, 0, rec.width() / 3, 10);
+ loadSensor(screen, "right", rec.width() - 1, rec.height() / 3, 1, rec.height() / 3);
+ loadSensor(screen, "bottom", rec.width() / 3, rec.height() - 1, rec.width() / 3, 1);
+ loadSensor(screen, "left", 0, rec.height() / 3, 1, rec.height() / 3);
+ loadSensor(screen, "topLeft", 0, 0, 1, 1);
+ loadSensor(screen, "topRight", rec.width() - 1, 0, 1, 1);
+ loadSensor(screen, "bottomRight", rec.width() - 1, rec.height() - 1, 1, 1);
+ loadSensor(screen, "bottomLeft", 0, rec.height() - 1, 1, 1);
+}
+
+
+void
+Lead::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h)
+{
+
+ QString key = screen->name() + "/" + name;
+
+
+ if (!settings.contains(key) )
+ {
+ qDebug() << "kernladung::Lead::loadSensor() key " << name << " not found";
+
+ // restore missing key
+ settings.setValue(key, QString());
+ return;
+ }
+
+ if (settings.value(key).toString().isEmpty())
+ {
+ qDebug() << "kernladung::Lead::loadSensor() key " << name << " is empty";
+ return;
+ }
+
+
+ // create sensor and save in list so we can delete all sensors on delete
+
+ sensors.append( new lead::Sensor(x, y, w, h, settings.value(key).toString()) );
+}
+
+
+} // namespace
diff --git a/src/lead.h b/src/lead.h
new file mode 100644
index 0000000..035e0f2
--- /dev/null
+++ b/src/lead.h
@@ -0,0 +1,67 @@
+/*
+MIT License
+
+Copyright (c) 2017 Noah Andreas
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+
+#pragma once
+
+
+#include "sensor.h"
+#include <QApplication>
+#include <QList>
+#include <QSettings>
+#include <QScreen>
+#include <QFileSystemWatcher>
+
+
+namespace kernladung {
+
+
+class Lead : public QApplication
+{
+ Q_OBJECT
+
+public:
+ explicit Lead(int &argc, char** argv);
+ ~Lead();
+
+private:
+ QSettings settings;
+ QFileSystemWatcher watcher;
+ QList<lead::Sensor*> sensors;
+
+ void screenAdded(QScreen* screen);
+ void screenRemoved(QScreen* screen);
+ void watchSettings();
+ void loadScreens();
+ void loadScreen(QScreen* screen);
+ void loadSensor(QScreen* screen, QString name, int x, int y, int w, int h);
+ void reloadScreens();
+
+public slots:
+ void fileChanged(QString fileName);
+
+};
+
+
+} // namespace
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..601c065
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,37 @@
+/*
+MIT License
+
+Copyright (c) 2017 Noah Andreas
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+
+#include "lead.h"
+#include <QApplication>
+
+
+int
+main(int argc, char *argv[])
+{
+ kernladung::Lead lead(argc, argv);
+
+ return lead.exec();
+}
+
diff --git a/src/sensor.cpp b/src/sensor.cpp
new file mode 100644
index 0000000..41c4326
--- /dev/null
+++ b/src/sensor.cpp
@@ -0,0 +1,65 @@
+/*
+MIT License
+
+Copyright (c) 2017 Noah Andreas
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+
+#include "sensor.h"
+#include <QEvent>
+#include <QDebug>
+#include <QProcess>
+
+
+namespace kernladung {
+namespace lead {
+
+
+Sensor::Sensor(int x, int y, int w, int h, QString action):
+ QWidget()
+{
+ qDebug() << "kernladung::lead::Sensor() " << x << "," << y << "," << w << "," << h << " : " << action;
+
+ this->action = action;
+
+ //setStyleSheet("background-color:red;");
+ setGeometry(x, y, w, h);
+ setAttribute(Qt::WA_TranslucentBackground, true);
+ setWindowFlags(windowFlags() | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint );
+
+ show();
+}
+
+
+Sensor::~Sensor()
+{}
+
+
+void
+Sensor::enterEvent(QEvent * event)
+{
+ qDebug() << "kernladung::lead::Sensor::enterEvent() " << this->x() << ":" << this->y() << " action: " << this->action;
+
+ QProcess::startDetached(action);
+}
+
+
+}} // namespace
diff --git a/src/sensor.h b/src/sensor.h
new file mode 100644
index 0000000..0404583
--- /dev/null
+++ b/src/sensor.h
@@ -0,0 +1,54 @@
+/*
+MIT License
+
+Copyright (c) 2017 Noah Andreas
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+
+#pragma once
+
+
+#include <QWidget>
+#include <QScreen>
+
+
+namespace kernladung {
+namespace lead {
+
+
+class Sensor : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit Sensor(int x, int y, int w, int h, QString action);
+ ~Sensor();
+
+protected:
+ void enterEvent(QEvent * event);
+
+private:
+ QString action;
+
+};
+
+
+}} // namespace