Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow KeePassXC to be built without X11 #8147

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ if(UNIX AND NOT APPLE)
endif()
option(WITH_XC_DOCS "Enable building of documentation" ON)

set(WITH_XC_X11 ON CACHE BOOL "Enable building with X11 deps")

if(APPLE)
# Perform the platform checks before applying the stricter compiler flags.
# Otherwise the kSecAccessControlTouchIDCurrentSet deprecation warning will result in an error.
Expand Down Expand Up @@ -110,6 +112,11 @@ if(NOT WITH_XC_NETWORKING AND WITH_XC_UPDATECHECK)
set(WITH_XC_UPDATECHECK OFF)
endif()

if(UNIX AND NOT APPLE AND 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 @@ -466,7 +473,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)
list(APPEND 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
10 changes: 8 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ 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)
list(APPEND 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 +362,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::X11Extras X11)
endif()
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
endif()
if(WIN32)
Expand Down
28 changes: 27 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 @@ -183,6 +189,7 @@ void NixUtils::registerNativeEventFilter()

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 +202,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 +220,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 +270,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 +293,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