summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-04-18 15:55:48 +0200
committerSimon Rettberg2019-04-18 15:55:48 +0200
commitdd3ee3821fb6ebab9d1b0858e357ad110822d7e1 (patch)
treec658ab6fcad69fbfcd5b79363a2557df06ddf728
parentFix: mini-icon might get cropped if > 95px (diff)
downloadslxgreeter-dd3ee3821fb6ebab9d1b0858e357ad110822d7e1.tar.gz
slxgreeter-dd3ee3821fb6ebab9d1b0858e357ad110822d7e1.tar.xz
slxgreeter-dd3ee3821fb6ebab9d1b0858e357ad110822d7e1.zip
Add caps lock warning
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/loginform.cpp47
-rw-r--r--src/loginform.h6
-rw-r--r--src/loginform.ui1
-rw-r--r--src/x11util.cpp9
-rw-r--r--src/x11util.h3
6 files changed, 58 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e33c334..47eb417 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,8 +14,7 @@ set(CMAKE_AUTOMOC ON)
file(GLOB SRCS src/*.cpp)
file(GLOB UIS src/*.ui)
-find_package(Qt5Widgets REQUIRED)
-find_package(Qt5Svg REQUIRED)
+FIND_PACKAGE(Qt5 COMPONENTS Widgets X11Extras Svg REQUIRED)
FIND_PACKAGE(X11 REQUIRED)
QT5_ADD_RESOURCES(RSCS qt-lightdm-greeter.qrc)
@@ -50,6 +49,7 @@ add_executable ( qt-lightdm-greeter ${SRCS} ${RSCS} ${UI_HEADERS} )
target_link_libraries ( qt-lightdm-greeter
Qt5::Widgets
+ Qt5::X11Extras
Qt5::Svg
${LIGHTDM_QT_LIBRARIES}
${X11_LIBRARIES}
diff --git a/src/loginform.cpp b/src/loginform.cpp
index b8db5cf..5faa617 100644
--- a/src/loginform.cpp
+++ b/src/loginform.cpp
@@ -7,6 +7,18 @@
* It is distributed under the LGPL 2.1 or later license.
* Please refer to the LICENSE file for a copy of the license.
*/
+
+#include "loginform.h"
+#include "ui_loginform.h"
+#include "settings.h"
+#include "global.h"
+#include "namereplace.h"
+#include "x11util.h"
+#undef KeyPress
+#undef KeyRelease
+#undef FocusIn
+#undef FocusOut
+
#include <QAbstractListModel>
#include <QModelIndex>
#include <QPixmap>
@@ -15,19 +27,15 @@
#include <QMenu>
#include <QListView>
#include <QSvgRenderer>
+#include <QX11Info>
#include <iostream>
-#include "loginform.h"
-#include "ui_loginform.h"
-#include "settings.h"
-#include "global.h"
-#include "namereplace.h"
-
LoginForm::LoginForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::LoginForm),
- clearMsg(false)
+ clearMsg(false),
+ capsOn(-1)
{
ui->setupUi(this);
initialize();
@@ -101,6 +109,24 @@ void LoginForm::initialize()
ui->leaveComboBox->setDisabled(ui->leaveComboBox->count() <= 1);
ui->passwordInput->clear();
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
+ this->installEventFilter(this);
+ checkCaps();
+}
+
+void LoginForm::checkCaps()
+{
+ unsigned int mask = getKeyMask(QX11Info::display());
+ int caps = (mask & 1) == 1;
+ if (caps != capsOn) {
+ capsOn = caps;
+ QString message(tr("!! CAPS LOCK ACTIVE !!"));
+ if (caps) {
+ ui->messageLabel->setProperty("caps", message);
+ showMessage(message, false);
+ } else if (ui->messageLabel->property("caps").toString() == message) {
+ hideMessage();
+ }
+ }
}
void LoginForm::startAuthentication()
@@ -241,3 +267,10 @@ void LoginForm::keyPressEvent(QKeyEvent *event)
QWidget::keyPressEvent(event);
}
+bool LoginForm::eventFilter(QObject *object, QEvent *event)
+{
+ if (event->type() == QEvent::KeyRelease) {
+ checkCaps();
+ }
+ return false;
+}
diff --git a/src/loginform.h b/src/loginform.h
index 83ddd28..35d0fea 100644
--- a/src/loginform.h
+++ b/src/loginform.h
@@ -46,11 +46,12 @@ public slots:
void hideMessage();
protected:
- virtual void keyPressEvent(QKeyEvent *event);
+ virtual void keyPressEvent(QKeyEvent *event) override;
+ virtual bool eventFilter(QObject *object, QEvent *event) override;
private:
void initialize();
- void loadSubs();
+ void checkCaps();
void addLeaveEntry(bool canDo, QString iconName, QString text, QString actionName);
QString currentSession();
void setCurrentSession(QString session);
@@ -64,6 +65,7 @@ private:
QTimer hideMessageTimer;
bool clearMsg;
+ int capsOn;
};
#endif // LOGINFORM_H
diff --git a/src/loginform.ui b/src/loginform.ui
index d1f0678..f195294 100644
--- a/src/loginform.ui
+++ b/src/loginform.ui
@@ -52,6 +52,7 @@ QPushButton {
#messageLabel {
border: 1px solid #888;
+ background-color: rgba(150,150,150, 128);
}
QComboBox::drop-down {
diff --git a/src/x11util.cpp b/src/x11util.cpp
index 67dae90..c401b4f 100644
--- a/src/x11util.cpp
+++ b/src/x11util.cpp
@@ -2,6 +2,7 @@
extern "C" {
#include <X11/Xlib.h>
#include <X11/Xutil.h>
+ #include <X11/XKBlib.h>
}
#include <cstring>
#include <cstdlib>
@@ -62,3 +63,11 @@ cleanup:
XCloseDisplay(dpy);
}
}
+
+extern "C"
+unsigned int getKeyMask(Display *dpy)
+{
+ unsigned int n = 0;
+ XkbGetIndicatorState(dpy, XkbUseCoreKbd, &n);
+ return n;
+}
diff --git a/src/x11util.h b/src/x11util.h
index 0ae8bc7..f62de8f 100644
--- a/src/x11util.h
+++ b/src/x11util.h
@@ -4,9 +4,10 @@
#include <cstddef>
extern "C" {
- #include <X11/X.h>
+ #include <X11/Xlib.h>
void AddPixmapToBackground(unsigned const char* imgData, const unsigned int width, const unsigned int height,
const unsigned int depth, const int bytesPerLine, const size_t byteCount);
+ unsigned int getKeyMask(Display *dpy);
}
#endif /* X11UTIL_H_ */