593 | | const char* label = B_TRANSLATE("Switch shortcut keys"); |
594 | | if (fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY) == 0x5d |
595 | | && fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY) == 0x5c) { |
596 | | label = B_TRANSLATE("Switch shortcut keys to Windows/Linux mode"); |
597 | | } else if (fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY) == 0x5c |
598 | | && fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY) == 0x5d) { |
599 | | label = B_TRANSLATE("Switch shortcut keys to Haiku mode"); |
| 628 | // Remove the custom item (may be added back) |
| 629 | fModifiersMenu->RemoveItem(MODIFIERS_CUSTOM); |
| 630 | |
| 631 | // To be in a mode the modifier keys must either be unmapped (== 0), |
| 632 | // or mapped to the keys for the mode. |
| 633 | if (_HaikuMode()) |
| 634 | fModifiersMenu->ItemAt(MODIFIERS_HAIKU)->SetMarked(true); |
| 635 | else if (_WinLinuxMode()) |
| 636 | fModifiersMenu->ItemAt(MODIFIERS_WIN_LINUX)->SetMarked(true); |
| 637 | else if (_MacMode()) |
| 638 | fModifiersMenu->ItemAt(MODIFIERS_MAC)->SetMarked(true); |
| 639 | else { |
| 640 | // Custom modifiers setting |
| 641 | fModifiersMenu->AddItem(new BMenuItem(B_TRANSLATE("Custom"), NULL), |
| 642 | MODIFIERS_CUSTOM); |
| 643 | fModifiersMenu->ItemAt(MODIFIERS_CUSTOM)->SetMarked(true); |
668 | | uint32 leftCommand = fCurrentMap.Map().left_command_key; |
669 | | uint32 leftControl = fCurrentMap.Map().left_control_key; |
670 | | uint32 rightCommand = fCurrentMap.Map().right_command_key; |
671 | | uint32 rightControl = fCurrentMap.Map().right_control_key; |
| 711 | key_map& keyMap = fCurrentMap.Map(); |
| 712 | |
| 713 | uint32 leftControl = fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY); |
| 714 | uint32 leftCommand = fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY); |
| 715 | uint32 leftOption = fCurrentMap.KeyForModifier(B_LEFT_OPTION_KEY); |
| 716 | uint32 rightControl = fCurrentMap.KeyForModifier(B_RIGHT_CONTROL_KEY); |
| 717 | uint32 rightCommand = fCurrentMap.KeyForModifier(B_RIGHT_COMMAND_KEY); |
| 718 | uint32 rightOption = fCurrentMap.KeyForModifier(B_RIGHT_OPTION_KEY); |
| 719 | |
| 720 | if (_HaikuMode()) { |
| 721 | switch (mode) { |
| 722 | case MODIFIERS_HAIKU: |
| 723 | // switching from Haiku mode to Haiku mode |
| 724 | return; |
| 725 | |
| 726 | case MODIFIERS_WIN_LINUX: |
| 727 | // switching from Haiku mode to Windows/Linux mode |
| 728 | // swap command and control keys |
| 729 | |
| 730 | // swap left side |
| 731 | keyMap.left_control_key = leftCommand; |
| 732 | keyMap.left_command_key = leftControl; |
| 733 | |
| 734 | // swap right side |
| 735 | keyMap.right_control_key = rightCommand; |
| 736 | keyMap.right_command_key = rightControl; |
| 737 | break; |
677 | | // switch right side |
678 | | fCurrentMap.Map().right_command_key = rightControl; |
679 | | fCurrentMap.Map().right_control_key = rightCommand; |
| 743 | // swap left side |
| 744 | keyMap.left_command_key = leftOption; |
| 745 | keyMap.left_option_key = leftCommand; |
| 746 | |
| 747 | // swap right side |
| 748 | keyMap.right_command_key = rightOption; |
| 749 | keyMap.right_option_key = rightCommand; |
| 750 | break; |
| 751 | } |
| 752 | } else if (_WinLinuxMode()) { |
| 753 | switch (mode) { |
| 754 | case MODIFIERS_HAIKU: |
| 755 | // switching from Windows/Linux mode to Haiku mode |
| 756 | // swap command and control keys |
| 757 | |
| 758 | // swap left side |
| 759 | keyMap.left_control_key = leftCommand; |
| 760 | keyMap.left_command_key = leftControl; |
| 761 | |
| 762 | // swap right side |
| 763 | keyMap.right_control_key = rightCommand; |
| 764 | keyMap.right_command_key = rightControl; |
| 765 | break; |
| 766 | |
| 767 | case MODIFIERS_WIN_LINUX: |
| 768 | // switching from Windows/Linux mode to Windows/Linux mode |
| 769 | return; |
| 770 | |
| 771 | case MODIFIERS_MAC: |
| 772 | // switching from Windows/Linux mode to Mac mode |
| 773 | // swap control and option keys |
| 774 | // then swap command and option keys |
| 775 | |
| 776 | // swap left side |
| 777 | keyMap.left_control_key = leftCommand; |
| 778 | keyMap.left_command_key = leftOption; |
| 779 | keyMap.left_option_key = leftControl; |
| 780 | |
| 781 | // swap right side |
| 782 | keyMap.right_control_key = rightCommand; |
| 783 | keyMap.right_command_key = rightOption; |
| 784 | keyMap.right_option_key = rightControl; |
| 785 | break; |
| 786 | } |
| 787 | } else if (_MacMode()) { |
| 788 | switch (mode) { |
| 789 | case MODIFIERS_HAIKU: |
| 790 | // switching from Mac mode to Haiku mode |
| 791 | // swap command and option keys |
| 792 | |
| 793 | // swap left side |
| 794 | keyMap.left_command_key = leftOption; |
| 795 | keyMap.left_option_key = leftCommand; |
| 796 | |
| 797 | // swap right side |
| 798 | keyMap.right_command_key = rightOption; |
| 799 | keyMap.right_option_key = rightCommand; |
| 800 | break; |
| 801 | |
| 802 | case MODIFIERS_WIN_LINUX: |
| 803 | // switching from Mac mode to Windows/Linux mode |
| 804 | // swap control and command |
| 805 | // then swap command and option |
| 806 | |
| 807 | // switch left side |
| 808 | keyMap.left_control_key = leftOption; |
| 809 | keyMap.left_command_key = leftControl; |
| 810 | keyMap.left_option_key = leftCommand; |
| 811 | |
| 812 | // switch right side |
| 813 | keyMap.right_control_key = rightOption; |
| 814 | keyMap.right_command_key = rightControl; |
| 815 | keyMap.right_option_key = rightCommand; |
| 816 | break; |
| 817 | |
| 818 | case MODIFIERS_MAC: |
| 819 | return; |
| 820 | } |
| 821 | } else { // Custom |
| 822 | switch (mode) { |
| 823 | // Set modifiers to Haiku mode, the default |
| 824 | case MODIFIERS_HAIKU: |
| 825 | // switch left side |
| 826 | keyMap.left_control_key = kLeftControlKey; |
| 827 | keyMap.left_command_key = kLeftCommandKey; |
| 828 | keyMap.left_option_key = kLeftOptionKey; |
| 829 | |
| 830 | // switch right side |
| 831 | keyMap.right_control_key = kRightControlKey; |
| 832 | if (keyMap.right_control_key == 0 |
| 833 | || keyMap.right_command_key == 0 |
| 834 | || keyMap.right_option_key == 0) { |
| 835 | keyMap.right_command_key = 0; |
| 836 | keyMap.right_option_key = kRightCommandKey; |
| 837 | } else { |
| 838 | keyMap.right_command_key = kRightCommandKey; |
| 839 | keyMap.right_option_key = kRightOptionKey; |
| 840 | } |
| 841 | |
| 842 | break; |
| 843 | |
| 844 | // Set modifiers to Win/Linux mode, swap control and command |
| 845 | case MODIFIERS_WIN_LINUX: |
| 846 | // switch left side |
| 847 | keyMap.left_control_key = kLeftCommandKey; |
| 848 | keyMap.left_command_key = kLeftControlKey; |
| 849 | keyMap.left_option_key = kLeftOptionKey; |
| 850 | |
| 851 | // switch right side |
| 852 | keyMap.right_command_key = kRightControlKey; |
| 853 | if (keyMap.right_control_key == 0 |
| 854 | || keyMap.right_command_key == 0 |
| 855 | || keyMap.right_option_key == 0) { |
| 856 | keyMap.right_control_key = 0; |
| 857 | keyMap.right_option_key = kRightCommandKey; |
| 858 | } else { |
| 859 | keyMap.right_control_key = kRightCommandKey; |
| 860 | keyMap.right_option_key = kRightOptionKey; |
| 861 | } |
| 862 | |
| 863 | break; |
| 864 | |
| 865 | // Set modifiers to Mac mode swap option and command |
| 866 | case MODIFIERS_MAC: |
| 867 | // switch left side |
| 868 | keyMap.left_control_key = kLeftControlKey; |
| 869 | keyMap.left_command_key = kLeftOptionKey; |
| 870 | keyMap.left_option_key = kLeftCommandKey; |
| 871 | |
| 872 | // switch right side |
| 873 | keyMap.right_control_key = kRightControlKey; |
| 874 | if (keyMap.right_control_key == 0 |
| 875 | || keyMap.right_command_key == 0 |
| 876 | || keyMap.right_option_key == 0) { |
| 877 | keyMap.right_command_key = kRightCommandKey; |
| 878 | keyMap.right_option_key = 0; |
| 879 | } else { |
| 880 | keyMap.right_command_key = kRightOptionKey; |
| 881 | keyMap.right_option_key = kRightCommandKey; |
| 882 | } |
| 883 | |
| 884 | break; |
| 885 | } |
| 886 | } |
| 1153 | |
| 1154 | |
| 1155 | bool |
| 1156 | KeymapWindow::_HaikuMode() |
| 1157 | { |
| 1158 | uint32 leftControl = fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY); |
| 1159 | uint32 leftCommand = fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY); |
| 1160 | uint32 leftOption = fCurrentMap.KeyForModifier(B_LEFT_OPTION_KEY); |
| 1161 | uint32 rightControl = fCurrentMap.KeyForModifier(B_RIGHT_CONTROL_KEY); |
| 1162 | uint32 rightCommand = fCurrentMap.KeyForModifier(B_RIGHT_COMMAND_KEY); |
| 1163 | uint32 rightOption = fCurrentMap.KeyForModifier(B_RIGHT_OPTION_KEY); |
| 1164 | |
| 1165 | return leftControl == kLeftControlKey && leftCommand == kLeftCommandKey |
| 1166 | && leftOption == kLeftOptionKey |
| 1167 | && (rightControl == kRightControlKey || rightControl == 0) |
| 1168 | && (rightCommand == kRightCommandKey || rightCommand == kRightOptionKey |
| 1169 | || rightCommand == 0) |
| 1170 | && (rightOption == kRightOptionKey || rightOption == kRightCommandKey |
| 1171 | || rightOption == 0); |
| 1172 | } |
| 1173 | |
| 1174 | |
| 1175 | bool |
| 1176 | KeymapWindow::_WinLinuxMode() |
| 1177 | { |
| 1178 | uint32 leftControl = fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY); |
| 1179 | uint32 leftCommand = fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY); |
| 1180 | uint32 leftOption = fCurrentMap.KeyForModifier(B_LEFT_OPTION_KEY); |
| 1181 | uint32 rightControl = fCurrentMap.KeyForModifier(B_RIGHT_CONTROL_KEY); |
| 1182 | uint32 rightCommand = fCurrentMap.KeyForModifier(B_RIGHT_COMMAND_KEY); |
| 1183 | uint32 rightOption = fCurrentMap.KeyForModifier(B_RIGHT_OPTION_KEY); |
| 1184 | |
| 1185 | return leftControl == kLeftCommandKey && leftCommand == kLeftControlKey |
| 1186 | && leftOption == kLeftOptionKey |
| 1187 | && (rightControl == kRightCommandKey || rightControl == kRightOptionKey || |
| 1188 | rightControl == 0) |
| 1189 | && (rightCommand == kRightControlKey || rightCommand == 0) |
| 1190 | && (rightOption == kRightOptionKey || rightOption == kRightCommandKey |
| 1191 | || rightOption == 0); |
| 1192 | } |
| 1193 | |
| 1194 | |
| 1195 | bool |
| 1196 | KeymapWindow::_MacMode() |
| 1197 | { |
| 1198 | uint32 leftControl = fCurrentMap.KeyForModifier(B_LEFT_CONTROL_KEY); |
| 1199 | uint32 leftCommand = fCurrentMap.KeyForModifier(B_LEFT_COMMAND_KEY); |
| 1200 | uint32 leftOption = fCurrentMap.KeyForModifier(B_LEFT_OPTION_KEY); |
| 1201 | uint32 rightControl = fCurrentMap.KeyForModifier(B_RIGHT_CONTROL_KEY); |
| 1202 | uint32 rightCommand = fCurrentMap.KeyForModifier(B_RIGHT_COMMAND_KEY); |
| 1203 | uint32 rightOption = fCurrentMap.KeyForModifier(B_RIGHT_OPTION_KEY); |
| 1204 | |
| 1205 | return leftControl == kLeftControlKey && leftCommand == kLeftOptionKey |
| 1206 | && leftOption == kLeftCommandKey |
| 1207 | && (rightControl == kRightControlKey || rightControl == 0) |
| 1208 | && (rightCommand == kRightOptionKey || rightCommand == kRightCommandKey |
| 1209 | || rightCommand == 0) |
| 1210 | && (rightOption == kRightCommandKey || rightCommand == kRightOptionKey |
| 1211 | || rightOption == 0); |
| 1212 | } |