From 59d61e258c59dc695783e0b9adc419de2b174e75 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 11 Oct 2018 14:57:46 +0200 Subject: Initial commit --- src/main.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/main.cpp (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..2f59a14 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,72 @@ +#include "saverwidget.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +//#include +#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; +} -- cgit v1.2.3-55-g7522