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

Christophe Fergeau cfergeau at redhat.com
Thu Jul 19 02:55:06 PDT 2012


On Thu, Jul 19, 2012 at 12:35:43PM +0300, Alon Levy wrote:
> 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 ?

No real reason, probably felt more readable this way when I wrote the code,
but with the comments ,a multiline && should be no worse, I'll change it.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20120719/6c4019d5/attachment.pgp>


More information about the Spice-devel mailing list