summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2016-06-09 15:34:19 +0100
committerFrediano Ziglio <fziglio@redhat.com>2017-02-01 15:15:34 +0000
commite336a20abec65ba7d9000ffe7a7fc45a80f1e739 (patch)
tree8c08c696b55bc1ced6aadb02a7b1dadb1a9b87e0
parent21df96ee88834785e4759e6eea5eaa432a6ff0b3 (diff)
Move code to handle modifier in a specific file
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@redhat.com>
-rw-r--r--src/Makefile.am2
-rw-r--r--src/spice-gtk-keyboard.c94
-rw-r--r--src/spice-gtk-keyboard.h34
-rw-r--r--src/spice-gtk-session.c61
4 files changed, 131 insertions, 60 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7542fac..c611589 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -134,6 +134,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..ab66e14
--- /dev/null
+++ b/src/spice-gtk-keyboard.c
@@ -0,0 +1,94 @@
+/* -*- 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)
+/* Ignore GLib's too-new warnings */
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ 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;
+ }
+G_GNUC_END_IGNORE_DEPRECATIONS
+#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 a3a2e90..ad93bd1 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,66 +123,6 @@ enum {
PROP_SYNC_MODIFIERS,
};
-static guint32 get_keyboard_lock_modifiers(void)
-{
- guint32 modifiers = 0;
-#if GTK_CHECK_VERSION(3,18,0)
-/* Ignore GLib's too-new warnings */
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- 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;
- }
-G_GNUC_END_IGNORE_DEPRECATIONS
-#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)