[network/kdeconnect-kde/release/26.04] plugins/mousepad: Use the specialKey validation across remote input implementations
Albert Vaca Cintora <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit b67f3097104f448842d4ef0ddcb782289da68544 by Albert Vaca Cintora.
Committed on 02/08/2026 at 21:11.
Pushed by albertvaka into branch 'release/26.04'.
Use the specialKey validation across remote input implementations
(cherry picked from commit 60d3238d74bfcf205ae11fa818ce6be0a0cf4853)
M +3 -10 plugins/mousepad/macosremoteinput.mm
M +6 -4 plugins/mousepad/waylandremoteinput.cpp
M +3 -15 plugins/mousepad/windowsremoteinput.cpp
M +3 -16 plugins/mousepad/x11remoteinput.cpp
https://invent.kde.org/network/kdeconnect-kde/-/commit/b67f3097104f448842d4ef0ddcb782289da68544
diff --git a/plugins/mousepad/macosremoteinput.mm b/plugins/mousepad/macosremoteinput.mm
index 7a23769ac..49456e254 100644
--- a/plugins/mousepad/macosremoteinput.mm
+++ b/plugins/mousepad/macosremoteinput.mm
@@ -49,9 +49,6 @@ int SpecialKeysMap[] = {
kVK_F12, // 32
};
-template <typename T, size_t N>
-size_t arraySize(T(&arr)[N]) { (void)arr; return N; }
-
MacOSRemoteInput::MacOSRemoteInput(QObject* parent)
: AbstractRemoteInput(parent)
{
@@ -83,6 +80,7 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np)
bool isScroll = np.get<bool>(QStringLiteral("scroll"), false);
QString key = np.get<QString>(QStringLiteral("key"), QLatin1String(""));
int specialKey = np.get<int>(QStringLiteral("specialKey"), 0);
+ bool validSpecialKey = (specialKey > 0 && specialKey < (int)std::size(SpecialKeysMap));
if (isSingleClick || isDoubleClick || isMiddleClick || isRightClick || isSingleHold || isSingleRelease || isScroll || !key.isEmpty() || specialKey) {
QPoint point = QCursor::pos();
@@ -134,7 +132,7 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np)
CGEventRef event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, dy);
CGEventPost(kCGHIDEventTap, event);
CFRelease(event);
- } else if (!key.isEmpty() || specialKey) {
+ } else if (!key.isEmpty() || validSpecialKey) {
// Get function keys
bool ctrl = np.get<bool>(QStringLiteral("ctrl"), false);
bool alt = np.get<bool>(QStringLiteral("alt"), false);
@@ -164,13 +162,8 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np)
}
// Keys
- if (specialKey)
+ if (validSpecialKey)
{
- if (specialKey >= (int)arraySize(SpecialKeysMap)) {
- qWarning() << "Unsupported special key identifier";
- return false;
- }
-
CGEventRef specialKeyDownEvent = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)SpecialKeysMap[specialKey], true),
specialKeyUpEvent = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)SpecialKeysMap[specialKey], false);
diff --git a/plugins/mousepad/waylandremoteinput.cpp b/plugins/mousepad/waylandremoteinput.cpp
index 6f6eb0953..dd669faa1 100644
--- a/plugins/mousepad/waylandremoteinput.cpp
+++ b/plugins/mousepad/waylandremoteinput.cpp
@@ -453,6 +453,7 @@ bool WaylandRemoteInput::handlePacket(const NetworkPacket &np)
const bool isScroll = np.get<bool>(QStringLiteral("scroll"), false);
const QString key = np.get<QString>(QStringLiteral("key"), QLatin1String(""));
const int specialKey = np.get<int>(QStringLiteral("specialKey"), 0);
+ bool validSpecialKey = (specialKey > 0 && specialKey < (int)std::size(SpecialKeysMap));
if (isSingleClick || isDoubleClick || isMiddleClick || isRightClick || isSingleHold || isSingleRelease || isScroll || !key.isEmpty() || specialKey) {
if (isSingleClick) {
@@ -476,7 +477,7 @@ bool WaylandRemoteInput::handlePacket(const NetworkPacket &np)
s_session->pointerButton(BTN_LEFT, false);
} else if (isScroll) {
s_session->pointerAxis(dx, dy);
- } else if (specialKey || !key.isEmpty()) {
+ } else if (validSpecialKey || !key.isEmpty()) {
bool ctrl = np.get<bool>(QStringLiteral("ctrl"), false);
bool alt = np.get<bool>(QStringLiteral("alt"), false);
bool shift = np.get<bool>(QStringLiteral("shift"), false);
@@ -491,9 +492,10 @@ bool WaylandRemoteInput::handlePacket(const NetworkPacket &np)
if (super)
s_session->keyboardKeycode(KEY_LEFTMETA, true);
- if (specialKey) {
- s_session->keyboardKeycode(SpecialKeysMap[specialKey], true);
- s_session->keyboardKeycode(SpecialKeysMap[specialKey], false);
+ if (validSpecialKey) {
+ const int keycode = SpecialKeysMap[specialKey];
+ s_session->keyboardKeycode(keycode, true);
+ s_session->keyboardKeycode(keycode, false);
} else if (!key.isEmpty()) {
for (const QChar character : key) {
const auto keysym = xkb_utf32_to_keysym(character.unicode());
diff --git a/plugins/mousepad/windowsremoteinput.cpp b/plugins/mousepad/windowsremoteinput.cpp
index f6f2a280a..7e238e404 100644
--- a/plugins/mousepad/windowsremoteinput.cpp
+++ b/plugins/mousepad/windowsremoteinput.cpp
@@ -48,13 +48,6 @@ int SpecialKeysMap[] = {
VK_F12, // 32
};
-template<typename T, size_t N>
-size_t arraySize(T (&arr)[N])
-{
- (void)arr;
- return N;
-}
-
WindowsRemoteInput::WindowsRemoteInput(QObject *parent)
: AbstractRemoteInput(parent)
{
@@ -76,6 +69,7 @@ bool WindowsRemoteInput::handlePacket(const NetworkPacket &np)
bool isScroll = np.get<bool>(QStringLiteral("scroll"), false);
QString key = np.get<QString>(QStringLiteral("key"), QLatin1String(""));
int specialKey = np.get<int>(QStringLiteral("specialKey"), 0);
+ bool validSpecialKey = (specialKey > 0 && specialKey < (int)std::size(SpecialKeysMap));
if (isSingleClick || isDoubleClick || isMiddleClick || isRightClick || isSingleHold || isScroll || isSingleRelease || !key.isEmpty() || specialKey) {
INPUT input = {0};
@@ -116,7 +110,7 @@ bool WindowsRemoteInput::handlePacket(const NetworkPacket &np)
input.mi.mouseData = dy;
::SendInput(1, &input, sizeof(INPUT));
- } else if (!key.isEmpty() || specialKey) {
+ } else if (!key.isEmpty() || validSpecialKey) {
input.type = INPUT_KEYBOARD;
input.ki.time = 0;
@@ -146,18 +140,12 @@ bool WindowsRemoteInput::handlePacket(const NetworkPacket &np)
::SendInput(1, &input, sizeof(INPUT));
}
- if (specialKey) {
- if (specialKey >= (int)arraySize(SpecialKeysMap)) {
- qWarning() << "Unsupported special key identifier";
- return false;
- }
-
+ if (validSpecialKey) {
input.ki.wVk = SpecialKeysMap[specialKey];
::SendInput(1, &input, sizeof(INPUT));
input.ki.dwFlags = KEYEVENTF_KEYUP;
::SendInput(1, &input, sizeof(INPUT));
-
} else {
for (int i = 0; i < key.length(); i++) {
wchar_t inputChar = (wchar_t)key.at(i).unicode();
diff --git a/plugins/mousepad/x11remoteinput.cpp b/plugins/mousepad/x11remoteinput.cpp
index 7452bb5b2..fe5dfaba8 100644
--- a/plugins/mousepad/x11remoteinput.cpp
+++ b/plugins/mousepad/x11remoteinput.cpp
@@ -60,13 +60,6 @@ int SpecialKeysMap[] = {
XK_F12, // 32
};
-template<typename T, size_t N>
-size_t arraySize(T (&arr)[N])
-{
- (void)arr;
- return N;
-}
-
X11RemoteInput::X11RemoteInput(QObject *parent)
: AbstractRemoteInput(parent)
, m_fakekey(nullptr)
@@ -110,6 +103,7 @@ bool X11RemoteInput::handlePacket(const NetworkPacket &np)
bool isScroll = np.get<bool>(QStringLiteral("scroll"), false);
QString key = np.get<QString>(QStringLiteral("key"), QLatin1String(""));
int specialKey = np.get<int>(QStringLiteral("specialKey"), 0);
+ bool validSpecialKey = (specialKey > 0 && specialKey < (int)std::size(SpecialKeysMap));
if (isSingleClick || isDoubleClick || isMiddleClick || isRightClick || isSingleHold || isSingleRelease || isScroll || !key.isEmpty() || specialKey) {
Display *display = QX11Info::display();
@@ -148,7 +142,7 @@ bool X11RemoteInput::handlePacket(const NetworkPacket &np)
XTestFakeButtonEvent(display, MouseWheelUp, True, 0);
XTestFakeButtonEvent(display, MouseWheelUp, False, 0);
}
- } else if (!key.isEmpty() || specialKey) {
+ } else if (!key.isEmpty() || validSpecialKey) {
bool ctrl = np.get<bool>(QStringLiteral("ctrl"), false);
bool alt = np.get<bool>(QStringLiteral("alt"), false);
bool shift = np.get<bool>(QStringLiteral("shift"), false);
@@ -163,17 +157,10 @@ bool X11RemoteInput::handlePacket(const NetworkPacket &np)
if (super)
XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Super_L), True, 0);
- if (specialKey) {
- if (specialKey >= (int)arraySize(SpecialKeysMap)) {
- qWarning() << "Unsupported special key identifier";
- return false;
- }
-
+ if (validSpecialKey) {
int keycode = XKeysymToKeycode(display, SpecialKeysMap[specialKey]);
-
XTestFakeKeyEvent(display, keycode, True, 0);
XTestFakeKeyEvent(display, keycode, False, 0);
-
} else {
if (!m_fakekey) {
m_fakekey = fakekey_init(display);