summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2018-01-19 12:05:16 +0100
committerSimon Rettberg2018-01-19 12:05:16 +0100
commitd93a1abd2806bdab8f8d11d96b641989e333d7d4 (patch)
treeb0774802d596f35877ed12d132db34041eb024e6 /src
parentFix image scaling by using proper existing methods instead of broken copy & p... (diff)
downloadslxgreeter-d93a1abd2806bdab8f8d11d96b641989e333d7d4.tar.gz
slxgreeter-d93a1abd2806bdab8f8d11d96b641989e333d7d4.tar.xz
slxgreeter-d93a1abd2806bdab8f8d11d96b641989e333d7d4.zip
Temporarily show sleep icon when receiving USR1
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp32
-rw-r--r--src/mainwindow.cpp26
-rw-r--r--src/mainwindow.h4
3 files changed, 61 insertions, 1 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));
+}
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 <QSvgRenderer>
#include <QAbstractTextDocumentLayout>
+#include <sys/types.h>
+#include <sys/socket.h>
+
#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();