diff options
Diffstat (limited to 'platform')
| -rw-r--r-- | platform/linuxbsd/freedesktop_portal_desktop.cpp | 6 | ||||
| -rw-r--r-- | platform/linuxbsd/freedesktop_portal_desktop.h | 3 | ||||
| -rw-r--r-- | platform/linuxbsd/x11/display_server_x11.cpp | 4 | ||||
| -rw-r--r-- | platform/macos/display_server_macos.h | 1 | ||||
| -rw-r--r-- | platform/macos/display_server_macos.mm | 53 | ||||
| -rw-r--r-- | platform/macos/export/export_plugin.cpp | 6 | ||||
| -rw-r--r-- | platform/windows/display_server_windows.cpp | 52 | ||||
| -rw-r--r-- | platform/windows/display_server_windows.h | 3 | ||||
| -rw-r--r-- | platform/windows/platform_windows_builders.py | 16 |
9 files changed, 133 insertions, 11 deletions
diff --git a/platform/linuxbsd/freedesktop_portal_desktop.cpp b/platform/linuxbsd/freedesktop_portal_desktop.cpp index 91c14e0e91..e9f55faf7f 100644 --- a/platform/linuxbsd/freedesktop_portal_desktop.cpp +++ b/platform/linuxbsd/freedesktop_portal_desktop.cpp @@ -266,7 +266,7 @@ bool FreeDesktopPortalDesktop::file_chooser_parse_response(DBusMessageIter *p_it return true; } -Error FreeDesktopPortalDesktop::file_dialog_show(const String &p_xid, const String &p_title, const String &p_current_directory, const String &p_filename, DisplayServer::FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) { +Error FreeDesktopPortalDesktop::file_dialog_show(DisplayServer::WindowID p_window_id, const String &p_xid, const String &p_title, const String &p_current_directory, const String &p_filename, DisplayServer::FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) { if (unsupported) { return FAILED; } @@ -277,6 +277,7 @@ Error FreeDesktopPortalDesktop::file_dialog_show(const String &p_xid, const Stri // Open connection and add signal handler. FileDialogData fd; fd.callback = p_callback; + fd.prev_focus = p_window_id; CryptoCore::RandomGenerator rng; ERR_FAIL_COND_V_MSG(rng.init(), FAILED, "Failed to initialize random number generator."); @@ -416,6 +417,9 @@ void FreeDesktopPortalDesktop::_thread_file_dialog_monitor(void *p_ud) { Variant *v_args[2] = { &v_status, &v_files }; fd.callback.call_deferredp((const Variant **)&v_args, 2); } + if (fd.prev_focus != DisplayServer::INVALID_WINDOW_ID) { + callable_mp(DisplayServer::get_singleton(), &DisplayServer::window_move_to_foreground).call_deferred(fd.prev_focus); + } } dbus_message_unref(msg); diff --git a/platform/linuxbsd/freedesktop_portal_desktop.h b/platform/linuxbsd/freedesktop_portal_desktop.h index a9b83b3844..6ffb3e7b04 100644 --- a/platform/linuxbsd/freedesktop_portal_desktop.h +++ b/platform/linuxbsd/freedesktop_portal_desktop.h @@ -56,6 +56,7 @@ private: struct FileDialogData { DBusConnection *connection = nullptr; + DisplayServer::WindowID prev_focus = DisplayServer::INVALID_WINDOW_ID; Callable callback; String path; }; @@ -73,7 +74,7 @@ public: bool is_supported() { return !unsupported; } - Error file_dialog_show(const String &p_xid, const String &p_title, const String &p_current_directory, const String &p_filename, DisplayServer::FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback); + Error file_dialog_show(DisplayServer::WindowID p_window_id, const String &p_xid, const String &p_title, const String &p_current_directory, const String &p_filename, DisplayServer::FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback); // Retrieve the system's preferred color scheme. // 0: No preference or unknown. diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 897a6438d2..678ec340c0 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -364,14 +364,14 @@ bool DisplayServerX11::is_dark_mode() const { } Error DisplayServerX11::file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) { - WindowID window_id = _get_focused_window_or_popup(); + WindowID window_id = last_focused_window; if (!windows.has(window_id)) { window_id = MAIN_WINDOW_ID; } String xid = vformat("x11:%x", (uint64_t)windows[window_id].x11_window); - return portal_desktop->file_dialog_show(xid, p_title, p_current_directory, p_filename, p_mode, p_filters, p_callback); + return portal_desktop->file_dialog_show(last_focused_window, xid, p_title, p_current_directory, p_filename, p_mode, p_filters, p_callback); } #endif diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h index c03b4765f8..d89511927e 100644 --- a/platform/macos/display_server_macos.h +++ b/platform/macos/display_server_macos.h @@ -368,6 +368,7 @@ public: virtual void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override; virtual void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) override; + virtual Size2i window_get_title_size(const String &p_title, WindowID p_window) const override; virtual void window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window = MAIN_WINDOW_ID) override; virtual int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const override; diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 56cb4938ec..f984fd9dc5 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -1887,6 +1887,8 @@ Error DisplayServerMacOS::file_dialog_show(const String &p_title, const String & } } + WindowID prev_focus = last_focused_window; + Callable callback = p_callback; // Make a copy for async completion handler. switch (p_mode) { case FILE_DIALOG_MODE_SAVE_FILE: { @@ -1954,6 +1956,9 @@ Error DisplayServerMacOS::file_dialog_show(const String &p_title, const String & callback.callp((const Variant **)&v_args, 2, ret, ce); } } + if (prev_focus != INVALID_WINDOW_ID) { + callable_mp(DisplayServer::get_singleton(), &DisplayServer::window_move_to_foreground).call_deferred(prev_focus); + } }]; } break; case FILE_DIALOG_MODE_OPEN_ANY: @@ -2033,6 +2038,9 @@ Error DisplayServerMacOS::file_dialog_show(const String &p_title, const String & callback.callp((const Variant **)&v_args, 2, ret, ce); } } + if (prev_focus != INVALID_WINDOW_ID) { + callable_mp(DisplayServer::get_singleton(), &DisplayServer::window_move_to_foreground).call_deferred(prev_focus); + } }]; } break; } @@ -2626,6 +2634,47 @@ void DisplayServerMacOS::window_set_title(const String &p_title, WindowID p_wind [wd.window_object setTitle:[NSString stringWithUTF8String:p_title.utf8().get_data()]]; } +Size2i DisplayServerMacOS::window_get_title_size(const String &p_title, WindowID p_window) const { + _THREAD_SAFE_METHOD_ + + Size2i size; + ERR_FAIL_COND_V(!windows.has(p_window), size); + + const WindowData &wd = windows[p_window]; + if (wd.fullscreen || wd.borderless) { + return size; + } + if ([wd.window_object respondsToSelector:@selector(isMiniaturized)]) { + if ([wd.window_object isMiniaturized]) { + return size; + } + } + + float scale = screen_get_max_scale(); + + if (wd.window_button_view) { + size.x = ([wd.window_button_view getOffset].x + [wd.window_button_view frame].size.width); + size.y = ([wd.window_button_view getOffset].y + [wd.window_button_view frame].size.height); + } else { + NSButton *cb = [wd.window_object standardWindowButton:NSWindowCloseButton]; + NSButton *mb = [wd.window_object standardWindowButton:NSWindowMiniaturizeButton]; + float cb_frame = NSMinX([cb frame]); + float mb_frame = NSMinX([mb frame]); + bool is_rtl = ([wd.window_object windowTitlebarLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft); + + float window_buttons_spacing = (is_rtl) ? (cb_frame - mb_frame) : (mb_frame - cb_frame); + size.x = window_buttons_spacing * 4; + size.y = [cb frame].origin.y + [cb frame].size.height; + } + + NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSFont titleBarFontOfSize:0], NSFontAttributeName, nil]; + NSSize text_size = [[[NSAttributedString alloc] initWithString:[NSString stringWithUTF8String:p_title.utf8().get_data()] attributes:attributes] size]; + size.x += text_size.width; + size.y = MAX(size.y, text_size.height); + + return size * scale; +} + void DisplayServerMacOS::window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window) { _THREAD_SAFE_METHOD_ @@ -3176,7 +3225,9 @@ void DisplayServerMacOS::window_set_flag(WindowFlags p_flag, bool p_enabled, Win } break; case WINDOW_FLAG_BORDERLESS: { // OrderOut prevents a lose focus bug with the window. + bool was_visible = false; if ([wd.window_object isVisible]) { + was_visible = true; [wd.window_object orderOut:nil]; } wd.borderless = p_enabled; @@ -3191,7 +3242,7 @@ void DisplayServerMacOS::window_set_flag(WindowFlags p_flag, bool p_enabled, Win [wd.window_object setFrame:frameRect display:NO]; } _update_window_style(wd); - if ([wd.window_object isVisible]) { + if (was_visible || [wd.window_object isVisible]) { if ([wd.window_object isMiniaturized]) { return; } else if (wd.no_focus) { diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp index 639a7699ee..804028053d 100644 --- a/platform/macos/export/export_plugin.cpp +++ b/platform/macos/export/export_plugin.cpp @@ -1047,6 +1047,8 @@ Error EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_pre args.push_back("--p12-password"); args.push_back(certificate_pass); } + args.push_back("--code-signature-flags"); + args.push_back("runtime"); args.push_back("-v"); /* provide some more feedback */ @@ -1139,7 +1141,6 @@ Error EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_pre Error EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_should_error_on_non_code) { -#ifdef MACOS_ENABLED static Vector<String> extensions_to_sign; if (extensions_to_sign.is_empty()) { @@ -1186,7 +1187,6 @@ Error EditorExportPlatformMacOS::_code_sign_directory(const Ref<EditorExportPres current_file = dir_access->get_next(); } -#endif return OK; } @@ -1225,7 +1225,7 @@ Error EditorExportPlatformMacOS::_copy_and_sign_files(Ref<DirAccess> &dir_access if (extensions_to_sign.find(p_in_app_path.get_extension()) > -1) { err = _code_sign(p_preset, p_in_app_path, p_ent_path, false); } - if (is_executable(p_in_app_path)) { + if (dir_access->file_exists(p_in_app_path) && is_executable(p_in_app_path)) { // chmod with 0755 if the file is executable. FileAccess::set_unix_permissions(p_in_app_path, 0755); } diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index c7b7f6a65d..ed52c5eb92 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -240,6 +240,8 @@ Error DisplayServerWindows::file_dialog_show(const String &p_title, const String filters.push_back({ (LPCWSTR)filter_names[i].ptr(), (LPCWSTR)filter_exts[i].ptr() }); } + WindowID prev_focus = last_focused_window; + HRESULT hr = S_OK; IFileDialog *pfd = nullptr; if (p_mode == FILE_DIALOG_MODE_SAVE_FILE) { @@ -340,6 +342,9 @@ Error DisplayServerWindows::file_dialog_show(const String &p_title, const String } } pfd->Release(); + if (prev_focus != INVALID_WINDOW_ID) { + callable_mp(DisplayServer::get_singleton(), &DisplayServer::window_move_to_foreground).call_deferred(prev_focus); + } return OK; } else { @@ -1191,6 +1196,51 @@ void DisplayServerWindows::window_set_title(const String &p_title, WindowID p_wi SetWindowTextW(windows[p_window].hWnd, (LPCWSTR)(p_title.utf16().get_data())); } +Size2i DisplayServerWindows::window_get_title_size(const String &p_title, WindowID p_window) const { + _THREAD_SAFE_METHOD_ + + Size2i size; + ERR_FAIL_COND_V(!windows.has(p_window), size); + + const WindowData &wd = windows[p_window]; + if (wd.fullscreen || wd.minimized || wd.borderless) { + return size; + } + + HDC hdc = GetDCEx(wd.hWnd, NULL, DCX_WINDOW); + if (hdc) { + Char16String s = p_title.utf16(); + SIZE text_size; + if (GetTextExtentPoint32W(hdc, (LPCWSTR)(s.get_data()), s.length(), &text_size)) { + size.x = text_size.cx; + size.y = text_size.cy; + } + + ReleaseDC(wd.hWnd, hdc); + } + RECT rect; + if (DwmGetWindowAttribute(wd.hWnd, DWMWA_CAPTION_BUTTON_BOUNDS, &rect, sizeof(RECT)) == S_OK) { + if (rect.right - rect.left > 0) { + ClientToScreen(wd.hWnd, (POINT *)&rect.left); + ClientToScreen(wd.hWnd, (POINT *)&rect.right); + + if (win81p_PhysicalToLogicalPointForPerMonitorDPI) { + win81p_PhysicalToLogicalPointForPerMonitorDPI(0, (POINT *)&rect.left); + win81p_PhysicalToLogicalPointForPerMonitorDPI(0, (POINT *)&rect.right); + } + + size.x += (rect.right - rect.left); + size.y = MAX(size.y, rect.bottom - rect.top); + } + } + if (icon.is_valid()) { + size.x += 32; + } else { + size.x += 16; + } + return size; +} + void DisplayServerWindows::window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window) { _THREAD_SAFE_METHOD_ @@ -4385,6 +4435,7 @@ bool DisplayServerWindows::winink_available = false; GetPointerTypePtr DisplayServerWindows::win8p_GetPointerType = nullptr; GetPointerPenInfoPtr DisplayServerWindows::win8p_GetPointerPenInfo = nullptr; LogicalToPhysicalPointForPerMonitorDPIPtr DisplayServerWindows::win81p_LogicalToPhysicalPointForPerMonitorDPI = nullptr; +PhysicalToLogicalPointForPerMonitorDPIPtr DisplayServerWindows::win81p_PhysicalToLogicalPointForPerMonitorDPI = nullptr; typedef enum _SHC_PROCESS_DPI_AWARENESS { SHC_PROCESS_DPI_UNAWARE = 0, @@ -4522,6 +4573,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win win8p_GetPointerType = (GetPointerTypePtr)GetProcAddress(user32_lib, "GetPointerType"); win8p_GetPointerPenInfo = (GetPointerPenInfoPtr)GetProcAddress(user32_lib, "GetPointerPenInfo"); win81p_LogicalToPhysicalPointForPerMonitorDPI = (LogicalToPhysicalPointForPerMonitorDPIPtr)GetProcAddress(user32_lib, "LogicalToPhysicalPointForPerMonitorDPI"); + win81p_PhysicalToLogicalPointForPerMonitorDPI = (PhysicalToLogicalPointForPerMonitorDPIPtr)GetProcAddress(user32_lib, "PhysicalToLogicalPointForPerMonitorDPI"); winink_available = win8p_GetPointerType && win8p_GetPointerPenInfo; } diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h index 28f2f7e6ff..48c8c20280 100644 --- a/platform/windows/display_server_windows.h +++ b/platform/windows/display_server_windows.h @@ -262,6 +262,7 @@ typedef struct tagPOINTER_PEN_INFO { typedef BOOL(WINAPI *GetPointerTypePtr)(uint32_t p_id, POINTER_INPUT_TYPE *p_type); typedef BOOL(WINAPI *GetPointerPenInfoPtr)(uint32_t p_id, POINTER_PEN_INFO *p_pen_info); typedef BOOL(WINAPI *LogicalToPhysicalPointForPerMonitorDPIPtr)(HWND hwnd, LPPOINT lpPoint); +typedef BOOL(WINAPI *PhysicalToLogicalPointForPerMonitorDPIPtr)(HWND hwnd, LPPOINT lpPoint); typedef struct { BYTE bWidth; // Width, in pixels, of the image @@ -309,6 +310,7 @@ class DisplayServerWindows : public DisplayServer { // DPI conversion API static LogicalToPhysicalPointForPerMonitorDPIPtr win81p_LogicalToPhysicalPointForPerMonitorDPI; + static PhysicalToLogicalPointForPerMonitorDPIPtr win81p_PhysicalToLogicalPointForPerMonitorDPI; void _update_tablet_ctx(const String &p_old_driver, const String &p_new_driver); String tablet_driver; @@ -569,6 +571,7 @@ public: virtual void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override; virtual void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) override; + virtual Size2i window_get_title_size(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window = MAIN_WINDOW_ID) override; virtual int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const override; diff --git a/platform/windows/platform_windows_builders.py b/platform/windows/platform_windows_builders.py index b522a75a9c..51652fa814 100644 --- a/platform/windows/platform_windows_builders.py +++ b/platform/windows/platform_windows_builders.py @@ -5,14 +5,24 @@ All such functions are invoked in a subprocess on Windows to prevent build flaki """ import os from detect import get_mingw_bin_prefix +from detect import try_cmd from platform_methods import subprocess_main def make_debug_mingw(target, source, env): mingw_bin_prefix = get_mingw_bin_prefix(env["mingw_prefix"], env["arch"]) - os.system(mingw_bin_prefix + "objcopy --only-keep-debug {0} {0}.debugsymbols".format(target[0])) - os.system(mingw_bin_prefix + "strip --strip-debug --strip-unneeded {0}".format(target[0])) - os.system(mingw_bin_prefix + "objcopy --add-gnu-debuglink={0}.debugsymbols {0}".format(target[0])) + if try_cmd("objcopy --version", env["mingw_prefix"], env["arch"]): + os.system(mingw_bin_prefix + "objcopy --only-keep-debug {0} {0}.debugsymbols".format(target[0])) + else: + os.system("objcopy --only-keep-debug {0} {0}.debugsymbols".format(target[0])) + if try_cmd("strip --version", env["mingw_prefix"], env["arch"]): + os.system(mingw_bin_prefix + "strip --strip-debug --strip-unneeded {0}".format(target[0])) + else: + os.system("strip --strip-debug --strip-unneeded {0}".format(target[0])) + if try_cmd("objcopy --version", env["mingw_prefix"], env["arch"]): + os.system(mingw_bin_prefix + "objcopy --add-gnu-debuglink={0}.debugsymbols {0}".format(target[0])) + else: + os.system("objcopy --add-gnu-debuglink={0}.debugsymbols {0}".format(target[0])) if __name__ == "__main__": |
