[Spice-devel] [spice-gtk v3 1/7] Move code to handle modifier in a specific file
Frediano Ziglio
fziglio at redhat.com
Sat Sep 3 16:10:01 UTC 2016
Allows to extend it in the future.
This code is OS dependent and is not a good idea to keep with
SpiceGtkSession.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
src/Makefile.am | 2 ++
src/spice-gtk-keyboard.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
src/spice-gtk-keyboard.h | 34 ++++++++++++++++++
src/spice-gtk-session.c | 58 +-----------------------------
4 files changed, 128 insertions(+), 57 deletions(-)
create mode 100644 src/spice-gtk-keyboard.c
create mode 100644 src/spice-gtk-keyboard.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 7542580..7d704db 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -141,6 +141,8 @@ SPICE_GTK_SOURCES_COMMON = \
desktop-integration.c \
desktop-integration.h \
usb-device-widget.c \
+ spice-gtk-keyboard.c \
+ spice-gtk-keyboard.h \
$(NULL)
nodist_SPICE_GTK_SOURCES_COMMON = \
diff --git a/src/spice-gtk-keyboard.c b/src/spice-gtk-keyboard.c
new file mode 100644
index 0000000..0ebcb41
--- /dev/null
+++ b/src/spice-gtk-keyboard.c
@@ -0,0 +1,91 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ Copyright (C) 2016 Red Hat, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#include "config.h"
+
+#ifdef HAVE_X11_XKBLIB_H
+#include <X11/XKBlib.h>
+#include <gdk/gdkx.h>
+#endif
+#ifdef GDK_WINDOWING_X11
+#include <X11/Xlib.h>
+#include <gdk/gdkx.h>
+#endif
+#ifdef G_OS_WIN32
+#include <windows.h>
+#include <gdk/gdkwin32.h>
+#endif
+
+#include <gtk/gtk.h>
+
+#include "channel-inputs.h"
+#include "spice-gtk-keyboard.h"
+
+guint32 get_keyboard_lock_modifiers(void)
+{
+ guint32 modifiers = 0;
+#if GTK_CHECK_VERSION(3,18,0)
+ GdkKeymap *keyboard = gdk_keymap_get_default();
+
+ if (gdk_keymap_get_caps_lock_state(keyboard)) {
+ modifiers |= SPICE_INPUTS_CAPS_LOCK;
+ }
+
+ if (gdk_keymap_get_num_lock_state(keyboard)) {
+ modifiers |= SPICE_INPUTS_NUM_LOCK;
+ }
+
+ if (gdk_keymap_get_scroll_lock_state(keyboard)) {
+ modifiers |= SPICE_INPUTS_SCROLL_LOCK;
+ }
+#elif defined(HAVE_X11_XKBLIB_H)
+ Display *x_display = NULL;
+ XKeyboardState keyboard_state;
+
+ GdkScreen *screen = gdk_screen_get_default();
+ if (!GDK_IS_X11_DISPLAY(gdk_screen_get_display(screen))) {
+ SPICE_DEBUG("FIXME: gtk backend is not X11");
+ return 0;
+ }
+
+ x_display = GDK_SCREEN_XDISPLAY(screen);
+ XGetKeyboardControl(x_display, &keyboard_state);
+
+ if (keyboard_state.led_mask & 0x01) {
+ modifiers |= SPICE_INPUTS_CAPS_LOCK;
+ }
+ if (keyboard_state.led_mask & 0x02) {
+ modifiers |= SPICE_INPUTS_NUM_LOCK;
+ }
+ if (keyboard_state.led_mask & 0x04) {
+ modifiers |= SPICE_INPUTS_SCROLL_LOCK;
+ }
+#elif defined(G_OS_WIN32)
+ if (GetKeyState(VK_CAPITAL) & 1) {
+ modifiers |= SPICE_INPUTS_CAPS_LOCK;
+ }
+ if (GetKeyState(VK_NUMLOCK) & 1) {
+ modifiers |= SPICE_INPUTS_NUM_LOCK;
+ }
+ if (GetKeyState(VK_SCROLL) & 1) {
+ modifiers |= SPICE_INPUTS_SCROLL_LOCK;
+ }
+#else
+ g_warning("get_keyboard_lock_modifiers not implemented");
+#endif // GTK_CHECK_VERSION(3,18,0)
+ return modifiers;
+}
diff --git a/src/spice-gtk-keyboard.h b/src/spice-gtk-keyboard.h
new file mode 100644
index 0000000..d87a930
--- /dev/null
+++ b/src/spice-gtk-keyboard.h
@@ -0,0 +1,34 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ Copyright (C) 2016 Red Hat, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef KEYBOARD_MODIFIERS_H
+#define KEYBOARD_MODIFIERS_H
+
+#if !defined(__SPICE_CLIENT_GTK_H_INSIDE__) && !defined(SPICE_COMPILATION)
+#warning "Only <spice-client-gtk.h> can be included directly"
+#endif
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+guint32 get_keyboard_lock_modifiers(void);
+
+G_END_DECLS
+
+#endif /* KEYBOARD_MODIFIERS_H */
diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index 3ff4e9a..d88fed4 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -44,6 +44,7 @@
#include "spice-session-priv.h"
#include "spice-util-priv.h"
#include "spice-channel-priv.h"
+#include "spice-gtk-keyboard.h"
#define CLIPBOARD_LAST (VD_AGENT_CLIPBOARD_SELECTION_SECONDARY + 1)
@@ -122,63 +123,6 @@ enum {
PROP_SYNC_MODIFIERS,
};
-static guint32 get_keyboard_lock_modifiers(void)
-{
- guint32 modifiers = 0;
-#if GTK_CHECK_VERSION(3,18,0)
- GdkKeymap *keyboard = gdk_keymap_get_default();
-
- if (gdk_keymap_get_caps_lock_state(keyboard)) {
- modifiers |= SPICE_INPUTS_CAPS_LOCK;
- }
-
- if (gdk_keymap_get_num_lock_state(keyboard)) {
- modifiers |= SPICE_INPUTS_NUM_LOCK;
- }
-
- if (gdk_keymap_get_scroll_lock_state(keyboard)) {
- modifiers |= SPICE_INPUTS_SCROLL_LOCK;
- }
-#else
-#ifdef HAVE_X11_XKBLIB_H
- Display *x_display = NULL;
- XKeyboardState keyboard_state;
-
- GdkScreen *screen = gdk_screen_get_default();
- if (!GDK_IS_X11_DISPLAY(gdk_screen_get_display(screen))) {
- SPICE_DEBUG("FIXME: gtk backend is not X11");
- return 0;
- }
-
- x_display = GDK_SCREEN_XDISPLAY(screen);
- XGetKeyboardControl(x_display, &keyboard_state);
-
- if (keyboard_state.led_mask & 0x01) {
- modifiers |= SPICE_INPUTS_CAPS_LOCK;
- }
- if (keyboard_state.led_mask & 0x02) {
- modifiers |= SPICE_INPUTS_NUM_LOCK;
- }
- if (keyboard_state.led_mask & 0x04) {
- modifiers |= SPICE_INPUTS_SCROLL_LOCK;
- }
-#elif defined(G_OS_WIN32)
- if (GetKeyState(VK_CAPITAL) & 1) {
- modifiers |= SPICE_INPUTS_CAPS_LOCK;
- }
- if (GetKeyState(VK_NUMLOCK) & 1) {
- modifiers |= SPICE_INPUTS_NUM_LOCK;
- }
- if (GetKeyState(VK_SCROLL) & 1) {
- modifiers |= SPICE_INPUTS_SCROLL_LOCK;
- }
-#else
- g_warning("get_keyboard_lock_modifiers not implemented");
-#endif // HAVE_X11_XKBLIB_H
-#endif // GTK_CHECK_VERSION(3,18,0)
- return modifiers;
-}
-
static void spice_gtk_session_sync_keyboard_modifiers_for_channel(SpiceGtkSession *self,
SpiceInputsChannel* inputs,
gboolean force)
--
2.7.4
More information about the Spice-devel
mailing list