FreeRDP
Loading...
Searching...
No Matches
SdlWindow Class Reference

#include <sdl_window.hpp>

Public Member Functions

 SdlWindow (const std::string &title, Sint32 startupX, Sint32 startupY, Sint32 width, Sint32 height, Uint32 flags)
 SdlWindow (const SdlWindow &other)=delete
 SdlWindow (SdlWindow &&other) noexcept
SdlWindow & operator= (const SdlWindow &other)=delete
SdlWindow & operator= (SdlWindow &&other)=delete
Uint32 id () const
int displayIndex () const
SDL_Rect rect () const
SDL_Window * window () const
Sint32 offsetX () const
void setOffsetX (Sint32 x)
void setOffsetY (Sint32 y)
Sint32 offsetY () const
bool grabKeyboard (bool enable)
bool grabMouse (bool enable)
void setBordered (bool bordered)
void raise ()
void resizeable (bool use)
void fullscreen (bool enter)
void minimize ()
bool fill (Uint8 r=0x00, Uint8 g=0x00, Uint8 b=0x00, Uint8 a=0xff)
bool blit (SDL_Surface *surface, SDL_Rect src, SDL_Rect &dst)
void updateSurface ()
 SdlWindow (SdlWindow &&other) noexcept
 SdlWindow (const SdlWindow &other)=delete
SdlWindow & operator= (const SdlWindow &other)=delete
SdlWindow & operator= (SdlWindow &&other)=delete
SDL_WindowID id () const
SDL_DisplayID displayIndex () const
SDL_Rect rect () const
SDL_Rect bounds () const
SDL_Window * window () const
SDL_Renderer * renderer () const
Sint32 offsetX () const
void setOffsetX (Sint32 x)
void setOffsetY (Sint32 y)
Sint32 offsetY () const
rdpMonitor monitor (bool isPrimary) const
void setMonitor (rdpMonitor monitor)
float scale () const
SDL_DisplayOrientation orientation () const
bool grabKeyboard (bool enable)
bool grabMouse (bool enable)
void setBordered (bool bordered)
void raise ()
void resizeable (bool use)
void fullscreen (bool enter, bool forceOriginalDisplay)
void minimize ()
bool resizeToScale ()
bool resize (const SDL_Point &size)
bool drawRect (SDL_Surface *surface, SDL_Point offset, const SDL_Rect &srcRect)
bool drawRects (SDL_Surface *surface, SDL_Point offset, const std::vector< SDL_Rect > &rects={})
bool drawScaledRect (SDL_Surface *surface, const SDL_FPoint &scale, const SDL_Rect &srcRect)
bool drawScaledRects (SDL_Surface *surface, const SDL_FPoint &scale, const std::vector< SDL_Rect > &rects={})
bool fill (Uint8 r=0x00, Uint8 g=0x00, Uint8 b=0x00, Uint8 a=0xff)
bool blit (SDL_Surface *surface, const SDL_Rect &src, SDL_Rect &dst)
bool upload (SDL_Surface *surface, const SDL_Rect &src)
bool render (const SDL_Rect &src, const SDL_Rect &dst)
bool paintResizeFrame (SDL_Surface *surface, SDL_Point off, bool contentChanged, const SDL_Rect &inset={ 0, 0, 0, 0 }, bool fillRevealed=true, bool dashedBorder=true)
void updateSurface (const SdlOverlay *overlay=nullptr)
const char * rendererName () const
bool setVideoOverlay (Uint64 id, const void *pixels, int pitch, int w, int h, const SDL_FRect &dst, const std::vector< SDL_FRect > &clip, bool visible)
 redirected video id, drawn over the session at each present at dst (render coordinates), only in clip (render coordinates) when not empty: what the page draws over the video (player controls) stays visible. pixels (BGRA, wxh) is uploaded when not null
void pruneVideoOverlays (const std::function< bool(Uint64)> &keep)
 drops the overlays keep returns false for

Static Public Member Functions

static SdlWindow create (SDL_DisplayID id, const std::string &title, Uint32 flags, Uint32 width=0, Uint32 height=0)
static SdlWindow create (SDL_DisplayID id, const std::string &title, Uint32 flags, const SDL_Rect &rect)
static SdlWindow createPopup (SDL_Window *parent, const SDL_Rect &rect, bool transparent, bool tooltip=false)
static rdpMonitor query (SDL_DisplayID id, bool forceAsPrimary=false)

Protected Types

enum  HighDPIMode { MODE_INVALID , MODE_NONE , MODE_WINDOWS , MODE_MACOS }

Protected Member Functions

 SdlWindow (SDL_DisplayID id, const std::string &title, const SDL_Rect &rect, Uint32 flags)
 SdlWindow (SDL_Window *parent, const SDL_Rect &rect, bool transparent, bool tooltip)

Static Protected Member Functions

static bool fill (SDL_Window *window, Uint8 r=0x00, Uint8 g=0x00, Uint8 b=0x00, Uint8 a=0xff)
static rdpMonitor query (SDL_Window *window, SDL_DisplayID id, bool forceAsPrimary=false)
static SDL_Rect rect (SDL_Window *window, bool forceAsPrimary=false)
static SDL_Rect rect (SDL_DisplayID id, bool forceAsPrimary=false)
static bool tryFallback (bool isFullscreen)
static enum HighDPIMode isHighDPIWindowsMode (SDL_Window *window)

Detailed Description

FreeRDP: A Remote Desktop Protocol Implementation SDL Client

Copyright 2023 Armin Novak armin.nosp@m..nov.nosp@m.ak@th.nosp@m.inca.nosp@m.st.co.nosp@m.m Copyright 2023 Thincast Technologies GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition at line 25 of file SDL2/sdl_window.hpp.

Member Enumeration Documentation

◆ HighDPIMode

enum SdlWindow::HighDPIMode
protected

Definition at line 130 of file SDL3/sdl_window.hpp.

131 {
132 MODE_INVALID,
133 MODE_NONE,
134 MODE_WINDOWS,
135 MODE_MACOS
136 };

Constructor & Destructor Documentation

◆ SdlWindow() [1/4]

SdlWindow::SdlWindow ( const std::string & title,
Sint32 startupX,
Sint32 startupY,
Sint32 width,
Sint32 height,
Uint32 flags )

FreeRDP: A Remote Desktop Protocol Implementation SDL Client

Copyright 2023 Armin Novak armin.nosp@m..nov.nosp@m.ak@th.nosp@m.inca.nosp@m.st.co.nosp@m.m Copyright 2023 Thincast Technologies GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition at line 23 of file SDL2/sdl_window.cpp.

25 : _window(SDL_CreateWindow(title.c_str(), startupX, startupY, width, height, flags))
26{
27}

◆ SdlWindow() [2/4]

SdlWindow::SdlWindow ( SdlWindow && other)
noexcept

Definition at line 29 of file SDL2/sdl_window.cpp.

30 : _window(other._window), _offset_x(other._offset_x), _offset_y(other._offset_y)
31{
32 other._window = nullptr;
33}

◆ ~SdlWindow()

SdlWindow::~SdlWindow ( )

Definition at line 35 of file SDL2/sdl_window.cpp.

36{
37 SDL_DestroyWindow(_window);
38}

◆ SdlWindow() [3/4]

SdlWindow::SdlWindow ( SDL_DisplayID id,
const std::string & title,
const SDL_Rect & rect,
Uint32 flags )
protected

FreeRDP: A Remote Desktop Protocol Implementation SDL Client

Copyright 2023 Armin Novak armin.nosp@m..nov.nosp@m.ak@th.nosp@m.inca.nosp@m.st.co.nosp@m.m Copyright 2023 Thincast Technologies GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition at line 30 of file SDL3/sdl_window.cpp.

32 : _initialW(rect.w), _initialH(rect.h), _displayID(id)
33{
34 float pd = SDL_GetDisplayContentScale(id);
35 if (pd <= 0.0f)
36 pd = 1.0f;
37 const int createW = static_cast<int>(std::ceil(static_cast<float>(rect.w) / pd));
38 const int createH = static_cast<int>(std::ceil(static_cast<float>(rect.h) / pd));
39
40 auto props = SDL_CreateProperties();
41 SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, title.c_str());
42 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, rect.x);
43 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, rect.y);
44 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, createW);
45 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, createH);
46 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_RESIZABLE_BOOLEAN, true);
47
48 if (flags & SDL_WINDOW_HIGH_PIXEL_DENSITY)
49 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_HIGH_PIXEL_DENSITY_BOOLEAN, true);
50
51 if (flags & SDL_WINDOW_FULLSCREEN)
52 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_FULLSCREEN_BOOLEAN, true);
53
54 if (flags & SDL_WINDOW_BORDERLESS)
55 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_BORDERLESS_BOOLEAN, true);
56
57 if (flags & SDL_WINDOW_TRANSPARENT)
58 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_TRANSPARENT_BOOLEAN, true);
59
60 /* RAIL windows are created hidden until first paint to avoid black flash. */
61 if (flags & SDL_WINDOW_HIDDEN)
62 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_HIDDEN_BOOLEAN, true);
63
64 _window = SDL_CreateWindowWithProperties(props);
65 SDL_DestroyProperties(props);
66 SDL_SetHint(SDL_HINT_APP_NAME, "");
67 std::ignore = SDL_SyncWindow(_window);
68
69 _renderer = SDL_CreateRenderer(_window, nullptr);
70
71 std::ignore = resizeToScale();
72
73 _monitor = query(_window, id, true);
74}

◆ SdlWindow() [4/4]

SdlWindow::SdlWindow ( SDL_Window * parent,
const SDL_Rect & rect,
bool transparent,
bool tooltip )
protected

Definition at line 894 of file SDL3/sdl_window.cpp.

895 : _initialW(rect.w), _initialH(rect.h)
896{
897 auto props = SDL_CreateProperties();
898 SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_PARENT_POINTER, parent);
899 SDL_SetBooleanProperty(props,
900 tooltip ? SDL_PROP_WINDOW_CREATE_TOOLTIP_BOOLEAN
901 : SDL_PROP_WINDOW_CREATE_MENU_BOOLEAN,
902 true);
903 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN, false);
904#if defined(SDL_PROP_WINDOW_CREATE_CONSTRAIN_POPUP_BOOLEAN)
905 /* The server places RemoteApp popups; a moved one would map clicks to other points. */
906 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_CONSTRAIN_POPUP_BOOLEAN, false);
907#endif
908 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_BORDERLESS_BOOLEAN, true);
909 /* Transparent so menus' genuine per-pixel alpha (corners/shadow) isn't rendered black. */
910 if (transparent)
911 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_TRANSPARENT_BOOLEAN, true);
912 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, rect.x);
913 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, rect.y);
914 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, rect.w);
915 SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, rect.h);
916 /* Hidden until first paint, like the app constructor. */
917 SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_HIDDEN_BOOLEAN, true);
918
919 _window = SDL_CreateWindowWithProperties(props);
920 SDL_DestroyProperties(props);
921 if (_window)
922 {
923 std::ignore = SDL_SyncWindow(_window);
924 _renderer = SDL_CreateRenderer(_window, nullptr);
925 _displayID = SDL_GetDisplayForWindow(_window);
926 }
927}

Member Function Documentation

◆ blit() [1/2]

bool SdlWindow::blit ( SDL_Surface * surface,
const SDL_Rect & src,
SDL_Rect & dst )
nodiscard

Definition at line 615 of file SDL3/sdl_window.cpp.

616{
617 return upload(surface, srcRect) && render(srcRect, dstRect);
618}

◆ blit() [2/2]

bool SdlWindow::blit ( SDL_Surface * surface,
SDL_Rect src,
SDL_Rect & dst )

Definition at line 187 of file SDL2/sdl_window.cpp.

188{
189 auto screen = SDL_GetWindowSurface(_window);
190 if (!screen || !surface)
191 return false;
192 if (!SDL_SetClipRect(surface, &srcRect))
193 return true;
194 if (!SDL_SetClipRect(screen, &dstRect))
195 return true;
196 auto rc = SDL_BlitScaled(surface, &srcRect, screen, &dstRect);
197 if (rc != 0)
198 {
199 SDL_LogError(SDL_LOG_CATEGORY_RENDER, "SDL_BlitScaled: %s [%d]", sdl_error_string(rc), rc);
200 }
201 return rc == 0;
202}

◆ bounds()

SDL_Rect SdlWindow::bounds ( ) const
nodiscard

Definition at line 126 of file SDL3/sdl_window.cpp.

127{
128 SDL_Rect rect = {};
129 if (_window)
130 {
131 if (!SDL_GetWindowPosition(_window, &rect.x, &rect.y))
132 return {};
133 if (!SDL_GetWindowSize(_window, &rect.w, &rect.h))
134 return {};
135 }
136 return rect;
137}

◆ create() [1/2]

SdlWindow SdlWindow::create ( SDL_DisplayID id,
const std::string & title,
Uint32 flags,
const SDL_Rect & rect )
staticnodiscard

Definition at line 887 of file SDL3/sdl_window.cpp.

889{
890 return SdlWindow{ id, title, rect, flags };
891}
SdlWindow(const std::string &title, Sint32 startupX, Sint32 startupY, Sint32 width, Sint32 height, Uint32 flags)

◆ create() [2/2]

SdlWindow SdlWindow::create ( SDL_DisplayID id,
const std::string & title,
Uint32 flags,
Uint32 width = 0,
Uint32 height = 0 )
staticnodiscard

Definition at line 862 of file SDL3/sdl_window.cpp.

864{
865 flags |= SDL_WINDOW_HIGH_PIXEL_DENSITY;
866
867 SDL_Rect rect = { static_cast<int>(SDL_WINDOWPOS_CENTERED_DISPLAY(id)),
868 static_cast<int>(SDL_WINDOWPOS_CENTERED_DISPLAY(id)), static_cast<int>(width),
869 static_cast<int>(height) };
870
871 if ((flags & SDL_WINDOW_FULLSCREEN) != 0)
872 {
873 std::ignore = SDL_GetDisplayBounds(id, &rect);
874 }
875
876 SdlWindow window{ id, title, rect, flags };
877
878 if ((flags & SDL_WINDOW_FULLSCREEN) != 0)
879 {
880 window.setOffsetX(rect.x);
881 window.setOffsetY(rect.y);
882 }
883
884 return window;
885}

◆ createPopup()

SdlWindow SdlWindow::createPopup ( SDL_Window * parent,
const SDL_Rect & rect,
bool transparent,
bool tooltip = false )
staticnodiscard

Definition at line 929 of file SDL3/sdl_window.cpp.

931{
932 return SdlWindow{ parent, rect, transparent, tooltip };
933}

◆ displayIndex()

SDL_DisplayID SdlWindow::displayIndex ( ) const
nodiscard

Definition at line 47 of file SDL2/sdl_window.cpp.

48{
49 if (!_window)
50 return 0;
51 return SDL_GetWindowDisplayIndex(_window);
52}

◆ drawRect()

bool SdlWindow::drawRect ( SDL_Surface * surface,
SDL_Point offset,
const SDL_Rect & srcRect )
nodiscard

Definition at line 327 of file SDL3/sdl_window.cpp.

328{
329 WINPR_ASSERT(surface);
330 SDL_Rect dstRect = { offset.x + srcRect.x, offset.y + srcRect.y, srcRect.w, srcRect.h };
331 return blit(surface, srcRect, dstRect);
332}

◆ drawRects()

bool SdlWindow::drawRects ( SDL_Surface * surface,
SDL_Point offset,
const std::vector< SDL_Rect > & rects = {} )
nodiscard

Definition at line 334 of file SDL3/sdl_window.cpp.

336{
337 if (rects.empty())
338 {
339 return drawRect(surface, offset, { 0, 0, surface->w, surface->h });
340 }
341 for (auto& srcRect : rects)
342 {
343 if (!drawRect(surface, offset, srcRect))
344 return false;
345 }
346 return true;
347}

◆ drawScaledRect()

bool SdlWindow::drawScaledRect ( SDL_Surface * surface,
const SDL_FPoint & scale,
const SDL_Rect & srcRect )
nodiscard

Definition at line 365 of file SDL3/sdl_window.cpp.

367{
368 auto dstRect = scaledDstRect(scale, srcRect);
369 return blit(surface, srcRect, dstRect);
370}

◆ drawScaledRects()

bool SdlWindow::drawScaledRects ( SDL_Surface * surface,
const SDL_FPoint & scale,
const std::vector< SDL_Rect > & rects = {} )
nodiscard

Definition at line 372 of file SDL3/sdl_window.cpp.

374{
375 if (rects.empty())
376 {
377 return drawScaledRect(surface, scale, { 0, 0, surface->w, surface->h });
378 }
379
380 /* Upload every dirty rect before drawing any of them: scaling filters linearly, so the
381 * edge of each drawn rect also samples the texels just outside it. Drawn one by one,
382 * those can be a neighbouring dirty rect that is not uploaded yet, and the old picture
383 * stays behind as a faint line along the edge until that area changes again. */
384 for (const auto& srcRect : rects)
385 {
386 if (!upload(surface, srcRect))
387 return false;
388 }
389 for (const auto& srcRect : rects)
390 {
391 if (!render(srcRect, scaledDstRect(scale, srcRect)))
392 return false;
393 }
394 return true;
395}

◆ fill() [1/2]

bool SdlWindow::fill ( SDL_Window * window,
Uint8 r = 0x00,
Uint8 g = 0x00,
Uint8 b = 0x00,
Uint8 a = 0xff )
staticnodiscardprotected

Definition at line 411 of file SDL3/sdl_window.cpp.

412{
413 auto surface = SDL_GetWindowSurface(window);
414 if (!surface)
415 return false;
416 SDL_Rect rect = { 0, 0, surface->w, surface->h };
417 auto color = SDL_MapSurfaceRGBA(surface, r, g, b, a);
418
419 return SDL_FillSurfaceRect(surface, &rect, color);
420}

◆ fill() [2/2]

bool SdlWindow::fill ( Uint8 r = 0x00,
Uint8 g = 0x00,
Uint8 b = 0x00,
Uint8 a = 0xff )

Definition at line 175 of file SDL2/sdl_window.cpp.

176{
177 auto surface = SDL_GetWindowSurface(_window);
178 if (!surface)
179 return false;
180 SDL_Rect rect = { 0, 0, surface->w, surface->h };
181 auto color = SDL_MapRGBA(surface->format, r, g, b, a);
182
183 SDL_FillRect(surface, &rect, color);
184 return true;
185}

◆ fullscreen() [1/2]

void SdlWindow::fullscreen ( bool enter)

Definition at line 131 of file SDL2/sdl_window.cpp.

132{
133 auto curFlags = SDL_GetWindowFlags(_window);
134
135 if (enter)
136 {
137 if (!(curFlags & SDL_WINDOW_BORDERLESS))
138 {
139 auto idx = SDL_GetWindowDisplayIndex(_window);
140 SDL_DisplayMode mode = {};
141 SDL_GetCurrentDisplayMode(idx, &mode);
142
143 SDL_RestoreWindow(_window); // Maximize so we can see the caption and
144 // bits
145 SDL_SetWindowBordered(_window, SDL_FALSE);
146 SDL_SetWindowPosition(_window, 0, 0);
147#if SDL_VERSION_ATLEAST(2, 0, 16)
148 SDL_SetWindowAlwaysOnTop(_window, SDL_TRUE);
149#endif
150 SDL_RaiseWindow(_window);
151 SDL_SetWindowSize(_window, mode.w, mode.h);
152 }
153 }
154 else
155 {
156 if (curFlags & SDL_WINDOW_BORDERLESS)
157 {
158
159 SDL_SetWindowBordered(_window, SDL_TRUE);
160#if SDL_VERSION_ATLEAST(2, 0, 16)
161 SDL_SetWindowAlwaysOnTop(_window, SDL_FALSE);
162#endif
163 SDL_RaiseWindow(_window);
164 SDL_MinimizeWindow(_window); // Maximize so we can see the caption and bits
165 SDL_MaximizeWindow(_window); // Maximize so we can see the caption and bits
166 }
167 }
168}

◆ fullscreen() [2/2]

void SdlWindow::fullscreen ( bool enter,
bool forceOriginalDisplay )

Definition at line 233 of file SDL3/sdl_window.cpp.

234{
235 if (enter && forceOriginalDisplay && _displayID != 0)
236 {
237 /* Move the window to the desired display. We should not wait
238 * for the window to be moved, because some backends can refuse
239 * the move. The intent of moving the window is enough for SDL
240 * to decide which display will be used for fullscreen. */
241 SDL_Rect rect = {};
242 std::ignore = SDL_GetDisplayBounds(_displayID, &rect);
243 std::ignore = SDL_SetWindowPosition(_window, rect.x, rect.y);
244 }
245 std::ignore = SDL_SetWindowFullscreen(_window, enter);
246 std::ignore = SDL_SyncWindow(_window);
247}

◆ grabKeyboard()

bool SdlWindow::grabKeyboard ( bool enable)

Definition at line 90 of file SDL2/sdl_window.cpp.

91{
92 if (!_window)
93 return false;
94#if SDL_VERSION_ATLEAST(2, 0, 16)
95 SDL_SetWindowKeyboardGrab(_window, enable ? SDL_TRUE : SDL_FALSE);
96 return true;
97#else
98 SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Keyboard grabbing not supported by SDL2 < 2.0.16");
99 return false;
100#endif
101}

◆ grabMouse()

bool SdlWindow::grabMouse ( bool enable)

Definition at line 103 of file SDL2/sdl_window.cpp.

104{
105 if (!_window)
106 return false;
107#if SDL_VERSION_ATLEAST(2, 0, 16)
108 SDL_SetWindowMouseGrab(_window, enable ? SDL_TRUE : SDL_FALSE);
109#else
110 SDL_SetWindowGrab(_window, enable ? SDL_TRUE : SDL_FALSE);
111#endif
112 return true;
113}

◆ id()

SDL_WindowID SdlWindow::id ( ) const
nodiscard

Definition at line 40 of file SDL2/sdl_window.cpp.

41{
42 if (!_window)
43 return 0;
44 return SDL_GetWindowID(_window);
45}

◆ isHighDPIWindowsMode()

SdlWindow::HighDPIMode SdlWindow::isHighDPIWindowsMode ( SDL_Window * window)
staticnodiscardprotected

Definition at line 570 of file SDL3/sdl_window.cpp.

571{
572 if (!window)
573 return MODE_INVALID;
574
575 const auto id = SDL_GetDisplayForWindow(window);
576 if (id == 0)
577 return MODE_INVALID;
578
579 const auto cs = SDL_GetDisplayContentScale(id);
580 const auto ds = SDL_GetWindowDisplayScale(window);
581 const auto pd = SDL_GetWindowPixelDensity(window);
582
583 /* mac os x style, but no HighDPI display */
584 if ((cs == 1.0f) && (ds == 1.0f) && (pd == 1.0f))
585 return MODE_NONE;
586
587 /* mac os x style HighDPI */
588 if ((cs == 1.0f) && (ds > 1.0f) && (pd > 1.0f))
589 return MODE_MACOS;
590
591 /* rest is windows style */
592 return MODE_WINDOWS;
593}

◆ minimize()

void SdlWindow::minimize ( )

Definition at line 170 of file SDL2/sdl_window.cpp.

171{
172 SDL_MinimizeWindow(_window);
173}

◆ monitor()

rdpMonitor SdlWindow::monitor ( bool isPrimary) const
nodiscard

Definition at line 169 of file SDL3/sdl_window.cpp.

170{
171 auto m = _monitor;
172 if (isPrimary)
173 {
174 m.x = 0;
175 m.y = 0;
176 }
177 return m;
178}

◆ offsetX()

Sint32 SdlWindow::offsetX ( ) const
nodiscard

Definition at line 70 of file SDL2/sdl_window.cpp.

71{
72 return _offset_x;
73}

◆ offsetY()

Sint32 SdlWindow::offsetY ( ) const
nodiscard

Definition at line 85 of file SDL2/sdl_window.cpp.

86{
87 return _offset_y;
88}

◆ orientation()

SDL_DisplayOrientation SdlWindow::orientation ( ) const
nodiscard

Definition at line 190 of file SDL3/sdl_window.cpp.

191{
192 const auto did = displayIndex();
193 return SDL_GetCurrentDisplayOrientation(did);
194}

◆ paintResizeFrame()

bool SdlWindow::paintResizeFrame ( SDL_Surface * surface,
SDL_Point off,
bool contentChanged,
const SDL_Rect & inset = { 0, 0, 0, 0 },
bool fillRevealed = true,
bool dashedBorder = true )

Definition at line 777 of file SDL3/sdl_window.cpp.

779{
780 if (!_renderer || !surface)
781 return false;
782 ensureRenderTarget();
783
784 const int prevW = _gdiTextureW;
785 const int prevH = _gdiTextureH;
786 if (!ensureGdiTexture(surface))
787 return false;
788 /* A recreated texture is empty, so upload even when the content did not change. */
789 const bool recreated = (_gdiTextureW != prevW) || (_gdiTextureH != prevH);
790 if ((contentChanged || recreated) &&
791 !SDL_UpdateTexture(_gdiTexture, nullptr, surface->pixels, surface->pitch))
792 return false;
793
794 if (!SDL_SetRenderTarget(_renderer, _renderTarget))
795 return false;
796
797 int ww = 0;
798 int wh = 0;
799 SDL_GetWindowSizeInPixels(_window, &ww, &wh);
800 /* The visible frame; the ring outside it (the resize band) stays fully transparent. */
801 const SDL_FRect frame = { static_cast<float>(inset.x), static_cast<float>(inset.y),
802 static_cast<float>(ww - inset.x - inset.w),
803 static_cast<float>(wh - inset.y - inset.h) };
804
805 /* Translucent fill in revealed area awaiting server frame. */
806 constexpr Uint8 kFillAlpha = 0x80;
807 std::ignore = SDL_SetRenderDrawBlendMode(_renderer, SDL_BLENDMODE_NONE);
808 std::ignore = SDL_SetRenderDrawColor(_renderer, 0, 0, 0, 0);
809 std::ignore = SDL_RenderClear(_renderer);
810 if (fillRevealed)
811 {
812 std::ignore = SDL_SetRenderDrawColor(_renderer, 0x2B, 0x2B, 0x2B, kFillAlpha);
813 std::ignore = SDL_RenderFillRect(_renderer, &frame);
814 }
815 SDL_FRect fdst = { static_cast<float>(off.x), static_cast<float>(off.y),
816 static_cast<float>(surface->w), static_cast<float>(surface->h) };
817 /* Anchored frame clipped to visible bounds. */
818 const SDL_Rect clip = { inset.x, inset.y, ww - inset.x - inset.w, wh - inset.y - inset.h };
819 std::ignore = SDL_SetRenderClipRect(_renderer, &clip);
820 std::ignore = SDL_RenderTexture(_renderer, _gdiTexture, nullptr, &fdst);
821 std::ignore = SDL_SetRenderClipRect(_renderer, nullptr);
822
823 /* Dashed border indicating pending resize target. */
824 if (dashedBorder)
825 {
826 std::ignore = SDL_SetRenderDrawColor(_renderer, 0xC8, 0xC8, 0xC8, 0xFF);
827 const float dash = 8.0F;
828 const float gap = 5.0F;
829 const float fx2 = frame.x + frame.w;
830 const float fy2 = frame.y + frame.h;
831 const float lo = frame.y + 0.5F;
832 const float by = fy2 - 0.5F;
833 const float lx = frame.x + 0.5F;
834 const float rx = fx2 - 0.5F;
835 const float step = dash + gap;
836 const auto steps = [step](float len)
837 { return (len <= 0.0F) ? 0 : static_cast<int>(std::ceil(len / step)); };
838 for (int i = 0; i < steps(fx2 - frame.x); i++)
839 {
840 const float x = frame.x + (static_cast<float>(i) * step);
841 const float x2 = (x + dash < fx2) ? (x + dash) : rx;
842 std::ignore = SDL_RenderLine(_renderer, x, lo, x2, lo);
843 std::ignore = SDL_RenderLine(_renderer, x, by, x2, by);
844 }
845 for (int i = 0; i < steps(fy2 - frame.y); i++)
846 {
847 const float y = frame.y + (static_cast<float>(i) * step);
848 const float y2 = (y + dash < fy2) ? (y + dash) : by;
849 std::ignore = SDL_RenderLine(_renderer, lx, y, lx, y2);
850 std::ignore = SDL_RenderLine(_renderer, rx, y, rx, y2);
851 }
852 }
853
854 if (!SDL_SetRenderTarget(_renderer, nullptr))
855 return false;
856 std::ignore = SDL_RenderTexture(_renderer, _renderTarget, nullptr, nullptr);
857 drawVideoOverlays();
858 std::ignore = SDL_RenderPresent(_renderer);
859 return true;
860}

◆ pruneVideoOverlays()

void SdlWindow::pruneVideoOverlays ( const std::function< bool(Uint64)> & keep)

drops the overlays keep returns false for

Definition at line 746 of file SDL3/sdl_window.cpp.

747{
748 for (auto it = _videoOverlays.begin(); it != _videoOverlays.end();)
749 {
750 if (keep(it->first))
751 ++it;
752 else
753 {
754 SDL_DestroyTexture(it->second.texture);
755 it = _videoOverlays.erase(it);
756 }
757 }
758}

◆ query() [1/2]

rdpMonitor SdlWindow::query ( SDL_DisplayID id,
bool forceAsPrimary = false )
staticnodiscard

Definition at line 972 of file SDL3/sdl_window.cpp.

973{
974 if (sdl::utils::isWaylandDriver() || sdl::utils::isX11Driver())
975 return queryDisplay(id, forceAsPrimary);
976
977 std::unique_ptr<SDL_Window, void (*)(SDL_Window*)> window(createDummy(id), SDL_DestroyWindow);
978 if (!window)
979 return {};
980
981 std::unique_ptr<SDL_Renderer, void (*)(SDL_Renderer*)> renderer(
982 SDL_CreateRenderer(window.get(), nullptr), SDL_DestroyRenderer);
983
984 if (!SDL_SyncWindow(window.get()))
985 return {};
986
987 SDL_Event event{};
988 while (SDL_PollEvent(&event))
989 ;
990
991 return query(window.get(), id, forceAsPrimary);
992}

◆ query() [2/2]

rdpMonitor SdlWindow::query ( SDL_Window * window,
SDL_DisplayID id,
bool forceAsPrimary = false )
staticnodiscardprotected

Definition at line 476 of file SDL3/sdl_window.cpp.

477{
478 if (!window)
479 return {};
480 return makeMonitor(id, rect(window, forceAsPrimary), SDL_GetWindowDisplayScale(window),
481 forceAsPrimary);
482}

◆ raise()

void SdlWindow::raise ( )

Definition at line 121 of file SDL2/sdl_window.cpp.

122{
123 SDL_RaiseWindow(_window);
124}

◆ rect() [1/3]

SDL_Rect SdlWindow::rect ( ) const
nodiscard

Definition at line 54 of file SDL2/sdl_window.cpp.

55{
56 SDL_Rect rect = {};
57 if (_window)
58 {
59 SDL_GetWindowPosition(_window, &rect.x, &rect.y);
60 SDL_GetWindowSize(_window, &rect.w, &rect.h);
61 }
62 return rect;
63}

◆ rect() [2/3]

SDL_Rect SdlWindow::rect ( SDL_DisplayID id,
bool forceAsPrimary = false )
staticnodiscardprotected

Definition at line 994 of file SDL3/sdl_window.cpp.

995{
996 std::unique_ptr<SDL_Window, void (*)(SDL_Window*)> window(createDummy(id), SDL_DestroyWindow);
997 if (!window)
998 return {};
999
1000 std::unique_ptr<SDL_Renderer, void (*)(SDL_Renderer*)> renderer(
1001 SDL_CreateRenderer(window.get(), nullptr), SDL_DestroyRenderer);
1002
1003 if (!SDL_SyncWindow(window.get()))
1004 return {};
1005
1006 SDL_Event event{};
1007 while (SDL_PollEvent(&event))
1008 ;
1009
1010 return rect(window.get(), forceAsPrimary);
1011}

◆ rect() [3/3]

SDL_Rect SdlWindow::rect ( SDL_Window * window,
bool forceAsPrimary = false )
staticnodiscardprotected

Definition at line 504 of file SDL3/sdl_window.cpp.

505{
506 SDL_Rect rect = {};
507 if (!window)
508 return {};
509
510 if (!forceAsPrimary)
511 {
512 if (!SDL_GetWindowPosition(window, &rect.x, &rect.y))
513 return {};
514 }
515
516 if (!SDL_GetWindowSizeInPixels(window, &rect.w, &rect.h))
517 return {};
518
519 const bool placeholder = (rect.w < 200) || (rect.h < 200);
520 if (placeholder && tryFallback(true))
521 {
522 /* On wlroots compositors (Sway, river, etc.), windows that are hidden/unmapped
523 * don't get their actual display dimensions. The dummy window returns its creation size
524 * (64x64) instead of the display size. This causes validation errors since we require >=
525 * 200px. Workaround: If we got dimensions that are too small, query the display directly.
526 */
527
528 const auto displayID = SDL_GetDisplayForWindow(window);
529 SDL_Rect displayBounds = {};
530 if (SDL_GetDisplayBounds(displayID, &displayBounds))
531 {
532 if (forceAsPrimary)
533 {
534 rect.x = 0;
535 rect.y = 0;
536 }
537 else
538 {
539 /* The dummy window is centered on the display by the compositor, so its
540 * position is not the display origin. Use the display bounds as for w/h. */
541 rect.x = displayBounds.x;
542 rect.y = displayBounds.y;
543 }
544 rect.w = displayBounds.w;
545 rect.h = displayBounds.h;
546
547 float factor = 1.0f;
548 const auto mode = SDL_GetCurrentDisplayMode(displayID);
549 if (mode && (mode->pixel_density > 1.0f))
550 factor = mode->pixel_density;
551 else
552 {
553 const float contentScale = SDL_GetDisplayContentScale(displayID);
554 if (contentScale > 1.0f)
555 factor = contentScale;
556 }
557 if (factor > 1.0f)
558 {
559 const auto fw = static_cast<float>(rect.w);
560 const auto fh = static_cast<float>(rect.h);
561 rect.w = static_cast<int>(std::roundf(fw * factor));
562 rect.h = static_cast<int>(std::roundf(fh * factor));
563 }
564 }
565 }
566
567 return rect;
568}

◆ render()

bool SdlWindow::render ( const SDL_Rect & src,
const SDL_Rect & dst )
nodiscard

Definition at line 643 of file SDL3/sdl_window.cpp.

644{
645 if (!_renderer || !_gdiTexture)
646 return false;
647
648 /* Render onto persistent render target to accumulate dirty rects */
649 if (!SDL_SetRenderTarget(_renderer, _renderTarget))
650 return false;
651
652 SDL_FRect fsrc = { static_cast<float>(srcRect.x), static_cast<float>(srcRect.y),
653 static_cast<float>(srcRect.w), static_cast<float>(srcRect.h) };
654 SDL_FRect fdst = { static_cast<float>(dstRect.x), static_cast<float>(dstRect.y),
655 static_cast<float>(dstRect.w), static_cast<float>(dstRect.h) };
656 if (!SDL_RenderTexture(_renderer, _gdiTexture, &fsrc, &fdst))
657 {
658 SDL_LogError(SDL_LOG_CATEGORY_RENDER, "SDL_RenderTexture: %s", SDL_GetError());
659 return false;
660 }
661 return true;
662}

◆ renderer()

SDL_Renderer * SdlWindow::renderer ( ) const
nodiscard

Definition at line 144 of file SDL3/sdl_window.cpp.

145{
146 return _renderer;
147}

◆ rendererName()

const char * SdlWindow::rendererName ( ) const
nodiscard

Definition at line 760 of file SDL3/sdl_window.cpp.

761{
762 return _renderer ? SDL_GetRendererName(_renderer) : nullptr;
763}

◆ resize()

bool SdlWindow::resize ( const SDL_Point & size)
nodiscard

Definition at line 280 of file SDL3/sdl_window.cpp.

281{
282 return SDL_SetWindowSize(_window, size.x, size.y);
283}

◆ resizeable()

void SdlWindow::resizeable ( bool use)

Definition at line 126 of file SDL2/sdl_window.cpp.

127{
128 SDL_SetWindowResizable(_window, use ? SDL_TRUE : SDL_FALSE);
129}

◆ resizeToScale()

bool SdlWindow::resizeToScale ( )
nodiscard

Definition at line 255 of file SDL3/sdl_window.cpp.

256{
257 if (!_window || _initialW <= 0 || _initialH <= 0)
258 return false;
259 if ((SDL_GetWindowFlags(_window) & SDL_WINDOW_FULLSCREEN) != 0)
260 return true;
261
262 float pd = SDL_GetWindowPixelDensity(_window);
263 if (pd <= 0.0f)
264 pd = 1.0f;
265
266 const int targetW = static_cast<int>(std::ceil(static_cast<float>(_initialW) / pd));
267 const int targetH = static_cast<int>(std::ceil(static_cast<float>(_initialH) / pd));
268
269 int curW = 0;
270 int curH = 0;
271 if (!SDL_GetWindowSize(_window, &curW, &curH))
272 return false;
273
274 if (curW == targetW && curH == targetH)
275 return true;
276
277 return resize({ targetW, targetH });
278}

◆ scale()

float SdlWindow::scale ( ) const
nodiscard

Definition at line 185 of file SDL3/sdl_window.cpp.

186{
187 return SDL_GetWindowDisplayScale(_window);
188}

◆ setBordered()

void SdlWindow::setBordered ( bool bordered)

Definition at line 115 of file SDL2/sdl_window.cpp.

116{
117 if (_window)
118 SDL_SetWindowBordered(_window, bordered ? SDL_TRUE : SDL_FALSE);
119}

◆ setMonitor()

void SdlWindow::setMonitor ( rdpMonitor monitor)

Definition at line 180 of file SDL3/sdl_window.cpp.

181{
182 _monitor = monitor;
183}

◆ setOffsetX()

void SdlWindow::setOffsetX ( Sint32 x)

Definition at line 75 of file SDL2/sdl_window.cpp.

76{
77 _offset_x = x;
78}

◆ setOffsetY()

void SdlWindow::setOffsetY ( Sint32 y)

Definition at line 80 of file SDL2/sdl_window.cpp.

81{
82 _offset_y = y;
83}

◆ setVideoOverlay()

bool SdlWindow::setVideoOverlay ( Uint64 id,
const void * pixels,
int pitch,
int w,
int h,
const SDL_FRect & dst,
const std::vector< SDL_FRect > & clip,
bool visible )
nodiscard

redirected video id, drawn over the session at each present at dst (render coordinates), only in clip (render coordinates) when not empty: what the page draws over the video (player controls) stays visible. pixels (BGRA, wxh) is uploaded when not null

Definition at line 711 of file SDL3/sdl_window.cpp.

714{
715 if (!_renderer || (w <= 0) || (h <= 0))
716 return false;
717 auto& o = _videoOverlays[id];
718 if (!o.texture || (o.w != w) || (o.h != h))
719 {
720 if (o.texture)
721 SDL_DestroyTexture(o.texture);
722 o.texture =
723 SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_BGRA32, SDL_TEXTUREACCESS_STREAMING, w, h);
724 if (!o.texture)
725 {
726 SDL_LogError(SDL_LOG_CATEGORY_RENDER, "SDL_CreateTexture: %s", SDL_GetError());
727 _videoOverlays.erase(id);
728 return false;
729 }
730 /* the video is opaque: its alpha is not for us to blend */
731 std::ignore = SDL_SetTextureBlendMode(o.texture, SDL_BLENDMODE_NONE);
732 o.w = w;
733 o.h = h;
734 }
735 if (pixels && !SDL_UpdateTexture(o.texture, nullptr, pixels, pitch))
736 {
737 SDL_LogError(SDL_LOG_CATEGORY_RENDER, "SDL_UpdateTexture: %s", SDL_GetError());
738 return false;
739 }
740 o.dst = dst;
741 o.clip = clip;
742 o.visible = visible;
743 return true;
744}

◆ tryFallback()

bool SdlWindow::tryFallback ( bool isFullscreen)
staticnodiscardprotected

Definition at line 1013 of file SDL3/sdl_window.cpp.

1014{
1015 /* If we define a custom env variable to use the wlroots hack
1016 * then enable/disable according to this setting only.
1017 */
1018 const auto wlroots_hack = SDL_getenv("FREERDP_WLROOTS_HACK");
1019 if (wlroots_hack != nullptr)
1020 {
1021 const auto enabled = strcmp(wlroots_hack, "0") != 0;
1022 if (strcmp(wlroots_hack, "force") == 0)
1023 isFullscreen = true;
1024 return enabled && isFullscreen;
1025 }
1026
1027 const auto platform = SDL_GetPlatform();
1028 if ((platform == nullptr) || (strcmp(platform, "Linux") != 0))
1029 return false;
1030
1031 const auto driver = SDL_GetCurrentVideoDriver();
1032 if ((driver == nullptr) || (strcmp(driver, "wayland") != 0))
1033 return false;
1034
1035 /* Check XDG_SESSION_DESKTOP and XDG_CURRENT_DESKTOP for wlroots-based
1036 * compositors. The original check only matched Sway, but other wlroots
1037 * compositors (Hyprland, river, etc.) have the same dummy-window sizing
1038 * behavior where hidden/unmapped windows return 64x64 instead of the
1039 * display size. Use strstr for substring matching since XDG_CURRENT_DESKTOP
1040 * can be a colon-separated list (e.g. "sway:wlroots", "Hyprland").
1041 */
1042 auto isWlrootsCompositor = [](const char* value) -> bool
1043 {
1044 if (!value)
1045 return false;
1046 if (strstr(value, "sway") || strstr(value, "Sway") || strstr(value, "Hyprland") ||
1047 strstr(value, "hyprland") || strstr(value, "river") || strstr(value, "wlroots"))
1048 return true;
1049 return false;
1050 };
1051
1052 const auto xdg_session = SDL_getenv("XDG_SESSION_DESKTOP");
1053 if (isWlrootsCompositor(xdg_session))
1054 return isFullscreen;
1055
1056 const auto xdg_desktop = SDL_getenv("XDG_CURRENT_DESKTOP");
1057 if (isWlrootsCompositor(xdg_desktop))
1058 return isFullscreen;
1059
1060 return false;
1061}

◆ updateSurface() [1/2]

void SdlWindow::updateSurface ( )

Definition at line 204 of file SDL2/sdl_window.cpp.

205{
206 SDL_UpdateWindowSurface(_window);
207}

◆ updateSurface() [2/2]

void SdlWindow::updateSurface ( const SdlOverlay * overlay = nullptr)

Present the picture, with the overlay over it when one is given and shown.

Definition at line 664 of file SDL3/sdl_window.cpp.

665{
666 if (!_renderer)
667 return;
668
669 ensureRenderTarget();
670
671 /* Copy accumulated render target to screen and present */
672 if (!SDL_SetRenderTarget(_renderer, nullptr))
673 return;
674 if (!SDL_RenderTexture(_renderer, _renderTarget, nullptr, nullptr))
675 return;
676 drawVideoOverlays();
677 /* over the picture, never into it */
678 if (overlay && overlay->visible())
679 drawOverlay(*overlay);
680 if (!SDL_RenderPresent(_renderer))
681 return;
682}

◆ upload()

bool SdlWindow::upload ( SDL_Surface * surface,
const SDL_Rect & src )
nodiscard

Definition at line 620 of file SDL3/sdl_window.cpp.

621{
622 if (!_renderer || !surface)
623 return false;
624
625 ensureRenderTarget();
626
627 if (!ensureGdiTexture(surface))
628 return false;
629
630 /* Upload only the dirty region */
631 const auto* details = SDL_GetPixelFormatDetails(surface->format);
632 const int bpp = details ? details->bytes_per_pixel : 4;
633 const auto* pixels = static_cast<const uint8_t*>(surface->pixels) +
634 (1ll * srcRect.y * surface->pitch) + (1ll * srcRect.x * bpp);
635 if (!SDL_UpdateTexture(_gdiTexture, &srcRect, pixels, surface->pitch))
636 {
637 SDL_LogError(SDL_LOG_CATEGORY_RENDER, "SDL_UpdateTexture: %s", SDL_GetError());
638 return false;
639 }
640 return true;
641}

◆ window()

SDL_Window * SdlWindow::window ( ) const
nodiscard

Definition at line 65 of file SDL2/sdl_window.cpp.

66{
67 return _window;
68}

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