I wonder if we don't expect this quartz_accelerators thing to do more than they actually promise. It says it would replace
stock accelerators like Ctrl-O to the OSX equivalent. Not that they would change every Ctrl int Meta.
But we can do the latter in the (somewhat) hard way without touching menus.c, by inserting code in CreateMenuPopup() to do the replacement for us:
Code: Select all
if(mb[i].accel) {
guint accelerator_key;
GdkModifierType accelerator_mods;
char *p = strstr(mb[i].accel, "Ctrl"); // ADD
if(p) { // ADD this and next 2
p[0] = 'M'; p[1] = 'e'; p[2] = 't'; p[3] = 'a';
}
gtk_accelerator_parse(mb[i].accel, &accelerator_key, &accelerator_mods);
gtk_widget_add_accelerator (GTK_WIDGET(entry), "activate",GtkAccelerators,
accelerator_key, accelerator_mods, GTK_ACCEL_VISIBLE);
};
(This patch makes essential use of the fact that Ctrl and Meta are both 4 letters, so that any Ctrl that is detected in the accelerator name can be over-written in-place by Meta before offering it to GTK for parsing. There might be a smarter way to do this, which is detect the use of Ctrl only after parsing of the text, where presumably its use would be indicated by some bits in 'accelerator_mods', and then clear those bits, and set the bits corresponding to the Meta modifier instead. But that would require us to figure out how the modifier keys are encoded in the accelerator_mods. Advantage is that it would also work for replacing modifier keys by keys with names of unequal length.)
[Edit] This table could be helpful.
Code: Select all
typedef enum {
GDK_SHIFT_MASK = 1 << 0,
GDK_LOCK_MASK = 1 << 1,
GDK_CONTROL_MASK = 1 << 2,
GDK_MOD1_MASK = 1 << 3,
GDK_MOD2_MASK = 1 << 4,
GDK_MOD3_MASK = 1 << 5,
GDK_MOD4_MASK = 1 << 6,
GDK_MOD5_MASK = 1 << 7,
GDK_BUTTON1_MASK = 1 << 8,
GDK_BUTTON2_MASK = 1 << 9,
GDK_BUTTON3_MASK = 1 << 10,
GDK_BUTTON4_MASK = 1 << 11,
GDK_BUTTON5_MASK = 1 << 12,
/* The next few modifiers are used by XKB, so we skip to the end.
* Bits 15 - 25 are currently unused. Bit 29 is used internally.
*/
GDK_SUPER_MASK = 1 << 26,
GDK_HYPER_MASK = 1 << 27,
GDK_META_MASK = 1 << 28,
GDK_RELEASE_MASK = 1 << 30,
GDK_MODIFIER_MASK = 0x5c001fff
} GdkModifierType;
Using that, we would just have to add after the accelerator_parse:
Code: Select all
gtk_accelerator_parse(mb[i].accel, &accelerator_key, &accelerator_mods);
if(accelerator_mods & GDK_CONTROL_MASK) {
accelerator_mods &= ~GDK_CONTROL_MASK; // clear Ctrl flag
accelerator_mods |= GDK_META_MASK; // set Meta flag
}