Skip to content

Commit c9e1b9e

Browse files
committed
Fix use of raw CMD/CTRL key code.
1 parent efb40c1 commit c9e1b9e

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_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/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/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_key_pressed()) {
31203120
_move_operation_confirm(to_dir, true);
31213121
} else {
31223122
_move_operation_confirm(to_dir);

editor/plugins/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/plugins/gradient_texture_2d_editor_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void GradientTexture2DEdit::_draw() {
199199
draw_texture_rect(texture, Rect2(Point2(), size));
200200

201201
// Draw grid snap lines.
202-
if (snap_enabled || (Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL) && grabbed != HANDLE_NONE)) {
202+
if (snap_enabled || (Input::get_singleton()->is_command_or_control_pressed() && grabbed != HANDLE_NONE)) {
203203
const Color line_color = Color(0.5, 0.5, 0.5, 0.5);
204204

205205
for (int idx = 0; idx < snap_count + 1; idx++) {

editor/plugins/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/plugins/script_text_editor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
22182218

22192219
String text_to_drop;
22202220

2221-
const bool drop_modifier_pressed = Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL);
2221+
const bool drop_modifier_pressed = Input::get_singleton()->is_command_or_control_pressed();
22222222
const bool allow_uid = Input::get_singleton()->is_key_pressed(Key::SHIFT) != bool(EDITOR_GET("text_editor/behavior/files/drop_preload_resources_as_uid"));
22232223
const String &line = te->get_line(drop_at_line);
22242224
const bool is_empty_line = line_will_be_empty || line.is_empty() || te->get_first_non_whitespace_column(drop_at_line) == line.length();

editor/plugins/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)