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 ( String clipboard )

void

clipboard_set_primary ( String clipboard_primary )

CursorShape

cursor_get_shape ( ) const

void

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

void

cursor_set_shape ( CursorShape shape )

Error

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

Error

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

void

enable_for_stealing_focus ( int process_id )

Error

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

void

force_process_and_drop_events ( )

Color

get_accent_color ( ) const

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 ( Rect2 rect ) const

bool

get_swap_cancel_ok ( )

int

get_window_at_screen_position ( Vector2i position ) const

PackedInt32Array

get_window_list ( ) const

int

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

int

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

int

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

int

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

int

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

int

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

int

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

int

global_menu_add_separator ( String menu_root, int index=-1 )

int

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

void

global_menu_clear ( String menu_root )

Key

global_menu_get_item_accelerator ( String menu_root, int idx ) const

Callable

global_menu_get_item_callback ( String menu_root, int idx ) const

int

global_menu_get_item_count ( String menu_root ) const

Texture2D

global_menu_get_item_icon ( String menu_root, int idx ) const

int

global_menu_get_item_indentation_level ( String menu_root, int idx ) const

int

global_menu_get_item_index_from_tag ( String menu_root, Variant tag ) const

int

global_menu_get_item_index_from_text ( String menu_root, String text ) const

Callable

global_menu_get_item_key_callback ( String menu_root, int idx ) const

int

global_menu_get_item_max_states ( String menu_root, int idx ) const

int

global_menu_get_item_state ( String menu_root, int idx ) const

String

global_menu_get_item_submenu ( String menu_root, int idx ) const

Variant

global_menu_get_item_tag ( String menu_root, int idx ) const

String

global_menu_get_item_text ( String menu_root, int idx ) const

String

global_menu_get_item_tooltip ( String menu_root, int idx ) const

bool

global_menu_is_item_checkable ( String menu_root, int idx ) const

bool

global_menu_is_item_checked ( String menu_root, int idx ) const

bool

global_menu_is_item_disabled ( String menu_root, int idx ) const

bool

global_menu_is_item_hidden ( String menu_root, int idx ) const

bool

global_menu_is_item_radio_checkable ( String menu_root, int idx ) const

void

global_menu_remove_item ( String menu_root, int idx )

void

global_menu_set_item_accelerator ( String menu_root, int idx, Key keycode )

void

global_menu_set_item_callback ( String menu_root, int idx, Callable callback )

void

global_menu_set_item_checkable ( String menu_root, int idx, bool checkable )

void

global_menu_set_item_checked ( String menu_root, int idx, bool checked )

void

global_menu_set_item_disabled ( String menu_root, int idx, bool disabled )

void

global_menu_set_item_hidden ( String menu_root, int idx, bool hidden )

void

global_menu_set_item_hover_callbacks ( String menu_root, int idx, Callable callback )

void

global_menu_set_item_icon ( String menu_root, int idx, Texture2D icon )

void

global_menu_set_item_indentation_level ( String menu_root, int idx, int level )

void

global_menu_set_item_key_callback ( String menu_root, int idx, Callable key_callback )

void

global_menu_set_item_max_states ( String menu_root, int idx, int max_states )

void

global_menu_set_item_radio_checkable ( String menu_root, int idx, bool checkable )

void

global_menu_set_item_state ( String menu_root, int idx, int state )

void

global_menu_set_item_submenu ( String menu_root, int idx, String submenu )

void

global_menu_set_item_tag ( String menu_root, int idx, Variant tag )

void

global_menu_set_item_text ( String menu_root, int idx, String text )

void

global_menu_set_item_tooltip ( String menu_root, int idx, String tooltip )

void

global_menu_set_popup_callbacks ( String menu_root, Callable open_callback, Callable close_callback )

bool

has_feature ( Feature feature ) const

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

int

keyboard_get_current_layout ( ) const

Key

keyboard_get_keycode_from_physical ( Key keycode ) const

Key

keyboard_get_label_from_physical ( Key keycode ) const

int

keyboard_get_layout_count ( ) const

String

keyboard_get_layout_language ( int index ) const

String

keyboard_get_layout_name ( int index ) const

void

keyboard_set_current_layout ( int index )

BitField<MouseButtonMask>

mouse_get_button_state ( ) const

MouseMode

mouse_get_mode ( ) const

Vector2i

mouse_get_position ( ) const

void

mouse_set_mode ( MouseMode mouse_mode )

void

process_events ( )

int

screen_get_dpi ( int screen=-1 ) const

Image

screen_get_image ( int screen=-1 ) const

float

screen_get_max_scale ( ) const

ScreenOrientation

screen_get_orientation ( int screen=-1 ) const

Color

screen_get_pixel ( Vector2i position ) const

Vector2i

screen_get_position ( int screen=-1 ) const

float

screen_get_refresh_rate ( int screen=-1 ) const

float

screen_get_scale ( int screen=-1 ) const

Vector2i

screen_get_size ( int screen=-1 ) const

Rect2i

screen_get_usable_rect ( int screen=-1 ) const

bool

screen_is_kept_on ( ) const

void

screen_set_keep_on ( bool enable )

void

screen_set_orientation ( ScreenOrientation orientation, int screen=-1 )

void

set_icon ( Image image )

void

set_native_icon ( String filename )

String

tablet_get_current_driver ( ) const

int

tablet_get_driver_count ( ) const

String

tablet_get_driver_name ( int idx ) const

void

tablet_set_current_driver ( String name )

Dictionary[]

tts_get_voices ( ) const

PackedStringArray

tts_get_voices_for_language ( String language ) const

bool

tts_is_paused ( ) const

bool

tts_is_speaking ( ) const

void

tts_pause ( )

void

tts_resume ( )

void

tts_set_utterance_callback ( TTSUtteranceEvent event, Callable callable )

void

tts_speak ( String text, String voice, int volume=50, float pitch=1.0, float rate=1.0, int utterance_id=0, bool interrupt=false )

void

tts_stop ( )

int

virtual_keyboard_get_height ( ) const

void

virtual_keyboard_hide ( )

void

virtual_keyboard_show ( String existing_text, Rect2 position=Rect2(0, 0, 0, 0), VirtualKeyboardType type=0, int max_length=-1, int cursor_start=-1, int cursor_end=-1 )

void

warp_mouse ( Vector2i position )

bool

window_can_draw ( int window_id=0 ) const

int

window_get_active_popup ( ) const

int

window_get_attached_instance_id ( int window_id=0 ) const

int

window_get_current_screen ( int window_id=0 ) const

bool

window_get_flag ( WindowFlags flag, int window_id=0 ) const

Vector2i

window_get_max_size ( int window_id=0 ) const

Vector2i

window_get_min_size ( int window_id=0 ) const

WindowMode

window_get_mode ( int window_id=0 ) const

int

window_get_native_handle ( HandleType handle_type, int window_id=0 ) const

Rect2i

window_get_popup_safe_rect ( int window ) const

Vector2i

window_get_position ( int window_id=0 ) const

Vector2i

window_get_position_with_decorations ( int window_id=0 ) const

Vector3i

window_get_safe_title_margins ( int window_id=0 ) const

Vector2i

window_get_size ( int window_id=0 ) const

Vector2i

window_get_size_with_decorations ( int window_id=0 ) const

Vector2i

window_get_title_size ( String title, int window_id=0 ) const

VSyncMode

window_get_vsync_mode ( int window_id=0 ) const

bool

window_is_focused ( int window_id=0 ) const

bool

window_is_maximize_allowed ( int window_id=0 ) const

bool

window_maximize_on_title_dbl_click ( ) const

bool

window_minimize_on_title_dbl_click ( ) const

void

window_move_to_foreground ( int window_id=0 )

void

window_request_attention ( int window_id=0 )

void

window_set_current_screen ( int screen, int window_id=0 )

void

window_set_drop_files_callback ( Callable callback, int window_id=0 )

void

window_set_exclusive ( int window_id, bool exclusive )

void

window_set_flag ( WindowFlags flag, bool enabled, int window_id=0 )

void

window_set_ime_active ( bool active, int window_id=0 )

void

window_set_ime_position ( Vector2i position, int window_id=0 )

void

window_set_input_event_callback ( Callable callback, int window_id=0 )

void

window_set_input_text_callback ( Callable callback, int window_id=0 )

void

window_set_max_size ( Vector2i max_size, int window_id=0 )

void

window_set_min_size ( Vector2i min_size, int window_id=0 )

void

window_set_mode ( WindowMode mode, int window_id=0 )

void

window_set_mouse_passthrough ( PackedVector2Array region, int window_id=0 )

void

window_set_popup_safe_rect ( int window, Rect2i rect )

void

window_set_position ( Vector2i position, int window_id=0 )

void

window_set_rect_changed_callback ( Callable callback, int window_id=0 )

void

window_set_size ( Vector2i size, int window_id=0 )

void

window_set_title ( String title, int window_id=0 )

void

window_set_transient ( int window_id, int parent_window_id )

void

window_set_vsync_mode ( VSyncMode vsync_mode, int window_id=0 )

void

window_set_window_buttons_offset ( Vector2i offset, int window_id=0 )

void

window_set_window_event_callback ( Callable callback, int window_id=0 )


枚举

enum Feature:

Feature FEATURE_GLOBAL_MENU = 0

显示服务器支持全局菜单。能够让应用程序在操作系统的顶部栏显示其菜单项。macOS

Feature FEATURE_SUBWINDOWS = 1

显示服务器支持多窗口,可以移动到主窗口之外。Windows、macOS、Linux(X11)

Feature FEATURE_TOUCHSCREEN = 2

显示服务器支持触屏输入。Windows、Linux(X11)、Android、iOS、Web

Feature FEATURE_MOUSE = 3

显示服务器支持鼠标输入。Windows、macOS、Linux(X11)、Android、Web

Feature FEATURE_MOUSE_WARP = 4

显示服务器支持扭曲鼠标坐标以将鼠标光标限制在一个区域内,但在到达其中一个边缘时循环。Windows, macOS, Linux (X11)

Feature FEATURE_CLIPBOARD = 5

显示服务器支持剪贴板数据的设置和获取。另见 FEATURE_CLIPBOARD_PRIMARYWindows、macOS、Linux(X11)、Android、iOS、Web

Feature FEATURE_VIRTUAL_KEYBOARD = 6

显示服务器支持在请求输入文本但没有物理键盘时弹出虚拟键盘。Android、iOS、Web

Feature FEATURE_CURSOR_SHAPE = 7

显示服务器支持将鼠标光标形状设置为与默认不同。Windows、macOS、Linux(X11)、Android、Web

Feature FEATURE_CUSTOM_CURSOR_SHAPE = 8

显示服务器支持将鼠标光标形状设置为自定义图像。Windows、macOS、Linux(X11)、Web

Feature FEATURE_NATIVE_DIALOG = 9

显示服务器支持使用操作系统的本地界面外观来生成对话框。macOS

Feature FEATURE_IME = 10

显示服务器支持 输入法,它通常用于输入中文、日文和韩文文本。这由操作系统处理,而不是由 Godot 处理。Windows, macOS, Linux (X11)

Feature FEATURE_WINDOW_TRANSPARENCY = 11

显示服务器支持窗口可以使用逐像素透明,以使它们后面的窗口部分或完全可见。Windows, macOS, Linux (X11)

Feature FEATURE_HIDPI = 12

显示服务器支持查询操作系统的显示缩放系数。这允许可靠地执行自动 hiDPI 显示器检测,而不是根据屏幕分辨率和报告的显示器 DPI 进行猜测(由于显示器 EDID 损坏,这可能不可靠)。Windows, macOS

Feature FEATURE_ICON = 13

显示服务器支持改变窗口图标(通常