Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support VK_PACKET in vncviewer on Windows #1852

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

svenssonaxel
Copy link

Fixes #1847

@@ -971,6 +972,12 @@ int Viewport::handleSystemEvent(void *event, void *data)
keyCode = 0x38;
}

// VK_PACKET handling: Translate to WM_*CHAR message, handled below.
if (vKey == VK_PACKET) {
TranslateMessage(msg);
Copy link
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
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.

// 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
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
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?

codePoint = ucsCode;
}
uint32_t keySym = ucs2keysym(codePoint);
uint32_t keyCode = 0x100 + keySym; // Fake key code
Copy link
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
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.

/* 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
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
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
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.

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
2 participants