Skip to content

Commit

Permalink
Allow KeePassXC to be built without X11
Browse files Browse the repository at this point in the history
KeePassXC can be built without X11 (with disabled autotype) before commit 404fd94.
Current commit is restoring this behaviour, by option WITH_XC_X11 (enabled by default)
  • Loading branch information
ya-isakov committed Jun 13, 2022
1 parent 6cb6f1f commit db8e1ef
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ if(UNIX AND NOT APPLE)
option(WITH_XC_FDOSECRETS "Implement freedesktop.org Secret Storage Spec server side API." OFF)
endif()
option(WITH_XC_DOCS "Enable building of documentation" ON)
option(WITH_XC_X11 "Enable building with X11 deps" ON)

if(WITH_CCACHE)
# Use the Compiler Cache (ccache) program
Expand Down Expand Up @@ -91,6 +92,11 @@ if(NOT WITH_XC_NETWORKING AND WITH_XC_UPDATECHECK)
set(WITH_XC_UPDATECHECK OFF)
endif()

if(NOT WITH_XC_X11)
message(STATUS "Disabling WITH_XC_AUTOTYPE because WITH_XC_X11 is disabled")
set(WITH_XC_AUTOTYPE OFF)
endif()

set(KEEPASSXC_VERSION_MAJOR "2")
set(KEEPASSXC_VERSION_MINOR "7")
set(KEEPASSXC_VERSION_PATCH "1")
Expand Down Expand Up @@ -447,7 +453,10 @@ 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)
if(WITH_XC_X11)
set(QT_COMPONENTS ${QT_COMPONENTS} X11Extras)
endif()
find_package(Qt5 COMPONENTS ${QT_COMPONENTS} DBus REQUIRED)
elseif(APPLE)
find_package(Qt5 COMPONENTS ${QT_COMPONENTS} REQUIRED HINTS
/usr/local/opt/qt/lib/cmake
Expand Down
11 changes: 9 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,12 @@ if(UNIX AND NOT APPLE)
set(keepassx_SOURCES
${keepassx_SOURCES}
gui/osutils/nixutils/ScreenLockListenerDBus.cpp
gui/osutils/nixutils/NixUtils.cpp
gui/osutils/nixutils/NixUtils.cpp)
if(WITH_XC_X11)
set(keepassx_SOURCES
${keepassx_SOURCES}
gui/osutils/nixutils/X11Funcs.cpp)
endif()
qt5_add_dbus_adaptor(keepassx_SOURCES
gui/org.keepassxc.KeePassXC.MainWindow.xml
gui/MainWindow.h
Expand Down Expand Up @@ -359,7 +363,10 @@ 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)
if(WITH_XC_X11)
target_link_libraries(keepassx_core Qt5::DBus Qt5::X11Extras X11)
endif()
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
endif()
if(WIN32)
Expand Down
30 changes: 29 additions & 1 deletion src/gui/osutils/nixutils/NixUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QStandardPaths>
#include <QStyle>
#include <QTextStream>
#ifdef WITH_XC_AUTOTYPE
#include <QX11Info>

#include <qpa/qplatformnativeinterface.h>
Expand All @@ -44,6 +45,7 @@ namespace
return 1;
}
} // namespace
#endif

QPointer<NixUtils> NixUtils::m_instance = nullptr;

Expand All @@ -59,8 +61,10 @@ NixUtils* NixUtils::instance()
NixUtils::NixUtils(QObject* parent)
: OSUtilsBase(parent)
{
#ifdef WITH_XC_X11
dpy = QX11Info::display();
rootWindow = QX11Info::appRootWindow();
#endif

// notify about system color scheme changes
QDBusConnection sessionBus = QDBusConnection::sessionBus();
Expand Down Expand Up @@ -157,6 +161,7 @@ void NixUtils::setLaunchAtStartup(bool enable)

bool NixUtils::isCapslockEnabled()
{
#ifdef WITH_XC_X11
QPlatformNativeInterface* native = QGuiApplication::platformNativeInterface();
auto* display = native->nativeResourceForWindow("display", nullptr);
if (!display) {
Expand All @@ -170,6 +175,7 @@ bool NixUtils::isCapslockEnabled()
return ((state & 1u) != 0);
}
}
#endif

// TODO: Wayland

Expand All @@ -178,11 +184,14 @@ bool NixUtils::isCapslockEnabled()

void NixUtils::registerNativeEventFilter()
{
#ifdef WITH_XC_X11
qApp->installNativeEventFilter(this);
#endif
}

bool NixUtils::nativeEventFilter(const QByteArray& eventType, void* message, long*)
{
#ifdef WITH_XC_X11
if (eventType != QByteArrayLiteral("xcb_generic_event_t")) {
return false;
}
Expand All @@ -195,12 +204,16 @@ bool NixUtils::nativeEventFilter(const QByteArray& eventType, void* message, lon
auto modifierMask = ControlMask | ShiftMask | Mod1Mask | Mod4Mask;
return triggerGlobalShortcut(keyPressEvent->detail, keyPressEvent->state & modifierMask);
}

#else
Q_UNUSED(eventType);
Q_UNUSED(message);
#endif
return false;
}

bool NixUtils::triggerGlobalShortcut(uint keycode, uint modifiers)
{
#ifdef WITH_XC_X11
QHashIterator<QString, QSharedPointer<globalShortcut>> i(m_globalShortcuts);
while (i.hasNext()) {
i.next();
Expand All @@ -209,11 +222,16 @@ bool NixUtils::triggerGlobalShortcut(uint keycode, uint modifiers)
return true;
}
}
#else
Q_UNUSED(keycode);
Q_UNUSED(modifiers);
#endif
return false;
}

bool NixUtils::registerGlobalShortcut(const QString& name, Qt::Key key, Qt::KeyboardModifiers modifiers, QString* error)
{
#ifdef WITH_XC_X11
auto keycode = XKeysymToKeycode(dpy, qcharToNativeKeyCode(key));
auto modifierscode = qtToNativeModifiers(modifiers);

Expand Down Expand Up @@ -254,11 +272,18 @@ bool NixUtils::registerGlobalShortcut(const QString& name, Qt::Key key, Qt::Keyb
gs->nativeKeyCode = keycode;
gs->nativeModifiers = modifierscode;
m_globalShortcuts.insert(name, gs);
#else
Q_UNUSED(name);
Q_UNUSED(key);
Q_UNUSED(modifiers);
Q_UNUSED(error);
#endif
return true;
}

bool NixUtils::unregisterGlobalShortcut(const QString& name)
{
#ifdef WITH_XC_X11
if (!m_globalShortcuts.contains(name)) {
return false;
}
Expand All @@ -270,6 +295,9 @@ bool NixUtils::unregisterGlobalShortcut(const QString& name)
XUngrabKey(dpy, gs->nativeKeyCode, gs->nativeModifiers | Mod2Mask | LockMask, rootWindow);

m_globalShortcuts.remove(name);
#else
Q_UNUSED(name);
#endif
return true;
}

Expand Down

0 comments on commit db8e1ef

Please sign in to comment.