mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-22 15:39:57 -05:00
Allow KeePassXC to be built without X11
This commit is contained in:
parent
ed693e146d
commit
bdeef63fe4
@ -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.
|
||||
@ -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")
|
||||
@ -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
|
||||
|
@ -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
|
||||
@ -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)
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QStyle>
|
||||
#include <QTextStream>
|
||||
#ifdef WITH_XC_AUTOTYPE
|
||||
#include <QX11Info>
|
||||
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
@ -44,6 +45,7 @@ namespace
|
||||
return 1;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
QPointer<NixUtils> NixUtils::m_instance = nullptr;
|
||||
|
||||
@ -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();
|
||||
@ -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) {
|
||||
@ -170,6 +175,7 @@ bool NixUtils::isCapslockEnabled()
|
||||
return ((state & 1u) != 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO: Wayland
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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();
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user