Skip to content

Commit fe30a5c

Browse files
committed
Fix use of raw CMD/CTRL key code.
1 parent 53be3b7 commit fe30a5c

17 files changed

+51
-36
lines changed

core/input/input.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,20 @@ bool Input::is_anything_pressed_except_mouse() const {
312312
return false;
313313
}
314314

315+
bool Input::is_command_or_control_pressed() const {
316+
_THREAD_SAFE_METHOD_
317+
318+
if (disable_input) {
319+
return false;
320+
}
321+
322+
if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
323+
return keys_pressed.has(Key::META);
324+
} else {
325+
return keys_pressed.has(Key::CTRL);
326+
}
327+
}
328+
315329
bool Input::is_key_pressed(Key p_keycode) const {
316330
_THREAD_SAFE_METHOD_
317331

core/input/input.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ class Input : public Object {
298298

299299
bool is_anything_pressed() const;
300300
bool is_anything_pressed_except_mouse() const;
301+
bool is_command_or_control_pressed() const;
301302
bool is_key_pressed(Key p_keycode) const;
302303
bool is_physical_key_pressed(Key p_keycode) const;
303304
bool is_key_label_pressed(Key p_keycode) const;

editor/animation/animation_track_editor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4923,11 +4923,11 @@ bool AnimationTrackEditor::is_key_clipboard_active() const {
49234923
}
49244924

49254925
bool AnimationTrackEditor::is_snap_timeline_enabled() const {
4926-
return snap_timeline->is_pressed() ^ Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL);
4926+
return snap_timeline->is_pressed() ^ Input::get_singleton()->is_command_or_control_pressed();
49274927
}
49284928

49294929
bool AnimationTrackEditor::is_snap_keys_enabled() const {
4930-
return snap_keys->is_pressed() ^ Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL);
4930+
return snap_keys->is_pressed() ^ Input::get_singleton()->is_command_or_control_pressed();
49314931
}
49324932

49334933
bool AnimationTrackEditor::is_bezier_editor_active() const {

editor/audio/editor_audio_buses.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ void EditorAudioBus::_volume_changed(float p_normalized) {
353353

354354
const float p_db = _normalized_volume_to_scaled_db(p_normalized);
355355

356-
if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
356+
if (Input::get_singleton()->is_command_or_control_pressed()) {
357357
// Snap the value when holding Ctrl for easier editing.
358358
// To do so, it needs to be converted back to normalized volume (as the slider uses that unit).
359359
slider->set_value(_scaled_db_to_normalized_volume(Math::round(p_db)));
@@ -413,7 +413,7 @@ float EditorAudioBus::_scaled_db_to_normalized_volume(float db) {
413413

414414
void EditorAudioBus::_show_value(float slider_value) {
415415
float db;
416-
if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
416+
if (Input::get_singleton()->is_command_or_control_pressed()) {
417417
// Display the correct (snapped) value when holding Ctrl
418418
db = Math::round(_normalized_volume_to_scaled_db(slider_value));
419419
} else {

editor/docks/filesystem_dock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3116,7 +3116,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
31163116
}
31173117
}
31183118
if (!to_move.is_empty()) {
3119-
if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
3119+
if (Input::get_singleton()->is_command_or_control_pressed()) {
31203120
_move_operation_confirm(to_dir, true);
31213121
} else {
31223122
_move_operation_confirm(to_dir);

editor/docks/scene_tree_dock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3624,7 +3624,7 @@ void SceneTreeDock::_script_dropped(const String &p_file, NodePath p_to) {
36243624
}
36253625

36263626
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
3627-
if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
3627+
if (Input::get_singleton()->is_command_or_control_pressed()) {
36283628
Object *obj = ClassDB::instantiate(scr->get_instance_base_type());
36293629
ERR_FAIL_NULL(obj);
36303630

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,12 @@ bool TileMapLayerEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEven
726726
}
727727
} else {
728728
// Check if we are picking a tile.
729-
if (picker_button->is_pressed() || (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL) && !Input::get_singleton()->is_key_pressed(Key::SHIFT))) {
729+
if (picker_button->is_pressed() || (Input::get_singleton()->is_command_or_control_pressed() && !Input::get_singleton()->is_key_pressed(Key::SHIFT))) {
730730
drag_type = DRAG_TYPE_PICK;
731731
drag_start_mouse_pos = mpos;
732732
} else {
733733
// Paint otherwise.
734-
if (tool_buttons_group->get_pressed_button() == paint_tool_button && !Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL) && !Input::get_singleton()->is_key_pressed(Key::SHIFT)) {
734+
if (tool_buttons_group->get_pressed_button() == paint_tool_button && !Input::get_singleton()->is_command_or_control_pressed() && !Input::get_singleton()->is_key_pressed(Key::SHIFT)) {
735735
drag_type = DRAG_TYPE_PAINT;
736736
drag_start_mouse_pos = mpos;
737737
drag_modified.clear();
@@ -747,11 +747,11 @@ bool TileMapLayerEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEven
747747
edited_layer->set_cell(coords, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
748748
}
749749
_fix_invalid_tiles_in_tile_map_selection();
750-
} else if (tool_buttons_group->get_pressed_button() == line_tool_button || (tool_buttons_group->get_pressed_button() == paint_tool_button && Input::get_singleton()->is_key_pressed(Key::SHIFT) && !Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL))) {
750+
} else if (tool_buttons_group->get_pressed_button() == line_tool_button || (tool_buttons_group->get_pressed_button() == paint_tool_button && Input::get_singleton()->is_key_pressed(Key::SHIFT) && !Input::get_singleton()->is_command_or_control_pressed())) {
751751
drag_type = DRAG_TYPE_LINE;
752752
drag_start_mouse_pos = mpos;
753753
drag_modified.clear();
754-
} else if (tool_buttons_group->get_pressed_button() == rect_tool_button || (tool_buttons_group->get_pressed_button() == paint_tool_button && Input::get_singleton()->is_key_pressed(Key::SHIFT) && Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL))) {
754+
} else if (tool_buttons_group->get_pressed_button() == rect_tool_button || (tool_buttons_group->get_pressed_button() == paint_tool_button && Input::get_singleton()->is_key_pressed(Key::SHIFT) && Input::get_singleton()->is_command_or_control_pressed())) {
755755
drag_type = DRAG_TYPE_RECT;
756756
drag_start_mouse_pos = mpos;
757757
drag_modified.clear();
@@ -813,7 +813,7 @@ void TileMapLayerEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p
813813
// Draw the selection.
814814
if ((tiles_bottom_panel->is_visible_in_tree() || patterns_bottom_panel->is_visible_in_tree()) && tool_buttons_group->get_pressed_button() == select_tool_button) {
815815
// In select mode, we only draw the current selection if we are modifying it (pressing control or shift).
816-
if (drag_type == DRAG_TYPE_MOVE || (drag_type == DRAG_TYPE_SELECT && !Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL) && !Input::get_singleton()->is_key_pressed(Key::SHIFT))) {
816+
if (drag_type == DRAG_TYPE_MOVE || (drag_type == DRAG_TYPE_SELECT && !Input::get_singleton()->is_command_or_control_pressed() && !Input::get_singleton()->is_key_pressed(Key::SHIFT))) {
817817
// Do nothing.
818818
} else {
819819
Color grid_color = EDITOR_GET("editors/tiles_editor/grid_color");
@@ -883,7 +883,7 @@ void TileMapLayerEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p
883883
Vector2i coords = tile_set->map_pattern(tile_set->local_to_map(mpos - mouse_offset), clipboard_used_cells[i], tile_map_clipboard);
884884
preview[coords] = TileMapCell(tile_map_clipboard->get_cell_source_id(clipboard_used_cells[i]), tile_map_clipboard->get_cell_atlas_coords(clipboard_used_cells[i]), tile_map_clipboard->get_cell_alternative_tile(clipboard_used_cells[i]));
885885
}
886-
} else if (!picker_button->is_pressed() && !(drag_type == DRAG_TYPE_NONE && Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL) && !Input::get_singleton()->is_key_pressed(Key::SHIFT))) {
886+
} else if (!picker_button->is_pressed() && !(drag_type == DRAG_TYPE_NONE && Input::get_singleton()->is_command_or_control_pressed() && !Input::get_singleton()->is_key_pressed(Key::SHIFT))) {
887887
bool expand_grid = false;
888888
if (tool_buttons_group->get_pressed_button() == paint_tool_button && drag_type == DRAG_TYPE_NONE) {
889889
// Preview for a single pattern.
@@ -1284,14 +1284,14 @@ void TileMapLayerEditorTilesPlugin::_stop_dragging() {
12841284
undo_redo->create_action_for_history(TTR("Change selection"), EditorNode::get_editor_data().get_current_edited_scene_history_id(), UndoRedo::MERGE_DISABLE, false, false);
12851285
undo_redo->add_undo_method(this, "_set_tile_map_selection", _get_tile_map_selection());
12861286

1287-
if (!Input::get_singleton()->is_key_pressed(Key::SHIFT) && !Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
1287+
if (!Input::get_singleton()->is_key_pressed(Key::SHIFT) && !Input::get_singleton()->is_command_or_control_pressed()) {
12881288
tile_map_selection.clear();
12891289
}
12901290
Rect2i rect = Rect2i(tile_set->local_to_map(drag_start_mouse_pos), tile_set->local_to_map(mpos) - tile_set->local_to_map(drag_start_mouse_pos)).abs();
12911291
for (int x = rect.position.x; x <= rect.get_end().x; x++) {
12921292
for (int y = rect.position.y; y <= rect.get_end().y; y++) {
12931293
Vector2i coords = Vector2i(x, y);
1294-
if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
1294+
if (Input::get_singleton()->is_command_or_control_pressed()) {
12951295
if (tile_map_selection.has(coords)) {
12961296
tile_map_selection.erase(coords);
12971297
}
@@ -3054,7 +3054,7 @@ bool TileMapLayerEditorTerrainsPlugin::forward_canvas_gui_input(const Ref<InputE
30543054
drag_type = DRAG_TYPE_PICK;
30553055
} else {
30563056
// Paint otherwise.
3057-
if (tool_buttons_group->get_pressed_button() == paint_tool_button && !Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL) && !Input::get_singleton()->is_key_pressed(Key::SHIFT)) {
3057+
if (tool_buttons_group->get_pressed_button() == paint_tool_button && !Input::get_singleton()->is_command_or_control_pressed() && !Input::get_singleton()->is_key_pressed(Key::SHIFT)) {
30583058
if (selected_terrain_set < 0 || selected_terrain < 0 || (selected_type == SELECTED_TYPE_PATTERN && !selected_terrains_pattern.is_valid())) {
30593059
return true;
30603060
}
@@ -3069,14 +3069,14 @@ bool TileMapLayerEditorTerrainsPlugin::forward_canvas_gui_input(const Ref<InputE
30693069
drag_modified[E.key] = edited_layer->get_cell(E.key);
30703070
edited_layer->set_cell(E.key, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
30713071
}
3072-
} else if (tool_buttons_group->get_pressed_button() == line_tool_button || (tool_buttons_group->get_pressed_button() == paint_tool_button && Input::get_singleton()->is_key_pressed(Key::SHIFT) && !Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL))) {
3072+
} else if (tool_buttons_group->get_pressed_button() == line_tool_button || (tool_buttons_group->get_pressed_button() == paint_tool_button && Input::get_singleton()->is_key_pressed(Key::SHIFT) && !Input::get_singleton()->is_command_or_control_pressed())) {
30733073
if (selected_terrain_set < 0 || selected_terrain < 0 || (selected_type == SELECTED_TYPE_PATTERN && !selected_terrains_pattern.is_valid())) {
30743074
return true;
30753075
}
30763076
drag_type = DRAG_TYPE_LINE;
30773077
drag_start_mouse_pos = mpos;
30783078
drag_modified.clear();
3079-
} else if (tool_buttons_group->get_pressed_button() == rect_tool_button || (tool_buttons_group->get_pressed_button() == paint_tool_button && Input::get_singleton()->is_key_pressed(Key::SHIFT) && Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL))) {
3079+
} else if (tool_buttons_group->get_pressed_button() == rect_tool_button || (tool_buttons_group->get_pressed_button() == paint_tool_button && Input::get_singleton()->is_key_pressed(Key::SHIFT) && Input::get_singleton()->is_command_or_control_pressed())) {
30803080
if (selected_terrain_set < 0 || selected_terrain < 0 || (selected_type == SELECTED_TYPE_PATTERN && !selected_terrains_pattern.is_valid())) {
30813081
return true;
30823082
}
@@ -3147,7 +3147,7 @@ void TileMapLayerEditorTerrainsPlugin::forward_canvas_draw_over_viewport(Control
31473147
tile_xform.set_scale(tile_shape_size);
31483148
tile_set->draw_tile_shape(p_overlay, xform * tile_xform, Color(1.0, 1.0, 1.0), false);
31493149
}
3150-
} else if (!picker_button->is_pressed() && !(drag_type == DRAG_TYPE_NONE && Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL) && !Input::get_singleton()->is_key_pressed(Key::SHIFT))) {
3150+
} else if (!picker_button->is_pressed() && !(drag_type == DRAG_TYPE_NONE && Input::get_singleton()->is_command_or_control_pressed() && !Input::get_singleton()->is_key_pressed(Key::SHIFT))) {
31513151
bool expand_grid = false;
31523152
if (tool_buttons_group->get_pressed_button() == paint_tool_button && drag_type == DRAG_TYPE_NONE) {
31533153
// Preview for a single tile.

editor/scene/3d/polygon_3d_editor_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ EditorPlugin::AfterGUIInput Polygon3DEditor::forward_3d_gui_input(Camera3D *p_ca
325325

326326
Vector2 cpoint(spoint.x, spoint.y);
327327

328-
if (snap_ignore && !Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
328+
if (snap_ignore && !Input::get_singleton()->is_command_or_control_pressed()) {
329329
snap_ignore = false;
330330
}
331331

editor/scene/canvas_item_editor_plugin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsig
365365
snap_target[0] = SNAP_TARGET_NONE;
366366
snap_target[1] = SNAP_TARGET_NONE;
367367

368-
bool is_snap_active = smart_snap_active ^ Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL);
368+
bool is_snap_active = smart_snap_active ^ Input::get_singleton()->is_command_or_control_pressed();
369369

370370
// Smart snap using the canvas position
371371
Vector2 output = p_target;
@@ -491,7 +491,7 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsig
491491
}
492492

493493
real_t CanvasItemEditor::snap_angle(real_t p_target, real_t p_start) const {
494-
if (((smart_snap_active || snap_rotation) ^ Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) && snap_rotation_step != 0) {
494+
if (((smart_snap_active || snap_rotation) ^ Input::get_singleton()->is_command_or_control_pressed()) && snap_rotation_step != 0) {
495495
if (snap_relative) {
496496
return Math::snapped(p_target - snap_rotation_offset, snap_rotation_step) + snap_rotation_offset + (p_start - (int)(p_start / snap_rotation_step) * snap_rotation_step);
497497
} else {
@@ -3702,7 +3702,7 @@ void CanvasItemEditor::_draw_selection() {
37023702
CanvasItem *ci = selection.front()->get();
37033703

37043704
Transform2D xform = transform * ci->get_screen_transform();
3705-
bool is_ctrl = Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL);
3705+
bool is_ctrl = Input::get_singleton()->is_command_or_control_pressed();
37063706
bool is_alt = Input::get_singleton()->is_key_pressed(Key::ALT);
37073707

37083708
// Draw the move handles.

editor/scene/sprite_frames_editor_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
17941794
if (String(d["type"]) == "files") {
17951795
Vector<String> files = d["files"];
17961796

1797-
if (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL)) {
1797+
if (Input::get_singleton()->is_command_or_control_pressed()) {
17981798
_prepare_sprite_sheet(files[0]);
17991799
} else {
18001800
_file_load_request(files, at_pos);

0 commit comments

Comments
 (0)