aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/lumina-session/session.h
blob: bee244eebcb03644a45567bdcb610aa8198b3686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//===========================================
//  Lumina-DE source code
//  Copyright (c) 2016, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include <QObject>
#include <QProcess>
#include <QDebug>
#include <QFileSystemWatcher>
#include <QTimer>

#include <sys/types.h>
#include <signal.h>

class LProcess : public QProcess{
	Q_OBJECT
private:
	QFileSystemWatcher *watcher;
	QString id;
private slots:
	void filechanged(QString path){
          //qDebug() << "File Changed:" << path;
	  //qDebug() << " - Program:" << this->program();
	  if(watcher==0){ return; } //just in case
	  if(this->state()==QProcess::Running){
	    if(this->program().section(" ",0,0).section("/",-1) == "fluxbox" ){
             // qDebug() << "Sending Fluxbox signal to reload configs...";
              ::kill(this->pid(), SIGUSR2); } //Fluxbox needs SIGUSR2 to reload it's configs
	    else if(this->program().section(" ",0,0).section("/",-1) == "compton" ){
              //qDebug() << "Sending Compton signal to reload configs...";
              ::kill(this->pid(), SIGUSR1); } //Compton needs SIGUSR1 to reload it's configs
	  }
	  //Now make sure this file/dir was not removed from the watcher
	  QStringList watched; watched << watcher->files() << watcher->directories();
	  if(!watched.contains(path)){ watcher->addPath(path); } //re-add it
	}

public:
	LProcess(QString ID, QStringList watchfiles) : QProcess(){
	  id=ID;
	  watcher = 0;
          if(!watchfiles.isEmpty()){
            //qDebug() << "Watch Files for changes:" << ID << watchfiles;
	    watcher = new QFileSystemWatcher(this);
	    connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(filechanged(QString)) );
	    connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(filechanged(QString)) );
	    watcher->addPaths(watchfiles);
	  }
	}
	~LProcess(){

	}
	QString ID(){ return id; }

};

class LSession : public QObject{
	Q_OBJECT
private:
	QList<QProcess*> PROCS;
	bool stopping;
	int wmfails;
	QTimer *wmTimer;

private slots:
	void stopall();

	void procFinished();

	void startProcess(QString ID, QString command, QStringList watchfiles = QStringList());

	void resetWMCounter(){ wmfails = 0; }
public:
	LSession(){
	stopping = false; wmfails = 0;
	  wmTimer = new QTimer(this);
	  wmTimer->setSingleShot(true);
	  wmTimer->setInterval(5000); //5 second timeout
           connect(wmTimer, SIGNAL(timeout()), this, SLOT(resetWMCounter()) );
	}
	~LSession(){ }

	void start(bool unified = false);

};
bgstack15