[virt-tools-list] [PATCH virt-viewer] Allow to use numpad accelerators for zoom

Fabiano Fidêncio fidencio at redhat.com
Mon Feb 2 10:26:39 UTC 2015


On Mon, 2015-02-02 at 04:04 -0500, Pavel Grunt wrote:
> NACK, It doesn't work in Gnome Shell

Just for the record. The keys are being passed to the VM even when the
keyboard should not be grabbed (when using gnome-shell). So, sometimes
when you're doing any zoom action, the VM receives that input, what is a
not expected behavior.

> 
> ----- Original Message -----
> > 
> > Resolves https://bugzilla.redhat.com/show_bug.cgi?id=921326
> > ---
> >  src/virt-gtk-compat.h    |  3 +++
> >  src/virt-viewer-window.c | 28 ++++++++++++++++++++++++++++
> >  2 files changed, 31 insertions(+)
> > 
> > diff --git a/src/virt-gtk-compat.h b/src/virt-gtk-compat.h
> > index 110c17a..99965ff 100644
> > --- a/src/virt-gtk-compat.h
> > +++ b/src/virt-gtk-compat.h
> > @@ -57,6 +57,9 @@ G_BEGIN_DECLS
> >  #define GDK_0 GDK_KEY_0
> >  #define GDK_plus GDK_KEY_plus
> >  #define GDK_minus GDK_KEY_minus
> > +#define GDK_KP_0 GDK_KEY_KP_0
> > +#define GDK_KP_Add GDK_KEY_KP_Add
> > +#define GDK_KP_Subtract GDK_KEY_KP_Subtract
> >  #endif
> >  
> >  #if !GTK_CHECK_VERSION(3, 0, 0)
> > diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
> > index c5f7c75..62f0d86 100644
> > --- a/src/virt-viewer-window.c
> > +++ b/src/virt-viewer-window.c
> > @@ -283,6 +283,33 @@ can_activate_cb (GtkWidget *widget
> > G_GNUC_UNUSED,
> >  }
> >  
> >  static void
> > +numpad_closure (VirtViewerWindow *self,
> > +                GObject *acceleratable,
> > +                guint keyval)
> > +{
> > +    if (keyval == GDK_KP_0)
> > +
> >        virt_viewer_window_menu_view_zoom_reset(GTK_WIDGET(acceleratable),
> > self);
> > +    else if (keyval == GDK_KP_Add)
> > +
> >        virt_viewer_window_menu_view_zoom_in(GTK_WIDGET(acceleratable),
> > self);
> > +    else if (keyval == GDK_KP_Subtract)
> > +
> >        virt_viewer_window_menu_view_zoom_out(GTK_WIDGET(acceleratable),
> > self);
> > +}
> > +
> > +static void
> > +add_numpad_accelerators (VirtViewerWindow *self)
> > +{
> > +    VirtViewerWindowPrivate *priv = self->priv;
> > +    g_return_if_fail(VIRT_VIEWER_IS_WINDOW(self));
> > +
> > +    gtk_accel_group_connect(priv->accel_group, GDK_KP_0,
> > GDK_CONTROL_MASK, GTK_ACCEL_MASK,
> > +
> >                            g_cclosure_new_object_swap(G_CALLBACK(numpad_closure),
> > G_OBJECT(self)));
> > +    gtk_accel_group_connect(priv->accel_group, GDK_KP_Add,
> > GDK_CONTROL_MASK, GTK_ACCEL_MASK,
> > +
> >                            g_cclosure_new_object_swap(G_CALLBACK(numpad_closure),
> > G_OBJECT(self)));
> > +    gtk_accel_group_connect(priv->accel_group, GDK_KP_Subtract,
> > GDK_CONTROL_MASK, GTK_ACCEL_MASK,
> > +
> >                            g_cclosure_new_object_swap(G_CALLBACK(numpad_closure),
> > G_OBJECT(self)));
> > +}
> > +
> > +static void
> >  virt_viewer_window_init (VirtViewerWindow *self)
> >  {
> >      VirtViewerWindowPrivate *priv;
> > @@ -305,6 +332,7 @@ virt_viewer_window_init (VirtViewerWindow *self)
> >      gtk_builder_connect_signals(priv->builder, self);
> >  
> >      priv->accel_group =
> >      GTK_ACCEL_GROUP(gtk_builder_get_object(priv->builder,
> >      "accelgroup"));
> > +    add_numpad_accelerators(self);
> >  
> >      /* make sure they can be activated even if the menu item is not
> >      visible */
> >      g_signal_connect(gtk_builder_get_object(priv->builder,
> >      "menu-view-fullscreen"),
> > --
> > 1.9.3
> > 
> > _______________________________________________
> > virt-tools-list mailing list
> > virt-tools-list at redhat.com
> > https://www.redhat.com/mailman/listinfo/virt-tools-list
> > 
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list

Best Regards,
--
Fabiano Fidêncio




More information about the virt-tools-list mailing list