Skip to content

Commit e33c423

Browse files
committed
Merge pull request godotengine#108314 from KoBeWi/shift_in_meta
Replace repetitive meta/ctrl condition with a method
2 parents a627ee6 + 98141c3 commit e33c423

File tree

11 files changed

+25
-13
lines changed

11 files changed

+25
-13
lines changed

core/input/input_event.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void InputEventWithModifiers::set_command_or_control_autoremap(bool p_enabled) {
158158
}
159159
command_or_control_autoremap = p_enabled;
160160
if (command_or_control_autoremap) {
161-
if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
161+
if (OS::prefer_meta_over_ctrl()) {
162162
ctrl_pressed = false;
163163
meta_pressed = true;
164164
} else {
@@ -178,7 +178,7 @@ bool InputEventWithModifiers::is_command_or_control_autoremap() const {
178178
}
179179

180180
bool InputEventWithModifiers::is_command_or_control_pressed() const {
181-
if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
181+
if (OS::prefer_meta_over_ctrl()) {
182182
return meta_pressed;
183183
} else {
184184
return ctrl_pressed;
@@ -245,7 +245,7 @@ BitField<KeyModifierMask> InputEventWithModifiers::get_modifiers_mask() const {
245245
mask.set_flag(KeyModifierMask::META);
246246
}
247247
if (is_command_or_control_autoremap()) {
248-
if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
248+
if (OS::prefer_meta_over_ctrl()) {
249249
mask.set_flag(KeyModifierMask::META);
250250
} else {
251251
mask.set_flag(KeyModifierMask::CTRL);

core/os/keyboard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ bool keycode_has_unicode(Key p_keycode) {
361361

362362
String keycode_get_string(Key p_code) {
363363
Vector<String> keycode_string;
364-
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"))) {
364+
if ((p_code & KeyModifierMask::CMD_OR_CTRL) != Key::NONE && !OS::prefer_meta_over_ctrl()) {
365365
keycode_string.push_back(find_keycode_name(Key::CTRL));
366366
}
367367
if ((p_code & KeyModifierMask::CTRL) != Key::NONE) {
@@ -373,7 +373,7 @@ String keycode_get_string(Key p_code) {
373373
if ((p_code & KeyModifierMask::SHIFT) != Key::NONE) {
374374
keycode_string.push_back(find_keycode_name(Key::SHIFT));
375375
}
376-
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"))) {
376+
if ((p_code & KeyModifierMask::CMD_OR_CTRL) != Key::NONE && OS::prefer_meta_over_ctrl()) {
377377
keycode_string.push_back(find_keycode_name(Key::META));
378378
}
379379
if ((p_code & KeyModifierMask::META) != Key::NONE) {

core/os/os.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ OS *OS::get_singleton() {
5555
return singleton;
5656
}
5757

58+
bool OS::prefer_meta_over_ctrl() {
59+
#if defined(MACOS_ENABLED) || defined(APPLE_EMBEDDED_ENABLED)
60+
return true;
61+
#elif defined(WEB_ENABLED)
62+
return singleton->has_feature("web_macos") || singleton->has_feature("web_ios");
63+
#else
64+
return false;
65+
#endif
66+
}
67+
5868
uint64_t OS::get_ticks_msec() const {
5969
return get_ticks_usec() / 1000ULL;
6070
}

core/os/os.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class OS {
132132

133133
static OS *get_singleton();
134134

135+
static bool prefer_meta_over_ctrl();
136+
135137
void set_current_rendering_driver_name(const String &p_driver_name) { _current_rendering_driver_name = p_driver_name; }
136138
void set_current_rendering_method(const String &p_name) { _current_rendering_method = p_name; }
137139
void set_gles_over_gl(bool p_enabled) { _is_gles_over_gl = p_enabled; }

editor/gui/editor_spin_slider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const {
4141
String value = get_text_value() + suffix;
4242
if (!read_only && grabber->is_visible()) {
4343
String tooltip = value;
44-
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;
44+
Key key = OS::prefer_meta_over_ctrl() ? Key::META : Key::CTRL;
4545
if (!editing_integer) {
4646
tooltip += "\n\n" + vformat(TTR("Hold %s to round to integers."), find_keycode_name(key));
4747
}

editor/scene/2d/polygon_2d_editor_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ Polygon2DEditor::Polygon2DEditor() {
13181318
action_buttons[ACTION_CREATE]->set_tooltip_text(TTR("Create Polygon"));
13191319
action_buttons[ACTION_CREATE_INTERNAL]->set_tooltip_text(TTR("Create Internal Vertex"));
13201320
action_buttons[ACTION_REMOVE_INTERNAL]->set_tooltip_text(TTR("Remove Internal Vertex"));
1321-
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;
1321+
Key key = OS::prefer_meta_over_ctrl() ? Key::META : Key::CTRL;
13221322
// TRANSLATORS: %s is Control or Command key name.
13231323
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)));
13241324
action_buttons[ACTION_MOVE]->set_tooltip_text(TTR("Move Polygon"));

editor/scene/2d/tiles/tile_map_layer_editor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,7 @@ TileMapLayerEditorTilesPlugin::TileMapLayerEditorTilesPlugin() {
22292229
picker_button->set_theme_type_variation(SceneStringName(FlatButton));
22302230
picker_button->set_toggle_mode(true);
22312231
picker_button->set_shortcut(ED_GET_SHORTCUT("tiles_editor/picker"));
2232-
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;
2232+
Key key = OS::prefer_meta_over_ctrl() ? Key::META : Key::CTRL;
22332233
picker_button->set_tooltip_text(vformat(TTR("Alternatively hold %s with other tools to pick tile."), find_keycode_name(key)));
22342234
picker_button->connect(SceneStringName(pressed), callable_mp(CanvasItemEditor::get_singleton(), &CanvasItemEditor::update_viewport));
22352235
picker_button->set_accessibility_name(TTRC("Pick"));

editor/scene/3d/node_3d_editor_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3152,7 +3152,7 @@ void Node3DEditorViewport::_notification(int p_what) {
31523152
_update_centered_labels();
31533153
message_time = MIN(message_time, 0.001); // Make it disappear.
31543154

3155-
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;
3155+
Key key = OS::prefer_meta_over_ctrl() ? Key::META : Key::CTRL;
31563156
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)));
31573157

31583158
const int item_count = display_submenu->get_item_count();

editor/settings/editor_settings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, c
19971997
for (int i = 0; i < p_keycodes.size(); i++) {
19981998
Key keycode = (Key)p_keycodes[i];
19991999

2000-
if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
2000+
if (OS::prefer_meta_over_ctrl()) {
20012001
// Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
20022002
if (keycode == Key::KEY_DELETE) {
20032003
keycode = KeyModifierMask::META | Key::BACKSPACE;
@@ -2031,7 +2031,7 @@ Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, cons
20312031
for (int i = 0; i < p_keycodes.size(); i++) {
20322032
Key keycode = (Key)p_keycodes[i];
20332033

2034-
if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
2034+
if (OS::prefer_meta_over_ctrl()) {
20352035
// Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
20362036
if (keycode == Key::KEY_DELETE) {
20372037
keycode = KeyModifierMask::META | Key::BACKSPACE;

editor/settings/event_listener_line_edit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ String EventListenerLineEdit::get_event_text(const Ref<InputEvent> &p_event, boo
6666
String mods_text = key->InputEventWithModifiers::as_text();
6767
mods_text = mods_text.is_empty() ? mods_text : mods_text + "+";
6868
if (key->is_command_or_control_autoremap()) {
69-
if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
69+
if (OS::prefer_meta_over_ctrl()) {
7070
mods_text = mods_text.replace("Command", "Command/Ctrl");
7171
} else {
7272
mods_text = mods_text.replace("Ctrl", "Command/Ctrl");

0 commit comments

Comments
 (0)