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
 
bool credentialsRead () const
 
void setCredentialsRead ()
 

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 46 of file sdl_context.hpp.

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

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 957 of file sdl_context.cpp.

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

◆ args()

COMMAND_LINE_ARGUMENT_A * SdlContext::args ( )

Definition at line 1425 of file sdl_context.cpp.

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

◆ argsCount()

size_t SdlContext::argsCount ( ) const

Definition at line 1430 of file sdl_context.cpp.

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

◆ argumentHandler()

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

Definition at line 1437 of file sdl_context.cpp.

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

◆ 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 1472 of file sdl_context.cpp.

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

◆ 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 373 of file sdl_context.cpp.

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

◆ credentialsRead()

bool SdlContext::credentialsRead ( ) const

Definition at line 1482 of file sdl_context.cpp.

1483{
1484 return _credentialsRead;
1485}

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const

Definition at line 1623 of file sdl_context.cpp.

1624{
1625 return _cursor.get();
1626}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )

Definition at line 977 of file sdl_context.cpp.

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

◆ drawToWindow()

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

Definition at line 896 of file sdl_context.cpp.

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

◆ drawToWindows()

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

Definition at line 1515 of file sdl_context.cpp.

1516{
1517 for (auto& window : _windows)
1518 {
1519 if (!drawToWindow(window.second, rects))
1520 return FALSE;
1521 }
1522
1523 return TRUE;
1524}

◆ exitCode()

int SdlContext::exitCode ( ) const

Definition at line 947 of file sdl_context.cpp.

948{
949 return _exitCode;
950}

◆ getClipboardChannelContext()

sdlClip & SdlContext::getClipboardChannelContext ( )

Definition at line 1041 of file sdl_context.cpp.

1042{
1043 return _clip;
1044}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )

Definition at line 1046 of file sdl_context.cpp.

1047{
1048 return _dialog;
1049}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID  id) const

Definition at line 992 of file sdl_context.cpp.

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

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )

Definition at line 1031 of file sdl_context.cpp.

1032{
1033 return _disp;
1034}

◆ getDisplayIds()

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

Definition at line 997 of file sdl_context.cpp.

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

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )

Definition at line 1024 of file sdl_context.cpp.

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

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )

Definition at line 1036 of file sdl_context.cpp.

1037{
1038 return _input;
1039}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id)

Definition at line 1016 of file sdl_context.cpp.

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

◆ getWindowForId() [2/2]

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

Definition at line 1008 of file sdl_context.cpp.

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

◆ getWLog()

wLog * SdlContext::getWLog ( )

Definition at line 1051 of file sdl_context.cpp.

1052{
1053 return _log;
1054}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const

Definition at line 1744 of file sdl_context.cpp.

1745{
1746 return _grabKeyboard;
1747}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const

Definition at line 1728 of file sdl_context.cpp.

1729{
1730 return _grabMouse;
1731}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event &  ev)

Definition at line 1358 of file sdl_context.cpp.

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

◆ 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 1591 of file sdl_context.cpp.

1592{
1593 return _connected;
1594}

◆ 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 1462 of file sdl_context.cpp.

1463{
1464 return _critical;
1465}

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )

Definition at line 940 of file sdl_context.cpp.

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

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t  index) const

Definition at line 1684 of file sdl_context.cpp.

1685{
1686 if (index >= _monitorIds.size())
1687 {
1688 return -1;
1689 }
1690 return _monitorIds.at(index);
1691}

◆ monitorIds()

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

Definition at line 1679 of file sdl_context.cpp.

1680{
1681 return _monitorIds;
1682}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint &  pos)

Definition at line 1056 of file sdl_context.cpp.

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

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const

Definition at line 952 of file sdl_context.cpp.

953{
954 return _sdlPixelFormat;
955}

◆ pixelToScreen() [1/2]

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

Definition at line 1326 of file sdl_context.cpp.

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

◆ pixelToScreen() [2/2]

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

Definition at line 1343 of file sdl_context.cpp.

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

◆ pointers()

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

Definition at line 1467 of file sdl_context.cpp.

1468{
1469 return _valid_pointers;
1470}

◆ pop()

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

Definition at line 1699 of file sdl_context.cpp.

1700{
1701 std::unique_lock lock(_queue_mux);
1702 if (_queue.empty())
1703 {
1704 return {};
1705 }
1706 auto val = std::move(_queue.front());
1707 _queue.pop();
1708 return val;
1709}

◆ push()

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

Definition at line 1693 of file sdl_context.cpp.

1694{
1695 std::unique_lock lock(_queue_mux);
1696 _queue.emplace(std::move(rects));
1697}

◆ redraw()

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

Definition at line 1576 of file sdl_context.cpp.

1577{
1578 if (!_connected)
1579 return true;
1580
1581 auto gdi = context()->gdi;
1582 WINPR_ASSERT(gdi);
1583 return gdi_send_suppress_output(gdi, suppress);
1584}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID  id)

Definition at line 967 of file sdl_context.cpp.

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

◆ restoreCursor()

bool SdlContext::restoreCursor ( )

Definition at line 1628 of file sdl_context.cpp.

1629{
1630 WLog_Print(getWLog(), WLOG_DEBUG, "restore cursor: %d", _cursorType);
1631 switch (_cursorType)
1632 {
1633 case CURSOR_NULL:
1634 if (!SDL_HideCursor())
1635 {
1636 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
1637 return false;
1638 }
1639
1640 setHasCursor(false);
1641 return true;
1642
1643 case CURSOR_DEFAULT:
1644 {
1645 auto def = SDL_GetDefaultCursor();
1646 if (!SDL_SetCursor(def))
1647 {
1648 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
1649 static_cast<void*>(def));
1650 return false;
1651 }
1652 if (!SDL_ShowCursor())
1653 {
1654 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
1655 return false;
1656 }
1657 setHasCursor(true);
1658 return true;
1659 }
1660 case CURSOR_IMAGE:
1661 setHasCursor(true);
1662 return sdl_Pointer_Set_Process(this);
1663 default:
1664 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
1665 sdl::utils::toString(_cursorType).c_str());
1666 return false;
1667 }
1668}

◆ screenToPixel()

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

Definition at line 1308 of file sdl_context.cpp.

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

◆ setConnected()

void SdlContext::setConnected ( bool  val)

Definition at line 1586 of file sdl_context.cpp.

1587{
1588 _connected = val;
1589}

◆ setCredentialsRead()

void SdlContext::setCredentialsRead ( )

Definition at line 1487 of file sdl_context.cpp.

1488{
1489 _credentialsRead = true;
1490}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( const rdpPointer *  cursor)

Definition at line 1613 of file sdl_context.cpp.

1614{
1615 std::unique_lock lock(_critical);
1616 if (!contains(cursor))
1617 return true;
1618
1619 _cursor = { sdl_Pointer_Copy(cursor), sdl_PointerFreeCopyAll };
1620 return setCursor(CURSOR_IMAGE);
1621}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType  type)

Definition at line 1607 of file sdl_context.cpp.

1608{
1609 _cursorType = type;
1610 return restoreCursor();
1611}

◆ setFullscreen()

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

Definition at line 1711 of file sdl_context.cpp.

1712{
1713 for (const auto& window : _windows)
1714 {
1715 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
1716 forceOriginalDisplay))
1717 return false;
1718 }
1719 _fullscreen = enter;
1720 return true;
1721}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool  enter)

Definition at line 1754 of file sdl_context.cpp.

1755{
1756 _grabKeyboard = enter;
1757 return true;
1758}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool  enter)

Definition at line 1738 of file sdl_context.cpp.

1739{
1740 _grabMouse = enter;
1741 return true;
1742}

◆ 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 1723 of file sdl_context.cpp.

1724{
1725 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1726}

◆ setMonitorIds()

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

Definition at line 1670 of file sdl_context.cpp.

1671{
1672 _monitorIds.clear();
1673 for (auto id : ids)
1674 {
1675 _monitorIds.push_back(id);
1676 }
1677}

◆ setResizeable()

bool SdlContext::setResizeable ( bool  enable)

Definition at line 1760 of file sdl_context.cpp.

1761{
1762 const auto settings = context()->settings;
1763 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1764 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1765 bool use = (dyn && enable) || smart;
1766
1767 for (const auto& window : _windows)
1768 {
1769 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1770 return false;
1771 }
1772 _resizeable = use;
1773
1774 return true;
1775}

◆ 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 1792 of file sdl_context.cpp.

1793{
1794 return setFullscreen(!fullscreen());
1795}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )

Definition at line 1749 of file sdl_context.cpp.

1750{
1751 return setGrabKeyboard(!grabKeyboard());
1752}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )

Definition at line 1733 of file sdl_context.cpp.

1734{
1735 return setGrabMouse(!grabMouse());
1736}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )

Definition at line 1782 of file sdl_context.cpp.

1783{
1784 return setResizeable(!resizeable());
1785}

◆ 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 471 of file sdl_context.cpp.

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

◆ updateWindowList()

bool SdlContext::updateWindowList ( )

Definition at line 453 of file sdl_context.cpp.

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