Menu

#80 ability to change keybindings

open
nobody
None
5
2018-08-27
2011-06-14
No

I'd like to be able to change keybindings. For instance, I'd like to map the number keys to set different pen colors, and perhaps some of the other keys to change between select mode, etc. using the mouse for such things really gets in the way, since I have my stylus in the same hand as i use for my mouse. It would be better if at least the default keybindings could be used with only the left hand, and if they existed for all the items on the default menubars.

Discussion

  • Denis Auroux

    Denis Auroux - 2011-06-16

    With the current architecture, changing keybindings requires recompiling from the source.
    Use glade-2 to edit the interface ("glade-2 xournal.glade") including the key bindings for the menu accelerators, regenerate the code, recompile. Sorry there isn't a simpler option...

    Denis

     
  • Antonello Lobianco

    Hello, ok to change it I need to recompile, but which is the default key binding for the colour pallette ?

     
  • Denis Auroux

    Denis Auroux - 2018-08-27

    There is no default key binding (other than navigating the menu: Alt+T, C, up arrow, enter). If you want to create one, either edit the interface in glade-2, or less straightforward or less risky (glade-2 has plenty of bugs), edit src/xo-interface.c (beware glade-2 overwrites this file if you use it to generate code).

    To add an accelerator for the color palette which is Tools -> Color -> other,
    after the lines

      colorOther = gtk_menu_item_new_with_mnemonic (_("other..."));
      gtk_widget_show (colorOther);
      gtk_container_add (GTK_CONTAINER (toolsColor_menu), colorOther);
    

    (near line 1060 in src/xo-interface.c),
    add a line for the shortcut, for example if you want to map it to Control+Shift+Z,

      gtk_widget_add_accelerator (toolsHand, "activate", accel_group,
                                  GDK_Z, (GdkModifierType) GDK_CONTROL_MASK | GDK_SHIFT_MASK,
                                  GTK_ACCEL_VISIBLE);
    

    (change GDK_Z to your preferred key. If you want just control+key, change the modifier to (GdkModifierType) GDK_CONTROL_MASK (remove " | GDK_SHIFT_MASK"); if you want just the plain key, replace the whole modifier to (GdkModifierType) 0).

    Denis

     
  • Antonello Lobianco

    Thank you, great, it works. Just in your example you left "toolsHand". It should be:

    gtk_widget_add_accelerator (colorOther, "activate", accel_group,
                                   GDK_Z, (GdkModifierType) GDK_CONTROL_MASK | GDK_SHIFT_MASK,
                                   GTK_ACCEL_VISIBLE);
    

    However, how to do with numbers (e.g. control+shift+1 for black, control+shift+2 for blue, etc..)?
    I did try GDK_1, GDK_KEY_1, GDK_KP_1, all without success.

     

    Last edit: Antonello Lobianco 2018-08-27
    • Denis Auroux

      Denis Auroux - 2018-08-27

      Ah, of course you are right I forgot to change toolsHand to colorOther.

      Regarding numbers: the issue is that shift+1 doesn't produce the number
      1 anymore, so it gets messed up. On a US keyboard, shift+1 is
      exclamation mark, so one apparently needs to use GDK_exclam

      For Control+1 you can use GDK_1 and GDK_CONTROL_MASK, it works.

      For Control+shift+1, though, I had to use GDK_exclam and
      GDK_CONTROL_MASK | GDK_SHIFT_MASK

      (GDK_1 didn't work for me, just as you reported. And then annoyingly, if
      you use GDK_exclam so that it works, then it shows in the menu as
      Control+Shift+! instead of Control+Shift+1...)

      Denis

       

Log in to post a comment.

MongoDB Logo MongoDB