[virt-tools-list] [PATCH] Add support to use numpad accelarators for zoom-{in.out, reset}

Marc-André Lureau mlureau at redhat.com
Mon Aug 4 08:51:56 UTC 2014



----- Original Message -----
> GTK doesn't treat in the same way shortcuts/mnemonics from keypad and
> numpad. A way to workaround this problem, while it's not fixed on GTK,
> is adding special support for the numpad keys in the virt-viewer code.
> 

It's nice to add a link to the gtk+ bug:
https://bugzilla.gnome.org/show_bug.cgi?id=699823

I am worried what could happen when it is fixed in gtk+ and we have two
bindings for the same shortcut..

> https://bugzilla.redhat.com/show_bug.cgi?id=883433
> ---
>  src/virt-gtk-compat.h |  3 +++
>  src/virt-viewer-app.c |  6 ++++++
>  src/virt-viewer.xml   | 36 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 45 insertions(+)
> 
> diff --git a/src/virt-gtk-compat.h b/src/virt-gtk-compat.h
> index 110c17a..aca38b1 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_Add GDK_KEY_KP_Add
> +#define GDK_KP_Subtract GDK_KEY_KP_Subtract
> +#define GDK_KP_0 GDK_KEY_KP_0
>  #endif
>  
>  #if !GTK_CHECK_VERSION(3, 0, 0)
> diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
> index 89289a0..698fefd 100644
> --- a/src/virt-viewer-app.c
> +++ b/src/virt-viewer-app.c
> @@ -1709,8 +1709,11 @@ virt_viewer_app_constructor (GType gtype,
>      gtk_accel_map_add_entry("<virt-viewer>/view/toggle-fullscreen", GDK_F11,
>      0);
>      gtk_accel_map_add_entry("<virt-viewer>/view/release-cursor", GDK_F12,
>      GDK_SHIFT_MASK);
>      gtk_accel_map_add_entry("<virt-viewer>/view/zoom-reset", GDK_0,
>      GDK_CONTROL_MASK);
> +    gtk_accel_map_add_entry("<virt-viewer>/view/kp-zoom-reset", GDK_KP_0,
> GDK_CONTROL_MASK);
>      gtk_accel_map_add_entry("<virt-viewer>/view/zoom-out", GDK_minus,
>      GDK_CONTROL_MASK);
> +    gtk_accel_map_add_entry("<virt-viewer>/view/kp-zoom-out",
> GDK_KP_Subtract, GDK_CONTROL_MASK);
>      gtk_accel_map_add_entry("<virt-viewer>/view/zoom-in", GDK_plus,
>      GDK_CONTROL_MASK);
> +    gtk_accel_map_add_entry("<virt-viewer>/view/kp-zoom-in", GDK_KP_Add,
> GDK_CONTROL_MASK);
>      gtk_accel_map_add_entry("<virt-viewer>/send/secure-attention", GDK_End,
>      GDK_CONTROL_MASK | GDK_MOD1_MASK);
>  
>      virt_viewer_app_set_fullscreen(self, opt_fullscreen);
> @@ -1878,8 +1881,11 @@ virt_viewer_app_clear_hotkeys(VirtViewerApp *self)
>      gtk_accel_map_change_entry("<virt-viewer>/view/toggle-fullscreen", 0, 0,
>      TRUE);
>      gtk_accel_map_change_entry("<virt-viewer>/view/release-cursor", 0, 0,
>      TRUE);
>      gtk_accel_map_change_entry("<virt-viewer>/view/zoom-reset", 0, 0, TRUE);
> +    gtk_accel_map_change_entry("<virt-viewer>/view/kp-zoom-reset", 0, 0,
> TRUE);
>      gtk_accel_map_change_entry("<virt-viewer>/view/zoom-in", 0, 0, TRUE);
> +    gtk_accel_map_change_entry("<virt-viewer>/view/kp-zoom-in", 0, 0, TRUE);
>      gtk_accel_map_change_entry("<virt-viewer>/view/zoom-out", 0, 0, TRUE);
> +    gtk_accel_map_change_entry("<virt-viewer>/view/kp-zoom-out", 0, 0,
> TRUE);
>      gtk_accel_map_change_entry("<virt-viewer>/send/secure-attention", 0, 0,
>      TRUE);
>      virt_viewer_set_insert_smartcard_accel(self, 0, 0);
>      virt_viewer_set_remove_smartcard_accel(self, 0, 0);
> diff --git a/src/virt-viewer.xml b/src/virt-viewer.xml
> index e2b836c..1a57408 100644
> --- a/src/virt-viewer.xml
> +++ b/src/virt-viewer.xml
> @@ -138,6 +138,18 @@
>                                </object>
>                              </child>
>                              <child>
> +                              <object class="GtkImageMenuItem"
> id="menu-view-kp-zoom-in">
> +                                <property
> name="accel_path"><virt-viewer>/view/kp-zoom-in</property>
> +                                <property
> name="label">gtk-zoom-in</property>
> +                                <property name="visible">True</property>
> +                                <property name="can_focus">False</property>
> +                                <property
> name="use_action_appearance">False</property>
> +                                <property
> name="use_underline">True</property>
> +                                <property name="use_stock">True</property>
> +                                <signal name="activate"
> handler="virt_viewer_window_menu_view_zoom_in" swapped="no"/>
> +                              </object>
> +                            </child>
> +                            <child>
>                                <object class="GtkImageMenuItem"
>                                id="menu-view-zoom-out">
>                                  <property
>                                  name="accel_path"><virt-viewer>/view/zoom-out</property>
>                                  <property
>                                  name="label">gtk-zoom-out</property>
> @@ -150,6 +162,18 @@
>                                </object>
>                              </child>
>                              <child>
> +                              <object class="GtkImageMenuItem"
> id="menu-view-kp-zoom-out">
> +                                <property
> name="accel_path"><virt-viewer>/view/kp-zoom-out</property>
> +                                <property
> name="label">gtk-zoom-out</property>
> +                                <property name="visible">True</property>
> +                                <property name="can_focus">False</property>
> +                                <property
> name="use_action_appearance">False</property>
> +                                <property
> name="use_underline">True</property>
> +                                <property name="use_stock">True</property>
> +                                <signal name="activate"
> handler="virt_viewer_window_menu_view_zoom_out" swapped="no"/>
> +                              </object>
> +                            </child>
> +                            <child>
>                                <object class="GtkSeparatorMenuItem"
>                                id="separatormenuitem4">
>                                  <property name="visible">True</property>
>                                  <property name="can_focus">False</property>
> @@ -167,6 +191,18 @@
>                                  <signal name="activate"
>                                  handler="virt_viewer_window_menu_view_zoom_reset"
>                                  swapped="no"/>
>                                </object>
>                              </child>
> +                            <child>
> +                              <object class="GtkImageMenuItem"
> id="menu-view-kp-zoom-reset">
> +                                <property
> name="accel_path"><virt-viewer>/view/kp-zoom-reset</property>
> +                                <property
> name="label">gtk-zoom-100</property>
> +                                <property name="visible">True</property>
> +                                <property name="can_focus">False</property>
> +                                <property
> name="use_action_appearance">False</property>
> +                                <property
> name="use_underline">True</property>
> +                                <property name="use_stock">True</property>
> +                                <signal name="activate"
> handler="virt_viewer_window_menu_view_zoom_reset" swapped="no"/>
> +                              </object>
> +                            </child>
>                            </object>
>                          </child>
>                        </object>

It looks reasonable, but if you want to fix this bug, please try first to
fix it in gtk+, if the problem is hard to fix there, then we could accept this
workaround soon imho.

> --
> 1.9.3
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
> 




More information about the virt-tools-list mailing list