blob: e5e14a369f8bf8e046f2ab81295f6f45db08f8a7 (
plain) (
blame)
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
|
#include "windowmanager.h"
#include <QProcess>
#include <QTimer>
#include <QDebug>
namespace WindowManager {
static QProcess wm;
void ensureRunning()
{
wm.start(QLatin1String("openbox"));
wm.closeReadChannel(QProcess::StandardError);
wm.closeReadChannel(QProcess::StandardOutput);
wm.closeWriteChannel();
wm.waitForStarted(1000);
QTimer::singleShot(200, []() {
if (wm.state() == QProcess::Running) {
qDebug() << "- Spawned openbox";
} else if (wm.exitCode() == 0) {
qDebug() << "- A WM is already running";
} else {
qDebug() << "- openbox binary not in $PATH";
}
});
}
void stopOwnInstance()
{
if (wm.state() == QProcess::Running) {
qDebug() << "- Politely terminating spawned WM";
wm.terminate();
QTimer::singleShot(1000, []() {
if (wm.state() == QProcess::Running) {
qDebug() << "- Forcefully killing spawned WM";
wm.kill();
}
});
}
}
}
|