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

952{
953 const auto flags =
954 SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
955 auto title = sdl::utils::windowTitle(context()->settings);
956 auto w = SdlWindow::create(id, title, flags);
957 _windows.emplace(w.id(), std::move(w));
958 return true;
959}

◆ args()

COMMAND_LINE_ARGUMENT_A * SdlContext::args ( )

Definition at line 1419 of file sdl_context.cpp.

1420{
1421 return _args.data();
1422}

◆ argsCount()

size_t SdlContext::argsCount ( ) const

Definition at line 1424 of file sdl_context.cpp.

1425{
1426 if (_args.size() <= 1)
1427 return 0;
1428 return _args.size() - 1;
1429}

◆ argumentHandler()

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

Definition at line 1431 of file sdl_context.cpp.

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

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 121 of file sdl_context.cpp.

122{
123 std::unique_lock lock(_critical);
124 _windows.clear();
125 _dialog.destroy();
126 _primary.reset();
127}

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

1467{
1468 for (const auto& cur : _valid_pointers)
1469 {
1470 if (cur == ptr)
1471 return true;
1472 }
1473 return false;
1474}

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

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

1477{
1478 return _credentialsRead;
1479}

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const

Definition at line 1617 of file sdl_context.cpp.

1618{
1619 return _cursor.get();
1620}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )

Definition at line 971 of file sdl_context.cpp.

972{
973 int count = 0;
974 auto display = SDL_GetDisplays(&count);
975 if (!display)
976 return false;
977 for (int x = 0; x < count; x++)
978 {
979 const auto id = display[x];
980 addOrUpdateDisplay(id);
981 }
982 SDL_free(display);
983 return true;
984}

◆ drawToWindow()

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

Definition at line 890 of file sdl_context.cpp.

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

◆ drawToWindows()

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

Definition at line 1509 of file sdl_context.cpp.

1510{
1511 for (auto& window : _windows)
1512 {
1513 if (!drawToWindow(window.second, rects))
1514 return FALSE;
1515 }
1516
1517 return TRUE;
1518}

◆ exitCode()

int SdlContext::exitCode ( ) const

Definition at line 941 of file sdl_context.cpp.

942{
943 return _exitCode;
944}

◆ getClipboardChannelContext()

sdlClip & SdlContext::getClipboardChannelContext ( )

Definition at line 1035 of file sdl_context.cpp.

1036{
1037 return _clip;
1038}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )

Definition at line 1040 of file sdl_context.cpp.

1041{
1042 return _dialog;
1043}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID  id) const

Definition at line 986 of file sdl_context.cpp.

987{
988 return _displays.at(id);
989}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )

Definition at line 1025 of file sdl_context.cpp.

1026{
1027 return _disp;
1028}

◆ getDisplayIds()

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

Definition at line 991 of file sdl_context.cpp.

992{
993 std::vector<SDL_DisplayID> keys;
994 keys.reserve(_displays.size());
995 for (const auto& entry : _displays)
996 {
997 keys.push_back(entry.first);
998 }
999 return keys;
1000}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )

Definition at line 1018 of file sdl_context.cpp.

1019{
1020 if (_windows.empty())
1021 return nullptr;
1022 return &_windows.begin()->second;
1023}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )

Definition at line 1030 of file sdl_context.cpp.

1031{
1032 return _input;
1033}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id)

Definition at line 1010 of file sdl_context.cpp.

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

◆ getWindowForId() [2/2]

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

Definition at line 1002 of file sdl_context.cpp.

1003{
1004 auto it = _windows.find(id);
1005 if (it == _windows.end())
1006 return nullptr;
1007 return &it->second;
1008}

◆ getWLog()

wLog * SdlContext::getWLog ( )

Definition at line 1045 of file sdl_context.cpp.

1046{
1047 return _log;
1048}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const

Definition at line 1738 of file sdl_context.cpp.

1739{
1740 return _grabKeyboard;
1741}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const

Definition at line 1722 of file sdl_context.cpp.

1723{
1724 return _grabMouse;
1725}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event &  ev)

Definition at line 1352 of file sdl_context.cpp.

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

◆ hasCursor()

bool SdlContext::hasCursor ( ) const

Definition at line 83 of file sdl_context.cpp.

84{
85 return _cursor_visible;
86}

◆ isConnected()

bool SdlContext::isConnected ( ) const

Definition at line 1585 of file sdl_context.cpp.

1586{
1587 return _connected;
1588}

◆ join()

int SdlContext::join ( )

Definition at line 109 of file sdl_context.cpp.

110{
111 /* We do not want to use freerdp_abort_connect_context here.
112 * It would change the exit code and we do not want that. */
113 HANDLE event = freerdp_abort_event(context());
114 if (!SetEvent(event))
115 return -1;
116
117 _thread.join();
118 return 0;
119}

◆ lock()

CriticalSection & SdlContext::lock ( )

Definition at line 1456 of file sdl_context.cpp.

1457{
1458 return _critical;
1459}

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )

Definition at line 934 of file sdl_context.cpp.

935{
936 for (auto& w : _windows)
937 w.second.minimize();
938 return true;
939}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t  index) const

Definition at line 1678 of file sdl_context.cpp.

1679{
1680 if (index >= _monitorIds.size())
1681 {
1682 return -1;
1683 }
1684 return _monitorIds.at(index);
1685}

◆ monitorIds()

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

Definition at line 1673 of file sdl_context.cpp.

1674{
1675 return _monitorIds;
1676}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint &  pos)

Definition at line 1050 of file sdl_context.cpp.

1051{
1052 auto window = SDL_GetMouseFocus();
1053 if (!window)
1054 return true;
1055
1056 const auto id = SDL_GetWindowID(window);
1057 const auto spos = pixelToScreen(id, pos);
1058 SDL_WarpMouseInWindow(window, spos.x, spos.y);
1059 return true;
1060}

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const

Definition at line 946 of file sdl_context.cpp.

947{
948 return _sdlPixelFormat;
949}

◆ pixelToScreen() [1/2]

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

Definition at line 1320 of file sdl_context.cpp.

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

◆ pixelToScreen() [2/2]

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

Definition at line 1337 of file sdl_context.cpp.

1338{
1339 const auto fpos = pixelToScreen(id, SDL_FPoint{ pos.x, pos.y });
1340 const auto size = pixelToScreen(id, SDL_FPoint{ pos.w, pos.h });
1341 SDL_FRect r{ fpos.x, fpos.y, size.x, size.y };
1342 if (round)
1343 {
1344 r.w = std::ceil(r.w);
1345 r.h = std::ceil(r.h);
1346 r.x = std::floor(r.x);
1347 r.y = std::floor(r.y);
1348 }
1349 return r;
1350}

◆ pointers()

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

Definition at line 1461 of file sdl_context.cpp.

1462{
1463 return _valid_pointers;
1464}

◆ pop()

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

Definition at line 1693 of file sdl_context.cpp.

1694{
1695 std::unique_lock lock(_queue_mux);
1696 if (_queue.empty())
1697 {
1698 return {};
1699 }
1700 auto val = std::move(_queue.front());
1701 _queue.pop();
1702 return val;
1703}

◆ push()

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

Definition at line 1687 of file sdl_context.cpp.

1688{
1689 std::unique_lock lock(_queue_mux);
1690 _queue.emplace(std::move(rects));
1691}

◆ redraw()

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

Definition at line 1570 of file sdl_context.cpp.

1571{
1572 if (!_connected)
1573 return true;
1574
1575 auto gdi = context()->gdi;
1576 WINPR_ASSERT(gdi);
1577 return gdi_send_suppress_output(gdi, suppress);
1578}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID  id)

Definition at line 961 of file sdl_context.cpp.

962{
963 for (auto& w : _windows)
964 {
965 if (w.second.displayIndex() == id)
966 _windows.erase(w.first);
967 }
968 return true;
969}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )

Definition at line 1622 of file sdl_context.cpp.

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

◆ screenToPixel()

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

Definition at line 1302 of file sdl_context.cpp.

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

◆ setConnected()

void SdlContext::setConnected ( bool  val)

Definition at line 1580 of file sdl_context.cpp.

1581{
1582 _connected = val;
1583}

◆ setCredentialsRead()

void SdlContext::setCredentialsRead ( )

Definition at line 1481 of file sdl_context.cpp.

1482{
1483 _credentialsRead = true;
1484}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( const rdpPointer *  cursor)

Definition at line 1607 of file sdl_context.cpp.

1608{
1609 std::unique_lock lock(_critical);
1610 if (!contains(cursor))
1611 return true;
1612
1613 _cursor = { sdl_Pointer_Copy(cursor), sdl_PointerFreeCopyAll };
1614 return setCursor(CURSOR_IMAGE);
1615}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType  type)

Definition at line 1601 of file sdl_context.cpp.

1602{
1603 _cursorType = type;
1604 return restoreCursor();
1605}

◆ setFullscreen()

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

Definition at line 1705 of file sdl_context.cpp.

1706{
1707 for (const auto& window : _windows)
1708 {
1709 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
1710 forceOriginalDisplay))
1711 return false;
1712 }
1713 _fullscreen = enter;
1714 return true;
1715}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool  enter)

Definition at line 1748 of file sdl_context.cpp.

1749{
1750 _grabKeyboard = enter;
1751 return true;
1752}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool  enter)

Definition at line 1732 of file sdl_context.cpp.

1733{
1734 _grabMouse = enter;
1735 return true;
1736}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool  val)

Definition at line 78 of file sdl_context.cpp.

79{
80 this->_cursor_visible = val;
81}

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 88 of file sdl_context.cpp.

89{
90 auto wmclass = freerdp_settings_get_string(_context->settings, FreeRDP_WmClass);
91 if (!wmclass || (strlen(wmclass) == 0))
92 wmclass = SDL_CLIENT_UUID;
93
94 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING, wmclass);
95 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING, SDL_CLIENT_NAME);
96 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_VERSION_STRING, SDL_CLIENT_VERSION);
97 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_CREATOR_STRING, SDL_CLIENT_VENDOR);
98 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_COPYRIGHT_STRING, SDL_CLIENT_COPYRIGHT);
99 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_URL_STRING, SDL_CLIENT_URL);
100 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_TYPE_STRING, SDL_CLIENT_TYPE);
101}
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 1717 of file sdl_context.cpp.

1718{
1719 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1720}

◆ setMonitorIds()

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

Definition at line 1664 of file sdl_context.cpp.

1665{
1666 _monitorIds.clear();
1667 for (auto id : ids)
1668 {
1669 _monitorIds.push_back(id);
1670 }
1671}

◆ setResizeable()

bool SdlContext::setResizeable ( bool  enable)

Definition at line 1754 of file sdl_context.cpp.

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

◆ shallAbort()

bool SdlContext::shallAbort ( bool  ignoreDialogs = false)

Definition at line 129 of file sdl_context.cpp.

130{
131 std::unique_lock lock(_critical);
132 if (freerdp_shall_disconnect_context(context()))
133 {
134 if (ignoreDialogs)
135 return true;
136 if (_rdpThreadRunning)
137 return false;
138 return !getDialog().isRunning();
139 }
140 return false;
141}

◆ start()

int SdlContext::start ( )

Definition at line 103 of file sdl_context.cpp.

104{
105 _thread = std::thread(rdpThreadRun, this);
106 return 0;
107}

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )

Definition at line 1786 of file sdl_context.cpp.

1787{
1788 return setFullscreen(!fullscreen());
1789}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )

Definition at line 1743 of file sdl_context.cpp.

1744{
1745 return setGrabKeyboard(!grabKeyboard());
1746}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )

Definition at line 1727 of file sdl_context.cpp.

1728{
1729 return setGrabMouse(!grabMouse());
1730}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )

Definition at line 1776 of file sdl_context.cpp.

1777{
1778 return setResizeable(!resizeable());
1779}

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

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

◆ updateWindowList()

bool SdlContext::updateWindowList ( )

Definition at line 447 of file sdl_context.cpp.

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