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 <QApplication>
5 #include <QProcess>
6 #include <QDesktopWidget>
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 
47  _message = message;
48 
49  this->setGeometry(QApplication::desktop()->geometry());
50  this->showFullScreen();
51  this->activateWindow();
52  this->raise();
53 
54  // grabbing of keyboard and mouse
55 #
56  XGrabKeyboard(_sysdep->dpy, DefaultRootWindow(_sysdep->dpy), false, GrabModeAsync, GrabModeAsync, CurrentTime);
57  XGrabPointer(_sysdep->dpy, DefaultRootWindow(_sysdep->dpy), false, 0, GrabModeAsync, GrabModeAsync, None, 0, CurrentTime);
58 
59 
60  QProcess ungrabP;
61  ungrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-lock.sh");
62  ungrabP.waitForFinished();
63 
64  _locked = true;
65  return true;
66 }
67 
69 {
70  this->hide();
71  if (!_locked)
72  return true;
73  if (_sysdep->dpy == nullptr)
74  return false;
75 
76  // ungrabbing of keyboard and mouse
77  XUngrabPointer(_sysdep->dpy, CurrentTime);
78  XUngrabKeyboard(_sysdep->dpy, CurrentTime);
79 
80  XFlush(_sysdep->dpy);
81 
82  /* start the kb-unlock.sh script */
83  QProcess regrabP;
84  regrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-unlock.sh");
85  regrabP.waitForFinished();
86 
87  _locked = false;
88  return true;
89 }
90 
92 {
93  if (this->isHidden())
94  return;
95  activateWindow();
96  raise();
97 }
virtual ~BlankScreen()
Definition: blankscreen.cpp:31
void timer_moveToTop()
Definition: blankscreen.cpp:91
QString _message
Definition: blankscreen.h:22
bool unlock()
Definition: blankscreen.cpp:68
bool lock(const QString &message)
Definition: blankscreen.cpp:40
BlankScreen_Sysdep * _sysdep
Definition: blankscreen.h:23
bool _locked
Definition: blankscreen.h:21