Pool Video Switch v2
Software video switch for distributed remote display in a lecture environment
blankscreen.cpp
Go to the documentation of this file.
1 
2 #include "blankscreen.h"
3 
4 #include <QGuiApplication>
5 #include <QProcess>
6 #include <QScreen>
7 #include <QTimer>
8 
9 #include <X11/Xlib.h>
10 
12  Display *dpy;
13 };
14 
16 {
18  _sysdep->dpy = XOpenDisplay(nullptr);
19  if (_sysdep->dpy == nullptr)
20  return;
21 
22  setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint);
23  setStyleSheet("background-color:#000");
24 
25  _locked = false;
26  auto *upper = new QTimer(this);
27  connect(upper, &QTimer::timeout, this, &BlankScreen::timer_moveToTop);
28  upper->start(1111);
29 }
30 
32 {
33  unlock();
34  if (_sysdep->dpy != nullptr) {
35  XCloseDisplay(_sysdep->dpy);
36  }
37  delete _sysdep;
38 }
39 
40 bool BlankScreen::lock(const QString& message)
41 {
42  if (_locked)
43  return true;
44  if (_sysdep->dpy == nullptr)
45  return false;
46  QScreen *screen = QGuiApplication::primaryScreen();
47  if (screen == nullptr)
48  return false;
49 
50  _message = message;
51 
52  this->setGeometry(screen->virtualGeometry());
53  this->showFullScreen();
54  this->activateWindow();
55  this->raise();
56 
57  // grabbing of keyboard and mouse
58 #
59  XGrabKeyboard(_sysdep->dpy, DefaultRootWindow(_sysdep->dpy), false, GrabModeAsync, GrabModeAsync, CurrentTime);
60  XGrabPointer(_sysdep->dpy, DefaultRootWindow(_sysdep->dpy), false, 0, GrabModeAsync, GrabModeAsync, None, 0, CurrentTime);
61 
62 
63  QProcess ungrabP;
64  ungrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-lock.sh");
65  ungrabP.waitForFinished();
66 
67  _locked = true;
68  return true;
69 }
70 
72 {
73  this->hide();
74  if (!_locked)
75  return true;
76  if (_sysdep->dpy == nullptr)
77  return false;
78 
79  // ungrabbing of keyboard and mouse
80  XUngrabPointer(_sysdep->dpy, CurrentTime);
81  XUngrabKeyboard(_sysdep->dpy, CurrentTime);
82 
83  XFlush(_sysdep->dpy);
84 
85  /* start the kb-unlock.sh script */
86  QProcess regrabP;
87  regrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-unlock.sh");
88  regrabP.waitForFinished();
89 
90  _locked = false;
91  return true;
92 }
93 
95 {
96  if (this->isHidden())
97  return;
98  activateWindow();
99  raise();
100 }
virtual ~BlankScreen()
Definition: blankscreen.cpp:31
void timer_moveToTop()
Definition: blankscreen.cpp:94
QString _message
Definition: blankscreen.h:22
bool unlock()
Definition: blankscreen.cpp:71
bool lock(const QString &message)
Definition: blankscreen.cpp:40
BlankScreen_Sysdep * _sysdep
Definition: blankscreen.h:23
bool _locked
Definition: blankscreen.h:21