Fix clipboard relying on focused window

(cherry picked from commit 942f8b9858)
This commit is contained in:
RedMser 2023-04-07 17:44:36 +02:00 committed by Yuri Sizov
parent b17f0f593e
commit f645bbaffb
1 changed files with 6 additions and 6 deletions

View File

@ -264,15 +264,15 @@ BitField<MouseButtonMask> DisplayServerWindows::mouse_get_button_state() const {
void DisplayServerWindows::clipboard_set(const String &p_text) { void DisplayServerWindows::clipboard_set(const String &p_text) {
_THREAD_SAFE_METHOD_ _THREAD_SAFE_METHOD_
if (!windows.has(last_focused_window)) { if (!windows.has(MAIN_WINDOW_ID)) {
return; // No focused window? return;
} }
// Convert LF line endings to CRLF in clipboard content. // Convert LF line endings to CRLF in clipboard content.
// Otherwise, line endings won't be visible when pasted in other software. // Otherwise, line endings won't be visible when pasted in other software.
String text = p_text.replace("\r\n", "\n").replace("\n", "\r\n"); // Avoid \r\r\n. String text = p_text.replace("\r\n", "\n").replace("\n", "\r\n"); // Avoid \r\r\n.
if (!OpenClipboard(windows[last_focused_window].hWnd)) { if (!OpenClipboard(windows[MAIN_WINDOW_ID].hWnd)) {
ERR_FAIL_MSG("Unable to open clipboard."); ERR_FAIL_MSG("Unable to open clipboard.");
} }
EmptyClipboard(); EmptyClipboard();
@ -305,12 +305,12 @@ void DisplayServerWindows::clipboard_set(const String &p_text) {
String DisplayServerWindows::clipboard_get() const { String DisplayServerWindows::clipboard_get() const {
_THREAD_SAFE_METHOD_ _THREAD_SAFE_METHOD_
if (!windows.has(last_focused_window)) { if (!windows.has(MAIN_WINDOW_ID)) {
return String(); // No focused window? return String();
} }
String ret; String ret;
if (!OpenClipboard(windows[last_focused_window].hWnd)) { if (!OpenClipboard(windows[MAIN_WINDOW_ID].hWnd)) {
ERR_FAIL_V_MSG("", "Unable to open clipboard."); ERR_FAIL_V_MSG("", "Unable to open clipboard.");
} }