Since Ctrl and Cmd tends to mess with the symbol generation, we need to do some
extra voodoo to get a good behaviour when any of those are pressed.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4366 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/vncviewer/CMakeLists.txt b/vncviewer/CMakeLists.txt
index 6a9f8ef..e1bda9d 100644
--- a/vncviewer/CMakeLists.txt
+++ b/vncviewer/CMakeLists.txt
@@ -1,8 +1,7 @@
include_directories(${FLTK_INCLUDE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/common)
-
-add_executable(vncviewer
+set(VNCVIEWER_SOURCES
CConn.cxx
DesktopWindow.cxx
UserDialog.cxx
@@ -10,4 +9,10 @@
keysym2ucs.c
vncviewer.cxx)
+if(APPLE)
+ set(VNCVIEWER_SOURCES ${VNCVIEWER_SOURCES} osx_utils.m)
+endif()
+
+add_executable(vncviewer ${VNCVIEWER_SOURCES})
+
target_link_libraries(vncviewer rfb network rdr os Xregion ${FLTK_LIBRARIES})
diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx
index 113b880..7da4320 100644
--- a/vncviewer/DesktopWindow.cxx
+++ b/vncviewer/DesktopWindow.cxx
@@ -45,6 +45,10 @@
using namespace rfb;
+#ifdef __APPLE__
+extern "C" const char *osx_event_string(void);
+#endif
+
extern void exit_vncviewer();
static rfb::LogWriter vlog("DesktopWindow");
@@ -371,6 +375,80 @@
return XK_KP_Divide;
}
+ // Ctrl and Cmd tend to fudge input handling, so we need to cheat here
+ if (Fl::event_state() & (FL_COMMAND | FL_CTRL)) {
+#ifdef WIN32
+ BYTE keystate[256];
+ WCHAR wbuf[8];
+ int ret;
+
+ static char buf[32];
+
+ switch (fl_msg.message) {
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ // Most buttons end up here when Ctrl is pressed. Here we can pretend
+ // that Ctrl isn't pressed, and do a character lookup.
+ GetKeyboardState(keystate);
+ keystate[VK_CONTROL] = keystate[VK_LCONTROL] = keystate[VK_RCONTROL] = 0;
+
+ ret = ToUnicode(fl_msg.wParam, 0, keystate, wbuf, sizeof(wbuf)/sizeof(wbuf[0]), 0);
+ if (ret != 0) {
+ // -1 means one dead character
+ ret = abs(ret);
+ wbuf[ret] = 0x0000;
+
+ if (fl_utf8fromwc(buf, sizeof(buf), wbuf, ret) >= sizeof(buf)) {
+ vlog.error(_("Out of buffer space whilst converting key event"));
+ return XK_VoidSymbol;
+ }
+
+ keyText = buf;
+ }
+ break;
+ case WM_CHAR:
+ case WM_SYSCHAR:
+ // Windows doesn't seem to have any sanity when it comes to control
+ // characters. We assume that Ctrl-A through Ctrl-Z range maps to
+ // the VK_A through VK_Z keys, and just let the rest fall through.
+ if ((fl_msg.wParam < 0x01) || (fl_msg.wParam > 0x1a))
+ break;
+
+ // Pretend that Ctrl isn't pressed, and do a character lookup.
+ GetKeyboardState(keystate);
+ keystate[VK_CONTROL] = keystate[VK_LCONTROL] = keystate[VK_RCONTROL] = 0;
+
+ // Ctrl-A is 0x01 and VK_A is 0x41, so add 0x40 for the conversion
+ ret = ToUnicode(fl_msg.wParam + 0x40, 0, keystate, wbuf, sizeof(wbuf)/sizeof(wbuf[0]), 0);
+ if (ret != 0) {
+ // -1 means one dead character
+ ret = abs(ret);
+ wbuf[ret] = 0x0000;
+
+ if (fl_utf8fromwc(buf, sizeof(buf), wbuf, ret) >= sizeof(buf)) {
+ vlog.error(_("Out of buffer space whilst converting key event"));
+ return XK_VoidSymbol;
+ }
+
+ keyText = buf;
+ }
+ break;
+ default:
+ // Not sure how we ended up here. Do nothing...
+ break;
+ }
+#elif defined(__APPLE__)
+ keyText = osx_event_string();
+#else
+ char buf[16];
+ KeySym sym;
+
+ XLookupString((XKeyEvent*)fl_xevent, buf, sizeof(buf), &sym, NULL);
+
+ return sym;
+#endif
+ }
+
// Unknown special key?
if (keyText[0] == '\0') {
vlog.error(_("Unknown FLTK key code %d (0x%04x)"), keyCode, keyCode);
diff --git a/vncviewer/osx_utils.m b/vncviewer/osx_utils.m
new file mode 100644
index 0000000..fdb1985
--- /dev/null
+++ b/vncviewer/osx_utils.m
@@ -0,0 +1,25 @@
+/* Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+const char *osx_event_string(void)
+{
+ return [[[NSApp currentEvent] charactersIgnoringModifiers] UTF8String];
+}
+