[Spice-devel] [spice-gtk 2/2] Block ctrl+alt+del if the corresponding property is set

Alon Levy alevy at redhat.com
Thu Jul 19 02:35:43 PDT 2012


On Thu, Jul 19, 2012 at 09:40:51AM +0200, Christophe Fergeau wrote:
> ---
>  gtk/spice-widget.c |   38 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
> 
> diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
> index 02bb089..e5c48ed 100644
> --- a/gtk/spice-widget.c
> +++ b/gtk/spice-widget.c
> @@ -979,6 +979,33 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *expose)
>  #endif
>  
>  /* ---------------------------------------------------------------- */
> +static gboolean is_key_pressed(SpiceDisplay *display, int scancode)
> +{
> +    uint32_t i, b, m;
> +    SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
> +
> +    i = scancode / 32;
> +    b = scancode % 32;
> +    m = (1 << b);
> +    g_return_val_if_fail(i < SPICE_N_ELEMENTS(d->key_state), FALSE);
> +
> +    return (d->key_state[i] & m);
> +}
> +
> +static gboolean check_for_ctrl_alt_del(SpiceDisplay *display, int scancode)
> +{
> +    /* we need to look at hardware scancodes for ctrl+alt+del detection
> +     * since the symbolic keys sent by gtk+ might have been remapped on the
> +     * client side, which means ctrl+alt+del on the client and ctrl+alt+del
> +     * on the guest might not correspond to the same physical keyboard keys
> +     */
> +    if (is_key_pressed(display, 0x1d) || is_key_pressed(display, 0x11d)) /* ctrl */
> +        if (is_key_pressed(display, 0x38) || is_key_pressed(display, 0x138)) /* alt */
> +            if ((scancode == 0x53) || (scancode == 0x153)) /* DEL or keypad . */

why not use or (||) instead of nested if ?

> +                return true;
> +
> +    return false;
> +}
>  
>  static void send_key(SpiceDisplay *display, int scancode, int down)
>  {
> @@ -1087,6 +1114,17 @@ static gboolean key_event(GtkWidget *widget, GdkEventKey *key)
>  
>      scancode = vnc_display_keymap_gdk2xtkbd(d->keycode_map, d->keycode_maplen,
>                                              key->hardware_keycode);
> +
> +    if (check_for_ctrl_alt_del(SPICE_DISPLAY(widget), scancode)) {
> +        if (key->type == GDK_KEY_PRESS) {
> +            gboolean disable;
> +            g_object_get(G_OBJECT(d->session), "disable-ctrlaltdel",
> +                         &disable, NULL);
> +            if (disable)
> +                return true;
> +        }
> +    }
> +
>      switch (key->type) {
>      case GDK_KEY_PRESS:
>          send_key(display, scancode, 1);
> -- 
> 1.7.10.4
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel


More information about the Spice-devel mailing list