video: set error code when SetWindowPosition fails

main
Anonymous Maarten 2023-04-27 02:16:12 +02:00 committed by Anonymous Maarten
parent 52c19bd21b
commit c810e5f63d
21 changed files with 67 additions and 41 deletions

View File

@ -233,7 +233,7 @@ struct SDL_VideoDevice
int (*CreateSDLWindowFrom)(_THIS, SDL_Window *window, const void *data);
void (*SetWindowTitle)(_THIS, SDL_Window *window);
int (*SetWindowIcon)(_THIS, SDL_Window *window, SDL_Surface *icon);
void (*SetWindowPosition)(_THIS, SDL_Window *window);
int (*SetWindowPosition)(_THIS, SDL_Window *window);
void (*SetWindowSize)(_THIS, SDL_Window *window);
void (*SetWindowMinimumSize)(_THIS, SDL_Window *window);
void (*SetWindowMaximumSize)(_THIS, SDL_Window *window);

View File

@ -2365,7 +2365,9 @@ int SDL_SetWindowPosition(SDL_Window *window, int x, int y)
}
SDL_zero(bounds);
SDL_GetDisplayBounds(displayID, &bounds);
if (SDL_GetDisplayBounds(displayID, &bounds) < 0) {
return -1;
}
if (SDL_WINDOWPOS_ISCENTERED(x)) {
x = bounds.x + (bounds.w - window->windowed.w) / 2;
}
@ -2387,7 +2389,7 @@ int SDL_SetWindowPosition(SDL_Window *window, int x, int y)
if (displayID != original_displayID) {
/* Set the new target display and update the fullscreen mode */
window->current_fullscreen_mode.displayID = displayID;
SDL_UpdateFullscreenMode(window, SDL_TRUE);
return SDL_UpdateFullscreenMode(window, SDL_TRUE);
}
}
} else {
@ -2396,10 +2398,10 @@ int SDL_SetWindowPosition(SDL_Window *window, int x, int y)
window->last_displayID = SDL_GetDisplayForWindow(window);
if (_this->SetWindowPosition) {
_this->SetWindowPosition(_this, window);
return _this->SetWindowPosition(_this, window);
}
}
return 0;
return SDL_Unsupported();
}
int SDL_GetWindowPosition(SDL_Window *window, int *x, int *y)

View File

@ -144,7 +144,7 @@ extern int Cocoa_CreateWindowFrom(_THIS, SDL_Window *window,
const void *data);
extern void Cocoa_SetWindowTitle(_THIS, SDL_Window *window);
extern int Cocoa_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon);
extern void Cocoa_SetWindowPosition(_THIS, SDL_Window *window);
extern int Cocoa_SetWindowPosition(_THIS, SDL_Window *window);
extern void Cocoa_SetWindowSize(_THIS, SDL_Window *window);
extern void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window);
extern void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window *window);

View File

@ -1985,7 +1985,7 @@ int Cocoa_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
}
}
void Cocoa_SetWindowPosition(_THIS, SDL_Window *window)
int Cocoa_SetWindowPosition(_THIS, SDL_Window *window)
{
@autoreleasepool {
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->driverdata;
@ -2026,6 +2026,7 @@ void Cocoa_SetWindowPosition(_THIS, SDL_Window *window)
ScheduleContextUpdates(windata);
}
return 0;
}
void Cocoa_SetWindowSize(_THIS, SDL_Window *window)

View File

@ -27,7 +27,7 @@
extern int HAIKU_CreateWindow(_THIS, SDL_Window *window);
extern int HAIKU_CreateWindowFrom(_THIS, SDL_Window *window, const void *data);
extern void HAIKU_SetWindowTitle(_THIS, SDL_Window *window);
extern void HAIKU_SetWindowPosition(_THIS, SDL_Window *window);
extern int HAIKU_SetWindowPosition(_THIS, SDL_Window *window);
extern void HAIKU_SetWindowSize(_THIS, SDL_Window *window);
extern void HAIKU_SetWindowMinimumSize(_THIS, SDL_Window *window);
extern void HAIKU_ShowWindow(_THIS, SDL_Window *window);

View File

@ -1559,8 +1559,9 @@ int KMSDRM_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
void KMSDRM_SetWindowTitle(_THIS, SDL_Window *window)
{
}
void KMSDRM_SetWindowPosition(_THIS, SDL_Window *window)
int KMSDRM_SetWindowPosition(_THIS, SDL_Window *window)
{
return SDL_Unsupported();
}
void KMSDRM_SetWindowSize(_THIS, SDL_Window *window)
{

View File

@ -124,7 +124,7 @@ int KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mod
int KMSDRM_CreateWindow(_THIS, SDL_Window *window);
int KMSDRM_CreateWindowFrom(_THIS, SDL_Window *window, const void *data);
void KMSDRM_SetWindowTitle(_THIS, SDL_Window *window);
void KMSDRM_SetWindowPosition(_THIS, SDL_Window *window);
int KMSDRM_SetWindowPosition(_THIS, SDL_Window *window);
void KMSDRM_SetWindowSize(_THIS, SDL_Window *window);
void KMSDRM_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *_display, SDL_bool fullscreen);
void KMSDRM_ShowWindow(_THIS, SDL_Window *window);

View File

@ -215,8 +215,9 @@ int PSP_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
void PSP_SetWindowTitle(_THIS, SDL_Window *window)
{
}
void PSP_SetWindowPosition(_THIS, SDL_Window *window)
int PSP_SetWindowPosition(_THIS, SDL_Window *window)
{
return SDL_Unsupported();
}
void PSP_SetWindowSize(_THIS, SDL_Window *window)
{

View File

@ -52,7 +52,7 @@ int PSP_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
int PSP_CreateWindow(_THIS, SDL_Window *window);
int PSP_CreateWindowFrom(_THIS, SDL_Window *window, const void *data);
void PSP_SetWindowTitle(_THIS, SDL_Window *window);
void PSP_SetWindowPosition(_THIS, SDL_Window *window);
int PSP_SetWindowPosition(_THIS, SDL_Window *window);
void PSP_SetWindowSize(_THIS, SDL_Window *window);
void PSP_ShowWindow(_THIS, SDL_Window *window);
void PSP_HideWindow(_THIS, SDL_Window *window);

View File

@ -349,8 +349,9 @@ int RPI_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
void RPI_SetWindowTitle(_THIS, SDL_Window *window)
{
}
void RPI_SetWindowPosition(_THIS, SDL_Window *window)
int RPI_SetWindowPosition(_THIS, SDL_Window *window)
{
return SDL_Unsupported();
}
void RPI_SetWindowSize(_THIS, SDL_Window *window)
{

View File

@ -66,7 +66,7 @@ int RPI_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
int RPI_CreateWindow(_THIS, SDL_Window *window);
int RPI_CreateWindowFrom(_THIS, SDL_Window *window, const void *data);
void RPI_SetWindowTitle(_THIS, SDL_Window *window);
void RPI_SetWindowPosition(_THIS, SDL_Window *window);
int RPI_SetWindowPosition(_THIS, SDL_Window *window);
void RPI_SetWindowSize(_THIS, SDL_Window *window);
void RPI_ShowWindow(_THIS, SDL_Window *window);
void RPI_HideWindow(_THIS, SDL_Window *window);

View File

@ -303,8 +303,9 @@ int VITA_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
void VITA_SetWindowTitle(_THIS, SDL_Window *window)
{
}
void VITA_SetWindowPosition(_THIS, SDL_Window *window)
int VITA_SetWindowPosition(_THIS, SDL_Window *window)
{
return SDL_Unsupported();
}
void VITA_SetWindowSize(_THIS, SDL_Window *window)
{

View File

@ -65,7 +65,7 @@ int VITA_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
int VITA_CreateWindow(_THIS, SDL_Window *window);
int VITA_CreateWindowFrom(_THIS, SDL_Window *window, const void *data);
void VITA_SetWindowTitle(_THIS, SDL_Window *window);
void VITA_SetWindowPosition(_THIS, SDL_Window *window);
int VITA_SetWindowPosition(_THIS, SDL_Window *window);
void VITA_SetWindowSize(_THIS, SDL_Window *window);
void VITA_ShowWindow(_THIS, SDL_Window *window);
void VITA_HideWindow(_THIS, SDL_Window *window);

View File

@ -314,9 +314,10 @@ void VIVANTE_SetWindowTitle(_THIS, SDL_Window *window)
#endif
}
void VIVANTE_SetWindowPosition(_THIS, SDL_Window *window)
int VIVANTE_SetWindowPosition(_THIS, SDL_Window *window)
{
/* FIXME */
return SDL_Unsupported();
}
void VIVANTE_SetWindowSize(_THIS, SDL_Window *window)

View File

@ -74,7 +74,7 @@ int VIVANTE_GetDisplayModes(_THIS, SDL_VideoDisplay *display);
int VIVANTE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
int VIVANTE_CreateWindow(_THIS, SDL_Window *window);
void VIVANTE_SetWindowTitle(_THIS, SDL_Window *window);
void VIVANTE_SetWindowPosition(_THIS, SDL_Window *window);
int VIVANTE_SetWindowPosition(_THIS, SDL_Window *window);
void VIVANTE_SetWindowSize(_THIS, SDL_Window *window);
void VIVANTE_ShowWindow(_THIS, SDL_Window *window);
void VIVANTE_HideWindow(_THIS, SDL_Window *window);

View File

@ -2124,22 +2124,28 @@ void Wayland_SetWindowMaximumSize(_THIS, SDL_Window *window)
SetMinMaxDimensions(window);
}
void Wayland_SetWindowPosition(_THIS, SDL_Window *window)
int Wayland_SetWindowPosition(_THIS, SDL_Window *window)
{
SDL_WindowData *wind = window->driverdata;
/* Only popup windows can be positioned relative to the parent. */
if (wind->shell_surface_type == WAYLAND_SURFACE_XDG_POPUP && !(window->flags & SDL_WINDOW_HIDDEN) &&
xdg_popup_get_version(wind->shell_surface.xdg.roleobj.popup.popup) >= XDG_POPUP_REPOSITION_SINCE_VERSION) {
int x, y;
if (wind->shell_surface_type == WAYLAND_SURFACE_XDG_POPUP) {
if (xdg_popup_get_version(wind->shell_surface.xdg.roleobj.popup.popup) < XDG_POPUP_REPOSITION_SINCE_VERSION) {
return SDL_Unsupported();
}
if (!(window->flags & SDL_WINDOW_HIDDEN)) {
int x, y;
EnsurePopupPositionIsValid(window);
GetPopupPosition(window, window->x, window->y, &x, &y);
xdg_positioner_set_offset(wind->shell_surface.xdg.roleobj.popup.positioner, x, y);
xdg_popup_reposition(wind->shell_surface.xdg.roleobj.popup.popup,
wind->shell_surface.xdg.roleobj.popup.positioner,
0);
EnsurePopupPositionIsValid(window);
GetPopupPosition(window, window->x, window->y, &x, &y);
xdg_positioner_set_offset(wind->shell_surface.xdg.roleobj.popup.positioner, x, y);
xdg_popup_reposition(wind->shell_surface.xdg.roleobj.popup.popup,
wind->shell_surface.xdg.roleobj.popup.positioner,
0);
}
return 0;
}
return SDL_SetError("wayland cannot position non-popup windows");
}
void Wayland_SetWindowSize(_THIS, SDL_Window *window)

View File

@ -141,7 +141,7 @@ extern void Wayland_RestoreWindow(_THIS, SDL_Window *window);
extern void Wayland_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered);
extern void Wayland_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable);
extern int Wayland_CreateWindow(_THIS, SDL_Window *window);
extern void Wayland_SetWindowPosition(_THIS, SDL_Window *window);
extern int Wayland_SetWindowPosition(_THIS, SDL_Window *window);
extern void Wayland_SetWindowSize(_THIS, SDL_Window *window);
extern void Wayland_SetWindowMinimumSize(_THIS, SDL_Window *window);
extern void Wayland_SetWindowMaximumSize(_THIS, SDL_Window *window);

View File

@ -130,7 +130,7 @@ static DWORD GetWindowStyleEx(SDL_Window *window)
* Returns arguments to pass to SetWindowPos - the window rect, including frame, in Windows coordinates.
* Can be called before we have a HWND.
*/
static void WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x, int *y, int *width, int *height, SDL_bool use_current)
static int WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x, int *y, int *width, int *height, SDL_bool use_current)
{
SDL_VideoData *videodata = SDL_GetVideoDevice() ? SDL_GetVideoDevice()->driverdata : NULL;
RECT rect;
@ -196,10 +196,14 @@ static void WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL
frame_dpi = 96;
}
videodata->AdjustWindowRectExForDpi(&rect, style, menu, 0, frame_dpi);
if (videodata->AdjustWindowRectExForDpi(&rect, style, menu, 0, frame_dpi) == 0) {
return WIN_SetError("AdjustWindowRectExForDpi()");
}
}
} else {
AdjustWindowRectEx(&rect, style, menu, 0);
if (AdjustWindowRectEx(&rect, style, menu, 0) == 0) {
return WIN_SetError("AdjustWindowRectEx()");
}
}
#endif
}
@ -218,6 +222,7 @@ static void WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL
(use_current ? window->h : window->windowed.h),
*x, *y, *width, *height, frame_dpi);
#endif
return 0;
}
static void WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_bool use_current)
@ -236,7 +241,7 @@ static void WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width,
WIN_AdjustWindowRectWithStyle(window, style, menu, x, y, width, height, use_current);
}
void WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags)
int WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags)
{
SDL_Window *child_window;
SDL_WindowData *data = window->driverdata;
@ -244,6 +249,7 @@ void WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags)
HWND top;
int x, y;
int w, h;
int result = 0;
/* Figure out what the window area will be */
if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_ALWAYS_ON_TOP)) {
@ -255,13 +261,18 @@ void WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags)
WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_TRUE);
data->expected_resize = SDL_TRUE;
SetWindowPos(hwnd, top, x, y, w, h, flags);
if (SetWindowPos(hwnd, top, x, y, w, h, flags) == 0) {
result = WIN_SetError("SetWindowPos()");
}
data->expected_resize = SDL_FALSE;
/* Update any child windows */
for (child_window = window->first_child; child_window != NULL; child_window = child_window->next_sibling) {
WIN_SetWindowPositionInternal(child_window, flags);
if (WIN_SetWindowPositionInternal(child_window, flags) < 0) {
result = -1;
}
}
return result;
}
static void SDLCALL WIN_MouseRelativeModeCenterChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
@ -793,13 +804,13 @@ int WIN_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
#endif
}
void WIN_SetWindowPosition(_THIS, SDL_Window *window)
int WIN_SetWindowPosition(_THIS, SDL_Window *window)
{
/* HighDPI support: removed SWP_NOSIZE. If the move results in a DPI change, we need to allow
* the window to resize (e.g. AdjustWindowRectExForDpi frame sizes are different).
*/
WIN_ConstrainPopup(window);
WIN_SetWindowPositionInternal(window, window->driverdata->copybits_flag | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
return WIN_SetWindowPositionInternal(window, window->driverdata->copybits_flag | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
}
void WIN_SetWindowSize(_THIS, SDL_Window *window)

View File

@ -84,7 +84,7 @@ extern int WIN_CreateWindow(_THIS, SDL_Window *window);
extern int WIN_CreateWindowFrom(_THIS, SDL_Window *window, const void *data);
extern void WIN_SetWindowTitle(_THIS, SDL_Window *window);
extern int WIN_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon);
extern void WIN_SetWindowPosition(_THIS, SDL_Window *window);
extern int WIN_SetWindowPosition(_THIS, SDL_Window *window);
extern void WIN_SetWindowSize(_THIS, SDL_Window *window);
extern int WIN_GetWindowBordersSize(_THIS, SDL_Window *window, int *top, int *left, int *bottom, int *right);
extern void WIN_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *width, int *height);
@ -116,7 +116,7 @@ extern void WIN_ClientPointFromSDLFloat(const SDL_Window *window, float x, float
extern void WIN_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept);
extern int WIN_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation);
extern void WIN_UpdateDarkModeForHWND(HWND hwnd);
extern void WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags);
extern int WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -959,12 +959,13 @@ void X11_UpdateWindowPosition(SDL_Window *window)
}
}
void X11_SetWindowPosition(_THIS, SDL_Window *window)
int X11_SetWindowPosition(_THIS, SDL_Window *window)
{
if (SDL_WINDOW_IS_POPUP(window)) {
X11_ConstrainPopup(window);
}
X11_UpdateWindowPosition(window);
return 0;
}
static void X11_SetWMNormalHints(_THIS, SDL_Window *window, XSizeHints *sizehints)

View File

@ -89,7 +89,7 @@ extern int X11_CreateWindowFrom(_THIS, SDL_Window *window, const void *data);
extern char *X11_GetWindowTitle(_THIS, Window xwindow);
extern void X11_SetWindowTitle(_THIS, SDL_Window *window);
extern int X11_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon);
extern void X11_SetWindowPosition(_THIS, SDL_Window *window);
extern int X11_SetWindowPosition(_THIS, SDL_Window *window);
extern void X11_SetWindowMinimumSize(_THIS, SDL_Window *window);
extern void X11_SetWindowMaximumSize(_THIS, SDL_Window *window);
extern int X11_GetWindowBordersSize(_THIS, SDL_Window *window, int *top, int *left, int *bottom, int *right);