diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index 7ba8758..a5fa5db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,9 +13,13 @@ #include <QIcon> #include <QPainter> #include <QMap> +#include <QSocketNotifier> #include <fcntl.h> /* Obtain O_* constant definitions */ #include <unistd.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/socket.h> #include <iostream> @@ -24,8 +28,12 @@ #include "x11util.h" #include "global.h" +static int sockets[2]; + static void createSimpleBackground(); +static void sigUsr1(int); + static void messageHandler(QtMsgType type, const QMessageLogContext&, const QString& msg) { std::cerr << type << ": " << msg.toUtf8().constData() << '\n'; @@ -112,6 +120,21 @@ int main(int argc, char *argv[]) primary = screens.begin().key(); } + struct sigaction usr1; + + usr1.sa_handler = &sigUsr1; + sigemptyset(&usr1.sa_mask); + usr1.sa_flags = SA_RESTART; + + QSocketNotifier *sn = NULL; + if (sigaction(SIGUSR1, &usr1, 0) == 0 && ::socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == 0) { + sn = new QSocketNotifier(sockets[1], QSocketNotifier::Read); + QObject::connect(sn, &QSocketNotifier::activated, [](int fd) { + char tmp[1000]; + read(fd, tmp, sizeof tmp); + }); + } + // Now set up all the screens QPainter painter(&entire); MainWindow *focusWindow = 0; @@ -120,6 +143,9 @@ int main(int argc, char *argv[]) it.next(); MainWindow *w = new MainWindow(primary == it.key(), it.key(), it.value()); w->show(); + if (sn != NULL) { + QObject::connect(sn, SIGNAL(activated(int)), w, SLOT(showStandby())); + } if (w->showLoginForm()) { focusWindow = w; } @@ -152,3 +178,9 @@ static void createSimpleBackground() img = img.scaled(QApplication::desktop()->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); AddPixmapToBackground(img.constBits(), img.width(), img.height(), 24, img.bytesPerLine(), img.byteCount()); } + +static void sigUsr1(int) +{ + char a = 1; + ::write(sockets[0], &a, sizeof(a)); +} |