-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreenlock.cpp
More file actions
62 lines (43 loc) · 1.11 KB
/
screenlock.cpp
File metadata and controls
62 lines (43 loc) · 1.11 KB
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
#include "screenlock.h"
#include <QDebug>
#include <QApplication>
#include <QDesktopWidget>
#include "screenlockdisplay.h"
ScreenLock::ScreenLock(QObject *parent) : QObject(parent) {}
/**
* Lock the display(s)
*/
void ScreenLock::lock() {
if (!locked) {
QDesktopWidget* dw = QApplication::desktop();
for (int i = 0; i < dw->screenCount(); i++) {
// Show display
QRect displayGeometry = dw->availableGeometry(i);
ScreenLockDisplay* display = new ScreenLockDisplay();
display->move(displayGeometry.topLeft());
display->showFullScreen();
// Connect display
connect(display, SIGNAL(unlockTriggered()), this, SLOT(unlock()));
displays.append(display);
// Set focus on first display (to catch key events)
if (i == 0) {
display->activateWindow();
display->setFocus();
}
}
locked = true;
}
}
/**
* Unlock the display(s)
*/
void ScreenLock::unlock() {
if (locked) {
foreach(ScreenLockDisplay* display, displays) {
display->hide();
}
qDeleteAll(displays);
displays.clear();
locked = false;
}
}