From 6b9622db86bf4e35f8e5baf1be2321401659a42d Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 21 Jul 2014 16:42:12 +0200 Subject: [PATCH] Add X11 keyboard handler --- vncviewer/Viewport.cxx | 41 +++++++++++++++++++++++++++++++++++++++++ vncviewer/vncviewer.cxx | 10 ++++++++++ 2 files changed, 51 insertions(+) diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index 2b22a973..0f627229 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -647,6 +647,47 @@ bool Viewport::handleXEvent(void *event, void *data) assert(event); +#if !defined(WIN32) && !defined(__APPLE__) + XEvent *xevent = (XEvent*)event; + + if (xevent->type == KeyPress) { + char str; + KeySym keysym; + + XLookupString(&xevent->xkey, &str, 1, &keysym, NULL); + if (keysym == NoSymbol) { + vlog.error(_("No symbol for key code %d (in the current state)"), + (int)xevent->xkey.keycode); + return true; + } + + switch (keysym) { + // For the first few years, there wasn't a good consensus on what the + // Windows keys should be mapped to for X11. So we need to help out a + // bit and map all variants to the same key... + case XK_Meta_L: + case XK_Hyper_L: + keysym = XK_Super_L; + break; + case XK_Meta_R: + case XK_Hyper_R: + keysym = XK_Super_R; + break; + // There has been several variants for Shift-Tab over the years. + // RFB states that we should always send a normal tab. + case XK_ISO_Left_Tab: + keysym = XK_Tab; + break; + } + + self->handleKeyPress(xevent->xkey.keycode, keysym); + return true; + } else if (xevent->type == KeyRelease) { + self->handleKeyRelease(xevent->xkey.keycode); + return true; + } +#endif + return false; } diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 3f039379..82286ab8 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -36,6 +36,11 @@ #define mkdir(path, mode) _mkdir(path) #endif +#if !defined(WIN32) && !defined(__APPLE__) +#include +#include +#endif + #include #include #include @@ -386,6 +391,11 @@ int main(int argc, char** argv) init_fltk(); +#if !defined(WIN32) && !defined(__APPLE__) + fl_open_display(); + XkbSetDetectableAutoRepeat(fl_display, True, NULL); +#endif + Configuration::enableViewerParams(); /* Load the default parameter settings */ -- 2.39.5