Skip to content

Support VK_PACKET in vncviewer on Windows - #1852

Closed
svenssonaxel wants to merge 2 commits into
TigerVNC:masterfrom
svenssonaxel:vkpacket
Closed

Support VK_PACKET in vncviewer on Windows#1852
svenssonaxel wants to merge 2 commits into
TigerVNC:masterfrom
svenssonaxel:vkpacket

Conversation

@svenssonaxel

Copy link
Copy Markdown
Contributor

Fixes #1847

Fixes TigerVNC#1847

Co-authored-by: Pierre Ossman <ossman@cendio.se>
Comment thread vncviewer/Viewport.cxx

// VK_PACKET handling: Translate to WM_*CHAR message, handled below.
if (vKey == VK_PACKET) {
TranslateMessage(msg);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather avoid the risk of intercepting another message type. Was there not enough information in the WM_KEYDOWN event? TranslateMessage() is able to make sense of it somehow, so there should be something there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I analyzed a hex dump of the entire WM_KEYDOWN message, and there is nothing there. TranslateMessage() is a Windows API call and need not be limited to the information contained in the parameter. Perhaps there is something in adjacent memory, but even if so it'd be riskier to access that than to use the provided API.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with it here and I could not find anything in the event either.

But I was getting proper symbols back from win32_vkey_to_keysym(). The complexity from TranslateMessage() might not be needed.

Did you test that path?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, TranslateMessage() was not needed. Rewritten as you suggested.

Comment thread vncviewer/Viewport.cxx
// Plane, BMP), are encoded as a pair of UTF-16 code units that will need to
// be synthesized into one Unicode code point.
uint32_t ucsCode = msg->wParam;
if ((ucsCode & 0xfc00) == 0xd800) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the surrogate handling be a separate commit? Makes it easier to see which parts are connected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could, but only by making a first commit that exhibits wrong behavior w.r.t. surrogate pairs. Would you like that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread vncviewer/Viewport.cxx Outdated
codePoint = ucsCode;
}
uint32_t keySym = ucs2keysym(codePoint);
uint32_t keyCode = 0x100 + keySym; // Fake key code

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keysym is 32-bit, so this is not going to work. Perhaps something similar to the universal keysyms? I.e. 0x01000000 | codePoint?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will change to what you suggested. Another option is actually a constant, e.g. keyCode = 0x123, since we expect only one concurrent VK_PACKET key down.

Comment thread vncviewer/keysym2ucs.c Outdated
/* us the directly encoded 24-bit UCS character */
if ((ucs & 0xff000000) == 0)
/* ucs is a directly encoded 21-bit Unicode character */
if (ucs <= 0x10ffff && ((ucs & 0xfff800) != 0x00d800))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a safety net? Good idea, but I think it is a bit hidden here. Perhaps instead:

diff --git a/vncviewer/keysym2ucs.c b/vncviewer/keysym2ucs.c
index 6607e3065..ad9b7ebf3 100644
--- a/vncviewer/keysym2ucs.c
+++ b/vncviewer/keysym2ucs.c
@@ -167,6 +167,14 @@ unsigned ucs2keysym(unsigned ucs)
   if (keysym != NoSymbol)
     return keysym;
 
+  /* surrogates? */
+  if (ucs >= 0xd800 && ucs <= 0xdfff)
+    return NoSymbol;
+
+  /* private use? */
+  if (ucs >= 0xe000 && ucs <= 0xf8ff)
+    return NoSymbol;
+
   /* us the directly encoded 24-bit UCS character */
   if ((ucs & 0xff000000) == 0)
     return ucs | 0x01000000;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make more explicit as you suggest, but I will leave the 0x10ffff limit since code points above that values are not valid.

@svenssonaxel

Copy link
Copy Markdown
Contributor Author

@CendioOssman Addressed your review comments and pushed a fix. Once you decide what you want me to do with commit splitting, I'll clean up the commit history.

@CendioOssman

Copy link
Copy Markdown
Member

No response. Closing.

@svenssonaxel

Copy link
Copy Markdown
Contributor Author

@CendioOssman @Neustradamus Rebased and rewrote as suggested without TranslateMessage(). Pushed commit b617739b to branch svenssonaxel/vkpacket, perhaps you have to reopen the PR to see it.

@svenssonaxel

Copy link
Copy Markdown
Contributor Author

Pushed 3f0f7bbb

@samhed

samhed commented Nov 24, 2025

Copy link
Copy Markdown
Member

GitHub can't reopen a PR on a branch that was force-pushed. You will have to create a new PR.

@samhed samhed added apple remote desktop This is for compatibility with the macOS server and removed apple remote desktop This is for compatibility with the macOS server labels Nov 24, 2025
@svenssonaxel

Copy link
Copy Markdown
Contributor Author

See #2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VK_PACKET ignored by VNC viewer for Windows

3 participants