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
|
#include "blankscreen.h"
#include <QApplication>
#include <QDesktopWidget>
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include <cassert>
#include <cstring>
struct BlankScreen_Sysdep
{
Display *dpy;
};
BlankScreen::BlankScreen() : QDialog(NULL)
{
_sysdep = new BlankScreen_Sysdep;
_sysdep->dpy = XOpenDisplay(NULL);
if (_sysdep->dpy == NULL)
return;
assert(_sysdep->dpy);
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint);
setStyleSheet("background-color:#000");
_locked = false;
}
BlankScreen::~BlankScreen()
{
unlock();
delete _sysdep;
}
bool BlankScreen::lock(const QString& message)
{
if (_locked)
return true;
if (_sysdep->dpy == NULL)
return false;
_message = message;
this->setGeometry(QApplication::desktop()->geometry());
this->showFullScreen();
this->activateWindow();
this->raise();
// grabbing of keyboard and mouse
XGrabKeyboard(_sysdep->dpy, DefaultRootWindow(_sysdep->dpy) , false, GrabModeAsync, GrabModeAsync, CurrentTime);
XGrabPointer(_sysdep->dpy, DefaultRootWindow(_sysdep->dpy) , false, 0, GrabModeAsync, GrabModeAsync, None, 0, CurrentTime);
_locked = true;
return true;
}
bool BlankScreen::unlock()
{
this->hide();
if (!_locked)
return true;
if (_sysdep->dpy == NULL)
return false;
// ungrabbing of keyboard and mouse
XUngrabPointer(_sysdep->dpy, CurrentTime);
XUngrabKeyboard(_sysdep->dpy, CurrentTime);
XFlush(_sysdep->dpy);
_locked = false;
return true;
}
|