Skip to content

Commit

Permalink
Added SDL_SetWindowResizable(). (thanks, Ethan!)
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Sep 30, 2016
1 parent 257c897 commit 4f4c4b6
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 0 deletions.
18 changes: 18 additions & 0 deletions include/SDL_video.h
Expand Up @@ -83,6 +83,7 @@ typedef struct
* \sa SDL_SetWindowPosition()
* \sa SDL_SetWindowSize()
* \sa SDL_SetWindowBordered()
* \sa SDL_SetWindowResizable()
* \sa SDL_SetWindowTitle()
* \sa SDL_ShowWindow()
*/
Expand Down Expand Up @@ -706,6 +707,23 @@ extern DECLSPEC void SDLCALL SDL_GetWindowMaximumSize(SDL_Window * window,
extern DECLSPEC void SDLCALL SDL_SetWindowBordered(SDL_Window * window,
SDL_bool bordered);

/**
* \brief Set the user-resizable state of a window.
*
* This will add or remove the window's SDL_WINDOW_RESIZABLE flag and
* allow/disallow user resizing of the window. This is a no-op if the
* window's resizable state already matches the requested state.
*
* \param window The window of which to change the resizable state.
* \param resizable SDL_TRUE to allow resizing, SDL_FALSE to disallow.
*
* \note You can't change the resizable state of a fullscreen window.
*
* \sa SDL_GetWindowFlags()
*/
extern DECLSPEC void SDLCALL SDL_SetWindowResizable(SDL_Window * window,
SDL_bool resizable);

/**
* \brief Show a window.
*
Expand Down
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_overrides.h
Expand Up @@ -606,3 +606,4 @@
#define SDL_RenderSetIntegerScale SDL_RenderSetIntegerScale_REAL
#define SDL_RenderGetIntegerScale SDL_RenderGetIntegerScale_REAL
#define SDL_DequeueAudio SDL_DequeueAudio_REAL
#define SDL_SetWindowResizable SDL_SetWindowResizable_REAL
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_procs.h
Expand Up @@ -640,3 +640,4 @@ SDL_DYNAPI_PROC(int,SDL_SetWindowModalFor,(SDL_Window *a, SDL_Window *b),(a,b),r
SDL_DYNAPI_PROC(int,SDL_RenderSetIntegerScale,(SDL_Renderer *a, SDL_bool b),(a,b),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_RenderGetIntegerScale,(SDL_Renderer *a),(a),return)
SDL_DYNAPI_PROC(Uint32,SDL_DequeueAudio,(SDL_AudioDeviceID a, void *b, Uint32 c),(a,b,c),return)
SDL_DYNAPI_PROC(void,SDL_SetWindowResizable,(SDL_Window *a, SDL_bool b),(a,b),)
1 change: 1 addition & 0 deletions src/video/SDL_sysvideo.h
Expand Up @@ -219,6 +219,7 @@ struct SDL_VideoDevice
void (*MinimizeWindow) (_THIS, SDL_Window * window);
void (*RestoreWindow) (_THIS, SDL_Window * window);
void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
void (*SetWindowResizable) (_THIS, SDL_Window * window, SDL_bool resizable);
void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
Expand Down
18 changes: 18 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -1841,6 +1841,24 @@ SDL_SetWindowBordered(SDL_Window * window, SDL_bool bordered)
}
}

void
SDL_SetWindowResizable(SDL_Window * window, SDL_bool resizable)
{
CHECK_WINDOW_MAGIC(window,);
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
const int want = (resizable != SDL_FALSE); /* normalize the flag. */
const int have = ((window->flags & SDL_WINDOW_RESIZABLE) != 0);
if ((want != have) && (_this->SetWindowResizable)) {
if (want) {
window->flags |= SDL_WINDOW_RESIZABLE;
} else {
window->flags &= ~SDL_WINDOW_RESIZABLE;
}
_this->SetWindowResizable(_this, window, (SDL_bool) want);
}
}
}

void
SDL_SetWindowSize(SDL_Window * window, int w, int h)
{
Expand Down
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoavideo.m
Expand Up @@ -96,6 +96,7 @@
device->MinimizeWindow = Cocoa_MinimizeWindow;
device->RestoreWindow = Cocoa_RestoreWindow;
device->SetWindowBordered = Cocoa_SetWindowBordered;
device->SetWindowResizable = Cocoa_SetWindowResizable;
device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
device->SetWindowGammaRamp = Cocoa_SetWindowGammaRamp;
device->GetWindowGammaRamp = Cocoa_GetWindowGammaRamp;
Expand Down
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoawindow.h
Expand Up @@ -133,6 +133,7 @@ extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window);
extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
extern void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
extern void Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
extern int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
extern int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
Expand Down
14 changes: 14 additions & 0 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -1492,6 +1492,20 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
}
}}

void
Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
{ @autoreleasepool
{
/* Don't set this if we're in a space!
* The window will get permanently stuck if resizable is false.
* -flibit
*/
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
Cocoa_WindowListener *listener = data->listener;
if (![listener isInFullscreenSpace]) {
SetWindowStyle(window, GetWindowStyle(window));
}
}}

void
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
Expand Down
16 changes: 16 additions & 0 deletions src/video/haiku/SDL_BWin.h
Expand Up @@ -56,6 +56,7 @@ enum WinCommands {
BWIN_RESTORE_WINDOW,
BWIN_SET_TITLE,
BWIN_SET_BORDERED,
BWIN_SET_RESIZABLE,
BWIN_FULLSCREEN
};

Expand Down Expand Up @@ -378,6 +379,9 @@ class SDL_BWin:public BDirectWindow
case BWIN_SET_BORDERED:
_SetBordered(message);
break;
case BWIN_SET_RESIZABLE:
_SetResizable(message);
break;
case BWIN_SHOW_WINDOW:
Show();
break;
Expand Down Expand Up @@ -568,6 +572,18 @@ class SDL_BWin:public BDirectWindow
SetLook(bEnabled ? B_BORDERED_WINDOW_LOOK : B_NO_BORDER_WINDOW_LOOK);
}

void _SetResizable(BMessage *msg) {
bool bEnabled;
if(msg->FindBool("window-resizable", &bEnabled) != B_OK) {
return;
}
if (bEnabled) {
SetFlags(GetFlags() & ~(B_NOT_RESIZABLE | B_NOT_ZOOMABLE));
} else {
SetFlags(GetFlags() | (B_NOT_RESIZABLE | B_NOT_ZOOMABLE));
}
}

void _Restore() {
if(IsMinimized()) {
Minimize(false);
Expand Down
1 change: 1 addition & 0 deletions src/video/haiku/SDL_bvideo.cc
Expand Up @@ -81,6 +81,7 @@ BE_CreateDevice(int devindex)
device->MinimizeWindow = BE_MinimizeWindow;
device->RestoreWindow = BE_RestoreWindow;
device->SetWindowBordered = BE_SetWindowBordered;
device->SetWindowResizable = BE_SetWindowResizable;
device->SetWindowFullscreen = BE_SetWindowFullscreen;
device->SetWindowGammaRamp = BE_SetWindowGammaRamp;
device->GetWindowGammaRamp = BE_GetWindowGammaRamp;
Expand Down
6 changes: 6 additions & 0 deletions src/video/haiku/SDL_bwindow.cc
Expand Up @@ -145,6 +145,12 @@ void BE_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) {
_ToBeWin(window)->PostMessage(&msg);
}

void BE_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable) {
BMessage msg(BWIN_SET_RESIZABLE);
msg.AddBool("window-resizable", resizable != SDL_FALSE);
_ToBeWin(window)->PostMessage(&msg);
}

void BE_ShowWindow(_THIS, SDL_Window * window) {
BMessage msg(BWIN_SHOW_WINDOW);
_ToBeWin(window)->PostMessage(&msg);
Expand Down
1 change: 1 addition & 0 deletions src/video/haiku/SDL_bwindow.h
Expand Up @@ -39,6 +39,7 @@ extern void BE_MaximizeWindow(_THIS, SDL_Window * window);
extern void BE_MinimizeWindow(_THIS, SDL_Window * window);
extern void BE_RestoreWindow(_THIS, SDL_Window * window);
extern void BE_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
extern void BE_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
extern void BE_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
extern int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
extern int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
Expand Down
1 change: 1 addition & 0 deletions src/video/mir/SDL_mirvideo.c
Expand Up @@ -186,6 +186,7 @@ MIR_CreateDevice(int device_index)
device->SetWindowIcon = NULL;
device->RaiseWindow = NULL;
device->SetWindowBordered = NULL;
device->SetWindowResizable = NULL;
device->OnWindowEnter = NULL;
device->SetWindowPosition = NULL;

Expand Down
1 change: 1 addition & 0 deletions src/video/windows/SDL_windowsvideo.c
Expand Up @@ -145,6 +145,7 @@ WIN_CreateDevice(int devindex)
device->MinimizeWindow = WIN_MinimizeWindow;
device->RestoreWindow = WIN_RestoreWindow;
device->SetWindowBordered = WIN_SetWindowBordered;
device->SetWindowResizable = WIN_SetWindowResizable;
device->SetWindowFullscreen = WIN_SetWindowFullscreen;
device->SetWindowGammaRamp = WIN_SetWindowGammaRamp;
device->GetWindowGammaRamp = WIN_GetWindowGammaRamp;
Expand Down
16 changes: 16 additions & 0 deletions src/video/windows/SDL_windowswindow.c
Expand Up @@ -519,6 +519,22 @@ WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
data->in_border_change = SDL_FALSE;
}

void
WIN_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
{
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
HWND hwnd = data->hwnd;
DWORD style = GetWindowLong(hwnd, GWL_STYLE);

if (resizable) {
style |= STYLE_RESIZABLE;
} else {
style &= ~STYLE_RESIZABLE;
}

SetWindowLong(hwnd, GWL_STYLE, style);
}

void
WIN_RestoreWindow(_THIS, SDL_Window * window)
{
Expand Down
1 change: 1 addition & 0 deletions src/video/windows/SDL_windowswindow.h
Expand Up @@ -64,6 +64,7 @@ extern void WIN_MaximizeWindow(_THIS, SDL_Window * window);
extern void WIN_MinimizeWindow(_THIS, SDL_Window * window);
extern void WIN_RestoreWindow(_THIS, SDL_Window * window);
extern void WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
extern void WIN_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
extern void WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
extern int WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
extern int WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
Expand Down
1 change: 1 addition & 0 deletions src/video/x11/SDL_x11video.c
Expand Up @@ -243,6 +243,7 @@ X11_CreateDevice(int devindex)
device->MinimizeWindow = X11_MinimizeWindow;
device->RestoreWindow = X11_RestoreWindow;
device->SetWindowBordered = X11_SetWindowBordered;
device->SetWindowResizable = X11_SetWindowResizable;
device->SetWindowFullscreen = X11_SetWindowFullscreen;
device->SetWindowGammaRamp = X11_SetWindowGammaRamp;
device->SetWindowGrab = X11_SetWindowGrab;
Expand Down
38 changes: 38 additions & 0 deletions src/video/x11/SDL_x11window.c
Expand Up @@ -981,6 +981,44 @@ X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
X11_XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
}

void
X11_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
Display *display = data->videodata->display;

XSizeHints *sizehints = X11_XAllocSizeHints();
long userhints;

X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);

if (resizable) {
/* FIXME: Is there a better way to get max window size from X? -flibit */
const int maxsize = 0x7FFFFFFF;
sizehints->min_width = window->min_w;
sizehints->min_height = window->min_h;
sizehints->max_width = (window->max_w == 0) ? maxsize : window->max_w;
sizehints->max_height = (window->max_h == 0) ? maxsize : window->max_h;
} else {
sizehints->min_width = window->w;
sizehints->min_height = window->h;
sizehints->max_width = window->w;
sizehints->max_height = window->h;
}
sizehints->flags |= PMinSize | PMaxSize;

X11_XSetWMNormalHints(display, data->xwindow, sizehints);

X11_XFree(sizehints);

/* See comment in X11_SetWindowSize. */
X11_XResizeWindow(display, data->xwindow, window->w, window->h);
X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
X11_XRaiseWindow(display, data->xwindow);

X11_XFlush(display);
}

void
X11_ShowWindow(_THIS, SDL_Window * window)
{
Expand Down
1 change: 1 addition & 0 deletions src/video/x11/SDL_x11window.h
Expand Up @@ -96,6 +96,7 @@ extern void X11_MaximizeWindow(_THIS, SDL_Window * window);
extern void X11_MinimizeWindow(_THIS, SDL_Window * window);
extern void X11_RestoreWindow(_THIS, SDL_Window * window);
extern void X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
extern void X11_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
extern void X11_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
extern int X11_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
extern void X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
Expand Down

0 comments on commit 4f4c4b6

Please sign in to comment.