From 959357b391dc5d561788f50d0b84ddc11fefd478 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Murcia Date: Wed, 20 Feb 2019 09:57:51 +0100 Subject: 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 --- README.md | 15 +++++++++-- makefile | 2 +- screenshot.png | Bin 1382699 -> 0 bytes screenshots/screenshot1.png | Bin 0 -> 1382699 bytes screenshots/screenshot2.png | Bin 0 -> 806767 bytes src/app.cpp | 33 ++++++++++++++++++++++-- src/app.h | 4 +++ src/screenname.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ src/screenname.h | 48 +++++++++++++++++++++++++++++++++++ src/sensor.cpp | 27 ++++++++++++++++---- src/sensor.h | 3 ++- 11 files changed, 181 insertions(+), 11 deletions(-) delete mode 100644 screenshot.png create mode 100644 screenshots/screenshot1.png create mode 100644 screenshots/screenshot2.png create mode 100644 src/screenname.cpp create mode 100644 src/screenname.h diff --git a/README.md b/README.md index 790ec39..75d2085 100644 --- a/README.md +++ b/README.md @@ -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. -![Screenshot of lead](https://github.com/mlde/lead/blob/master/screenshot.png) -> Despite the screenshot, the sensors are only 1px in size and invisible. +![Screenshot of lead](https://github.com/almamu/lead/blob/master/screenshots/screenshot1.png) +![Screenshot of lead](https://github.com/almamu/lead/blob/master/screenshots/screenshot2.png) +> 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. diff --git a/makefile b/makefile index dc31aa0..78a4df5 100644 --- a/makefile +++ b/makefile @@ -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/screenshot.png deleted file mode 100644 index a9047ad..0000000 Binary files a/screenshot.png and /dev/null differ diff --git a/screenshots/screenshot1.png b/screenshots/screenshot1.png new file mode 100644 index 0000000..a9047ad Binary files /dev/null and b/screenshots/screenshot1.png differ diff --git a/screenshots/screenshot2.png b/screenshots/screenshot2.png new file mode 100644 index 0000000..21bdbb5 Binary files /dev/null and b/screenshots/screenshot2.png differ 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 #include #include @@ -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 diff --git a/src/app.h b/src/app.h index 0906d5b..93393aa 100644 --- a/src/app.h +++ b/src/app.h @@ -29,6 +29,7 @@ SOFTWARE. #include "sensor.h" +#include "screenname.h" #include #include #include @@ -51,6 +52,8 @@ private: QSettings settings; QFileSystemWatcher watcher; QList sensors; + QList 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 +#include +#include +#include +#include + +#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 +#include + + +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(); -- cgit v1.2.3