Ticket #3176: menu.diff

File menu.diff, 2.4 KB (added by karmak, 16 years ago)

Diff for Menu Preference applet to detect and correctly Invert modifiers

  • src/preferences/menu/MenuSettings.cpp

     
    7575MenuSettings::AltAsShortcut() const
    7676{
    7777    key_map *keys;
    78     char* chars; 
     78    char* chars;
    7979   
    8080    get_key_map(&keys, &chars);
    81 
    82     bool altAsShortcut = (keys->left_command_key == 0x5d)
    83         && (keys->left_control_key == 0x5c);
    84 
     81   
     82    // TODO: don't hardcode Alt to 0x5d ; instead get it from the current
     83    // keymap at the first invocation of Menu pref applet, with an assupmtion
     84    // that for every new keymap loaded and at the very first invocation of
     85    // applet, Alt (Command Key) is the default modifier (which is always the
     86    // case, in reality, cf. System Keymap and factory Keymaps).
     87    // Then, to get rid of hardcoding: at first invocation of Menu preferences
     88    // applet, if no pref file exists, or if pref file exists but keymap has
     89    // been changed by user), record the new keymap and the value of
     90    // left_command_key in the ~/config/.../pref file, in order
     91    // to know what it was on subsequent calls. Everytime the user
     92    // changes keymap and we notice it from here, we should reset the
     93    // preference file, like if it was the first invocation of Menu
     94    // preference applet.
     95   
     96    bool altAsShortcut = (keys->left_command_key == 0x5d);
     97   
    8598    free(chars);
    8699    free(keys);
    87    
     100       
    88101    return altAsShortcut;   
    89102}
    90103
     
    92105void
    93106MenuSettings::SetAltAsShortcut(bool altAsShortcut)
    94107{
    95     if (altAsShortcut) {
     108
     109    key_map *keys;
     110    char* chars;
     111   
     112    get_key_map(&keys, &chars);
     113
     114    if ( (altAsShortcut && !AltAsShortcut())
     115        || (!altAsShortcut && AltAsShortcut()) ) {
     116        // as the current settings are recorded directly in the keymap,
     117        // we just need to invert them from a temp local copy.
     118       
    96119        // This might not be the same for all keyboards
    97         set_modifier_key(B_LEFT_COMMAND_KEY, 0x5d);
    98         set_modifier_key(B_LEFT_CONTROL_KEY, 0x5c);
    99     } else {
    100         // This might not be the same for all keyboards
    101         set_modifier_key(B_LEFT_COMMAND_KEY, 0x5c);
    102         set_modifier_key(B_LEFT_CONTROL_KEY, 0x5d);
     120        set_modifier_key(B_LEFT_COMMAND_KEY, keys->left_control_key);
     121        set_modifier_key(B_LEFT_CONTROL_KEY, keys->left_command_key);
     122
     123        be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED));   
    103124    }
    104     be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED));   
     125   
     126    free(chars);
     127    free(keys);
    105128}
    106129
    107130