mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 04:06:14 +00:00
Fix Determining Window for Touchscreen
DisplayServer::screen_is_touchscreen will likely never utilize its parameter p_screen. This PR replaces this function by DisplayServer::is_touchscreen_available() with the same functionality. This solves the problem, that a SubViewport was used for determining the screen, which resulted in error messages.
This commit is contained in:
parent
c241f1c523
commit
e18107a57c
@ -719,6 +719,12 @@
|
|||||||
[b]Note:[/b] This method is implemented on macOS, Windows and Linux (X11).
|
[b]Note:[/b] This method is implemented on macOS, Windows and Linux (X11).
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="is_touchscreen_available" qualifiers="const">
|
||||||
|
<return type="bool" />
|
||||||
|
<description>
|
||||||
|
Returns [code]true[/code] if touch events are available (Android or iOS), the capability is detected on the Webplatform or if [member ProjectSettings.input_devices/pointing/emulate_touch_from_mouse] is [code]true[/code].
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="keyboard_get_current_layout" qualifiers="const">
|
<method name="keyboard_get_current_layout" qualifiers="const">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<description>
|
<description>
|
||||||
@ -889,13 +895,6 @@
|
|||||||
Returns [code]true[/code] if the screen should never be turned off by the operating system's power-saving measures. See also [method screen_set_keep_on].
|
Returns [code]true[/code] if the screen should never be turned off by the operating system's power-saving measures. See also [method screen_set_keep_on].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="screen_is_touchscreen" qualifiers="const">
|
|
||||||
<return type="bool" />
|
|
||||||
<param index="0" name="screen" type="int" default="-1" />
|
|
||||||
<description>
|
|
||||||
Returns [code]true[/code] if the screen can send touch events or if [member ProjectSettings.input_devices/pointing/emulate_touch_from_mouse] is [code]true[/code].
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="screen_set_keep_on">
|
<method name="screen_set_keep_on">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<param index="0" name="enable" type="bool" />
|
<param index="0" name="enable" type="bool" />
|
||||||
|
@ -6038,14 +6038,7 @@ EditorNode::EditorNode() {
|
|||||||
Input *id = Input::get_singleton();
|
Input *id = Input::get_singleton();
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
bool found_touchscreen = false;
|
if (!DisplayServer::get_singleton()->is_touchscreen_available() && Input::get_singleton()) {
|
||||||
for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
|
|
||||||
if (DisplayServer::get_singleton()->screen_is_touchscreen(i)) {
|
|
||||||
found_touchscreen = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found_touchscreen && Input::get_singleton()) {
|
|
||||||
// Only if no touchscreen ui hint, disable emulation just in case.
|
// Only if no touchscreen ui hint, disable emulation just in case.
|
||||||
id->set_emulate_touch_from_mouse(false);
|
id->set_emulate_touch_from_mouse(false);
|
||||||
}
|
}
|
||||||
|
@ -8420,7 +8420,7 @@ Node3DEditor::Node3DEditor() {
|
|||||||
EDITOR_DEF("editors/3d/manipulator_gizmo_opacity", 0.9);
|
EDITOR_DEF("editors/3d/manipulator_gizmo_opacity", 0.9);
|
||||||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::FLOAT, "editors/3d/manipulator_gizmo_opacity", PROPERTY_HINT_RANGE, "0,1,0.01"));
|
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::FLOAT, "editors/3d/manipulator_gizmo_opacity", PROPERTY_HINT_RANGE, "0,1,0.01"));
|
||||||
EDITOR_DEF_RST("editors/3d/navigation/show_viewport_rotation_gizmo", true);
|
EDITOR_DEF_RST("editors/3d/navigation/show_viewport_rotation_gizmo", true);
|
||||||
EDITOR_DEF_RST("editors/3d/navigation/show_viewport_navigation_gizmo", DisplayServer::get_singleton()->screen_is_touchscreen());
|
EDITOR_DEF_RST("editors/3d/navigation/show_viewport_navigation_gizmo", DisplayServer::get_singleton()->is_touchscreen_available());
|
||||||
|
|
||||||
current_hover_gizmo_handle = -1;
|
current_hover_gizmo_handle = -1;
|
||||||
current_hover_gizmo_handle_secondary = false;
|
current_hover_gizmo_handle_secondary = false;
|
||||||
|
@ -2233,13 +2233,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
|
|||||||
|
|
||||||
if (bool(GLOBAL_DEF("input_devices/pointing/emulate_touch_from_mouse", false)) &&
|
if (bool(GLOBAL_DEF("input_devices/pointing/emulate_touch_from_mouse", false)) &&
|
||||||
!(editor || project_manager)) {
|
!(editor || project_manager)) {
|
||||||
bool found_touchscreen = false;
|
if (!DisplayServer::get_singleton()->is_touchscreen_available()) {
|
||||||
for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
|
|
||||||
if (DisplayServer::get_singleton()->screen_is_touchscreen(i)) {
|
|
||||||
found_touchscreen = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found_touchscreen) {
|
|
||||||
//only if no touchscreen ui hint, set emulation
|
//only if no touchscreen ui hint, set emulation
|
||||||
id->set_emulate_touch_from_mouse(true);
|
id->set_emulate_touch_from_mouse(true);
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ float DisplayServerAndroid::screen_get_refresh_rate(int p_screen) const {
|
|||||||
return godot_io_java->get_screen_refresh_rate(SCREEN_REFRESH_RATE_FALLBACK);
|
return godot_io_java->get_screen_refresh_rate(SCREEN_REFRESH_RATE_FALLBACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DisplayServerAndroid::screen_is_touchscreen(int p_screen) const {
|
bool DisplayServerAndroid::is_touchscreen_available() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ public:
|
|||||||
virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||||
virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||||
virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
||||||
virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
virtual bool is_touchscreen_available() const override;
|
||||||
|
|
||||||
virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1) override;
|
virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1) override;
|
||||||
virtual void virtual_keyboard_hide() override;
|
virtual void virtual_keyboard_hide() override;
|
||||||
|
@ -199,7 +199,7 @@ public:
|
|||||||
virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override;
|
virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override;
|
||||||
virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override;
|
virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override;
|
||||||
|
|
||||||
virtual bool screen_is_touchscreen(int p_screen) const override;
|
virtual bool is_touchscreen_available() const override;
|
||||||
|
|
||||||
virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_length, int p_cursor_start, int p_cursor_end) override;
|
virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_length, int p_cursor_start, int p_cursor_end) override;
|
||||||
virtual void virtual_keyboard_hide() override;
|
virtual void virtual_keyboard_hide() override;
|
||||||
|
@ -581,7 +581,7 @@ bool DisplayServerIOS::can_any_window_draw() const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DisplayServerIOS::screen_is_touchscreen(int p_screen) const {
|
bool DisplayServerIOS::is_touchscreen_available() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,8 +579,8 @@ void DisplayServerWeb::touch_callback(int p_type, int p_count) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DisplayServerWeb::screen_is_touchscreen(int p_screen) const {
|
bool DisplayServerWeb::is_touchscreen_available() const {
|
||||||
return godot_js_display_touchscreen_is_available();
|
return godot_js_display_touchscreen_is_available() || (Input::get_singleton() && Input::get_singleton()->is_emulating_touch_from_mouse());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Virtual Keyboard
|
// Virtual Keyboard
|
||||||
|
@ -143,7 +143,7 @@ public:
|
|||||||
virtual Point2i mouse_get_position() const override;
|
virtual Point2i mouse_get_position() const override;
|
||||||
|
|
||||||
// touch
|
// touch
|
||||||
virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
|
virtual bool is_touchscreen_available() const override;
|
||||||
|
|
||||||
// clipboard
|
// clipboard
|
||||||
virtual void clipboard_set(const String &p_text) override;
|
virtual void clipboard_set(const String &p_text) override;
|
||||||
|
@ -100,7 +100,7 @@ void TouchScreenButton::_notification(int p_what) {
|
|||||||
if (!is_inside_tree()) {
|
if (!is_inside_tree()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
|
if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->is_touchscreen_available() && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ void TouchScreenButton::_notification(int p_what) {
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_ENTER_TREE: {
|
case NOTIFICATION_ENTER_TREE: {
|
||||||
if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
|
if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->is_touchscreen_available() && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
queue_redraw();
|
queue_redraw();
|
||||||
|
@ -550,7 +550,7 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
|
|||||||
drag_node_accum = Vector2();
|
drag_node_accum = Vector2();
|
||||||
last_drag_node_accum = Vector2();
|
last_drag_node_accum = Vector2();
|
||||||
drag_node_from = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
|
drag_node_from = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
|
||||||
drag_node_touching = DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id()));
|
drag_node_touching = DisplayServer::get_singleton()->is_touchscreen_available();
|
||||||
drag_node_touching_deaccel = false;
|
drag_node_touching_deaccel = false;
|
||||||
time_since_motion = 0;
|
time_since_motion = 0;
|
||||||
|
|
||||||
|
@ -164,8 +164,8 @@ void ScrollContainer::gui_input(const Ref<InputEvent> &p_gui_input) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool screen_is_touchscreen = DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id()));
|
bool is_touchscreen_available = DisplayServer::get_singleton()->is_touchscreen_available();
|
||||||
if (!screen_is_touchscreen) {
|
if (!is_touchscreen_available) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3671,7 +3671,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
|
|||||||
drag_accum = 0;
|
drag_accum = 0;
|
||||||
//last_drag_accum=0;
|
//last_drag_accum=0;
|
||||||
drag_from = v_scroll->get_value();
|
drag_from = v_scroll->get_value();
|
||||||
drag_touching = DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id()));
|
drag_touching = DisplayServer::get_singleton()->is_touchscreen_available();
|
||||||
drag_touching_deaccel = false;
|
drag_touching_deaccel = false;
|
||||||
if (drag_touching) {
|
if (drag_touching) {
|
||||||
set_physics_process_internal(true);
|
set_physics_process_internal(true);
|
||||||
|
@ -367,8 +367,7 @@ float DisplayServer::screen_get_scale(int p_screen) const {
|
|||||||
return 1.0f;
|
return 1.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool DisplayServer::screen_is_touchscreen(int p_screen) const {
|
bool DisplayServer::is_touchscreen_available() const {
|
||||||
//return false;
|
|
||||||
return Input::get_singleton() && Input::get_singleton()->is_emulating_touch_from_mouse();
|
return Input::get_singleton() && Input::get_singleton()->is_emulating_touch_from_mouse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,7 +617,7 @@ void DisplayServer::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("screen_get_usable_rect", "screen"), &DisplayServer::screen_get_usable_rect, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
ClassDB::bind_method(D_METHOD("screen_get_usable_rect", "screen"), &DisplayServer::screen_get_usable_rect, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
||||||
ClassDB::bind_method(D_METHOD("screen_get_dpi", "screen"), &DisplayServer::screen_get_dpi, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
ClassDB::bind_method(D_METHOD("screen_get_dpi", "screen"), &DisplayServer::screen_get_dpi, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
||||||
ClassDB::bind_method(D_METHOD("screen_get_scale", "screen"), &DisplayServer::screen_get_scale, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
ClassDB::bind_method(D_METHOD("screen_get_scale", "screen"), &DisplayServer::screen_get_scale, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
||||||
ClassDB::bind_method(D_METHOD("screen_is_touchscreen", "screen"), &DisplayServer::screen_is_touchscreen, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
ClassDB::bind_method(D_METHOD("is_touchscreen_available"), &DisplayServer::is_touchscreen_available, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
||||||
ClassDB::bind_method(D_METHOD("screen_get_max_scale"), &DisplayServer::screen_get_max_scale);
|
ClassDB::bind_method(D_METHOD("screen_get_max_scale"), &DisplayServer::screen_get_max_scale);
|
||||||
ClassDB::bind_method(D_METHOD("screen_get_refresh_rate", "screen"), &DisplayServer::screen_get_refresh_rate, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
ClassDB::bind_method(D_METHOD("screen_get_refresh_rate", "screen"), &DisplayServer::screen_get_refresh_rate, DEFVAL(SCREEN_OF_MAIN_WINDOW));
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ public:
|
|||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
|
virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0;
|
||||||
virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const;
|
virtual bool is_touchscreen_available() const;
|
||||||
|
|
||||||
// Keep the ScreenOrientation enum values in sync with the `display/window/handheld/orientation`
|
// Keep the ScreenOrientation enum values in sync with the `display/window/handheld/orientation`
|
||||||
// project setting hint.
|
// project setting hint.
|
||||||
|
Loading…
Reference in New Issue
Block a user