diff options
| author | MageJohn <MageJohn@users.noreply.github.com> | 2019-02-19 16:59:06 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-19 16:59:06 +0000 |
| commit | 7e9c4e1b9bfa3966cca992256b885f75c8660753 (patch) | |
| tree | d1126cb0e6975ae678cd021c004ccf51f02b3079 | |
| parent | a1ddbe5b94b21877c1a082256857d2e6feb692fe (diff) | |
| parent | d843e6a66a11e07595c8c4964fb8a1d343172990 (diff) | |
| download | lead-7e9c4e1b9bfa3966cca992256b885f75c8660753.tar lead-7e9c4e1b9bfa3966cca992256b885f75c8660753.tar.gz lead-7e9c4e1b9bfa3966cca992256b885f75c8660753.zip | |
Merge pull request #1 from Almamu/master
Merge changes from Almamu
| -rw-r--r-- | README.md | 45 | ||||
| -rw-r--r-- | src/app.cpp | 62 | ||||
| -rw-r--r-- | src/sensor.cpp | 70 | ||||
| -rw-r--r-- | src/sensor.h | 15 |
4 files changed, 127 insertions, 65 deletions
@@ -53,30 +53,27 @@ On the first run lead will look into these dirs for a conf-file. The first one f If none of these exists, it will create `~/.config/lead/lead.conf` with default values for each screen, ie: [eDP1] - bottom-action= - bottom-interval=0 - bottomLeft-action= - bottomLeft-interval=0 - bottomRight-action= - bottomRight-interval=0 - left-action= - left-interval=0 - right-action= - right-interval=0 - top-action= - top-interval=0 - topLeft-action= - topLeft-interval=0 - topRight-action= - topRight-interval=0 - -To enable a action for a sensor, simply add a command to the corner or side: - - bottomLeft-action=chromium - -The intervals are set in milliseconds. For example, to set chromium to open only after the mouse has been in the corner for 1 second, do: - - bottomLeft-interval=1000 + bottom= + bottomLeft= + bottomRight= + left= + right= + top= + topLeft= + topRight= + +Sensors have their own sections in the configuration, so if you want to add an action to a corner you can do so: + [eDP1] + bottomLeft=SensorName + + [SensorName] + enterAction=chromium + exitAction=firefox + enterDelay=5000 + exitDelay=1000 + +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. The configuration file is monitored and changes are applied automatically. diff --git a/src/app.cpp b/src/app.cpp index 1b63b72..bb7c777 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -136,40 +136,64 @@ App::loadScreen(QScreen* screen) void App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h) { + QString sensorNameKey = screen->name() + "/" + name; - QString action = screen->name() + "/" + name + "-" + "action"; - QString interval = screen->name() + "/" + name + "-" + "interval"; + if (settings.contains (sensorNameKey) == false) + { + return; + } + + QString sensorName = settings.value (sensorNameKey).toString (); + QString sensorEnterAction = sensorName + "/enterAction"; + QString sensorExitAction = sensorName + "/exitAction"; + QString sensorEnterDelay = sensorName + "/enterDelay"; + QString sensorExitDelay = sensorName + "/exitDelay"; + int emptyCount = 0; - if (!settings.contains(interval)) + if (sensorName.isEmpty () == true) { - qDebug() << "App::loadSensor() interval for " << name << " not found; setting to 0"; + return; + } - // set default - settings.setValue(interval, QVariant(0)); + if (!settings.contains (sensorEnterAction)) + { + emptyCount ++; } - if (!settings.contains(action)) + if (!settings.contains (sensorExitAction)) { - qDebug() << "App::loadSensor() action for " << name << " not found; creating empty key"; - - // restore missing action - settings.setValue(action, QString()); - return; + emptyCount ++; } - if (settings.value(action).toString().isEmpty()) + if (emptyCount == 2) { - qDebug() << "App::loadSensor() action for " << name << " is empty"; + // to not make this a breaking change, keep compatibility with old configurations + sensors.append (new Sensor (x, y, w, h, sensorName, "", 0, 0)); return; } - - // create sensor and save in list so we can delete all sensors on delete + if (!settings.contains (sensorEnterDelay)) + { + qDebug () << "App::loadSensor () sensor " << sensorName << " does not have delay; setting to 0"; + settings.setValue (sensorEnterDelay, QVariant (0)); + } - qDebug() << "App::loadSensor() action for " << name << " is " << settings.value(action).toString(); - qDebug() << "App::loadSensor() interval for " << name << " is " << settings.value(interval).toInt(); + if (!settings.contains (sensorExitDelay)) + { + qDebug () << "App::loadSensor () sensor " << sensorName << " does not have exit delay; setting to 0"; + settings.setValue (sensorExitDelay, QVariant (0)); + } - sensors.append( new Sensor(x, y, w, h, settings.value(action).toString(), settings.value(interval).toInt()) ); + qDebug () << "App::loadSensor () loaded sensor " << sensorName << " on screen " + screen->name(); + sensors.append ( + new Sensor ( + x, y, w, h, + settings.value (sensorEnterAction).toString (), + settings.value (sensorExitAction).toString (), + settings.value (sensorEnterDelay).toInt (), + settings.value (sensorExitDelay).toInt () + ) + ); } diff --git a/src/sensor.cpp b/src/sensor.cpp index 49fd149..597d4f9 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -34,18 +34,32 @@ SOFTWARE. namespace Lead { -Sensor::Sensor(int x, int y, int w, int h, QString action, int interval): +Sensor::Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval): QWidget(), - action(action), - interval(interval) + enterAction(enterAction), + exitAction(exitAction), + enterInterval(enterInterval), + exitInterval(exitInterval) { - qDebug() << "lead::Sensor() " << x << "," << y << "," << w << "," << h << " : action=" << action << " : interval=" << interval; + qDebug() + << "lead::Sensor() " << x << "," << y << "," << w << "," << h + << " : enterAction=" << enterAction + << " : exitAction=" << exitAction + << " : enterInterval=" << enterInterval + << " : exitInterval=" << exitInterval; - this->timer = new QTimer(this); - this->timer->setSingleShot(true); - this->timer->setInterval(interval); + this->canTriggerExit = false; - connect(this->timer, SIGNAL(timeout()), this, SLOT(activate())); + this->enterTimer = new QTimer(this); + this->enterTimer->setSingleShot(true); + this->enterTimer->setInterval(enterInterval); + + this->exitTimer = new QTimer (this); + this->exitTimer->setSingleShot (true); + this->exitTimer->setInterval (exitInterval); + + 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); @@ -58,34 +72,56 @@ Sensor::Sensor(int x, int y, int w, int h, QString action, int interval): Sensor::~Sensor() { - delete this->timer; + delete this->enterTimer; + delete this->exitTimer; } void Sensor::enterEvent(QEvent * event) { - qDebug() << "lead::Sensor::enterEvent() " << this->x() << ":" << this->y() << " interval: " << this->interval; + qDebug() + << "lead::Sensor::enterEvent() "<< this->x() << ":" << this->y() + << " enterInterval: " << this->enterTimer + << " exitInterval: " << this->exitTimer; - this->timer->start(); + this->enterTimer->start(); + this->exitTimer->start(); } void Sensor::leaveEvent(QEvent * event) { - qDebug() << "lead::Sensor::leaveEvent() " << this->x() << ":" << this->y() << " interval: " << this->interval; - - this->timer->stop(); + qDebug() + << "lead::Sensor::leaveEvent() "<< this->x() << ":" << this->y() + << " enterInterval: " << this->enterTimer + << " exitInterval: " << this->exitTimer; + + if (this->canTriggerExit) + { + QProcess::startDetached(exitAction); + } + + this->enterTimer->stop(); + this->exitTimer->stop(); + this->canTriggerExit = false; } void -Sensor::activate() +Sensor::activateEnter() +{ + qDebug() << "lead::Sensor::activateEnter() " << this->x() << ":" << this->y() << " action: " << this->enterAction; + + QProcess::startDetached(enterAction); +} + +void Sensor::activateExit() { - qDebug() << "lead::Sensor::activate() " << this->x() << ":" << this->y() << " action: " << this->action; + qDebug () << "lead::Sensor::activateExit() " << this->x() << ":" << this->y() << " action: " << this->exitAction << " can run now"; - QProcess::startDetached(action); + this->canTriggerExit = true; } diff --git a/src/sensor.h b/src/sensor.h index ed5add8..bc4857b 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 action, int interval); + explicit Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval); ~Sensor(); protected: @@ -49,12 +49,17 @@ protected: void leaveEvent(QEvent * event); private: - QString action; - QTimer *timer; - int interval; + QString enterAction; + QString exitAction; + QTimer *enterTimer; + QTimer *exitTimer; + int enterInterval; + int exitInterval; + bool canTriggerExit; public slots: - void activate(); + void activateEnter(); + void activateExit(); }; |
