[PATCH linux/vd_agent v2 1/2] Set keyboard layout

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This commit introduces a function for changing the keyboard
layout on the guest side.
---
v2:
 - check whether the keyboard description string is null-terminated
---
 configure.ac      |  2 ++
 src/vdagent-x11.c | 20 ++++++++++++++++++++
 src/vdagent-x11.h |  3 +++
 3 files changed, 25 insertions(+)

diff --git a/configure.ac b/configure.ac
index 79905a8..a5916d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -126,6 +126,8 @@ if test x"$enable_static_uinput" = "xyes" ; then
     AC_DEFINE([WITH_STATIC_UINPUT], [1], [If defined, vdagentd will use a static uinput device] )
 fi
 
+AC_CHECK_HEADERS([X11/XKBlib.h])
+
 # If no CFLAGS are set, set some sane default CFLAGS
 if test "$ac_test_CFLAGS" != set; then
   DEFAULT_CFLAGS="-Wall -Werror -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4"
diff --git a/src/vdagent-x11.c b/src/vdagent-x11.c
index 752b337..c277e8f 100644
--- a/src/vdagent-x11.c
+++ b/src/vdagent-x11.c
@@ -31,6 +31,8 @@
    Calling XPending when-ever we return to the mainloop also ensures any
    pending writes are flushed. */
 
+#include <config.h>
+
 #include <glib.h>
 #include <stdlib.h>
 #include <limits.h>
@@ -40,6 +42,9 @@
 #include <unistd.h>
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
+#ifdef HAVE_X11_XKBLIB_H
+#include <X11/XKBlib.h>
+#endif
 #include <X11/extensions/Xfixes.h>
 #include "vdagentd-proto.h"
 #include "vdagent-x11.h"
@@ -1352,3 +1357,18 @@ int vdagent_x11_has_icons_on_desktop(struct vdagent_x11 *x11)
 
     return 0;
 }
+
+void vdagent_x11_set_keyboard_description(struct vdagent_x11 *x11,
+    uint8_t *keyboard_desc, uint32_t size)
+{
+#ifdef HAVE_X11_XKBLIB_H
+    XkbComponentNamesRec comp = {.symbols = (char *) keyboard_desc};
+    if (comp.symbols[size-1] != '\0') {
+        syslog(LOG_WARNING, "received not null-terminated keyboard description");
+        return;
+    }
+
+    XkbGetKeyboardByName(x11->display, XkbUseCoreKbd, &comp,
+                         XkbGBN_SymbolsMask, XkbGBN_SymbolsMask, True);
+#endif
+}
diff --git a/src/vdagent-x11.h b/src/vdagent-x11.h
index d64a42a..9c1cf17 100644
--- a/src/vdagent-x11.h
+++ b/src/vdagent-x11.h
@@ -50,4 +50,7 @@ void vdagent_x11_client_disconnected(struct vdagent_x11 *x11);
 
 int vdagent_x11_has_icons_on_desktop(struct vdagent_x11 *x11);
 
+void vdagent_x11_set_keyboard_description(struct vdagent_x11 *x11,
+    uint8_t *keyboard_desc, uint32_t size);
+
 #endif
-- 
1.9.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]