summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp72
1 files changed, 72 insertions, 0 deletions
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 <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;
+}