fix: Split XKB code out of XWindowsUtil to allow building without X11

the xprotoheaders are still required for EI, but nothing more.
This commit is contained in:
James Le Cuirot
2025-11-13 11:05:52 -05:00
committed by Nick Bolton
parent 6d89ee0660
commit 93beb491db
8 changed files with 1709 additions and 1670 deletions

View File

@ -97,6 +97,8 @@ elseif(UNIX)
XDGPortalRegistry.h
XDGPowerManager.cpp
XDGPowerManager.h
XDGKeyUtil.h
XDGKeyUtil.cpp
XWindowsClipboard.cpp
XWindowsClipboard.h
XWindowsClipboardAnyBitmapConverter.cpp

View File

@ -11,7 +11,7 @@
#include "base/Log.h"
#include "common/Settings.h"
#include "deskflow/AppUtil.h"
#include "platform/XWindowsUtil.h"
#include "platform/XDGKeyUtil.h"
#include <cstddef>
#include <memory>
@ -251,7 +251,7 @@ void EiKeyState::getKeyMap(deskflow::KeyMap &keyMap)
deskflow::KeyMap::KeyItem item{};
KeySym sym = keysym;
item.m_id = XWindowsUtil::mapKeySymToKeyID(sym);
item.m_id = XDGKeyUtil::mapKeySymToKeyID(sym);
item.m_button = static_cast<KeyButton>(keycode) - 8; // X keycode offset
item.m_group = group;
@ -332,7 +332,7 @@ KeyID EiKeyState::mapKeyFromKeyval(uint32_t keyval) const
}
auto keysym = static_cast<KeySym>(xkbKeysym);
KeyID keyid = XWindowsUtil::mapKeySymToKeyID(keysym);
KeyID keyid = XDGKeyUtil::mapKeySymToKeyID(keysym);
LOG_DEBUG1("mapped key: code=%d keysym=0x%04lx to keyID=%d", keyval, keysym, keyid);
return keyid;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,43 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#pragma once
#include <X11/X.h>
#include <cstdint>
#include <map>
#include <vector>
//! XKB utility functions
class XDGKeyUtil
{
public:
typedef std::vector<KeySym> KeySyms;
//! Convert KeySym to KeyID
/*!
Converts a KeySym to the equivalent KeyID. Returns kKeyNone if the
KeySym cannot be mapped.
*/
static std::uint32_t mapKeySymToKeyID(KeySym);
//! Convert KeySym to corresponding KeyModifierMask
/*!
Converts a KeySym to the corresponding KeyModifierMask, or 0 if the
KeySym is not a modifier.
*/
static std::uint32_t getModifierBitForKeySym(KeySym keysym);
private:
static void initKeyMaps();
typedef std::map<KeySym, std::uint32_t> KeySymMap;
static KeySymMap s_keySymToUCS4;
};

View File

@ -18,7 +18,7 @@
#include "base/Log.h"
#include "deskflow/AppUtil.h"
#include "platform/XWindowsUtil.h"
#include "platform/XDGKeyUtil.h"
#include <X11/X.h>
#include <X11/Xutil.h>
@ -479,15 +479,15 @@ void XWindowsKeyState::updateKeysymMap(deskflow::KeyMap &keyMap)
// do each keysym (shift level)
for (int j = 0; j < maxKeysyms; ++j) {
item.m_id = XWindowsUtil::mapKeySymToKeyID(keysyms[j]);
item.m_id = XDGKeyUtil::mapKeySymToKeyID(keysyms[j]);
if (item.m_id == kKeyNone) {
if (j != 0 && modifierButtons.contains(keycode)) {
// pretend the modifier works in other shift levels
// because it probably does.
if (keysyms[1] == NoSymbol || j != 3) {
item.m_id = XWindowsUtil::mapKeySymToKeyID(keysyms[0]);
item.m_id = XDGKeyUtil::mapKeySymToKeyID(keysyms[0]);
} else {
item.m_id = XWindowsUtil::mapKeySymToKeyID(keysyms[1]);
item.m_id = XDGKeyUtil::mapKeySymToKeyID(keysyms[1]);
}
}
if (item.m_id == kKeyNone) {
@ -700,7 +700,7 @@ void XWindowsKeyState::updateKeysymMapXKB(deskflow::KeyMap &keyMap)
// record the modifier mask for this key. don't bother
// for keys that change the group.
item.m_generates = 0;
if (uint32_t modifierBit = XWindowsUtil::getModifierBitForKeySym(keysym);
if (uint32_t modifierBit = XDGKeyUtil::getModifierBitForKeySym(keysym);
isModifier && modifierBit != kKeyModifierBitNone) {
item.m_generates = (1u << modifierBit);
for (int32_t j = 0; j < 8; ++j) {
@ -740,8 +740,8 @@ void XWindowsKeyState::updateKeysymMapXKB(deskflow::KeyMap &keyMap)
item.m_sensitive |= ShiftMask | LockMask;
KeyID lKeyID = XWindowsUtil::mapKeySymToKeyID(lKeysym);
KeyID uKeyID = XWindowsUtil::mapKeySymToKeyID(uKeysym);
KeyID lKeyID = XDGKeyUtil::mapKeySymToKeyID(lKeysym);
KeyID uKeyID = XDGKeyUtil::mapKeySymToKeyID(uKeysym);
if (lKeyID == kKeyNone || uKeyID == kKeyNone) {
continue;
}
@ -765,7 +765,7 @@ void XWindowsKeyState::updateKeysymMapXKB(deskflow::KeyMap &keyMap)
}
// add entry
item.m_id = XWindowsUtil::mapKeySymToKeyID(keysym);
item.m_id = XDGKeyUtil::mapKeySymToKeyID(keysym);
keyMap.addKeyEntry(item);
if (group == 0) {
m_keyCodeFromKey.insert(std::make_pair(item.m_id, keycode));

View File

@ -19,6 +19,7 @@
#include "deskflow/Clipboard.h"
#include "deskflow/KeyMap.h"
#include "deskflow/ScreenException.h"
#include "platform/XDGKeyUtil.h"
#include "platform/XWindowsClipboard.h"
#include "platform/XWindowsEventQueueBuffer.h"
#include "platform/XWindowsKeyState.h"
@ -1736,7 +1737,7 @@ KeyID XWindowsScreen::mapKeyFromX(XKeyEvent *event) const
LOG_DEBUG2("mapped code=%d to keysym=0x%04x", event->keycode, keysym);
// convert key
KeyID result = XWindowsUtil::mapKeySymToKeyID(keysym);
KeyID result = XDGKeyUtil::mapKeySymToKeyID(keysym);
LOG_DEBUG2("mapped keysym=0x%04x to keyID=%d", keysym, result);
return result;
}

File diff suppressed because it is too large Load Diff

View File

@ -8,9 +8,7 @@
#pragma once
#include <cstdint>
#include <map>
#include <string>
#include <vector>
#include <X11/Xlib.h>
@ -18,8 +16,6 @@
class XWindowsUtil
{
public:
using KeySyms = std::vector<KeySym>;
//! Get property
/*!
Gets property \c property on \c window. \b Appends the data to
@ -47,20 +43,6 @@ public:
*/
static Time getCurrentTime(Display *, Window);
//! Convert KeySym to KeyID
/*!
Converts a KeySym to the equivalent KeyID. Returns kKeyNone if the
KeySym cannot be mapped.
*/
static uint32_t mapKeySymToKeyID(KeySym);
//! Convert KeySym to corresponding KeyModifierMask
/*!
Converts a KeySym to the corresponding KeyModifierMask, or 0 if the
KeySym is not a modifier.
*/
static uint32_t getModifierBitForKeySym(KeySym keysym);
//! Convert Atom to its string
/*!
Converts \p atom to its string representation.
@ -165,11 +147,4 @@ private:
};
static Bool propertyNotifyPredicate(Display *, XEvent *xevent, XPointer arg);
static void initKeyMaps();
private:
using KeySymMap = std::map<KeySym, uint32_t>;
static KeySymMap s_keySymToUCS4;
};