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

#include <sdl_context.hpp>

Collaboration diagram for SdlContext:

Public Types

enum  CursorType { CURSOR_NULL , CURSOR_DEFAULT , CURSOR_IMAGE }
 

Public Member Functions

 SdlContext (rdpContext *context)
 
 SdlContext (const SdlContext &other)=delete
 
 SdlContext (SdlContext &&other)=delete
 
SdlContextoperator= (const SdlContext &other)=delete
 
SdlContextoperator= (SdlContext &&other)=delete
 
BOOL update_resizeable (BOOL enable)
 
BOOL update_fullscreen (BOOL enter)
 
BOOL update_minimize ()
 
rdpContext * context () const
 
rdpClientContext * common () const
 
 SdlContext (rdpContext *context)
 
 SdlContext (const SdlContext &other)=delete
 
 SdlContext (SdlContext &&other)=delete
 
SdlContextoperator= (const SdlContext &other)=delete
 
SdlContextoperator= (SdlContext &&other)=delete
 
bool redraw (bool suppress=false) const
 
void setConnected (bool val)
 
bool isConnected () const
 
void cleanup ()
 
bool resizeable () const
 
bool toggleResizeable ()
 
bool setResizeable (bool enable)
 
bool fullscreen () const
 
bool toggleFullscreen ()
 
bool setFullscreen (bool enter, bool forceOriginalDisplay=false)
 
bool setMinimized ()
 
bool grabMouse () const
 
bool toggleGrabMouse ()
 
bool setGrabMouse (bool enter)
 
bool grabKeyboard () const
 
bool toggleGrabKeyboard ()
 
bool setGrabKeyboard (bool enter)
 
rdpContext * context () const
 
rdpClientContext * common () const
 
bool setCursor (CursorType type)
 
bool setCursor (const rdpPointer *cursor)
 
rdpPointer * cursor () const
 
bool restoreCursor ()
 
void setMonitorIds (const std::vector< SDL_DisplayID > &ids)
 
const std::vector< SDL_DisplayID > & monitorIds () const
 
int64_t monitorId (uint32_t index) const
 
void push (std::vector< SDL_Rect > &&rects)
 
std::vector< SDL_Rect > pop ()
 
void setHasCursor (bool val)
 
bool hasCursor () const
 
void setMetadata ()
 
int start ()
 
int join ()
 
bool shallAbort (bool ignoreDialogs=false)
 
bool createWindows ()
 
bool updateWindowList ()
 
bool updateWindow (SDL_WindowID id)
 
bool drawToWindows (const std::vector< SDL_Rect > &rects={})
 
bool drawToWindow (SdlWindow &window, const std::vector< SDL_Rect > &rects={})
 
bool minimizeAllWindows ()
 
int exitCode () const
 
SDL_PixelFormat pixelFormat () const
 
const SdlWindowgetWindowForId (SDL_WindowID id) const
 
SdlWindowgetWindowForId (SDL_WindowID id)
 
SdlWindowgetFirstWindow ()
 
bool addDisplayWindow (SDL_DisplayID id)
 
bool removeDisplayWindow (SDL_DisplayID id)
 
bool detectDisplays ()
 
rdpMonitor getDisplay (SDL_DisplayID id) const
 
std::vector< SDL_DisplayID > getDisplayIds () const
 
sdlDispContextgetDisplayChannelContext ()
 
sdlInputgetInputChannelContext ()
 
sdlClipgetClipboardChannelContext ()
 
SdlConnectionDialogWrappergetDialog ()
 
wLog * getWLog ()
 
bool moveMouseTo (const SDL_FPoint &pos)
 
SDL_FPoint screenToPixel (SDL_WindowID id, const SDL_FPoint &pos)
 
SDL_FPoint pixelToScreen (SDL_WindowID id, const SDL_FPoint &pos)
 
SDL_FRect pixelToScreen (SDL_WindowID id, const SDL_FRect &pos, bool round=false)
 
bool handleEvent (const SDL_Event &ev)
 
COMMAND_LINE_ARGUMENT_Aargs ()
 
size_t argsCount () const
 
CriticalSectionlock ()
 
std::vector< rdpPointer * > & pointers ()
 
bool contains (const rdpPointer *ptr) const
 

Static Public Member Functions

static int argumentHandler (const COMMAND_LINE_ARGUMENT_A *arg, void *custom)
 

Data Fields

wLog * log
 
bool fullscreen = false
 
bool resizeable = false
 
bool grab_mouse = false
 
bool grab_kbd = false
 
bool grab_kbd_enabled = true
 
std::map< Uint32, SdlWindowwindows
 
CriticalSection critical
 
std::thread thread
 
WinPREvent initialize
 
WinPREvent initialized
 
WinPREvent update_complete
 
WinPREvent windows_created
 
int exit_code = -1
 
sdlDispContext disp
 
sdlInput input
 
SDLSurfacePtr primary
 
SDLPixelFormatPtr primary_format
 
Uint32 sdl_pixel_format = 0
 
std::unique_ptr< SDLConnectionDialogconnection_dialog
 
std::atomic< bool > rdp_thread_running
 

Detailed Description

FreeRDP: A Remote Desktop Protocol Implementation SDL Client

Copyright 2022 Armin Novak armin.nosp@m..nov.nosp@m.ak@th.nosp@m.inca.nosp@m.st.co.nosp@m.m

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 46 of file SDL2/sdl_freerdp.hpp.

Member Enumeration Documentation

◆ CursorType

enum SdlContext::CursorType

Definition at line 47 of file sdl_context.hpp.

48 {
49 CURSOR_NULL,
50 CURSOR_DEFAULT,
51 CURSOR_IMAGE
52 };

Constructor & Destructor Documentation

◆ SdlContext()

SdlContext::SdlContext ( rdpContext *  context)
explicit

Definition at line 1775 of file SDL2/sdl_freerdp.cpp.

1776 : _context(context), log(WLog_Get(SDL_TAG)), update_complete(true), disp(this), input(this),
1777 primary(nullptr, SDL_FreeSurface), primary_format(nullptr, SDL_FreeFormat),
1778 rdp_thread_running(false)
1779{
1780 WINPR_ASSERT(context);
1781 grab_kbd_enabled = freerdp_settings_get_bool(context->settings, FreeRDP_GrabKeyboard);
1782}
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.

Member Function Documentation

◆ addDisplayWindow()

bool SdlContext::addDisplayWindow ( SDL_DisplayID  id)

Definition at line 956 of file sdl_context.cpp.

957{
958 const auto flags =
959 SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
960 auto title = sdl::utils::windowTitle(context()->settings);
961 auto w = SdlWindow::create(id, title, flags);
962 _windows.emplace(w.id(), std::move(w));
963 return true;
964}

◆ args()

COMMAND_LINE_ARGUMENT_A * SdlContext::args ( )

Definition at line 1424 of file sdl_context.cpp.

1425{
1426 return _args.data();
1427}

◆ argsCount()

size_t SdlContext::argsCount ( ) const

Definition at line 1429 of file sdl_context.cpp.

1430{
1431 if (_args.size() <= 1)
1432 return 0;
1433 return _args.size() - 1;
1434}

◆ argumentHandler()

int SdlContext::argumentHandler ( const COMMAND_LINE_ARGUMENT_A arg,
void *  custom 
)
static

Definition at line 1436 of file sdl_context.cpp.

1437{
1438 auto sdl = static_cast<SdlContext*>(custom);
1439 if (!sdl)
1440 return -1;
1441
1442 if (arg->Name)
1443 {
1444 if (strcmp(arg->Name, sdl_allow_screensaver) == 0)
1445 {
1446 if (arg->Value != nullptr)
1447 {
1448 if (!SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"))
1449 {
1450 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
1451 "SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER) failed with %s",
1452 SDL_GetError());
1453 return -2;
1454 }
1455 }
1456 }
1457 }
1458 return 0;
1459}

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 127 of file sdl_context.cpp.

128{
129 std::unique_lock lock(_critical);
130 _windows.clear();
131 _dialog.destroy();
132 _primary.reset();
133}

◆ common()

rdpClientContext * SdlContext::common ( ) const

Definition at line 1789 of file SDL2/sdl_freerdp.cpp.

1790{
1791 return reinterpret_cast<rdpClientContext*>(_context);
1792}

◆ contains()

bool SdlContext::contains ( const rdpPointer *  ptr) const

Definition at line 1471 of file sdl_context.cpp.

1472{
1473 for (const auto& cur : _valid_pointers)
1474 {
1475 if (cur == ptr)
1476 return true;
1477 }
1478 return false;
1479}

◆ context()

rdpContext * SdlContext::context ( ) const

Definition at line 1784 of file SDL2/sdl_freerdp.cpp.

1785{
1786 return _context;
1787}

◆ createWindows()

bool SdlContext::createWindows ( )

Definition at line 372 of file sdl_context.cpp.

373{
374 auto settings = context()->settings;
375 const auto& title = windowTitle();
376
377 ScopeGuard guard1([&]() { _windowsCreatedEvent.set(); });
378
379 UINT32 windowCount = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
380
381 Sint32 originX = 0;
382 Sint32 originY = 0;
383 for (UINT32 x = 0; x < windowCount; x++)
384 {
385 auto id = monitorId(x);
386 if (id < 0)
387 return false;
388
389 auto monitor = static_cast<rdpMonitor*>(
390 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
391
392 originX = std::min<Sint32>(monitor->x, originX);
393 originY = std::min<Sint32>(monitor->y, originY);
394 }
395
396 for (UINT32 x = 0; x < windowCount; x++)
397 {
398 auto id = monitorId(x);
399 if (id < 0)
400 return false;
401
402 auto monitor = static_cast<rdpMonitor*>(
403 freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
404
405 Uint32 w = WINPR_ASSERTING_INT_CAST(Uint32, monitor->width);
406 Uint32 h = WINPR_ASSERTING_INT_CAST(Uint32, monitor->height);
407 if (!(freerdp_settings_get_bool(settings, FreeRDP_UseMultimon) ||
408 freerdp_settings_get_bool(settings, FreeRDP_Fullscreen)))
409 {
410 if (_windowWidth > 0)
411 w = _windowWidth;
412 else
413 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
414
415 if (_windowHeigth > 0)
416 h = _windowHeigth;
417 else
418 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
419 }
420
421 Uint32 flags = SDL_WINDOW_HIGH_PIXEL_DENSITY;
422
423 if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen) &&
424 !freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
425 {
426 flags |= SDL_WINDOW_FULLSCREEN;
427 }
428
429 if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
430 {
431 flags |= SDL_WINDOW_BORDERLESS;
432 }
433
434 if (!freerdp_settings_get_bool(settings, FreeRDP_Decorations))
435 flags |= SDL_WINDOW_BORDERLESS;
436
437 auto did = WINPR_ASSERTING_INT_CAST(SDL_DisplayID, id);
438 auto window = SdlWindow::create(did, title, flags, w, h);
439
440 if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
441 {
442 window.setOffsetX(originX - monitor->x);
443 window.setOffsetY(originY - monitor->y);
444 }
445
446 _windows.insert({ window.id(), std::move(window) });
447 }
448
449 return true;
450}
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const

Definition at line 1612 of file sdl_context.cpp.

1613{
1614 return _cursor.get();
1615}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )

Definition at line 976 of file sdl_context.cpp.

977{
978 int count = 0;
979 auto display = SDL_GetDisplays(&count);
980 if (!display)
981 return false;
982 for (int x = 0; x < count; x++)
983 {
984 const auto id = display[x];
985 addOrUpdateDisplay(id);
986 }
987 SDL_free(display);
988 return true;
989}

◆ drawToWindow()

bool SdlContext::drawToWindow ( SdlWindow window,
const std::vector< SDL_Rect > &  rects = {} 
)

Definition at line 895 of file sdl_context.cpp.

896{
897 if (!isConnected())
898 return true;
899
900 auto gdi = context()->gdi;
901 WINPR_ASSERT(gdi);
902
903 auto size = window.rect();
904
905 std::unique_lock lock(_critical);
906 auto surface = _primary.get();
907
908 if (useLocalScale())
909 {
910 window.setOffsetX(0);
911 window.setOffsetY(0);
912 if (gdi->width < size.w)
913 {
914 window.setOffsetX((size.w - gdi->width) / 2);
915 }
916 if (gdi->height < size.h)
917 {
918 window.setOffsetY((size.h - gdi->height) / 2);
919 }
920
921 _localScale = { static_cast<float>(size.w) / static_cast<float>(gdi->width),
922 static_cast<float>(size.h) / static_cast<float>(gdi->height) };
923 if (!window.drawScaledRects(surface, _localScale, rects))
924 return false;
925 }
926 else
927 {
928 SDL_Point offset{ 0, 0 };
929 if (freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon))
930 offset = { window.offsetX(), window.offsetY() };
931 if (!window.drawRects(surface, offset, rects))
932 return false;
933 }
934
935 window.updateSurface();
936 return true;
937}

◆ drawToWindows()

bool SdlContext::drawToWindows ( const std::vector< SDL_Rect > &  rects = {})

Definition at line 1504 of file sdl_context.cpp.

1505{
1506 for (auto& window : _windows)
1507 {
1508 if (!drawToWindow(window.second, rects))
1509 return FALSE;
1510 }
1511
1512 return TRUE;
1513}

◆ exitCode()

int SdlContext::exitCode ( ) const

Definition at line 946 of file sdl_context.cpp.

947{
948 return _exitCode;
949}

◆ getClipboardChannelContext()

sdlClip & SdlContext::getClipboardChannelContext ( )

Definition at line 1040 of file sdl_context.cpp.

1041{
1042 return _clip;
1043}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )

Definition at line 1045 of file sdl_context.cpp.

1046{
1047 return _dialog;
1048}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID  id) const

Definition at line 991 of file sdl_context.cpp.

992{
993 return _displays.at(id);
994}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )

Definition at line 1030 of file sdl_context.cpp.

1031{
1032 return _disp;
1033}

◆ getDisplayIds()

std::vector< SDL_DisplayID > SdlContext::getDisplayIds ( ) const

Definition at line 996 of file sdl_context.cpp.

997{
998 std::vector<SDL_DisplayID> keys;
999 keys.reserve(_displays.size());
1000 for (const auto& entry : _displays)
1001 {
1002 keys.push_back(entry.first);
1003 }
1004 return keys;
1005}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )

Definition at line 1023 of file sdl_context.cpp.

1024{
1025 if (_windows.empty())
1026 return nullptr;
1027 return &_windows.begin()->second;
1028}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )

Definition at line 1035 of file sdl_context.cpp.

1036{
1037 return _input;
1038}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id)

Definition at line 1015 of file sdl_context.cpp.

1016{
1017 auto it = _windows.find(id);
1018 if (it == _windows.end())
1019 return nullptr;
1020 return &it->second;
1021}

◆ getWindowForId() [2/2]

const SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id) const

Definition at line 1007 of file sdl_context.cpp.

1008{
1009 auto it = _windows.find(id);
1010 if (it == _windows.end())
1011 return nullptr;
1012 return &it->second;
1013}

◆ getWLog()

wLog * SdlContext::getWLog ( )

Definition at line 1050 of file sdl_context.cpp.

1051{
1052 return _log;
1053}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const

Definition at line 1733 of file sdl_context.cpp.

1734{
1735 return _grabKeyboard;
1736}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const

Definition at line 1717 of file sdl_context.cpp.

1718{
1719 return _grabMouse;
1720}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event &  ev)

Definition at line 1357 of file sdl_context.cpp.

1358{
1359 if ((ev.type >= SDL_EVENT_DISPLAY_FIRST) && (ev.type <= SDL_EVENT_DISPLAY_LAST))
1360 {
1361 const auto& dev = ev.display;
1362 return handleEvent(dev);
1363 }
1364 if ((ev.type >= SDL_EVENT_WINDOW_FIRST) && (ev.type <= SDL_EVENT_WINDOW_LAST))
1365 {
1366 const auto& wev = ev.window;
1367 return handleEvent(wev);
1368 }
1369 switch (ev.type)
1370 {
1371 case SDL_EVENT_RENDER_TARGETS_RESET:
1372 case SDL_EVENT_RENDER_DEVICE_RESET:
1373 case SDL_EVENT_WILL_ENTER_FOREGROUND:
1374 return redraw();
1375 default:
1376 break;
1377 }
1378
1379 if (!isConnected())
1380 return true;
1381
1382 switch (ev.type)
1383 {
1384 case SDL_EVENT_FINGER_DOWN:
1385 case SDL_EVENT_FINGER_UP:
1386 case SDL_EVENT_FINGER_MOTION:
1387 {
1388 const auto& cev = ev.tfinger;
1389 return handleEvent(cev);
1390 }
1391 case SDL_EVENT_MOUSE_MOTION:
1392
1393 {
1394 const auto& cev = ev.motion;
1395 return handleEvent(cev);
1396 }
1397 case SDL_EVENT_MOUSE_BUTTON_DOWN:
1398 case SDL_EVENT_MOUSE_BUTTON_UP:
1399 {
1400 const auto& cev = ev.button;
1401 return handleEvent(cev);
1402 }
1403 case SDL_EVENT_MOUSE_WHEEL:
1404 {
1405 const auto& cev = ev.wheel;
1406 return handleEvent(cev);
1407 }
1408 case SDL_EVENT_CLIPBOARD_UPDATE:
1409 {
1410 const auto& cev = ev.clipboard;
1411 return getClipboardChannelContext().handleEvent(cev);
1412 }
1413 case SDL_EVENT_KEY_DOWN:
1414 case SDL_EVENT_KEY_UP:
1415 {
1416 const auto& cev = ev.key;
1417 return getInputChannelContext().handleEvent(cev);
1418 }
1419 default:
1420 return true;
1421 }
1422}

◆ hasCursor()

bool SdlContext::hasCursor ( ) const

Definition at line 89 of file sdl_context.cpp.

90{
91 return _cursor_visible;
92}

◆ isConnected()

bool SdlContext::isConnected ( ) const

Definition at line 1580 of file sdl_context.cpp.

1581{
1582 return _connected;
1583}

◆ join()

int SdlContext::join ( )

Definition at line 115 of file sdl_context.cpp.

116{
117 /* We do not want to use freerdp_abort_connect_context here.
118 * It would change the exit code and we do not want that. */
119 HANDLE event = freerdp_abort_event(context());
120 if (!SetEvent(event))
121 return -1;
122
123 _thread.join();
124 return 0;
125}

◆ lock()

CriticalSection & SdlContext::lock ( )

Definition at line 1461 of file sdl_context.cpp.

1462{
1463 return _critical;
1464}

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )

Definition at line 939 of file sdl_context.cpp.

940{
941 for (auto& w : _windows)
942 w.second.minimize();
943 return true;
944}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t  index) const

Definition at line 1673 of file sdl_context.cpp.

1674{
1675 if (index >= _monitorIds.size())
1676 {
1677 return -1;
1678 }
1679 return _monitorIds.at(index);
1680}

◆ monitorIds()

const std::vector< SDL_DisplayID > & SdlContext::monitorIds ( ) const

Definition at line 1668 of file sdl_context.cpp.

1669{
1670 return _monitorIds;
1671}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint &  pos)

Definition at line 1055 of file sdl_context.cpp.

1056{
1057 auto window = SDL_GetMouseFocus();
1058 if (!window)
1059 return true;
1060
1061 const auto id = SDL_GetWindowID(window);
1062 const auto spos = pixelToScreen(id, pos);
1063 SDL_WarpMouseInWindow(window, spos.x, spos.y);
1064 return true;
1065}

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const

Definition at line 951 of file sdl_context.cpp.

952{
953 return _sdlPixelFormat;
954}

◆ pixelToScreen() [1/2]

SDL_FPoint SdlContext::pixelToScreen ( SDL_WindowID  id,
const SDL_FPoint &  pos 
)

Definition at line 1325 of file sdl_context.cpp.

1326{
1327 auto w = getWindowForId(id);
1328 if (!w)
1329 return {};
1330
1331 /* Ignore errors here, sometimes SDL has no renderer */
1332 auto renderer = w->renderer();
1333 if (!renderer)
1334 return pos;
1335
1336 SDL_FPoint rpos{};
1337 if (!SDL_RenderCoordinatesToWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1338 return {};
1339 return applyLocalScaling(rpos);
1340}

◆ pixelToScreen() [2/2]

SDL_FRect SdlContext::pixelToScreen ( SDL_WindowID  id,
const SDL_FRect &  pos,
bool  round = false 
)

Definition at line 1342 of file sdl_context.cpp.

1343{
1344 const auto fpos = pixelToScreen(id, SDL_FPoint{ pos.x, pos.y });
1345 const auto size = pixelToScreen(id, SDL_FPoint{ pos.w, pos.h });
1346 SDL_FRect r{ fpos.x, fpos.y, size.x, size.y };
1347 if (round)
1348 {
1349 r.w = std::ceil(r.w);
1350 r.h = std::ceil(r.h);
1351 r.x = std::floor(r.x);
1352 r.y = std::floor(r.y);
1353 }
1354 return r;
1355}

◆ pointers()

std::vector< rdpPointer * > & SdlContext::pointers ( )

Definition at line 1466 of file sdl_context.cpp.

1467{
1468 return _valid_pointers;
1469}

◆ pop()

std::vector< SDL_Rect > SdlContext::pop ( )

Definition at line 1688 of file sdl_context.cpp.

1689{
1690 std::unique_lock lock(_queue_mux);
1691 if (_queue.empty())
1692 {
1693 return {};
1694 }
1695 auto val = std::move(_queue.front());
1696 _queue.pop();
1697 return val;
1698}

◆ push()

void SdlContext::push ( std::vector< SDL_Rect > &&  rects)

Definition at line 1682 of file sdl_context.cpp.

1683{
1684 std::unique_lock lock(_queue_mux);
1685 _queue.emplace(std::move(rects));
1686}

◆ redraw()

bool SdlContext::redraw ( bool  suppress = false) const

Definition at line 1565 of file sdl_context.cpp.

1566{
1567 if (!_connected)
1568 return true;
1569
1570 auto gdi = context()->gdi;
1571 WINPR_ASSERT(gdi);
1572 return gdi_send_suppress_output(gdi, suppress);
1573}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID  id)

Definition at line 966 of file sdl_context.cpp.

967{
968 for (auto& w : _windows)
969 {
970 if (w.second.displayIndex() == id)
971 _windows.erase(w.first);
972 }
973 return true;
974}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )

Definition at line 1617 of file sdl_context.cpp.

1618{
1619 WLog_Print(getWLog(), WLOG_DEBUG, "restore cursor: %d", _cursorType);
1620 switch (_cursorType)
1621 {
1622 case CURSOR_NULL:
1623 if (!SDL_HideCursor())
1624 {
1625 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
1626 return false;
1627 }
1628
1629 setHasCursor(false);
1630 return true;
1631
1632 case CURSOR_DEFAULT:
1633 {
1634 auto def = SDL_GetDefaultCursor();
1635 if (!SDL_SetCursor(def))
1636 {
1637 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
1638 static_cast<void*>(def));
1639 return false;
1640 }
1641 if (!SDL_ShowCursor())
1642 {
1643 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
1644 return false;
1645 }
1646 setHasCursor(true);
1647 return true;
1648 }
1649 case CURSOR_IMAGE:
1650 setHasCursor(true);
1651 return sdl_Pointer_Set_Process(this);
1652 default:
1653 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
1654 sdl::utils::toString(_cursorType).c_str());
1655 return false;
1656 }
1657}

◆ screenToPixel()

SDL_FPoint SdlContext::screenToPixel ( SDL_WindowID  id,
const SDL_FPoint &  pos 
)

Definition at line 1307 of file sdl_context.cpp.

1308{
1309 auto w = getWindowForId(id);
1310 if (!w)
1311 return {};
1312
1313 /* Ignore errors here, sometimes SDL has no renderer */
1314 auto renderer = w->renderer();
1315 if (!renderer)
1316 return pos;
1317
1318 SDL_FPoint rpos{};
1319 if (!SDL_RenderCoordinatesFromWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1320 return {};
1321 removeLocalScaling(rpos.x, rpos.y);
1322 return rpos;
1323}

◆ setConnected()

void SdlContext::setConnected ( bool  val)

Definition at line 1575 of file sdl_context.cpp.

1576{
1577 _connected = val;
1578}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( const rdpPointer *  cursor)

Definition at line 1602 of file sdl_context.cpp.

1603{
1604 std::unique_lock lock(_critical);
1605 if (!contains(cursor))
1606 return true;
1607
1608 _cursor = { sdl_Pointer_Copy(cursor), sdl_PointerFreeCopyAll };
1609 return setCursor(CURSOR_IMAGE);
1610}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType  type)

Definition at line 1596 of file sdl_context.cpp.

1597{
1598 _cursorType = type;
1599 return restoreCursor();
1600}

◆ setFullscreen()

bool SdlContext::setFullscreen ( bool  enter,
bool  forceOriginalDisplay = false 
)

Definition at line 1700 of file sdl_context.cpp.

1701{
1702 for (const auto& window : _windows)
1703 {
1704 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
1705 forceOriginalDisplay))
1706 return false;
1707 }
1708 _fullscreen = enter;
1709 return true;
1710}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool  enter)

Definition at line 1743 of file sdl_context.cpp.

1744{
1745 _grabKeyboard = enter;
1746 return true;
1747}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool  enter)

Definition at line 1727 of file sdl_context.cpp.

1728{
1729 _grabMouse = enter;
1730 return true;
1731}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool  val)

Definition at line 84 of file sdl_context.cpp.

85{
86 this->_cursor_visible = val;
87}

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 94 of file sdl_context.cpp.

95{
96 auto wmclass = freerdp_settings_get_string(_context->settings, FreeRDP_WmClass);
97 if (!wmclass || (strlen(wmclass) == 0))
98 wmclass = SDL_CLIENT_UUID;
99
100 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING, wmclass);
101 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING, SDL_CLIENT_NAME);
102 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_VERSION_STRING, SDL_CLIENT_VERSION);
103 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_CREATOR_STRING, SDL_CLIENT_VENDOR);
104 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_COPYRIGHT_STRING, SDL_CLIENT_COPYRIGHT);
105 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_URL_STRING, SDL_CLIENT_URL);
106 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_TYPE_STRING, SDL_CLIENT_TYPE);
107}
WINPR_ATTR_NODISCARD FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.

◆ setMinimized()

bool SdlContext::setMinimized ( )

Definition at line 1712 of file sdl_context.cpp.

1713{
1714 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1715}

◆ setMonitorIds()

void SdlContext::setMonitorIds ( const std::vector< SDL_DisplayID > &  ids)

Definition at line 1659 of file sdl_context.cpp.

1660{
1661 _monitorIds.clear();
1662 for (auto id : ids)
1663 {
1664 _monitorIds.push_back(id);
1665 }
1666}

◆ setResizeable()

bool SdlContext::setResizeable ( bool  enable)

Definition at line 1749 of file sdl_context.cpp.

1750{
1751 const auto settings = context()->settings;
1752 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1753 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1754 bool use = (dyn && enable) || smart;
1755
1756 for (const auto& window : _windows)
1757 {
1758 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1759 return false;
1760 }
1761 _resizeable = use;
1762
1763 return true;
1764}

◆ shallAbort()

bool SdlContext::shallAbort ( bool  ignoreDialogs = false)

Definition at line 135 of file sdl_context.cpp.

136{
137 std::unique_lock lock(_critical);
138 if (freerdp_shall_disconnect_context(context()))
139 {
140 if (ignoreDialogs)
141 return true;
142 if (_rdpThreadRunning)
143 return false;
144 return !getDialog().isRunning();
145 }
146 return false;
147}

◆ start()

int SdlContext::start ( )

Definition at line 109 of file sdl_context.cpp.

110{
111 _thread = std::thread(rdpThreadRun, this);
112 return 0;
113}

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )

Definition at line 1781 of file sdl_context.cpp.

1782{
1783 return setFullscreen(!fullscreen());
1784}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )

Definition at line 1738 of file sdl_context.cpp.

1739{
1740 return setGrabKeyboard(!grabKeyboard());
1741}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )

Definition at line 1722 of file sdl_context.cpp.

1723{
1724 return setGrabMouse(!grabMouse());
1725}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )

Definition at line 1771 of file sdl_context.cpp.

1772{
1773 return setResizeable(!resizeable());
1774}

◆ update_fullscreen()

BOOL SdlContext::update_fullscreen ( BOOL  enter)

Definition at line 1738 of file SDL2/sdl_freerdp.cpp.

1739{
1740 std::scoped_lock lock(critical);
1741 for (const auto& window : windows)
1742 {
1743 if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_FULLSCREEN, &window.second, enter))
1744 return FALSE;
1745 }
1746 fullscreen = enter;
1747 return TRUE;
1748}

◆ update_minimize()

BOOL SdlContext::update_minimize ( )

Definition at line 1750 of file SDL2/sdl_freerdp.cpp.

1751{
1752 std::scoped_lock lock(critical);
1753 return sdl_push_user_event(SDL_USEREVENT_WINDOW_MINIMIZE);
1754}

◆ update_resizeable()

BOOL SdlContext::update_resizeable ( BOOL  enable)

Definition at line 1756 of file SDL2/sdl_freerdp.cpp.

1757{
1758 std::scoped_lock lock(critical);
1759
1760 const auto settings = context()->settings;
1761 const BOOL dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1762 const BOOL smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1763 BOOL use = (dyn && enable) || smart;
1764
1765 for (const auto& window : windows)
1766 {
1767 if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_RESIZEABLE, &window.second, use))
1768 return FALSE;
1769 }
1770 resizeable = use;
1771
1772 return TRUE;
1773}

◆ updateWindow()

bool SdlContext::updateWindow ( SDL_WindowID  id)

Definition at line 470 of file sdl_context.cpp.

471{
472 if (freerdp_settings_get_bool(_context->settings, FreeRDP_Fullscreen) ||
473 freerdp_settings_get_bool(_context->settings, FreeRDP_UseMultimon))
474 return true;
475
476 auto& w = _windows.at(id);
477 auto m = w.monitor(true);
478 auto r = w.rect();
479 m.width = r.w;
480 m.height = r.h;
481 m.attributes.physicalWidth = static_cast<UINT32>(r.w);
482 m.attributes.physicalHeight = static_cast<UINT32>(r.h);
483 w.setMonitor(m);
484 return true;
485}

◆ updateWindowList()

bool SdlContext::updateWindowList ( )

Definition at line 452 of file sdl_context.cpp.

453{
454 std::vector<rdpMonitor> list;
455 list.reserve(_windows.size());
456 for (const auto& win : _windows)
457 list.push_back(win.second.monitor(_windows.size() == 1));
458
459 // /monitors: subset may exclude the SDL primary. The library requires
460 // the array to mark one monitor as primary, so promote the first when
461 // none of the kept windows cover the original primary.
462 if (!list.empty() &&
463 std::none_of(list.cbegin(), list.cend(), [](const rdpMonitor& m) { return m.is_primary; }))
464 list.at(0).is_primary = true;
465
466 return freerdp_settings_set_monitor_def_array_sorted(context()->settings, list.data(),
467 list.size());
468}
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_monitor_def_array_sorted(rdpSettings *settings, const rdpMonitor *monitors, size_t count)
Sort monitor array according to:

Field Documentation

◆ connection_dialog

std::unique_ptr<SDLConnectionDialog> SdlContext::connection_dialog

Definition at line 88 of file SDL2/sdl_freerdp.hpp.

◆ critical

CriticalSection SdlContext::critical

Definition at line 72 of file SDL2/sdl_freerdp.hpp.

◆ disp

sdlDispContext SdlContext::disp

Definition at line 80 of file SDL2/sdl_freerdp.hpp.

◆ exit_code

int SdlContext::exit_code = -1

Definition at line 78 of file SDL2/sdl_freerdp.hpp.

◆ fullscreen

bool SdlContext::fullscreen = false

Definition at line 64 of file SDL2/sdl_freerdp.hpp.

◆ grab_kbd

bool SdlContext::grab_kbd = false

Definition at line 67 of file SDL2/sdl_freerdp.hpp.

◆ grab_kbd_enabled

bool SdlContext::grab_kbd_enabled = true

Definition at line 68 of file SDL2/sdl_freerdp.hpp.

◆ grab_mouse

bool SdlContext::grab_mouse = false

Definition at line 66 of file SDL2/sdl_freerdp.hpp.

◆ initialize

WinPREvent SdlContext::initialize

Definition at line 74 of file SDL2/sdl_freerdp.hpp.

◆ initialized

WinPREvent SdlContext::initialized

Definition at line 75 of file SDL2/sdl_freerdp.hpp.

◆ input

sdlInput SdlContext::input

Definition at line 81 of file SDL2/sdl_freerdp.hpp.

◆ log

wLog* SdlContext::log

Definition at line 61 of file SDL2/sdl_freerdp.hpp.

◆ primary

SDLSurfacePtr SdlContext::primary

Definition at line 83 of file SDL2/sdl_freerdp.hpp.

◆ primary_format

SDLPixelFormatPtr SdlContext::primary_format

Definition at line 84 of file SDL2/sdl_freerdp.hpp.

◆ rdp_thread_running

std::atomic<bool> SdlContext::rdp_thread_running

Definition at line 90 of file SDL2/sdl_freerdp.hpp.

◆ resizeable

bool SdlContext::resizeable = false

Definition at line 65 of file SDL2/sdl_freerdp.hpp.

◆ sdl_pixel_format

Uint32 SdlContext::sdl_pixel_format = 0

Definition at line 86 of file SDL2/sdl_freerdp.hpp.

◆ thread

std::thread SdlContext::thread

Definition at line 73 of file SDL2/sdl_freerdp.hpp.

◆ update_complete

WinPREvent SdlContext::update_complete

Definition at line 76 of file SDL2/sdl_freerdp.hpp.

◆ windows

std::map<Uint32, SdlWindow> SdlContext::windows

Definition at line 70 of file SDL2/sdl_freerdp.hpp.

◆ windows_created

WinPREvent SdlContext::windows_created

Definition at line 77 of file SDL2/sdl_freerdp.hpp.


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