SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::WindowBase Struct Reference

Represents a handle to a window. More...

Inheritance diagram for SDL::WindowBase:
Inheritance graph
[legend]

Public Member Functions

 WindowBase (StringParam title, SDL_Point size, WindowFlags flags=0)
 Create a window with the specified dimensions and flags.
 
 WindowBase (WindowBase &parent, SDL_Point offset, SDL_Point size, WindowFlags flags=0)
 Create a child popup window of the specified parent window.
 
 WindowBase (PropertiesBase &props)
 Create a window with the specified properties.
 
Display GetDisplay () const
 Get the display associated with a window.
 
float GetPixelDensity () const
 Get the pixel density of a window.
 
float GetDisplayScale () const
 Get the content display scale relative to a window's pixel size.
 
void SetFullscreenMode (OptionalRef< const DisplayMode > mode)
 Set the display mode to use when a window is visible and fullscreen.
 
const DisplayModeGetFullscreenMode () const
 Query the display mode to use when a window is visible at fullscreen.
 
OwnPtr< void > GetICCProfile (size_t *size) const
 Get the raw ICC profile data for the screen the window is currently on.
 
PixelFormat GetPixelFormat () const
 Get the pixel format associated with the window.
 
WindowID GetID () const
 Get the numeric ID of a window.
 
WindowRef GetParent () const
 Get parent of a window.
 
PropertiesRef GetProperties () const
 Get the properties associated with a window.
 
WindowFlags GetFlags () const
 Get the window flags.
 
void SetTitle (StringParam title)
 Set the title of a window.
 
const char * GetTitle () const
 Get the title of a window.
 
void SetIcon (SurfaceBase &icon)
 Set the icon for a window.
 
void SetRect (Rect rect)
 Request the window's position and size to be set.
 
Rect GetRect () const
 Get the position and client size of a window.
 
void SetPosition (SDL_Point p)
 Request that the window's position be set.
 
Point GetPosition () const
 Get the position of a window.
 
void GetPosition (int *x, int *y) const
 Get the position of a window.
 
void SetSize (SDL_Point p)
 Request that the size of a window's client area be set.
 
Point GetSize () const
 Get the size of a window's client area.
 
void GetSize (int *w, int *h) const
 Get the size of a window's client area.
 
Rect GetSafeArea () const
 Get the safe area for this window.
 
void SetAspectRatio (float min_aspect, float max_aspect)
 Request that the aspect ratio of a window's client area be set.
 
void GetAspectRatio (float *min_aspect, float *max_aspect) const
 Get the size of a window's client area.
 
void GetBordersSize (int *top, int *left, int *bottom, int *right) const
 Get the size of a window's borders (decorations) around the client area.
 
Point GetSizeInPixels () const
 Get the size of a window's client area, in pixels.
 
void GetSizeInPixels (int *w, int *h) const
 Get the size of a window's client area, in pixels.
 
void SetMinimumSize (SDL_Point p)
 Set the minimum size of a window's client area.
 
void GetMinimumSize (int *w, int *h) const
 Get the minimum size of a window's client area.
 
void SetMaximumSize (SDL_Point p)
 Set the maximum size of a window's client area.
 
void GetMaximumSize (int *w, int *h) const
 Get the maximum size of a window's client area.
 
void SetBordered (bool bordered)
 Set the border state of a window.
 
void SetResizable (bool resizable)
 Set the user-resizable state of a window.
 
void SetAlwaysOnTop (bool on_top)
 Set the window to always be above the others.
 
void Show ()
 Show a window.
 
void Hide ()
 Hide a window.
 
void Raise ()
 Request that a window be raised above other windows and gain the input focus.
 
void Maximize ()
 Request that the window be made as large as possible.
 
void Minimize ()
 Request that the window be minimized to an iconic representation.
 
void Restore ()
 Request that the size and position of a minimized or maximized window be restored.
 
void SetFullscreen (bool fullscreen)
 Request that the window's fullscreen state be changed.
 
void Sync ()
 Block until any pending window state is finalized.
 
bool HasSurface () const
 Return whether the window has a surface associated with it.
 
SurfaceRef GetSurface ()
 Get the SDL surface associated with the window.
 
void SetSurfaceVSync (int vsync)
 Toggle VSync for the window surface.
 
int GetSurfaceVSync () const
 Get VSync for the window surface.
 
void UpdateSurface ()
 Copy the window surface to the screen.
 
void UpdateSurfaceRects (SpanRef< const SDL_Rect > rects)
 Copy areas of the window surface to the screen.
 
void DestroySurface ()
 Destroy the surface associated with the window.
 
void SetKeyboardGrab (bool grabbed)
 Set a window's keyboard grab mode.
 
void SetMouseGrab (bool grabbed)
 Set a window's mouse grab mode.
 
bool GetKeyboardGrab () const
 Get a window's keyboard grab mode.
 
bool GetMouseGrab () const
 Get a window's mouse grab mode.
 
void SetMouseRect (const SDL_Rect &rect)
 Confines the cursor to the specified area of a window.
 
const SDL_Rect * GetMouseRect () const
 Get the mouse confinement rectangle of a window.
 
void SetOpacity (float opacity)
 Set the opacity for a window.
 
float GetOpacity () const
 Get the opacity of a window.
 
void SetParent (OptionalWindow parent)
 Set the window as a child of a parent window.
 
void SetModal (bool modal)
 Toggle the state of the window as modal.
 
void SetFocusable (bool focusable)
 Set whether the window may have input focus.
 
void ShowSystemMenu (SDL_Point p)
 Display the system-level window menu.
 
void SetHitTest (HitTestCB callback)
 Provide a callback that decides if a window region has special properties.
 
void SetHitTest (HitTest callback, void *callback_data)
 Provide a callback that decides if a window region has special properties.
 
void SetShape (SurfaceBase &shape)
 Set the shape of a transparent window.
 
void Flash (FlashOperation operation)
 Request a window to demand attention from the user.
 
RendererRef GetRenderer () const
 Get the renderer associated with a window.
 
void StartTextInput ()
 Start accepting Unicode text input events in a window.
 
void StartTextInput (PropertiesBase &props)
 Start accepting Unicode text input events in a window, with properties describing the input.
 
bool IsTextInputActive () const
 Check whether or not Unicode text input events are enabled for a window.
 
void StopTextInput ()
 Stop receiving any text input events in a window.
 
void ClearComposition ()
 Dismiss the composition window/IME without disabling the subsystem.
 
void SetTextInputArea (const SDL_Rect &rect, int cursor)
 Set the area used to type Unicode text input.
 
void GetTextInputArea (Rect *rect, int *cursor)
 Get the area used to type Unicode text input.
 
bool IsScreenKeyboardShown () const
 Check whether the screen keyboard is shown for given window.
 
void WarpMouse (float x, float y)
 Move the mouse cursor to the given position within the window.
 
void SetRelativeMouseMode (bool enabled)
 Set relative mouse mode for a window.
 
bool GetRelativeMouseMode () const
 Query whether relative mouse mode is enabled for a window.
 
constexpr Resource (T resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
- Public Member Functions inherited from SDL::Resource< SDL_Window * >
constexpr Resource (SDL_Window * resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
Resourceoperator= (const Resource &other)=delete
 
Resourceoperator= (Resource &&other)=delete
 
constexpr operator bool () const
 True if contains a valid resource.
 
constexpr bool operator== (const Resource &other) const=default
 Comparison.
 
constexpr bool operator== (std::nullopt_t) const
 Comparison.
 
constexpr bool operator== (std::nullptr_t) const
 Comparison.
 
constexpr SDL_Window * get () const
 Return contained resource;.
 
constexpr SDL_Window * release (SDL_Window * newResource={})
 Return contained resource and empties or replace value.
 
constexpr const SDL_Window * operator-> () const
 Access to fields.
 
constexpr SDL_Window * operator-> ()
 Access to fields.
 

Detailed Description

Since
This struct is available since SDL 3.2.0.
See also
WindowBase.WindowBase
Category:
Resource
See also
Window
WindowRef

Constructor & Destructor Documentation

◆ WindowBase() [1/3]

SDL::WindowBase::WindowBase ( StringParam  title,
SDL_Point  size,
WindowFlags  flags = 0 
)
inline

The window size is a request and may be different than expected based on the desktop layout and window manager policies. Your application should be prepared to handle a window of any size.

flags may be any of the following OR'd together:

  • WINDOW_FULLSCREEN: fullscreen window at desktop resolution
  • WINDOW_OPENGL: window usable with an OpenGL context
  • WINDOW_OCCLUDED: window partially or completely obscured by another window
  • WINDOW_HIDDEN: window is not visible
  • WINDOW_BORDERLESS: no window decoration
  • WINDOW_RESIZABLE: window can be resized
  • WINDOW_MINIMIZED: window is minimized
  • WINDOW_MAXIMIZED: window is maximized
  • WINDOW_MOUSE_GRABBED: window has grabbed mouse focus
  • WINDOW_INPUT_FOCUS: window has input focus
  • WINDOW_MOUSE_FOCUS: window has mouse focus
  • WINDOW_EXTERNAL: window not created by SDL
  • WINDOW_MODAL: window is modal
  • WINDOW_HIGH_PIXEL_DENSITY: window uses high pixel density back buffer if possible
  • WINDOW_MOUSE_CAPTURE: window has mouse captured (unrelated to MOUSE_GRABBED)
  • WINDOW_ALWAYS_ON_TOP: window should always be above others
  • WINDOW_UTILITY: window should be treated as a utility window, not showing in the task bar and window list
  • WINDOW_TOOLTIP: window should be treated as a tooltip and does not get mouse or keyboard focus, requires a parent window
  • WINDOW_POPUP_MENU: window should be treated as a popup menu, requires a parent window
  • WINDOW_KEYBOARD_GRABBED: window has grabbed keyboard input
  • WINDOW_VULKAN: window usable with a Vulkan instance
  • WINDOW_METAL: window usable with a Metal instance
  • WINDOW_TRANSPARENT: window with transparent buffer
  • WINDOW_NOT_FOCUSABLE: window should not be focusable

The WindowBase is implicitly shown if WINDOW_HIDDEN is not set.

On Apple's macOS, you must set the NSHighResolutionCapable Info.plist property to YES, otherwise you will not receive a High-DPI OpenGL canvas.

The window pixel size may differ from its window coordinate size if the window is on a high pixel density display. Use WindowBase.GetSize() to query the client area's size in window coordinates, and WindowBase.GetSizeInPixels() or RendererBase.GetOutputSize() to query the drawable size in pixels. Note that the drawable size can vary after the window is created and should be queried again if you get an EVENT_WINDOW_PIXEL_SIZE_CHANGED event.

If the window is created with any of the WINDOW_OPENGL or WINDOW_VULKAN flags, then the corresponding LoadLibrary function (GL_LoadLibrary or SDL_Vulkan_LoadLibrary) is called and the corresponding UnloadLibrary function is called by WindowRef.reset().

If WINDOW_VULKAN is specified and there isn't a working Vulkan driver, WindowBase.WindowBase() will fail, because SDL_Vulkan_LoadLibrary() will fail.

If WINDOW_METAL is specified on an OS that does not support Metal, WindowBase.WindowBase() will fail.

If you intend to use this window with an RendererBase, you should use CreateWindowAndRenderer() instead of this function, to avoid window flicker.

On non-Apple devices, SDL requires you to either not link to the Vulkan loader or link to a dynamic library version. This limitation may be removed in a future version of SDL.

Parameters
titlethe title of the window, in UTF-8 encoding.
sizethe width and height of the window.
flags0, or one or more WindowFlags OR'd together.
Postcondition
the window that was created.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
CreateWindowAndRenderer()

◆ WindowBase() [2/3]

SDL::WindowBase::WindowBase ( WindowBase parent,
SDL_Point  offset,
SDL_Point  size,
WindowFlags  flags = 0 
)
inline

The window size is a request and may be different than expected based on the desktop layout and window manager policies. Your application should be prepared to handle a window of any size.

The flags parameter must contain at least one of the following:

  • WINDOW_TOOLTIP: The popup window is a tooltip and will not pass any input events.
  • WINDOW_POPUP_MENU: The popup window is a popup menu. The topmost popup menu will implicitly gain the keyboard focus.

The following flags are not relevant to popup window creation and will be ignored:

  • WINDOW_MINIMIZED
  • WINDOW_MAXIMIZED
  • WINDOW_FULLSCREEN
  • WINDOW_BORDERLESS

The following flags are incompatible with popup window creation and will cause it to fail:

  • WINDOW_UTILITY
  • WINDOW_MODAL

The parent parameter must be non-null and a valid window. The parent of a popup window can be either a regular, toplevel window, or another popup window.

Popup windows cannot be minimized, maximized, made fullscreen, raised, flash, be made a modal window, be the parent of a toplevel window, or grab the mouse and/or keyboard. Attempts to do so will fail.

Popup windows implicitly do not have a border/decorations and do not appear on the taskbar/dock or in lists of windows such as alt-tab menus.

If a parent window is hidden or destroyed, any child popup windows will be recursively hidden or destroyed as well. Child popup windows not explicitly hidden will be restored when the parent is shown.

Parameters
parentthe parent of the window, must not be nullptr.
offsetthe x, y position of the popup window relative to the origin of the parent.
sizethe width and height of the window.
flagsWINDOW_TOOLTIP or WINDOW_POPUP_MENU, and zero or more additional WindowFlags OR'd together.
Postcondition
the window that was created.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetParent

◆ WindowBase() [3/3]

SDL::WindowBase::WindowBase ( PropertiesBase props)
inline

The window size is a request and may be different than expected based on the desktop layout and window manager policies. Your application should be prepared to handle a window of any size.

These are the supported properties:

  • prop::Window.CREATE_ALWAYS_ON_TOP_BOOLEAN: true if the window should be always on top
  • prop::Window.CREATE_BORDERLESS_BOOLEAN: true if the window has no window decoration
  • prop::Window.CREATE_EXTERNAL_GRAPHICS_CONTEXT_BOOLEAN: true if the window will be used with an externally managed graphics context.
  • prop::Window.CREATE_FOCUSABLE_BOOLEAN: true if the window should accept keyboard input (defaults true)
  • prop::Window.CREATE_FULLSCREEN_BOOLEAN: true if the window should start in fullscreen mode at desktop resolution
  • prop::Window.CREATE_HEIGHT_NUMBER: the height of the window
  • prop::Window.CREATE_HIDDEN_BOOLEAN: true if the window should start hidden
  • prop::Window.CREATE_HIGH_PIXEL_DENSITY_BOOLEAN: true if the window uses a high pixel density buffer if possible
  • prop::Window.CREATE_MAXIMIZED_BOOLEAN: true if the window should start maximized
  • prop::Window.CREATE_MENU_BOOLEAN: true if the window is a popup menu
  • prop::Window.CREATE_METAL_BOOLEAN: true if the window will be used with Metal rendering
  • prop::Window.CREATE_MINIMIZED_BOOLEAN: true if the window should start minimized
  • prop::Window.CREATE_MODAL_BOOLEAN: true if the window is modal to its parent
  • prop::Window.CREATE_MOUSE_GRABBED_BOOLEAN: true if the window starts with grabbed mouse focus
  • prop::Window.CREATE_OPENGL_BOOLEAN: true if the window will be used with OpenGL rendering
  • prop::Window.CREATE_PARENT_POINTER: an WindowBase that will be the parent of this window, required for windows with the "tooltip", "menu", and "modal" properties
  • prop::Window.CREATE_RESIZABLE_BOOLEAN: true if the window should be resizable
  • prop::Window.CREATE_TITLE_STRING: the title of the window, in UTF-8 encoding
  • prop::Window.CREATE_TRANSPARENT_BOOLEAN: true if the window show transparent in the areas with alpha of 0
  • prop::Window.CREATE_TOOLTIP_BOOLEAN: true if the window is a tooltip
  • prop::Window.CREATE_UTILITY_BOOLEAN: true if the window is a utility window, not showing in the task bar and window list
  • prop::Window.CREATE_VULKAN_BOOLEAN: true if the window will be used with Vulkan rendering
  • prop::Window.CREATE_WIDTH_NUMBER: the width of the window
  • prop::Window.CREATE_X_NUMBER: the x position of the window, or SDL_WINDOWPOS_CENTERED, defaults to SDL_WINDOWPOS_UNDEFINED. This is relative to the parent for windows with the "tooltip" or "menu" property set.
  • prop::Window.CREATE_Y_NUMBER: the y position of the window, or SDL_WINDOWPOS_CENTERED, defaults to SDL_WINDOWPOS_UNDEFINED. This is relative to the parent for windows with the "tooltip" or "menu" property set.

These are additional supported properties on macOS:

  • prop::Window.CREATE_COCOA_WINDOW_POINTER: the (__unsafe_unretained) NSWindow associated with the window, if you want to wrap an existing window.
  • prop::Window.CREATE_COCOA_VIEW_POINTER: the (__unsafe_unretained) NSView associated with the window, defaults to [window contentView]

These are additional supported properties on Wayland:

  • prop::Window.CREATE_WAYLAND_SURFACE_ROLE_CUSTOM_BOOLEAN - true if the application wants to use the Wayland surface for a custom role and does not want it attached to an XDG toplevel window. See README/wayland for more information on using custom surfaces.
  • prop::Window.CREATE_WAYLAND_CREATE_EGL_WINDOW_BOOLEAN - true if the application wants an associated wl_egl_window object to be created and attached to the window, even if the window does not have the OpenGL property or WINDOW_OPENGL flag set.
  • prop::Window.CREATE_WAYLAND_WL_SURFACE_POINTER - the wl_surface associated with the window, if you want to wrap an existing window. See README/wayland for more information.

These are additional supported properties on Windows:

  • prop::Window.CREATE_WIN32_HWND_POINTER: the HWND associated with the window, if you want to wrap an existing window.
  • prop::Window.CREATE_WIN32_PIXEL_FORMAT_HWND_POINTER: optional, another window to share pixel format with, useful for OpenGL windows

These are additional supported properties with X11:

  • prop::Window.CREATE_X11_WINDOW_NUMBER: the X11 Window associated with the window, if you want to wrap an existing window.

The window is implicitly shown if the "hidden" property is not set.

Windows with the "tooltip" and "menu" properties are popup windows and have the behaviors and guidelines outlined in WindowBase.WindowBase().

If this window is being created to be used with an RendererBase, you should not add a graphics API specific property (prop::Window.CREATE_OPENGL_BOOLEAN, etc), as SDL will handle that internally when it chooses a renderer. However, SDL might need to recreate your window at that point, which may cause the window to appear briefly, and then flicker as it is recreated. The correct approach to this is to create the window with the prop::Window.CREATE_HIDDEN_BOOLEAN property set to true, then create the renderer, then show the window with WindowBase.Show().

Parameters
propsthe properties to use.
Postcondition
the window that was created.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
Properties.Properties

Member Function Documentation

◆ DestroySurface()

void SDL::WindowBase::DestroySurface ( )
inline
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetSurface
WindowBase.HasSurface

◆ Flash()

void SDL::WindowBase::Flash ( FlashOperation  operation)
inline
Parameters
operationthe operation to perform.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ GetAspectRatio()

void SDL::WindowBase::GetAspectRatio ( float *  min_aspect,
float *  max_aspect 
) const
inline
Parameters
min_aspecta pointer filled in with the minimum aspect ratio of the window, may be nullptr.
max_aspecta pointer filled in with the maximum aspect ratio of the window, may be nullptr.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.SetAspectRatio

◆ GetBordersSize()

void SDL::WindowBase::GetBordersSize ( int *  top,
int *  left,
int *  bottom,
int *  right 
) const
inline

Note: If this function fails (returns false), the size values will be initialized to 0, 0, 0, 0 (if a non-nullptr pointer is provided), as if the window in question was borderless.

Note: This function may fail on systems where the window has not yet been decorated by the display server (for example, immediately after calling WindowBase.WindowBase). It is recommended that you wait at least until the window has been presented and composited, so that the window system has a chance to decorate the window and provide the border dimensions to SDL.

This function also returns false if getting the information is not supported.

Parameters
toppointer to variable for storing the size of the top border; nullptr is permitted.
leftpointer to variable for storing the size of the left border; nullptr is permitted.
bottompointer to variable for storing the size of the bottom border; nullptr is permitted.
rightpointer to variable for storing the size of the right border; nullptr is permitted.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetSize

◆ GetDisplay()

Display SDL::WindowBase::GetDisplay ( ) const
inline
Returns
the instance ID of the display containing the center of the window on success or 0 on failure; call GetError() for more information.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
Display.GetBounds
Display.GetAll

◆ GetDisplayScale()

float SDL::WindowBase::GetDisplayScale ( ) const
inline

This is a combination of the window pixel density and the display content scale, and is the expected scale for displaying content in this window. For example, if a 3840x2160 window had a display scale of 2.0, the user expects the content to take twice as many pixels and be the same physical size as if it were being displayed in a 1920x1080 window with a display scale of 1.0.

Conceptually this value corresponds to the scale display setting, and is updated when that setting is changed, or the window moves to a display with a different scale setting.

Returns
the display scale, or 0.0f on failure; call GetError() for more information.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ GetFlags()

WindowFlags SDL::WindowBase::GetFlags ( ) const
inline
Returns
a mask of the WindowFlags associated with window.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.WindowBase
WindowBase.Hide
WindowBase.Maximize
WindowBase.Minimize
WindowBase.SetFullscreen
WindowBase.SetMouseGrab
WindowBase.Show

◆ GetFullscreenMode()

const DisplayMode * SDL::WindowBase::GetFullscreenMode ( ) const
inline
Returns
a pointer to the exclusive fullscreen mode to use or nullptr for borderless fullscreen desktop mode.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.SetFullscreenMode
WindowBase.SetFullscreen

◆ GetICCProfile()

OwnPtr< void > SDL::WindowBase::GetICCProfile ( size_t *  size) const
inline
Parameters
sizethe size of the ICC profile.
Returns
the raw ICC profile data on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ GetID()

WindowID SDL::WindowBase::GetID ( ) const
inline

The numeric ID is what WindowEvent references, and is necessary to map these events to specific WindowBase objects.

Returns
the ID of the window on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowRef.FromID

◆ GetKeyboardGrab()

bool SDL::WindowBase::GetKeyboardGrab ( ) const
inline
Returns
true if keyboard is grabbed, and false otherwise.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.SetKeyboardGrab

◆ GetMaximumSize()

void SDL::WindowBase::GetMaximumSize ( int *  w,
int *  h 
) const
inline
Parameters
wa pointer filled in with the maximum width of the window, may be nullptr.
ha pointer filled in with the maximum height of the window, may be nullptr.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetMinimumSize
WindowBase.SetMaximumSize

◆ GetMinimumSize()

void SDL::WindowBase::GetMinimumSize ( int *  w,
int *  h 
) const
inline
Parameters
wa pointer filled in with the minimum width of the window, may be nullptr.
ha pointer filled in with the minimum height of the window, may be nullptr.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetMaximumSize
WindowBase.SetMinimumSize

◆ GetMouseGrab()

bool SDL::WindowBase::GetMouseGrab ( ) const
inline
Returns
true if mouse is grabbed, and false otherwise.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetMouseRect
WindowBase.SetMouseRect
WindowBase.SetMouseGrab
WindowBase.SetKeyboardGrab

◆ GetMouseRect()

const SDL_Rect * SDL::WindowBase::GetMouseRect ( ) const
inline
Returns
a pointer to the mouse confinement rectangle of a window, or nullptr if there isn't one.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.SetMouseRect
WindowBase.GetMouseGrab
WindowBase.SetMouseGrab

◆ GetOpacity()

float SDL::WindowBase::GetOpacity ( ) const
inline

If transparency isn't supported on this platform, opacity will be returned as 1.0f without error.

Returns
the opacity, (0.0f - transparent, 1.0f - opaque), or -1.0f on failure; call GetError() for more information.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.SetOpacity

◆ GetPixelDensity()

float SDL::WindowBase::GetPixelDensity ( ) const
inline

This is a ratio of pixel size to window size. For example, if the window is 1920x1080 and it has a high density back buffer of 3840x2160 pixels, it would have a pixel density of 2.0.

Returns
the pixel density or 0.0f on failure; call GetError() for more information.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetDisplayScale

◆ GetPixelFormat()

PixelFormat SDL::WindowBase::GetPixelFormat ( ) const
inline
Returns
the pixel format of the window on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ GetPosition() [1/2]

Point SDL::WindowBase::GetPosition ( ) const
inline

This is the current position of the window as last reported by the windowing system.

Returns
the position on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
SetPosition()
SetPosition(int *, int *)

◆ GetPosition() [2/2]

void SDL::WindowBase::GetPosition ( int *  x,
int *  y 
) const
inline

This is the current position of the window as last reported by the windowing system.

If you do not need the value for one of the positions a nullptr may be passed in the x or y parameter.

Parameters
xa pointer filled in with the x position of the window, may be nullptr.
ya pointer filled in with the y position of the window, may be nullptr.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.SetPosition

◆ GetProperties()

PropertiesRef SDL::WindowBase::GetProperties ( ) const
inline

The following read-only properties are provided by SDL:

  • prop::Window.SHAPE_POINTER: the surface associated with a shaped window
  • prop::Window.HDR_ENABLED_BOOLEAN: true if the window has HDR headroom above the SDR white point. This property can change dynamically when EVENT_WINDOW_HDR_STATE_CHANGED is sent.
  • prop::Window.SDR_WHITE_LEVEL_FLOAT: the value of SDR white in the COLORSPACE_SRGB_LINEAR colorspace. On Windows this corresponds to the SDR white level in scRGB colorspace, and on Apple platforms this is always 1.0 for EDR content. This property can change dynamically when EVENT_WINDOW_HDR_STATE_CHANGED is sent.
  • prop::Window.HDR_HEADROOM_FLOAT: the additional high dynamic range that can be displayed, in terms of the SDR white point. When HDR is not enabled, this will be 1.0. This property can change dynamically when EVENT_WINDOW_HDR_STATE_CHANGED is sent.

On Android:

  • prop::Window.ANDROID_WINDOW_POINTER: the ANativeWindow associated with the window
  • prop::Window.ANDROID_SURFACE_POINTER: the EGLSurface associated with the window

On iOS:

  • prop::Window.UIKIT_WINDOW_POINTER: the (__unsafe_unretained) UIWindow associated with the window
  • prop::Window.UIKIT_METAL_VIEW_TAG_NUMBER: the NSInteger tag associated with metal views on the window
  • prop::Window.UIKIT_OPENGL_FRAMEBUFFER_NUMBER: the OpenGL view's framebuffer object. It must be bound when rendering to the screen using OpenGL.
  • prop::Window.UIKIT_OPENGL_RENDERBUFFER_NUMBER: the OpenGL view's renderbuffer object. It must be bound when GL_SwapWindow is called.
  • prop::Window.UIKIT_OPENGL_RESOLVE_FRAMEBUFFER_NUMBER: the OpenGL view's resolve framebuffer, when MSAA is used.

On KMS/DRM:

  • prop::Window.KMSDRM_DEVICE_INDEX_NUMBER: the device index associated with the window (e.g. the X in /dev/dri/cardX)
  • prop::Window.KMSDRM_DRM_FD_NUMBER: the DRM FD associated with the window
  • prop::Window.KMSDRM_GBM_DEVICE_POINTER: the GBM device associated with the window

On macOS:

  • prop::Window.COCOA_WINDOW_POINTER: the (__unsafe_unretained) NSWindow associated with the window
  • prop::Window.COCOA_METAL_VIEW_TAG_NUMBER: the NSInteger tag assocated with metal views on the window

On OpenVR:

  • prop::Window.OPENVR_OVERLAY_ID: the OpenVR Overlay Handle ID for the associated overlay window.

On Vivante:

  • prop::Window.VIVANTE_DISPLAY_POINTER: the EGLNativeDisplayType associated with the window
  • prop::Window.VIVANTE_WINDOW_POINTER: the EGLNativeWindowType associated with the window
  • prop::Window.VIVANTE_SURFACE_POINTER: the EGLSurface associated with the window

On Windows:

  • prop::Window.WIN32_HWND_POINTER: the HWND associated with the window
  • prop::Window.WIN32_HDC_POINTER: the HDC associated with the window
  • prop::Window.WIN32_INSTANCE_POINTER: the HINSTANCE associated with the window

On Wayland:

Note: The xdg_* window objects do not internally persist across window show/hide calls. They will be null if the window is hidden and must be queried each time it is shown.

  • prop::Window.WAYLAND_DISPLAY_POINTER: the wl_display associated with the window
  • prop::Window.WAYLAND_SURFACE_POINTER: the wl_surface associated with the window
  • prop::Window.WAYLAND_VIEWPORT_POINTER: the wp_viewport associated with the window
  • prop::Window.WAYLAND_EGL_WINDOW_POINTER: the wl_egl_window associated with the window
  • prop::Window.WAYLAND_XDG_SURFACE_POINTER: the xdg_surface associated with the window
  • prop::Window.WAYLAND_XDG_TOPLEVEL_POINTER: the xdg_toplevel role associated with the window
  • 'prop::Window.WAYLAND_XDG_TOPLEVEL_EXPORT_HANDLE_STRING': the export handle associated with the window
  • prop::Window.WAYLAND_XDG_POPUP_POINTER: the xdg_popup role associated with the window
  • prop::Window.WAYLAND_XDG_POSITIONER_POINTER: the xdg_positioner associated with the window, in popup mode

On X11:

  • prop::Window.X11_DISPLAY_POINTER: the X11 Display associated with the window
  • prop::Window.X11_SCREEN_NUMBER: the screen number associated with the window
  • prop::Window.X11_WINDOW_NUMBER: the X11 Window associated with the window
Returns
a valid property ID on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ GetRect()

Rect SDL::WindowBase::GetRect ( ) const
inline

This is the current position of the window as last reported by the windowing system.

The window pixel size may differ from its window coordinate size if the window is on a high pixel density display. Use Window.GetSizeInPixels() or RendererBase.GetOutputSize() to get the real client area size in pixels.

Returns
Rect with the position and size
Exceptions
Erroron failure.

◆ GetSafeArea()

Rect SDL::WindowBase::GetSafeArea ( ) const
inline

Some devices have portions of the screen which are partially obscured or not interactive, possibly due to on-screen controls, curved edges, camera notches, TV overscan, etc. This function provides the area of the window which is safe to have interactable content. You should continue rendering into the rest of the window, but it should not contain visually important or interactible content.

Returns
the client area that is safe for interactive content on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ GetSize() [1/2]

Point SDL::WindowBase::GetSize ( ) const
inline

The window pixel size may differ from its window coordinate size if the window is on a high pixel density display. Use GetSizeInPixels() or Renderer.GetOutputSize() to get the real client area size in pixels.

Returns
a point with width and height on success or std::nullopt on failure; call GetError() for more information.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
Renderer.GetOutputSize()
GetSizeInPixels()
SetSize()
GetSize(int *, int *)

◆ GetSize() [2/2]

void SDL::WindowBase::GetSize ( int *  w,
int *  h 
) const
inline

The window pixel size may differ from its window coordinate size if the window is on a high pixel density display. Use WindowBase.GetSizeInPixels() or RendererBase.GetOutputSize() to get the real client area size in pixels.

Parameters
wa pointer filled in with the width of the window, may be nullptr.
ha pointer filled in with the height of the window, may be nullptr.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
RendererBase.GetOutputSize
WindowBase.GetSizeInPixels
WindowBase.SetSize

◆ GetSizeInPixels() [1/2]

Point SDL::WindowBase::GetSizeInPixels ( ) const
inline
Returns
the size on success or std::nullopt on failure; call GetError() for more information.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
GetSize()
GetSizeInPixels(int*, int*)

◆ GetSizeInPixels() [2/2]

void SDL::WindowBase::GetSizeInPixels ( int *  w,
int *  h 
) const
inline
Parameters
wa pointer to variable for storing the width in pixels, may be nullptr.
ha pointer to variable for storing the height in pixels, may be nullptr.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.WindowBase
WindowBase.GetSize

◆ GetSurface()

SurfaceRef SDL::WindowBase::GetSurface ( )
inline

A new surface will be created with the optimal format for the window, if necessary. This surface will be freed when the window is destroyed. Do not free this surface.

This surface will be invalidated if the window is resized. After resizing a window this function must be called again to return a valid surface.

You may not combine this with 3D or the rendering API on this window.

This function is affected by SDL_HINT_FRAMEBUFFER_ACCELERATION.

Returns
the surface associated with the window, or nullptr on failure; call GetError() for more information.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.DestroySurface
WindowBase.HasSurface
WindowBase.UpdateSurface
WindowBase.UpdateSurfaceRects

◆ GetSurfaceVSync()

int SDL::WindowBase::GetSurfaceVSync ( ) const
inline
Returns
the current vertical refresh sync interval on success.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.SetSurfaceVSync

◆ GetTitle()

const char * SDL::WindowBase::GetTitle ( ) const
inline
Returns
the title of the window in UTF-8 format or "" if there is no title.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.SetTitle

◆ HasSurface()

bool SDL::WindowBase::HasSurface ( ) const
inline
Returns
true if there is a surface associated with the window, or false otherwise.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetSurface

◆ Hide()

void SDL::WindowBase::Hide ( )
inline
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.Show
WINDOW_HIDDEN

◆ Maximize()

void SDL::WindowBase::Maximize ( )
inline

Non-resizable windows can't be maximized. The window must have the WINDOW_RESIZABLE flag set, or this will have no effect.

On some windowing systems this request is asynchronous and the new window state may not have have been applied immediately upon the return of this function. If an immediate change is required, call WindowBase.Sync() to block until the changes have taken effect.

When the window state changes, an EVENT_WINDOW_MAXIMIZED event will be emitted. Note that, as this is just a request, the windowing system can deny the state change.

When maximizing a window, whether the constraints set via WindowBase.SetMaximumSize() are honored depends on the policy of the window manager. Win32 and macOS enforce the constraints when maximizing, while X11 and Wayland window managers may vary.

Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.Minimize
WindowBase.Restore
WindowBase.Sync

◆ Minimize()

void SDL::WindowBase::Minimize ( )
inline

If the window is in a fullscreen state, this request has no direct effect. It may alter the state the window is returned to when leaving fullscreen.

On some windowing systems this request is asynchronous and the new window state may not have been applied immediately upon the return of this function. If an immediate change is required, call WindowBase.Sync() to block until the changes have taken effect.

When the window state changes, an EVENT_WINDOW_MINIMIZED event will be emitted. Note that, as this is just a request, the windowing system can deny the state change.

Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.Maximize
WindowBase.Restore
WindowBase.Sync

◆ Raise()

void SDL::WindowBase::Raise ( )
inline

The result of this request is subject to desktop window manager policy, particularly if raising the requested window would result in stealing focus from another application. If the window is successfully raised and gains input focus, an EVENT_WINDOW_FOCUS_GAINED event will be emitted, and the window will have the WINDOW_INPUT_FOCUS flag set.

Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ Restore()

void SDL::WindowBase::Restore ( )
inline

If the window is in a fullscreen state, this request has no direct effect. It may alter the state the window is returned to when leaving fullscreen.

On some windowing systems this request is asynchronous and the new window state may not have have been applied immediately upon the return of this function. If an immediate change is required, call WindowBase.Sync() to block until the changes have taken effect.

When the window state changes, an EVENT_WINDOW_RESTORED event will be emitted. Note that, as this is just a request, the windowing system can deny the state change.

Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.Maximize
WindowBase.Minimize
WindowBase.Sync

◆ SetAlwaysOnTop()

void SDL::WindowBase::SetAlwaysOnTop ( bool  on_top)
inline

This will add or remove the window's WINDOW_ALWAYS_ON_TOP flag. This will bring the window to the front and keep the window above the rest.

Parameters
on_toptrue to set the window always on top, false to disable.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetFlags

◆ SetAspectRatio()

void SDL::WindowBase::SetAspectRatio ( float  min_aspect,
float  max_aspect 
)
inline

The aspect ratio is the ratio of width divided by height, e.g. 2560x1600 would be 1.6. Larger aspect ratios are wider and smaller aspect ratios are narrower.

If, at the time of this request, the window in a fixed-size state, such as maximized or fullscreen, the request will be deferred until the window exits this state and becomes resizable again.

On some windowing systems, this request is asynchronous and the new window aspect ratio may not have have been applied immediately upon the return of this function. If an immediate change is required, call WindowBase.Sync() to block until the changes have taken effect.

When the window size changes, an EVENT_WINDOW_RESIZED event will be emitted with the new window dimensions. Note that the new dimensions may not match the exact aspect ratio requested, as some windowing systems can restrict the window size in certain scenarios (e.g. constraining the size of the content area to remain within the usable desktop bounds). Additionally, as this is just a request, it can be denied by the windowing system.

Parameters
min_aspectthe minimum aspect ratio of the window, or 0.0f for no limit.
max_aspectthe maximum aspect ratio of the window, or 0.0f for no limit.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetAspectRatio
WindowBase.Sync

◆ SetBordered()

void SDL::WindowBase::SetBordered ( bool  bordered)
inline

This will add or remove the window's WINDOW_BORDERLESS flag and add or remove the border from the actual window. This is a no-op if the window's border already matches the requested state.

You can't change the border state of a fullscreen window.

Parameters
borderedfalse to remove border, true to add border.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetFlags

◆ SetFocusable()

void SDL::WindowBase::SetFocusable ( bool  focusable)
inline
Parameters
focusabletrue to allow input focus, false to not allow input focus.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ SetFullscreen()

void SDL::WindowBase::SetFullscreen ( bool  fullscreen)
inline

By default a window in fullscreen state uses borderless fullscreen desktop mode, but a specific exclusive display mode can be set using WindowBase.SetFullscreenMode().

On some windowing systems this request is asynchronous and the new fullscreen state may not have have been applied immediately upon the return of this function. If an immediate change is required, call WindowBase.Sync() to block until the changes have taken effect.

When the window state changes, an EVENT_WINDOW_ENTER_FULLSCREEN or EVENT_WINDOW_LEAVE_FULLSCREEN event will be emitted. Note that, as this is just a request, it can be denied by the windowing system.

Parameters
fullscreentrue for fullscreen mode, false for windowed mode.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetFullscreenMode
WindowBase.SetFullscreenMode
WindowBase.Sync
WINDOW_FULLSCREEN

◆ SetFullscreenMode()

void SDL::WindowBase::SetFullscreenMode ( OptionalRef< const DisplayMode mode)
inline

This only affects the display mode used when the window is fullscreen. To change the window size when the window is not fullscreen, use WindowBase.SetSize().

If the window is currently in the fullscreen state, this request is asynchronous on some windowing systems and the new mode dimensions may not be applied immediately upon the return of this function. If an immediate change is required, call WindowBase.Sync() to block until the changes have taken effect.

When the new mode takes effect, an EVENT_WINDOW_RESIZED and/or an EVENT_WINDOW_PIXEL_SIZE_CHANGED event will be emitted with the new mode dimensions.

Parameters
modethe display mode to use, which can be nullptr for borderless fullscreen desktop mode, or one of the fullscreen modes returned by Display.GetFullscreenModes() to set an exclusive fullscreen mode.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetFullscreenMode
WindowBase.SetFullscreen
WindowBase.Sync

◆ SetHitTest() [1/2]

void SDL::WindowBase::SetHitTest ( HitTest  callback,
void *  callback_data 
)
inline

Normally windows are dragged and resized by decorations provided by the system window manager (a title bar, borders, etc), but for some apps, it makes sense to drag them from somewhere else inside the window itself; for example, one might have a borderless window that wants to be draggable from any part, or simulate its own title bar, etc.

This function lets the app provide a callback that designates pieces of a given window as special. This callback is run during event processing if we need to tell the OS to treat a region of the window specially; the use of this callback is known as "hit testing."

Mouse input may not be delivered to your application if it is within a special area; the OS will often apply that input to moving the window or resizing the window and not deliver it to the application.

Specifying nullptr for a callback disables hit-testing. Hit-testing is disabled by default.

Platforms that don't support this functionality will return false unconditionally, even if you're attempting to disable hit-testing.

Your callback may fire at any time, and its firing does not indicate any specific behavior (for example, on Windows, this certainly might fire when the OS is deciding whether to drag your window, but it fires for lots of other reasons, too, some unrelated to anything you probably care about and when the mouse isn't actually at the location it is testing). Since this can fire at any time, you should try to keep your callback efficient, devoid of allocations, etc.

Parameters
callbackthe function to call when doing a hit-test.
callback_dataan app-defined void pointer passed to callback.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ SetHitTest() [2/2]

void SDL::WindowBase::SetHitTest ( HitTestCB  callback)
inline

Normally windows are dragged and resized by decorations provided by the system window manager (a title bar, borders, etc), but for some apps, it makes sense to drag them from somewhere else inside the window itself; for example, one might have a borderless window that wants to be draggable from any part, or simulate its own title bar, etc.

This function lets the app provide a callback that designates pieces of a given window as special. This callback is run during event processing if we need to tell the OS to treat a region of the window specially; the use of this callback is known as "hit testing."

Mouse input may not be delivered to your application if it is within a special area; the OS will often apply that input to moving the window or resizing the window and not deliver it to the application.

Specifying nullptr for a callback disables hit-testing. Hit-testing is disabled by default.

Platforms that don't support this functionality will return false unconditionally, even if you're attempting to disable hit-testing.

Your callback may fire at any time, and its firing does not indicate any specific behavior (for example, on Windows, this certainly might fire when the OS is deciding whether to drag your window, but it fires for lots of other reasons, too, some unrelated to anything you probably care about and when the mouse isn't actually at the location it is testing). Since this can fire at any time, you should try to keep your callback efficient, devoid of allocations, etc.

Parameters
callbackthe function to call when doing a hit-test.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
Category:
Listener callback

◆ SetIcon()

void SDL::WindowBase::SetIcon ( SurfaceBase icon)
inline

If this function is passed a surface with alternate representations, the surface will be interpreted as the content to be used for 100% display scale, and the alternate representations will be used for high DPI situations. For example, if the original surface is 32x32, then on a 2x macOS display or 200% display scale on Windows, a 64x64 version of the image will be used, if available. If a matching version of the image isn't available, the closest larger size image will be downscaled to the appropriate size and be used instead, if available. Otherwise, the closest smaller image will be upscaled and be used instead.

Parameters
iconan SurfaceBase structure containing the icon for the window.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ SetKeyboardGrab()

void SDL::WindowBase::SetKeyboardGrab ( bool  grabbed)
inline

Keyboard grab enables capture of system keyboard shortcuts like Alt+Tab or the Meta/Super key. Note that not all system keyboard shortcuts can be captured by applications (one example is Ctrl+Alt+Del on Windows).

This is primarily intended for specialized applications such as VNC clients or VM frontends. Normal games should not use keyboard grab.

When keyboard grab is enabled, SDL will continue to handle Alt+Tab when the window is full-screen to ensure the user is not trapped in your application. If you have a custom keyboard shortcut to exit fullscreen mode, you may suppress this behavior with SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED.

If the caller enables a grab while another window is currently grabbed, the other window loses its grab in favor of the caller's window.

Parameters
grabbedthis is true to grab keyboard, and false to release.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetKeyboardGrab
WindowBase.SetMouseGrab

◆ SetMaximumSize()

void SDL::WindowBase::SetMaximumSize ( SDL_Point  p)
inline
Parameters
pthe maximum width and height of the window, or 0 for no limit.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetMaximumSize
WindowBase.SetMinimumSize

◆ SetMinimumSize()

void SDL::WindowBase::SetMinimumSize ( SDL_Point  p)
inline
Parameters
pthe minimum width and height of the window, or 0 for no limit.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetMinimumSize
WindowBase.SetMaximumSize

◆ SetModal()

void SDL::WindowBase::SetModal ( bool  modal)
inline

To enable modal status on a window, the window must currently be the child window of a parent, or toggling modal status on will fail.

Parameters
modaltrue to toggle modal status on, false to toggle it off.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.SetParent
WINDOW_MODAL

◆ SetMouseGrab()

void SDL::WindowBase::SetMouseGrab ( bool  grabbed)
inline

Mouse grab confines the mouse cursor to the window.

Parameters
grabbedthis is true to grab mouse, and false to release.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetMouseRect
WindowBase.SetMouseRect
WindowBase.SetMouseGrab
WindowBase.SetKeyboardGrab

◆ SetMouseRect()

void SDL::WindowBase::SetMouseRect ( const SDL_Rect &  rect)
inline

Note that this does NOT grab the cursor, it only defines the area a cursor is restricted to when the window has mouse focus.

Parameters
recta rectangle area in window-relative coordinates. If nullptr the barrier for the specified window will be destroyed.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetMouseRect
WindowBase.GetMouseGrab
WindowBase.SetMouseGrab

◆ SetOpacity()

void SDL::WindowBase::SetOpacity ( float  opacity)
inline

The parameter opacity will be clamped internally between 0.0f (transparent) and 1.0f (opaque).

This function also returns false if setting the opacity isn't supported.

Parameters
opacitythe opacity value (0.0f - transparent, 1.0f - opaque).
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetOpacity

◆ SetParent()

void SDL::WindowBase::SetParent ( OptionalWindow  parent)

If the window is already the child of an existing window, it will be reparented to the new owner. Setting the parent window to nullptr unparents the window and removes child window status.

If a parent window is hidden or destroyed, the operation will be recursively applied to child windows. Child windows hidden with the parent that did not have their hidden status explicitly set will be restored when the parent is shown.

Attempting to set the parent of a window that is currently in the modal state will fail. Use WindowBase.SetModal() to cancel the modal status before attempting to change the parent.

Popup windows cannot change parents and attempts to do so will fail.

Setting a parent window that is currently the sibling or descendent of the child window results in undefined behavior.

Parameters
parentthe new parent window for the child window.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.SetModal

◆ SetPosition()

void SDL::WindowBase::SetPosition ( SDL_Point  p)
inline

If the window is in an exclusive fullscreen or maximized state, this request has no effect.

This can be used to reposition fullscreen-desktop windows onto a different display, however, as exclusive fullscreen windows are locked to a specific display, they can only be repositioned programmatically via WindowBase.SetFullscreenMode().

On some windowing systems this request is asynchronous and the new coordinates may not have have been applied immediately upon the return of this function. If an immediate change is required, call WindowBase.Sync() to block until the changes have taken effect.

When the window position changes, an EVENT_WINDOW_MOVED event will be emitted with the window's new coordinates. Note that the new coordinates may not match the exact coordinates requested, as some windowing systems can restrict the position of the window in certain scenarios (e.g. constraining the position so the window is always within desktop bounds). Additionally, as this is just a request, it can be denied by the windowing system.

Parameters
pthe x, y coordinate of the window, or WINDOWPOS_CENTERED or WINDOWPOS_UNDEFINED.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetPosition
WindowBase.Sync

◆ SetRect()

void SDL::WindowBase::SetRect ( Rect  rect)
inline
Parameters
rectthe rect containing the new coordinates
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
See also
WindowBase.SetPosition()
WindowBase.SetSize()

◆ SetResizable()

void SDL::WindowBase::SetResizable ( bool  resizable)
inline

This will add or remove the window's 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.

You can't change the resizable state of a fullscreen window.

Parameters
resizabletrue to allow resizing, false to disallow.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetFlags

◆ SetShape()

void SDL::WindowBase::SetShape ( SurfaceBase shape)
inline

This sets the alpha channel of a transparent window and any fully transparent areas are also transparent to mouse clicks. If you are using something besides the SDL render API, then you are responsible for drawing the alpha channel of the window to match the shape alpha channel to get consistent cross-platform results.

The shape is copied inside this function, so you can free it afterwards. If your shape surface changes, you should call WindowBase.SetShape() again to update the window. This is an expensive operation, so should be done sparingly.

The window must have been created with the WINDOW_TRANSPARENT flag.

Parameters
shapethe surface representing the shape of the window, or nullptr to remove any current shape.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ SetSize()

void SDL::WindowBase::SetSize ( SDL_Point  p)
inline

If the window is in a fullscreen or maximized state, this request has no effect.

To change the exclusive fullscreen mode of a window, use WindowBase.SetFullscreenMode().

On some windowing systems, this request is asynchronous and the new window size may not have have been applied immediately upon the return of this function. If an immediate change is required, call WindowBase.Sync() to block until the changes have taken effect.

When the window size changes, an EVENT_WINDOW_RESIZED event will be emitted with the new window dimensions. Note that the new dimensions may not match the exact size requested, as some windowing systems can restrict the window size in certain scenarios (e.g. constraining the size of the content area to remain within the usable desktop bounds). Additionally, as this is just a request, it can be denied by the windowing system.

Parameters
pthe width, height of the window, both must be > 0.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetSize
WindowBase.SetFullscreenMode
WindowBase.Sync

◆ SetSurfaceVSync()

void SDL::WindowBase::SetSurfaceVSync ( int  vsync)
inline

When a window surface is created, vsync defaults to SDL_WINDOW_SURFACE_VSYNC_DISABLED.

The vsync parameter can be 1 to synchronize present with every vertical refresh, 2 to synchronize present with every second vertical refresh, etc., SDL_WINDOW_SURFACE_VSYNC_ADAPTIVE for late swap tearing (adaptive vsync), or SDL_WINDOW_SURFACE_VSYNC_DISABLED to disable. Not every value is supported by every driver, so you should check the return value to see whether the requested setting is supported.

Parameters
vsyncthe vertical refresh sync interval.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetSurfaceVSync

◆ SetTitle()

void SDL::WindowBase::SetTitle ( StringParam  title)
inline

This string is expected to be in UTF-8 encoding.

Parameters
titlethe desired window title in UTF-8 format.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetTitle

◆ Show()

void SDL::WindowBase::Show ( )
inline
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.Hide
WindowBase.Raise

◆ ShowSystemMenu()

void SDL::WindowBase::ShowSystemMenu ( SDL_Point  p)
inline

This default window menu is provided by the system and on some platforms provides functionality for setting or changing privileged state on the window, such as moving it between workspaces or displays, or toggling the always-on-top property.

On platforms or desktops where this is unsupported, this function does nothing.

Parameters
pthe x, y coordinate of the menu, relative to the origin (top-left) of the client area.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.

◆ Sync()

void SDL::WindowBase::Sync ( )
inline

On asynchronous windowing systems, this acts as a synchronization barrier for pending window state. It will attempt to wait until any pending window state has been applied and is guaranteed to return within finite time. Note that for how long it can potentially block depends on the underlying window system, as window state changes may involve somewhat lengthy animations that must complete before the window is in its final requested state.

On windowing systems where changes are immediate, this does nothing.

Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.SetSize
WindowBase.SetPosition
WindowBase.SetFullscreen
WindowBase.Minimize
WindowBase.Maximize
WindowBase.Restore
SDL_HINT_VIDEO_SYNC_WINDOW_OPERATIONS

◆ UpdateSurface()

void SDL::WindowBase::UpdateSurface ( )
inline

This is the function you use to reflect any changes to the surface on the screen.

This function is equivalent to the SDL 1.2 API SDL_Flip().

Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetSurface
WindowBase.UpdateSurfaceRects

◆ UpdateSurfaceRects()

void SDL::WindowBase::UpdateSurfaceRects ( SpanRef< const SDL_Rect >  rects)
inline

This is the function you use to reflect changes to portions of the surface on the screen.

This function is equivalent to the SDL 1.2 API SDL_UpdateRects().

Note that this function will update at least the rectangles specified, but this is only intended as an optimization; in practice, this might update more of the screen (or all of the screen!), depending on what method SDL uses to send pixels to the system.

Parameters
rectsan array of Rect structures representing areas of the surface to copy, in pixels.
Exceptions
Erroron failure.
Thread safety:
This function should only be called on the main thread.
Since
This function is available since SDL 3.2.0.
See also
WindowBase.GetSurface
WindowBase.UpdateSurface

The documentation for this struct was generated from the following files: