Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple shortcuts for one action in GTK

What is the best way to bind multiple keyboard shortcuts to one action in GTK+ 3?

I have been searching for an answer to this for a few days and have come up with naught. The function gtk_accelerator_parse does not support comma-deliminated shortcuts. Putting multiple <accelerator> tags in a .ui file with the same action attribute and different key attributes also does not work.

I do not want to have to write a custom key press handler just so I can have two shortcuts for one action, but is that really the only way?

like image 729
Oz. Avatar asked Apr 16 '12 22:04

Oz.


2 Answers

Since GTK version 3.12 (released on 2014-03-25) there is a new method called gtk_application_set_accels_for_action() that should help.

like image 71
Brian Avatar answered Jan 02 '23 10:01

Brian


I have found a way, but it is truly terrible. Using gtk_accel_group_connect I can add additional accelerators for my own functions which can then trigger the action desired based off the key pressed and any modifiers. This however feels like a hack as I am basically creating my own accelerator-to-action map rather than using GTK's.

I would like to know a better way, if anyone knows of one.

like image 34
Oz. Avatar answered Jan 02 '23 09:01

Oz.