diff options
| author | Alexis Maiquez Murcia <almamu@almamu.com> | 2019-02-20 09:57:51 +0100 |
|---|---|---|
| committer | Alexis Maiquez Murcia <almamu@almamu.com> | 2019-02-20 09:57:51 +0100 |
| commit | 959357b391dc5d561788f50d0b84ddc11fefd478 (patch) | |
| tree | e4061246005f71644512f4ff6402a34814816faf | |
| parent | d843e6a66a11e07595c8c4964fb8a1d343172990 (diff) | |
| download | lead-959357b391dc5d561788f50d0b84ddc11fefd478.tar lead-959357b391dc5d561788f50d0b84ddc11fefd478.tar.gz lead-959357b391dc5d561788f50d0b84ddc11fefd478.zip | |
Added debug mode
This allows the user to display the screen names, the sensors activated and the status of those sensors:
red -> waiting for mouse to enter
yellow -> waiting for delay timer to reach 0
green -> fired the command
Signed-off-by: Alexis Maiquez Murcia <almamu@almamu.com>
| -rw-r--r-- | README.md | 15 | ||||
| -rw-r--r-- | makefile | 2 | ||||
| -rw-r--r-- | screenshots/screenshot1.png (renamed from screenshot.png) | bin | 1382699 -> 1382699 bytes | |||
| -rw-r--r-- | screenshots/screenshot2.png | bin | 0 -> 806767 bytes | |||
| -rw-r--r-- | src/app.cpp | 33 | ||||
| -rw-r--r-- | src/app.h | 4 | ||||
| -rw-r--r-- | src/screenname.cpp | 60 | ||||
| -rw-r--r-- | src/screenname.h | 48 | ||||
| -rw-r--r-- | src/sensor.cpp | 27 | ||||
| -rw-r--r-- | src/sensor.h | 3 |
10 files changed, 181 insertions, 11 deletions
@@ -2,8 +2,9 @@ This fork adds support for specifying an interval to wait before the action is triggered. There may be more improvements in the future. - -> Despite the screenshot, the sensors are only 1px in size and invisible. + + +> Sensors are not displayed unless the debug mode is enabled ### Features @@ -75,6 +76,16 @@ Sensors have their own sections in the configuration, so if you want to add an a Delays are configured in miliseconds and dictate the amount of time the mouse has to be in the sensor to trigger the specific action. In the case of exitDelay, this delay affects how much time the mouse has to be in the sensor for it to trigger the exitAction when the mouse moves out of the sensor. +If you are not sure why a sensor isn't properly firing you can enable the debug mode to visualize what their position is, your screen names and the status they're in. +Each configured sensor will be displayed in a red color when the sensor is waiting for the mouse to enter it. +Once the mouse is in, the sensor will turn to yellow, this indicates that it is waiting for the enter delay timer to end. Once the timer ends the sensor will turn green and the program should be run. +If still your program doesn't run please check lead's output to get a better idea of what's happening. + +In debug mode the screen names are shown on the top-left corner of each screen. +To enable the debug mode add the following section in the config file: + [systemsettings] + debug=1 + The configuration file is monitored and changes are applied automatically. @@ -12,7 +12,7 @@ MKDIR = mkdir -p $(dir $@) .SECONDARY: -data/usr/bin/lead: build/main.o build/app.o build/sensor.o build/moc_app.o build/moc_sensor.o +data/usr/bin/lead: build/main.o build/app.o build/sensor.o build/screenname.o build/moc_app.o build/moc_sensor.o build/moc_screenname.o $(MKDIR) $(LINKER) diff --git a/screenshot.png b/screenshots/screenshot1.png Binary files differindex a9047ad..a9047ad 100644 --- a/screenshot.png +++ b/screenshots/screenshot1.png diff --git a/screenshots/screenshot2.png b/screenshots/screenshot2.png Binary files differnew file mode 100644 index 0000000..21bdbb5 --- /dev/null +++ b/screenshots/screenshot2.png diff --git a/src/app.cpp b/src/app.cpp index bb7c777..a73b812 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -27,6 +27,7 @@ SOFTWARE. #include "app.h" #include "sensor.h" +#include "screenname.h" #include <QDebug> #include <QScreen> #include <QFileSystemWatcher> @@ -34,6 +35,7 @@ SOFTWARE. #define SENSOR_WIDTH 5 #define SENSOR_HEIGHT 5 +#define DEBUG_MODE_KEY "systemsettings/debug" namespace Lead { @@ -51,6 +53,7 @@ App::App(int &argc, char** argv) : App::~App() { qDeleteAll(sensors); + qDeleteAll(screenNames); } @@ -99,7 +102,9 @@ void App::reloadScreens() { qDeleteAll(sensors); + qDeleteAll(screenNames); sensors.clear(); + screenNames.clear(); loadScreens(); } @@ -108,6 +113,14 @@ App::reloadScreens() void App::loadScreens() { + // first load the debug mode flag + this->debugMode = false; + + if (settings.contains (DEBUG_MODE_KEY)) + { + this->debugMode = settings.value (DEBUG_MODE_KEY).toInt () > 0; + } + foreach (QScreen* screen, screens()) { loadScreen(screen); @@ -130,6 +143,8 @@ App::loadScreen(QScreen* screen) loadSensor(screen, "topRight", rec.x() + rec.width() - SENSOR_WIDTH, rec.y(), SENSOR_WIDTH, SENSOR_HEIGHT); loadSensor(screen, "bottomRight", rec.x() + rec.width() - SENSOR_WIDTH, rec.y() + rec.height() - SENSOR_HEIGHT, SENSOR_WIDTH, SENSOR_HEIGHT); loadSensor(screen, "bottomLeft", rec.x(), rec.y() + rec.height() - SENSOR_HEIGHT, SENSOR_WIDTH, SENSOR_HEIGHT); + + loadScreenNameDisplay (screen); } @@ -168,7 +183,7 @@ App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h) if (emptyCount == 2) { // to not make this a breaking change, keep compatibility with old configurations - sensors.append (new Sensor (x, y, w, h, sensorName, "", 0, 0)); + sensors.append (new Sensor (x, y, w, h, sensorName, "", 0, 0, this->debugMode)); return; } @@ -191,10 +206,24 @@ App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h) settings.value (sensorEnterAction).toString (), settings.value (sensorExitAction).toString (), settings.value (sensorEnterDelay).toInt (), - settings.value (sensorExitDelay).toInt () + settings.value (sensorExitDelay).toInt (), + this->debugMode ) ); } +void +App::loadScreenNameDisplay(QScreen* screen) +{ + if (!this->debugMode) + { + return; + } + + qDebug () << "App::loadScreenNameDisplay () loading widget for screen " << screen->name (); + + screenNames.append (new ScreenName (screen)); +} + } // namespace @@ -29,6 +29,7 @@ SOFTWARE. #include "sensor.h" +#include "screenname.h" #include <QApplication> #include <QList> #include <QSettings> @@ -51,6 +52,8 @@ private: QSettings settings; QFileSystemWatcher watcher; QList<Sensor*> sensors; + QList<ScreenName*> screenNames; + bool debugMode; void screenAdded(QScreen* screen); void screenRemoved(QScreen* screen); @@ -58,6 +61,7 @@ private: void loadScreens(); void loadScreen(QScreen* screen); void loadSensor(QScreen* screen, QString name, int x, int y, int w, int h); + void loadScreenNameDisplay(QScreen* screen); void reloadScreens(); public slots: diff --git a/src/screenname.cpp b/src/screenname.cpp new file mode 100644 index 0000000..6755433 --- /dev/null +++ b/src/screenname.cpp @@ -0,0 +1,60 @@ +/* + +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 "screenname.h" +#include <QEvent> +#include <QDebug> +#include <QProcess> +#include <QLabel> +#include <QHBoxLayout> + +#define SCREENNAME_WIDTH 150 +#define SCREENNAME_HEIGHT 45 + +namespace Lead { + ScreenName::ScreenName(QScreen* screen): + QWidget() + { + qDebug() + << "lead::ScreenName() " << screen->name (); + QRect rec = screen->geometry(); + + setGeometry(rec.x(), rec.y(), SCREENNAME_WIDTH, SCREENNAME_HEIGHT); + setAttribute(Qt::WA_TranslucentBackground, true); + setWindowFlags(windowFlags() | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint ); + + // create the text widget and put it in the widget + QHBoxLayout *layout = new QHBoxLayout (); + QLabel* label = new QLabel (); + label->setText (screen->name ()); + layout->addWidget (label); + + setLayout (layout); + + show(); + } +} // namespace diff --git a/src/screenname.h b/src/screenname.h new file mode 100644 index 0000000..1887036 --- /dev/null +++ b/src/screenname.h @@ -0,0 +1,48 @@ +/* + +MIT License + +Copyright (c) 2017 Alexis Maiquez + +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 Lead { + + + class ScreenName : public QWidget + { + Q_OBJECT + + public: + explicit ScreenName(QScreen* screen); + virtual ~ScreenName() {} + }; + + +} // namespace diff --git a/src/sensor.cpp b/src/sensor.cpp index 597d4f9..e33a9ac 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -34,12 +34,13 @@ SOFTWARE. namespace Lead { -Sensor::Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval): +Sensor::Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval, bool debugMode): QWidget(), enterAction(enterAction), exitAction(exitAction), enterInterval(enterInterval), - exitInterval(exitInterval) + exitInterval(exitInterval), + debugMode(debugMode) { qDebug() << "lead::Sensor() " << x << "," << y << "," << w << "," << h @@ -61,9 +62,16 @@ Sensor::Sensor(int x, int y, int w, int h, QString enterAction, QString exitActi connect(this->enterTimer, SIGNAL(timeout()), this, SLOT(activateEnter())); connect(this->exitTimer, SIGNAL(timeout()), this, SLOT(activateExit())); - //setStyleSheet("background-color:red;"); - setGeometry(x, y, w, h); - setAttribute(Qt::WA_TranslucentBackground, true); + if (this->debugMode) + { + setStyleSheet ("background-color: red"); + } + else + { + setAttribute(Qt::WA_TranslucentBackground, true); + } + + setGeometry(x, y, w, h); setWindowFlags(windowFlags() | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint ); show(); @@ -87,6 +95,9 @@ Sensor::enterEvent(QEvent * event) this->enterTimer->start(); this->exitTimer->start(); + + if (this->debugMode) + setStyleSheet ("background-color: yellow"); } @@ -103,6 +114,9 @@ Sensor::leaveEvent(QEvent * event) QProcess::startDetached(exitAction); } + if (this->debugMode) + setStyleSheet ("background-color: red"); + this->enterTimer->stop(); this->exitTimer->stop(); this->canTriggerExit = false; @@ -114,6 +128,9 @@ Sensor::activateEnter() { qDebug() << "lead::Sensor::activateEnter() " << this->x() << ":" << this->y() << " action: " << this->enterAction; + if (this->debugMode) + setStyleSheet ("background-color: green"); + QProcess::startDetached(enterAction); } diff --git a/src/sensor.h b/src/sensor.h index bc4857b..4b86690 100644 --- a/src/sensor.h +++ b/src/sensor.h @@ -41,7 +41,7 @@ class Sensor : public QWidget Q_OBJECT public: - explicit Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval); + explicit Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval, bool debugMode); ~Sensor(); protected: @@ -56,6 +56,7 @@ private: int enterInterval; int exitInterval; bool canTriggerExit; + bool debugMode; public slots: void activateEnter(); |
