Re: [spice-gtk 4/9] Move code to handle modifier in a specific file

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

 



Hi

On Wed, Jun 8, 2016 at 1:10 PM, Frediano Ziglio <fziglio@xxxxxxxxxx> wrote:
> 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@xxxxxxxxxx>
> ---
>  src/Makefile.am          |  2 ++
>  src/keyboard-modifiers.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
>  src/keyboard-modifiers.h | 34 ++++++++++++++++++
>  src/spice-gtk-session.c  | 58 +-----------------------------
>  4 files changed, 128 insertions(+), 57 deletions(-)
>  create mode 100644 src/keyboard-modifiers.c
>  create mode 100644 src/keyboard-modifiers.h
>
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 73bb39c..94e37bc 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -138,6 +138,8 @@ SPICE_GTK_SOURCES_COMMON =          \
>         desktop-integration.c           \
>         desktop-integration.h           \
>         usb-device-widget.c             \
> +       keyboard-modifiers.c            \
> +       keyboard-modifiers.h            \
>         $(NULL)

Why not, but I suggest to use a common prefix for file and functions,
such as spice-gtk-keyboard.

>
>  nodist_SPICE_GTK_SOURCES_COMMON =      \
> diff --git a/src/keyboard-modifiers.c b/src/keyboard-modifiers.c
> new file mode 100644
> index 0000000..9166dbc
> --- /dev/null
> +++ b/src/keyboard-modifiers.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 "keyboard-modifiers.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/keyboard-modifiers.h b/src/keyboard-modifiers.h
> new file mode 100644
> index 0000000..d87a930
> --- /dev/null
> +++ b/src/keyboard-modifiers.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 6cdae87..b2028d9 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 "keyboard-modifiers.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
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/spice-devel



-- 
Marc-André Lureau
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://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]