Skip to content

Commit

Permalink
Implement basic delay support
Browse files Browse the repository at this point in the history
The ini file now has two entries for each corner, one for the action to
be performed and one for the interval after which it will be performed
if the mouse doesn't leave the hot corner/edge. This is a little
inelegant, and I'd like to make the ini file nicer at some point.
  • Loading branch information
MageJohn committed Feb 18, 2019
1 parent fe8218f commit a79a11d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 16 deletions.
30 changes: 21 additions & 9 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SOFTWARE.
#include <QDebug>
#include <QScreen>
#include <QFileSystemWatcher>
#include <QVariant>

#define SENSOR_WIDTH 5
#define SENSOR_HEIGHT 5
Expand Down Expand Up @@ -136,29 +137,40 @@ void
App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h)
{

QString key = screen->name() + "/" + name;
QString action = screen->name() + "/" + name + "-" + "action";
QString interval = screen->name() + "/" + name + "-" + "interval";

if (!settings.contains(interval))
{
qDebug() << "App::loadSensor() interval for " << name << " not found; setting to 0";

// set default
settings.setValue(interval, QVariant(0));
}

if (!settings.contains(key) )
if (!settings.contains(action))
{
qDebug() << "App::loadSensor() key " << name << " not found";
qDebug() << "App::loadSensor() action for " << name << " not found; creating empty key";

// restore missing key
settings.setValue(key, QString());
// restore missing action
settings.setValue(action, QString());
return;
}

if (settings.value(key).toString().isEmpty())
if (settings.value(action).toString().isEmpty())
{
qDebug() << "App::loadSensor() key " << name << " is empty";
qDebug() << "App::loadSensor() action for " << name << " is empty";
return;
}


// create sensor and save in list so we can delete all sensors on delete

sensors.append( new Sensor(x, y, w, h, settings.value(key).toString()) );
qDebug() << "App::loadSensor() action for " << name << " is " << settings.value(action).toString();
qDebug() << "App::loadSensor() interval for " << name << " is " << settings.value(interval).toInt();

sensors.append( new Sensor(x, y, w, h, settings.value(action).toString(), settings.value(interval).toInt()) );
}


} // namespace
} // namespace
38 changes: 32 additions & 6 deletions src/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ SOFTWARE.
namespace Lead {


Sensor::Sensor(int x, int y, int w, int h, QString action):
QWidget()
Sensor::Sensor(int x, int y, int w, int h, QString action, int interval):
QWidget(),
action(action),
interval(interval)
{
qDebug() << "lead::Sensor() " << x << "," << y << "," << w << "," << h << " : " << action;
qDebug() << "lead::Sensor() " << x << "," << y << "," << w << "," << h << " : action=" << action << " : interval=" << interval;

this->action = action;
this->timer = new QTimer(this);
this->timer->setSingleShot(true);
this->timer->setInterval(interval);

connect(this->timer, SIGNAL(timeout()), this, SLOT(activate()));

//setStyleSheet("background-color:red;");
setGeometry(x, y, w, h);
Expand All @@ -51,13 +57,33 @@ Sensor::Sensor(int x, int y, int w, int h, QString action):


Sensor::~Sensor()
{}
{
delete this->timer;
}


void
Sensor::enterEvent(QEvent * event)
{
qDebug() << "lead::Sensor::enterEvent() " << this->x() << ":" << this->y() << " action: " << this->action;
qDebug() << "lead::Sensor::enterEvent() " << this->x() << ":" << this->y() << " interval: " << this->interval;

this->timer->start();
}


void
Sensor::leaveEvent(QEvent * event)
{
qDebug() << "lead::Sensor::leaveEvent() " << this->x() << ":" << this->y() << " interval: " << this->interval;

this->timer->stop();
}


void
Sensor::activate()
{
qDebug() << "lead::Sensor::activate() " << this->x() << ":" << this->y() << " action: " << this->action;

QProcess::startDetached(action);
}
Expand Down
10 changes: 9 additions & 1 deletion src/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SOFTWARE.

#include <QWidget>
#include <QScreen>
#include <QTimer>


namespace Lead {
Expand All @@ -40,14 +41,21 @@ class Sensor : public QWidget
Q_OBJECT

public:
explicit Sensor(int x, int y, int w, int h, QString action);
explicit Sensor(int x, int y, int w, int h, QString action, int interval);
~Sensor();

protected:
void enterEvent(QEvent * event);
void leaveEvent(QEvent * event);

private:
QString action;
QTimer *timer;
int interval;

public slots:
void activate();


};

Expand Down

0 comments on commit a79a11d

Please sign in to comment.