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
|
#include "saverwidget.h"
#include <QApplication>
#include <QMessageBox>
#include <QWindow>
#include <QLabel>
#include <QDebug>
#include <QX11Info>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
//#include <X11/Xlib.h>
#include "vroot.h"
static pid_t childId;
static void __attribute((noreturn)) sh(int)
{
// Clean up if xscreensaver kills us (relay to forked child)
kill(childId, SIGTERM);
exit(0);
}
int main(int argc, char **argv)
{
// Fork once and wait for child so SIGSTOP won't affect us and the counter keeps going
// while the auth dialog is up
childId = fork();
if (childId != 0) {
signal(SIGTERM, sh);
signal(SIGINT, sh);
int status;
for (;;) {
pid_t ret = waitpid(childId, &status, 0);
if (ret == childId)
return 0;
if (errno == EINTR)
continue;
fprintf(stderr, "errno=%d, bye\n", errno);
return 1;
}
}
for (int i = 0; i < argc; ++i) {
qDebug() << "Argument" << i << "=" << argv[i];
}
QApplication app(argc, argv);
Display *dpy = QX11Info::display();
if (dpy == nullptr) {
fprintf(stderr, "No display");
return 1;
}
Window win = DefaultRootWindow(dpy);
QWindow *xwin = QWindow::fromWinId(win);
qDebug() << "Foreign window id is" << win << "pointer is" << xwin;
//QWindow *qwin = new QWindow(xwin);
//QWidget *w = QWidget::createWindowContainer(qwin);
SaverWidget *w = new SaverWidget(win);
w->winId();
qDebug() << "New Qt window is" << w << "window handle is" << w->windowHandle();
w->windowHandle()->setParent(xwin);
XWindowAttributes attr;
// Because QWindow is broken and doesn't report any geometry for foreign windows
if (XGetWindowAttributes(dpy, win, &attr)) {
qDebug() << "Query:" << attr.width << attr.height;
w->setGeometry(0, 0, attr.width, attr.height);
}
w->show();
app.exec();
return 0;
}
|