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:
parent
6d89ee0660
commit
93beb491db
8 changed files with 1709 additions and 1670 deletions
|
|
@ -97,6 +97,8 @@ elseif(UNIX)
|
||||||
XDGPortalRegistry.h
|
XDGPortalRegistry.h
|
||||||
XDGPowerManager.cpp
|
XDGPowerManager.cpp
|
||||||
XDGPowerManager.h
|
XDGPowerManager.h
|
||||||
|
XDGKeyUtil.h
|
||||||
|
XDGKeyUtil.cpp
|
||||||
XWindowsClipboard.cpp
|
XWindowsClipboard.cpp
|
||||||
XWindowsClipboard.h
|
XWindowsClipboard.h
|
||||||
XWindowsClipboardAnyBitmapConverter.cpp
|
XWindowsClipboardAnyBitmapConverter.cpp
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
#include "common/Settings.h"
|
#include "common/Settings.h"
|
||||||
#include "deskflow/AppUtil.h"
|
#include "deskflow/AppUtil.h"
|
||||||
#include "platform/XWindowsUtil.h"
|
#include "platform/XDGKeyUtil.h"
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -251,7 +251,7 @@ void EiKeyState::getKeyMap(deskflow::KeyMap &keyMap)
|
||||||
|
|
||||||
deskflow::KeyMap::KeyItem item{};
|
deskflow::KeyMap::KeyItem item{};
|
||||||
KeySym sym = keysym;
|
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_button = static_cast<KeyButton>(keycode) - 8; // X keycode offset
|
||||||
item.m_group = group;
|
item.m_group = group;
|
||||||
|
|
||||||
|
|
@ -332,7 +332,7 @@ KeyID EiKeyState::mapKeyFromKeyval(uint32_t keyval) const
|
||||||
}
|
}
|
||||||
|
|
||||||
auto keysym = static_cast<KeySym>(xkbKeysym);
|
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);
|
LOG_DEBUG1("mapped key: code=%d keysym=0x%04lx to keyID=%d", keyval, keysym, keyid);
|
||||||
|
|
||||||
return keyid;
|
return keyid;
|
||||||
|
|
|
||||||
1651
src/lib/platform/XDGKeyUtil.cpp
Normal file
1651
src/lib/platform/XDGKeyUtil.cpp
Normal file
File diff suppressed because it is too large
Load diff
43
src/lib/platform/XDGKeyUtil.h
Normal file
43
src/lib/platform/XDGKeyUtil.h
Normal 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;
|
||||||
|
};
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
#include "deskflow/AppUtil.h"
|
#include "deskflow/AppUtil.h"
|
||||||
#include "platform/XWindowsUtil.h"
|
#include "platform/XDGKeyUtil.h"
|
||||||
|
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
|
|
@ -479,15 +479,15 @@ void XWindowsKeyState::updateKeysymMap(deskflow::KeyMap &keyMap)
|
||||||
|
|
||||||
// do each keysym (shift level)
|
// do each keysym (shift level)
|
||||||
for (int j = 0; j < maxKeysyms; ++j) {
|
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 (item.m_id == kKeyNone) {
|
||||||
if (j != 0 && modifierButtons.contains(keycode)) {
|
if (j != 0 && modifierButtons.contains(keycode)) {
|
||||||
// pretend the modifier works in other shift levels
|
// pretend the modifier works in other shift levels
|
||||||
// because it probably does.
|
// because it probably does.
|
||||||
if (keysyms[1] == NoSymbol || j != 3) {
|
if (keysyms[1] == NoSymbol || j != 3) {
|
||||||
item.m_id = XWindowsUtil::mapKeySymToKeyID(keysyms[0]);
|
item.m_id = XDGKeyUtil::mapKeySymToKeyID(keysyms[0]);
|
||||||
} else {
|
} else {
|
||||||
item.m_id = XWindowsUtil::mapKeySymToKeyID(keysyms[1]);
|
item.m_id = XDGKeyUtil::mapKeySymToKeyID(keysyms[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.m_id == kKeyNone) {
|
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
|
// record the modifier mask for this key. don't bother
|
||||||
// for keys that change the group.
|
// for keys that change the group.
|
||||||
item.m_generates = 0;
|
item.m_generates = 0;
|
||||||
if (uint32_t modifierBit = XWindowsUtil::getModifierBitForKeySym(keysym);
|
if (uint32_t modifierBit = XDGKeyUtil::getModifierBitForKeySym(keysym);
|
||||||
isModifier && modifierBit != kKeyModifierBitNone) {
|
isModifier && modifierBit != kKeyModifierBitNone) {
|
||||||
item.m_generates = (1u << modifierBit);
|
item.m_generates = (1u << modifierBit);
|
||||||
for (int32_t j = 0; j < 8; ++j) {
|
for (int32_t j = 0; j < 8; ++j) {
|
||||||
|
|
@ -740,8 +740,8 @@ void XWindowsKeyState::updateKeysymMapXKB(deskflow::KeyMap &keyMap)
|
||||||
|
|
||||||
item.m_sensitive |= ShiftMask | LockMask;
|
item.m_sensitive |= ShiftMask | LockMask;
|
||||||
|
|
||||||
KeyID lKeyID = XWindowsUtil::mapKeySymToKeyID(lKeysym);
|
KeyID lKeyID = XDGKeyUtil::mapKeySymToKeyID(lKeysym);
|
||||||
KeyID uKeyID = XWindowsUtil::mapKeySymToKeyID(uKeysym);
|
KeyID uKeyID = XDGKeyUtil::mapKeySymToKeyID(uKeysym);
|
||||||
if (lKeyID == kKeyNone || uKeyID == kKeyNone) {
|
if (lKeyID == kKeyNone || uKeyID == kKeyNone) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -765,7 +765,7 @@ void XWindowsKeyState::updateKeysymMapXKB(deskflow::KeyMap &keyMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
// add entry
|
// add entry
|
||||||
item.m_id = XWindowsUtil::mapKeySymToKeyID(keysym);
|
item.m_id = XDGKeyUtil::mapKeySymToKeyID(keysym);
|
||||||
keyMap.addKeyEntry(item);
|
keyMap.addKeyEntry(item);
|
||||||
if (group == 0) {
|
if (group == 0) {
|
||||||
m_keyCodeFromKey.insert(std::make_pair(item.m_id, keycode));
|
m_keyCodeFromKey.insert(std::make_pair(item.m_id, keycode));
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
#include "deskflow/Clipboard.h"
|
#include "deskflow/Clipboard.h"
|
||||||
#include "deskflow/KeyMap.h"
|
#include "deskflow/KeyMap.h"
|
||||||
#include "deskflow/ScreenException.h"
|
#include "deskflow/ScreenException.h"
|
||||||
|
#include "platform/XDGKeyUtil.h"
|
||||||
#include "platform/XWindowsClipboard.h"
|
#include "platform/XWindowsClipboard.h"
|
||||||
#include "platform/XWindowsEventQueueBuffer.h"
|
#include "platform/XWindowsEventQueueBuffer.h"
|
||||||
#include "platform/XWindowsKeyState.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);
|
LOG_DEBUG2("mapped code=%d to keysym=0x%04x", event->keycode, keysym);
|
||||||
|
|
||||||
// convert key
|
// convert key
|
||||||
KeyID result = XWindowsUtil::mapKeySymToKeyID(keysym);
|
KeyID result = XDGKeyUtil::mapKeySymToKeyID(keysym);
|
||||||
LOG_DEBUG2("mapped keysym=0x%04x to keyID=%d", keysym, result);
|
LOG_DEBUG2("mapped keysym=0x%04x to keyID=%d", keysym, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -8,9 +8,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
|
@ -18,8 +16,6 @@
|
||||||
class XWindowsUtil
|
class XWindowsUtil
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using KeySyms = std::vector<KeySym>;
|
|
||||||
|
|
||||||
//! Get property
|
//! Get property
|
||||||
/*!
|
/*!
|
||||||
Gets property \c property on \c window. \b Appends the data to
|
Gets property \c property on \c window. \b Appends the data to
|
||||||
|
|
@ -47,20 +43,6 @@ public:
|
||||||
*/
|
*/
|
||||||
static Time getCurrentTime(Display *, Window);
|
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
|
//! Convert Atom to its string
|
||||||
/*!
|
/*!
|
||||||
Converts \p atom to its string representation.
|
Converts \p atom to its string representation.
|
||||||
|
|
@ -165,11 +147,4 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
static Bool propertyNotifyPredicate(Display *, XEvent *xevent, XPointer arg);
|
static Bool propertyNotifyPredicate(Display *, XEvent *xevent, XPointer arg);
|
||||||
|
|
||||||
static void initKeyMaps();
|
|
||||||
|
|
||||||
private:
|
|
||||||
using KeySymMap = std::map<KeySym, uint32_t>;
|
|
||||||
|
|
||||||
static KeySymMap s_keySymToUCS4;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue