Re: [PATCH virt-viewer 1/1] window: Allow to control zoom using keypad

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

 



Hi,

On Fri, 2017-04-07 at 14:57 +0000, Marc-André Lureau wrote:
> 
> 
> On Thu, Apr 6, 2017 at 4:07 PM Pavel Grunt <pgrunt@xxxxxxxxxx>
> wrote:
> > Support for more than one key combo for accelerator is available
> > since GTK 3.12 through GAction.
> > 
> > Resolves: rhbz#1337575
> 
> That reminds me of this gtk bug:
> https://bugzilla.gnome.org/show_bug.cgi?id=699823

yes, mnemonics must be solved at the toolkit level. 
Strings like ".. _0 ..." should be activatable by both 0 and KP_0

Accelerators (key combos) are (may be) a different story for the
reasons mentioned in the bug
> 
> Have you looked at solving this at the gtk+ level? I suppose most
> applications with the same binding would like it to work on keypad
> too.

I agree that it would be easier for everyone... I can imagine a
solution similar to handling of left & right shift: <shift>, left &
right ctrl: <control> - something like 0 & KP_0: <0>, plus & KP_Add:
<plus> ... That would not break apps possibly relying on "plus" !=
KP_ADD

Looking at gtk code patching (terribly long)
gtk_accelerator_parse_with_keycode() should not be difficult.

Considering rhbz#1337575 I'd go for GAction for now

Thanks,
Pavel

>  
> > ---
> > Hello,
> > 
> > this patch fixes an old bug we attempted to fix several times in
> > the past
> > when it was not possible to use more than a single key combo to do
> > action.
> > GTK 3.12 fixed the limitation by introducing GAction.
> > 
> > My plan is to port "everything" to GAction. There were already
> > some patches
> > doing that (Headerbar series by Sagar).
> 
> I don't know how the API is evolving in gtk+, I hope you can sort it
> out!
> 
> thanks
> > Thanks,
> > Pavel
> > ---
> >  configure.ac             |  4 ++--
> >  src/virt-viewer-window.c | 55
> > ++++++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 57 insertions(+), 2 deletions(-)
> > 
> > diff --git a/configure.ac b/configure.ac
> > index 69e3708..d5eb258 100644
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -17,8 +17,8 @@ GLIB2_REQUIRED="2.38"
> >  GLIB2_ENCODED_VERSION="GLIB_VERSION_2_38"
> > 
> >  # Keep these two definitions in agreement.
> > -GTK_REQUIRED="3.10"
> > -GTK_ENCODED_VERSION="GDK_VERSION_3_10"
> > +GTK_REQUIRED="3.12"
> > +GTK_ENCODED_VERSION="GDK_VERSION_3_12"
> > 
> >  LIBXML2_REQUIRED="2.6.0"
> >  LIBVIRT_REQUIRED="0.10.0"
> > diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
> > index 867a7b0..d191e49 100644
> > --- a/src/virt-viewer-window.c
> > +++ b/src/virt-viewer-window.c
> > @@ -693,6 +693,44 @@
> > virt_viewer_window_get_keycombo_menu(VirtViewerWindow *self)
> >      return menu;
> >  }
> > 
> > +static void
> > +action_zoom_in(G_GNUC_UNUSED GSimpleAction *action,
> > +               G_GNUC_UNUSED GVariant *state,
> > +               gpointer user_data)
> > +{
> > +    virt_viewer_window_menu_view_zoom_in(NULL,
> > VIRT_VIEWER_WINDOW(user_data));
> > +}
> > +
> > +static void
> > +action_zoom_out(G_GNUC_UNUSED GSimpleAction *action,
> > +                G_GNUC_UNUSED GVariant *state,
> > +                gpointer user_data)
> > +{
> > +    virt_viewer_window_menu_view_zoom_out(NULL,
> > VIRT_VIEWER_WINDOW(user_data));
> > +}
> > +
> > +static void
> > +action_zoom_reset(G_GNUC_UNUSED GSimpleAction *action,
> > +                  G_GNUC_UNUSED GVariant *state,
> > +                  gpointer user_data)
> > +{
> > +    virt_viewer_window_menu_view_zoom_reset(NULL,
> > VIRT_VIEWER_WINDOW(user_data));
> > +}
> > +
> > +/* Keep keypad_action_entries and keypad_action_accels in sync */
> > +static const GActionEntry keypad_action_entries[] = {
> > +    {"zoom-in", action_zoom_in,},
> > +    {"zoom-out", action_zoom_out,},
> > +    {"zoom-reset", action_zoom_reset,},
> > +};
> > +
> > +static const gchar *const keypad_action_accels[][2] = {
> > +    {"<control>KP_Add", NULL},
> > +    {"<control>KP_Subtract", NULL},
> > +    {"<control>KP_0", NULL},
> > +};
> > +G_STATIC_ASSERT(G_N_ELEMENTS(keypad_action_entries) ==
> > G_N_ELEMENTS(keypad_action_accels));
> > +
> >  void
> >  virt_viewer_window_disable_modifiers(VirtViewerWindow *self)
> >  {
> > @@ -700,6 +738,7 @@
> > virt_viewer_window_disable_modifiers(VirtViewerWindow *self)
> >      VirtViewerWindowPrivate *priv = self->priv;
> >      GValue empty;
> >      GSList *accels;
> > +    guint i;
> > 
> >      if (!priv->accel_enabled)
> >          return;
> > @@ -726,6 +765,10 @@
> > virt_viewer_window_disable_modifiers(VirtViewerWindow *self)
> >                   "gtk-enable-mnemonics", FALSE,
> >                   NULL);
> > 
> > +    for (i = 0; i < G_N_ELEMENTS(keypad_action_entries); i++) {
> > +        g_action_map_remove_action(G_ACTION_MAP(priv->window),
> > keypad_action_entries[i].name);
> > +    }
> > +
> >      priv->accel_enabled = FALSE;
> >  }
> > 
> > @@ -735,6 +778,7 @@
> > virt_viewer_window_enable_modifiers(VirtViewerWindow *self)
> >      GtkSettings *settings = gtk_settings_get_default();
> >      VirtViewerWindowPrivate *priv = self->priv;
> >      GSList *accels;
> > +    guint i;
> > 
> >      if (priv->accel_enabled)
> >          return;
> > @@ -755,6 +799,17 @@
> > virt_viewer_window_enable_modifiers(VirtViewerWindow *self)
> >                   "gtk-enable-mnemonics", priv-
> > >enable_mnemonics_save,
> >                   NULL);
> > 
> > +    g_action_map_add_action_entries(G_ACTION_MAP(priv->window),
> > +                                    keypad_action_entries,
> > G_N_ELEMENTS(keypad_action_entries),
> > +                                    self);
> > +    for (i = 0; i < G_N_ELEMENTS(keypad_action_entries); i++) {
> > +        gchar *detailed_name = g_strdup_printf("win.%s",
> > keypad_action_entries[i].name);
> > +       
> > gtk_application_set_accels_for_action(GTK_APPLICATION(priv->app),
> > +                                              detailed_name,
> > +                                             
> > keypad_action_accels[i]);
> > +        g_free(detailed_name);
> > +    }
> > +
> >      priv->accel_enabled = TRUE;
> >  }
> > 
> > --
> > 2.12.2
> > 
> > _______________________________________________
> > virt-tools-list mailing list
> > virt-tools-list@xxxxxxxxxx
> > https://www.redhat.com/mailman/listinfo/virt-tools-list
> > 
> 
> -- 
> Marc-André Lureau

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list




[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux