Skip to content

Commit

Permalink
Use QPlatformNativeInterface for getting display on Linux (Wayland st…
Browse files Browse the repository at this point in the history
…ill incomplete)
  • Loading branch information
phoerious committed Oct 21, 2019
1 parent 8f92c2d commit e472c95
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ include(CLangFormat)

set(QT_COMPONENTS Core Network Concurrent Gui Svg Widgets Test LinguistTools)
if(UNIX AND NOT APPLE)
find_package(Qt5 COMPONENTS ${QT_COMPONENTS} DBus X11Extras REQUIRED)
find_package(Qt5 COMPONENTS ${QT_COMPONENTS} DBus REQUIRED)
elseif(APPLE)
find_package(Qt5 COMPONENTS ${QT_COMPONENTS} REQUIRED HINTS /usr/local/opt/qt/lib/cmake /usr/local/Cellar/qt/*/lib/cmake ENV PATH)
find_package(Qt5 COMPONENTS MacExtras HINTS /usr/local/opt/qt/lib/cmake /usr/local/Cellar/qt/*/lib/cmake ENV PATH)
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ if(HAIKU)
target_link_libraries(keepassx_core network)
endif()
if(UNIX AND NOT APPLE)
target_link_libraries(keepassx_core Qt5::DBus Qt5::X11Extras X11)
target_link_libraries(keepassx_core Qt5::DBus X11)
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
endif()
if(MINGW)
target_link_libraries(keepassx_core Wtsapi32.lib Ws2_32.lib)
Expand Down
11 changes: 5 additions & 6 deletions src/gui/DatabaseOpenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
m_ui->labelHeadline->setFont(font);
m_ui->labelHeadline->setText(tr("Unlock KeePassXC Database"));

m_ui->capslockWarningLabel->setVisible(false);
connect(m_ui->editPassword, &PasswordEdit::capslockToggled, [&](bool state) {
m_ui->capslockWarningLabel->setVisible(state);
});

m_ui->comboKeyFile->lineEdit()->addAction(m_ui->keyFileClearIcon, QLineEdit::TrailingPosition);

m_ui->buttonTogglePassword->setIcon(filePath()->onOffIcon("actions", "password-show"));
Expand All @@ -79,12 +84,6 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
m_ui->yubikeyProgress->setSizePolicy(sp);

connect(m_ui->buttonRedetectYubikey, SIGNAL(clicked()), SLOT(pollYubikey()));

m_ui->capsLockWarningLabel->setVisible(false);
connect(m_ui->editPassword, &PasswordEdit::capslockToggled, [&](bool state) {
m_ui->capsLockWarningLabel->setVisible(state);
});

#else
m_ui->buttonRedetectYubikey->setVisible(false);
m_ui->comboChallengeResponse->setVisible(false);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/DatabaseOpenWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="capsLockWarningLabel">
<widget class="QLabel" name="capslockWarningLabel">
<property name="styleSheet">
<string notr="true">QLabel { color: rgb(255, 125, 125); }</string>
</property>
Expand Down
19 changes: 15 additions & 4 deletions src/gui/PasswordEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "core/FilePath.h"
#include "gui/Font.h"

#include <QGuiApplication>
#include <qpa/qplatformnativeinterface.h>

#if defined(Q_OS_WIN)
#include <windows.h>
#elif defined(Q_OS_MACOS)
Expand Down Expand Up @@ -145,19 +148,27 @@ bool PasswordEdit::event(QEvent* event)
void PasswordEdit::checkCapslockState()
{
bool newCapslockState = m_capslockState;
Q_UNUSED(m_capslockState)

#if defined(Q_OS_WIN)
newCapslockState = (GetKeyState(VK_CAPITAL) == 1);
#elif defined(Q_OS_MACOS)
newCapslockState = ((CGEventSourceFlagsState(kCGEventSourceStateHIDSystemState) & kCGEventFlagMaskAlphaShift) != 0);
#elif defined(Q_OS_UNIX)
if (QX11Info::isPlatformX11() && QX11Info::display()) {
QPlatformNativeInterface* native = QGuiApplication::platformNativeInterface();
auto* display = native->nativeResourceForWindow("display", nullptr);
if (!display) {
return;
}

const QString platform = QGuiApplication::platformName();
if (platform == "xcb") {
unsigned state = 0;
// reinterpret cast needed, since we namespaced the XKBlib.h include
if (X11::XkbGetIndicatorState(
reinterpret_cast<X11::Display*>(QX11Info::display()), XkbUseCoreKbd, &state) == Success) {
if (X11::XkbGetIndicatorState(reinterpret_cast<X11::Display*>(display), XkbUseCoreKbd, &state) == Success) {
newCapslockState = ((state & 1u) != 0);
}
} else if (platform == "wayland") {
// struct wl_display* waylandDisplay = reinterpret_cast<struct wl_display*>(display);
}
#endif

Expand Down

0 comments on commit e472c95

Please sign in to comment.