Re: [Gtk-osx-users] accelerator problem with GtkOSXApplication



On 15/02/2011, at 11:36 AM, Olivier Sessink wrote:

> I ended up with the following function, which replaces <control> with
> <command and replaces <control><alt> with <command><control>
> accelerators:
> 
> static void osx_accel_map_foreach_lcb(gpointer data,const gchar
> *accel_path,guint accel_key, GdkModifierType accel_mods, gboolean
> changed) {
> 	if (accel_mods & GDK_MOD1_MASK && accel_mods & GDK_CONTROL_MASK) {
> 		accel_mods &= ~ GDK_MOD1_MASK;
> 		accel_mods |= GDK_META_MASK;
> 		if (!gtk_accel_map_change_entry(accel_path,accel_key,accel_mods,FALSE)) {
> 			g_print("could not change accelerator %s\n",accel_path);
> 		}
> 	} else if (accel_mods & GDK_CONTROL_MASK) {
> 		accel_mods &= ~ GDK_CONTROL_MASK;
> 		accel_mods |= GDK_META_MASK;
> 		if (!gtk_accel_map_change_entry(accel_path,accel_key,accel_mods,FALSE)) {
> 			g_print("could not change accelerator %s\n",accel_path);
> 		}
> 	}
> }

Stylistically, I'd be inclined to reduce this to: 

static void osx_accel_map_foreach_lcb(gpointer data,const gchar
*accel_path,guint accel_key, GdkModifierType accel_mods, gboolean
changed) {
    if (accel_mods & GDK_CONTROL_MASK) { 
		accel_mods |= GDK_META_MASK;
                accel_mods &= (accel_mods & GDK_MOD1_MASK) ? ~GDK_MOD1_MASK : ~GDK_CONTROL_MASK; 

                if (!gtk_accel_map_change_entry(accel_path,accel_key,accel_mods,FALSE)) {
                    g_print("could not change accelerator %s\n",accel_path);
		}
    } 
}

The logic is clearer to my eye, and there's less code to parse.

warm regards, 
Richard. 





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