From d93a1abd2806bdab8f8d11d96b641989e333d7d4 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 19 Jan 2018 12:05:16 +0100 Subject: Temporarily show sleep icon when receiving USR1 --- qt-lightdm-greeter.qrc | 1 + resources/gnome-face-tired.svg | 376 +++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 32 ++++ src/mainwindow.cpp | 26 ++- src/mainwindow.h | 4 + 5 files changed, 438 insertions(+), 1 deletion(-) create mode 100644 resources/gnome-face-tired.svg diff --git a/qt-lightdm-greeter.qrc b/qt-lightdm-greeter.qrc index 93e3e45..d632f53 100644 --- a/qt-lightdm-greeter.qrc +++ b/qt-lightdm-greeter.qrc @@ -3,5 +3,6 @@ resources/dropdown.svg resources/leaveIcon.svg resources/bwlp.svg + resources/gnome-face-tired.svg diff --git a/resources/gnome-face-tired.svg b/resources/gnome-face-tired.svg new file mode 100644 index 0000000..de43b1a --- /dev/null +++ b/resources/gnome-face-tired.svg @@ -0,0 +1,376 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Lapo Calamandrei + + + + emoticon, emots, smiley, saint, angel, smile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 #include #include +#include #include /* Obtain O_* constant definitions */ #include +#include +#include +#include #include @@ -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)); +} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d58b7f6..0e6a5e7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -18,6 +18,9 @@ #include #include +#include +#include + #include "mainwindow.h" #include "loginform.h" #include "settings.h" @@ -29,6 +32,7 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge QWidget(parent), m_ScreenRect(screenRect), m_Primary(primary), + m_LoginForm(NULL), m_messages(nullptr) { setObjectName(QString("MainWindow_%1").arg(screen)); @@ -254,4 +258,24 @@ void MainWindow::setBackground() this->setPalette(palette); } - +void MainWindow::showStandby() +{ + if (m_LoginForm != NULL) { + m_LoginForm->hide(); + } + QSvgWidget *img = new QSvgWidget(":/resources/gnome-face-tired.svg", this); + if (img->renderer()->isValid()) { + QSize sh = img->sizeHint().scaled(this->width() / 2, this->height() / 2, Qt::KeepAspectRatio); + img->setGeometry((this->width() - sh.width()) / 2, (this->height() - sh.height()) / 2, sh.width(), sh.height()); + img->show(); + } else { + qWarning() << "Shice!"; + } + QTimer::singleShot(8000, [this, img]() { + img->hide(); + img->deleteLater(); + if (this->m_LoginForm != NULL) { + m_LoginForm->show(); + } + }); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 53c54e0..e136540 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -43,6 +43,10 @@ public: QImage& getBackground() { return m_background; } LoginForm* loginForm() { return m_LoginForm; } + +public slots: + void showStandby(); + private: int getOffset(QString offset, int maxVal, int defaultVal); void setBackground(); -- cgit v1.2.3-55-g7522