diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 1435b024c8..ed865807fc 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -158,7 +158,7 @@ void InputEventWithModifiers::set_command_or_control_autoremap(bool p_enabled) { } command_or_control_autoremap = p_enabled; if (command_or_control_autoremap) { - if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) { + if (OS::prefer_meta_over_ctrl()) { ctrl_pressed = false; meta_pressed = true; } else { @@ -178,7 +178,7 @@ bool InputEventWithModifiers::is_command_or_control_autoremap() const { } bool InputEventWithModifiers::is_command_or_control_pressed() const { - if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) { + if (OS::prefer_meta_over_ctrl()) { return meta_pressed; } else { return ctrl_pressed; @@ -245,7 +245,7 @@ BitField InputEventWithModifiers::get_modifiers_mask() const { mask.set_flag(KeyModifierMask::META); } if (is_command_or_control_autoremap()) { - if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) { + if (OS::prefer_meta_over_ctrl()) { mask.set_flag(KeyModifierMask::META); } else { mask.set_flag(KeyModifierMask::CTRL); diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index 36e272eecc..c76744cde8 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -361,7 +361,7 @@ bool keycode_has_unicode(Key p_keycode) { String keycode_get_string(Key p_code) { Vector keycode_string; - if ((p_code & KeyModifierMask::CMD_OR_CTRL) != Key::NONE && !(OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios"))) { + if ((p_code & KeyModifierMask::CMD_OR_CTRL) != Key::NONE && !OS::prefer_meta_over_ctrl()) { keycode_string.push_back(find_keycode_name(Key::CTRL)); } if ((p_code & KeyModifierMask::CTRL) != Key::NONE) { @@ -373,7 +373,7 @@ String keycode_get_string(Key p_code) { if ((p_code & KeyModifierMask::SHIFT) != Key::NONE) { keycode_string.push_back(find_keycode_name(Key::SHIFT)); } - if ((p_code & KeyModifierMask::CMD_OR_CTRL) != Key::NONE && (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios"))) { + if ((p_code & KeyModifierMask::CMD_OR_CTRL) != Key::NONE && OS::prefer_meta_over_ctrl()) { keycode_string.push_back(find_keycode_name(Key::META)); } if ((p_code & KeyModifierMask::META) != Key::NONE) { diff --git a/core/os/os.cpp b/core/os/os.cpp index ef4669a5ea..790e9043d5 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -55,6 +55,16 @@ OS *OS::get_singleton() { return singleton; } +bool OS::prefer_meta_over_ctrl() { +#if defined(MACOS_ENABLED) || defined(APPLE_EMBEDDED_ENABLED) + return true; +#elif defined(WEB_ENABLED) + return singleton->has_feature("web_macos") || singleton->has_feature("web_ios"); +#else + return false; +#endif +} + uint64_t OS::get_ticks_msec() const { return get_ticks_usec() / 1000ULL; } diff --git a/core/os/os.h b/core/os/os.h index 2c9607d9e8..346584547a 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -132,6 +132,8 @@ public: static OS *get_singleton(); + static bool prefer_meta_over_ctrl(); + void set_current_rendering_driver_name(const String &p_driver_name) { _current_rendering_driver_name = p_driver_name; } void set_current_rendering_method(const String &p_name) { _current_rendering_method = p_name; } void set_gles_over_gl(bool p_enabled) { _is_gles_over_gl = p_enabled; } diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp index dddc9f90c1..a16a9bfbeb 100644 --- a/editor/gui/editor_spin_slider.cpp +++ b/editor/gui/editor_spin_slider.cpp @@ -41,7 +41,7 @@ String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const { String value = get_text_value() + suffix; if (!read_only && grabber->is_visible()) { String tooltip = value; - Key key = (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) ? Key::META : Key::CTRL; + Key key = OS::prefer_meta_over_ctrl() ? Key::META : Key::CTRL; if (!editing_integer) { tooltip += "\n\n" + vformat(TTR("Hold %s to round to integers."), find_keycode_name(key)); } diff --git a/editor/scene/2d/polygon_2d_editor_plugin.cpp b/editor/scene/2d/polygon_2d_editor_plugin.cpp index 989a1e1823..04a1100832 100644 --- a/editor/scene/2d/polygon_2d_editor_plugin.cpp +++ b/editor/scene/2d/polygon_2d_editor_plugin.cpp @@ -1318,7 +1318,7 @@ Polygon2DEditor::Polygon2DEditor() { action_buttons[ACTION_CREATE]->set_tooltip_text(TTR("Create Polygon")); action_buttons[ACTION_CREATE_INTERNAL]->set_tooltip_text(TTR("Create Internal Vertex")); action_buttons[ACTION_REMOVE_INTERNAL]->set_tooltip_text(TTR("Remove Internal Vertex")); - Key key = (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) ? Key::META : Key::CTRL; + Key key = OS::prefer_meta_over_ctrl() ? Key::META : Key::CTRL; // TRANSLATORS: %s is Control or Command key name. action_buttons[ACTION_EDIT_POINT]->set_tooltip_text(TTR("Move Points") + "\n" + vformat(TTR("%s: Rotate"), find_keycode_name(key)) + "\n" + TTR("Shift: Move All") + "\n" + vformat(TTR("%s + Shift: Scale"), find_keycode_name(key))); action_buttons[ACTION_MOVE]->set_tooltip_text(TTR("Move Polygon")); diff --git a/editor/scene/2d/tiles/tile_map_layer_editor.cpp b/editor/scene/2d/tiles/tile_map_layer_editor.cpp index 6cb27291a3..f61058cc6f 100644 --- a/editor/scene/2d/tiles/tile_map_layer_editor.cpp +++ b/editor/scene/2d/tiles/tile_map_layer_editor.cpp @@ -2229,7 +2229,7 @@ TileMapLayerEditorTilesPlugin::TileMapLayerEditorTilesPlugin() { picker_button->set_theme_type_variation(SceneStringName(FlatButton)); picker_button->set_toggle_mode(true); picker_button->set_shortcut(ED_GET_SHORTCUT("tiles_editor/picker")); - Key key = (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) ? Key::META : Key::CTRL; + Key key = OS::prefer_meta_over_ctrl() ? Key::META : Key::CTRL; picker_button->set_tooltip_text(vformat(TTR("Alternatively hold %s with other tools to pick tile."), find_keycode_name(key))); picker_button->connect(SceneStringName(pressed), callable_mp(CanvasItemEditor::get_singleton(), &CanvasItemEditor::update_viewport)); picker_button->set_accessibility_name(TTRC("Pick")); diff --git a/editor/scene/3d/node_3d_editor_plugin.cpp b/editor/scene/3d/node_3d_editor_plugin.cpp index dd8bda1779..3c47357d9f 100644 --- a/editor/scene/3d/node_3d_editor_plugin.cpp +++ b/editor/scene/3d/node_3d_editor_plugin.cpp @@ -3152,7 +3152,7 @@ void Node3DEditorViewport::_notification(int p_what) { _update_centered_labels(); message_time = MIN(message_time, 0.001); // Make it disappear. - Key key = (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) ? Key::META : Key::CTRL; + Key key = OS::prefer_meta_over_ctrl() ? Key::META : Key::CTRL; preview_material_label_desc->set_text(vformat(TTR("Drag and drop to override the material of any geometry node.\nHold %s when dropping to override a specific surface."), find_keycode_name(key))); const int item_count = display_submenu->get_item_count(); diff --git a/editor/settings/editor_settings.cpp b/editor/settings/editor_settings.cpp index 3f78ac9c52..7f3028f615 100644 --- a/editor/settings/editor_settings.cpp +++ b/editor/settings/editor_settings.cpp @@ -1997,7 +1997,7 @@ void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, c for (int i = 0; i < p_keycodes.size(); i++) { Key keycode = (Key)p_keycodes[i]; - if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) { + if (OS::prefer_meta_over_ctrl()) { // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS if (keycode == Key::KEY_DELETE) { keycode = KeyModifierMask::META | Key::BACKSPACE; @@ -2031,7 +2031,7 @@ Ref ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, cons for (int i = 0; i < p_keycodes.size(); i++) { Key keycode = (Key)p_keycodes[i]; - if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) { + if (OS::prefer_meta_over_ctrl()) { // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS if (keycode == Key::KEY_DELETE) { keycode = KeyModifierMask::META | Key::BACKSPACE; diff --git a/editor/settings/event_listener_line_edit.cpp b/editor/settings/event_listener_line_edit.cpp index 8da77323bf..719bbb5e3a 100644 --- a/editor/settings/event_listener_line_edit.cpp +++ b/editor/settings/event_listener_line_edit.cpp @@ -66,7 +66,7 @@ String EventListenerLineEdit::get_event_text(const Ref &p_event, boo String mods_text = key->InputEventWithModifiers::as_text(); mods_text = mods_text.is_empty() ? mods_text : mods_text + "+"; if (key->is_command_or_control_autoremap()) { - if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) { + if (OS::prefer_meta_over_ctrl()) { mods_text = mods_text.replace("Command", "Command/Ctrl"); } else { mods_text = mods_text.replace("Ctrl", "Command/Ctrl"); diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index ad4a8ad5ff..d5b73543f9 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -504,7 +504,7 @@ void CodeEdit::gui_input(const Ref &p_gui_input) { } /* Ctrl + Hover symbols */ - bool mac_keys = OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios"); + bool mac_keys = OS::prefer_meta_over_ctrl(); if ((mac_keys && k->get_keycode() == Key::META) || (!mac_keys && k->get_keycode() == Key::CTRL)) { if (symbol_lookup_on_click_enabled) { if (k->is_pressed() && !is_dragging_cursor()) {