Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

DisplayServer

继承: Object

用于低阶窗口管理的服务器接口。

描述

所有与窗口管理相关的内容都由 DisplayServer(显示服务器)处理。因为一个操作系统可能支持多个显示服务器,所以与 OS 是分开的。

无头模式:如果使用 --headless 命令行参数启动引擎,就会禁用所有渲染和窗口管理功能。此时 DisplayServer 的大多数函数都会返回虚设值。

方法

String

clipboard_get() const

Image

clipboard_get_image() const

String

clipboard_get_primary() const

bool

clipboard_has() const

bool

clipboard_has_image() const

void

clipboard_set(clipboard: String)

void

clipboard_set_primary(clipboard_primary: String)

int

create_status_indicator(icon: Texture2D, tooltip: String, callback: Callable)

CursorShape

cursor_get_shape() const

void

cursor_set_custom_image(cursor: Resource, shape: CursorShape = 0, hotspot: Vector2 = Vector2(0, 0))

void

cursor_set_shape(shape: CursorShape)

void

delete_status_indicator(id: int)

Error

dialog_input_text(title: String, description: String, existing_text: String, callback: Callable)

Error

dialog_show(title: String, description: String, buttons: PackedStringArray, callback: Callable)

void

enable_for_stealing_focus(process_id: int)

Error

file_dialog_show(title: String, current_directory: String, filename: String, show_hidden: bool, mode: FileDialogMode, filters: PackedStringArray, callback: Callable)

Error

file_dialog_with_options_show(title: String, current_directory: String, root: String, filename: String, show_hidden: bool, mode: FileDialogMode, filters: PackedStringArray, options: Array[Dictionary], callback: Callable)

void

force_process_and_drop_events()

Color

get_accent_color() const

Color

get_base_color() const

Array[Rect2]

get_display_cutouts() const

Rect2i

get_display_safe_area() const

int

get_keyboard_focus_screen() const

String

get_name() const

int

get_primary_screen() const

int

get_screen_count() const

int

get_screen_from_rect(rect: Rect2) const

bool

get_swap_cancel_ok()

int

get_window_at_screen_position(position: Vector2i) const

PackedInt32Array

get_window_list() const

int

global_menu_add_check_item(menu_root: String, label: String, callback: Callable = Callable(), key_callback: Callable = Callable(), tag: Variant = null, accelerator: Key = 0, index: int = -1)

int

global_menu_add_icon_check_item(menu_root: String, icon: Texture2D, label: String, callback: Callable = Callable(), key_callback: Callable = Callable(), tag: Variant = null, accelerator: Key = 0, index: int = -1)

int

global_menu_add_icon_item(menu_root: String, icon: Texture2D, label: String, callback: Callable = Callable(), key_callback: Callable = Callable(), tag: Variant = null, accelerator: Key = 0, index: int = -1)

int

global_menu_add_icon_radio_check_item(menu_root: String, icon: Texture2D, label: String, callback: Callable = Callable(), key_callback: Callable = Callable(), tag: Variant = null, accelerator: Key = 0, index: int = -1)

int

global_menu_add_item(menu_root: String, label: String, callback: Callable = Callable(), key_callback: Callable = Callable(), tag: Variant = null, accelerator: Key = 0, index: int = -1)

int

global_menu_add_multistate_item(menu_root: String, label: String, max_states: int, default_state: int, callback: Callable = Callable(), key_callback: Callable = Callable(), tag: Variant = null, accelerator: Key = 0, index: int = -1)

int

global_menu_add_radio_check_item(menu_root: String, label: String, callback: Callable = Callable(), key_callback: Callable = Callable(), tag: Variant = null, accelerator: Key = 0, index: int = -1)

int

global_menu_add_separator(menu_root: String, index: int = -1)

int

global_menu_add_submenu_item(menu_root: String, label: String, submenu: String, index: int = -1)

void

global_menu_clear(menu_root: String)

Key

global_menu_get_item_accelerator(menu_root: String, idx: int) const

Callable

global_menu_get_item_callback(menu_root: String, idx: int) const

int

global_menu_get_item_count(menu_root: String) const

Texture2D

global_menu_get_item_icon(menu_root: String, idx: int) const

int

global_menu_get_item_indentation_level(menu_root: String, idx: int) const

int

global_menu_get_item_index_from_tag(menu_root: String, tag: Variant) const

int

global_menu_get_item_index_from_text(menu_root: String, text: String) const

Callable

global_menu_get_item_key_callback(menu_root: String, idx: int) const

int

global_menu_get_item_max_states(menu_root: String, idx: int) const

int

global_menu_get_item_state(menu_root: String, idx: int) const

String

global_menu_get_item_submenu(menu_root: String, idx: int) const

Variant

global_menu_get_item_tag(menu_root: String, idx: int) const

String

global_menu_get_item_text(menu_root: String, idx: int) const

String

global_menu_get_item_tooltip(menu_root: String, idx: int) const

Dictionary

global_menu_get_system_menu_roots() const

bool

global_menu_is_item_checkable(menu_root: String, idx: int) const

bool

global_menu_is_item_checked(menu_root: String, idx: int) const

bool

global_menu_is_item_disabled(menu_root: String, idx: int) const

bool

global_menu_is_item_hidden(menu_root: String, idx: int) const

bool

global_menu_is_item_radio_checkable(menu_root: String, idx: int) const

void

global_menu_remove_item(menu_root: String, idx: int)

void

global_menu_set_item_accelerator(menu_root: String, idx: int, keycode: Key)

void

global_menu_set_item_callback(menu_root: String, idx: int, callback: Callable)

void

global_menu_set_item_checkable(menu_root: String, idx: int, checkable: bool)

void

global_menu_set_item_checked(menu_root: String, idx: int, checked: bool)

void

global_menu_set_item_disabled(menu_root: String, idx: int, disabled: bool)

void

global_menu_set_item_hidden(menu_root: String, idx: int, hidden: bool)

void

global_menu_set_item_hover_callbacks(menu_root: String, idx: int, callback: Callable)

void

global_menu_set_item_icon(menu_root: String, idx: int, icon: Texture2D)

void

global_menu_set_item_indentation_level(menu_root: String, idx: int, level: int)

void

global_menu_set_item_key_callback(menu_root: String, idx: int, key_callback: Callable)

void

global_menu_set_item_max_states(menu_root: String, idx: int, max_states: int)

void

global_menu_set_item_radio_checkable(menu_root: String, idx: int, checkable: bool)

void

global_menu_set_item_state(menu_root: String, idx: int, state: int)

void

global_menu_set_item_submenu(menu_root: String, idx: int, submenu: String)

void

global_menu_set_item_tag(menu_root: String, idx: int, tag: Variant)

void

global_menu_set_item_text(menu_root: String, idx: int, text: String)

void

global_menu_set_item_tooltip(menu_root: String, idx: int, tooltip: String)

void

global_menu_set_popup_callbacks(menu_root: String, open_callback: Callable, close_callback: Callable)

bool

has_additional_outputs() const

bool

has_feature(feature: Feature) const

void

help_set_search_callbacks(search_callback: Callable, action_callback: Callable)

Vector2i

ime_get_selection() const

String

ime_get_text() const

bool

is_dark_mode() const

bool

is_dark_mode_supported() const

bool

is_touchscreen_available() const

bool

is_window_transparency_available() const

int

keyboard_get_current_layout() const

Key

keyboard_get_keycode_from_physical(keycode: Key) const

Key

keyboard_get_label_from_physical(keycode: Key) const

int

keyboard_get_layout_count() const

String

keyboard_get_layout_language(index: int) const

String

keyboard_get_layout_name(index: int) const

void

keyboard_set_current_layout(index: int)

BitField[MouseButtonMask]

mouse_get_button_state() const

MouseMode

mouse_get_mode() const

Vector2i

mouse_get_position() const

void

mouse_set_mode(mouse_mode: