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
 
std::shared_ptr< SdlAadAuthHelper > & getAadAuthHelper ()
 
 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 ()
 
SdlRailgetRailChannelContext ()
 
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 48 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 1768 of file SDL2/sdl_freerdp.cpp.

1769 : _context(context), log(WLog_Get(SDL_TAG)), update_complete(true), disp(this), input(this),
1770 primary(nullptr, SDL_FreeSurface), primary_format(nullptr, SDL_FreeFormat),
1771 rdp_thread_running(false)
1772{
1773 WINPR_ASSERT(context);
1774 grab_kbd_enabled = freerdp_settings_get_bool(context->settings, FreeRDP_GrabKeyboard);
1775}
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 944 of file sdl_context.cpp.

945{
946 const auto flags =
947 SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
948 auto title = sdl::utils::windowTitle(context()->settings);
949 auto w = SdlWindow::create(id, title, flags);
950 _windows.emplace(w.id(), std::move(w));
951 return true;
952}

◆ args()

COMMAND_LINE_ARGUMENT_A * SdlContext::args ( )

Definition at line 1529 of file sdl_context.cpp.

1530{
1531 return _args.data();
1532}

◆ argsCount()

size_t SdlContext::argsCount ( ) const

Definition at line 1534 of file sdl_context.cpp.

1535{
1536 if (_args.size() <= 1)
1537 return 0;
1538 return _args.size() - 1;
1539}

◆ argumentHandler()

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

Definition at line 1541 of file sdl_context.cpp.

1542{
1543 auto sdl = static_cast<SdlContext*>(custom);
1544 if (!sdl)
1545 return -1;
1546
1547 if (arg->Name)
1548 {
1549 if (strcmp(arg->Name, sdl_allow_screensaver) == 0)
1550 {
1551 if (arg->Value != nullptr)
1552 {
1553 if (!SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"))
1554 {
1555 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
1556 "SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER) failed with %s",
1557 SDL_GetError());
1558 return -2;
1559 }
1560 }
1561 }
1562 }
1563 return 0;
1564}

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 114 of file sdl_context.cpp.

115{
116 std::unique_lock lock(_critical);
117 _windows.clear();
118 _dialog.destroy();
119 _primary.reset();
120}

◆ common()

rdpClientContext * SdlContext::common ( ) const

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

1783{
1784 return reinterpret_cast<rdpClientContext*>(_context);
1785}

◆ contains()

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

Definition at line 1576 of file sdl_context.cpp.

1577{
1578 for (const auto& cur : _valid_pointers)
1579 {
1580 if (cur == ptr)
1581 return true;
1582 }
1583 return false;
1584}

◆ context()

rdpContext * SdlContext::context ( ) const

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

1778{
1779 return _context;
1780}

◆ createWindows()

bool SdlContext::createWindows ( )

Definition at line 360 of file sdl_context.cpp.

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

1587{
1588 return _credentialsRead;
1589}

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const

Definition at line 1768 of file sdl_context.cpp.

1769{
1770 return _cursor.get();
1771}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )

Definition at line 964 of file sdl_context.cpp.

965{
966 int count = 0;
967 auto display = SDL_GetDisplays(&count);
968 if (!display)
969 return false;
970 for (int x = 0; x < count; x++)
971 {
972 const auto id = display[x];
973 addOrUpdateDisplay(id);
974 }
975 SDL_free(display);
976 return true;
977}

◆ drawToWindow()

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

Definition at line 883 of file sdl_context.cpp.

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

◆ drawToWindows()

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

Definition at line 1619 of file sdl_context.cpp.

1620{
1621 /* RAIL damage is per-window (_gfxDamage), not in the rects queue: repaint every tick. */
1622 if (_rail.enabled())
1623 {
1624 for (auto& window : _windows)
1625 {
1626 if ((SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN) == 0)
1627 SDL_HideWindow(window.second.window());
1628 }
1629
1630 std::unique_lock lock(_critical);
1631 _rail.paint(_primary.get(), pixelFormat(), rects);
1632 return true;
1633 }
1634
1635 /* Non-RAIL mode (e.g. Non-Monitored Desktop during UAC / Consent UI): show the desktop window.
1636 */
1637 bool firstShow = false;
1638 for (auto& window : _windows)
1639 {
1640 if (SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN)
1641 {
1642 SDL_ShowWindow(window.second.window());
1643 SDL_RaiseWindow(window.second.window());
1644 firstShow = true;
1645 }
1646 }
1647
1648 if (rects.empty() && !firstShow)
1649 return true;
1650
1651 std::vector<SDL_Rect> drawRects = rects;
1652 {
1653 std::unique_lock lock(_critical);
1654 if ((drawRects.empty() || firstShow) && _primary)
1655 drawRects = { { 0, 0, _primary->w, _primary->h } };
1656 }
1657
1658 for (auto& window : _windows)
1659 {
1660 if (!drawToWindow(window.second, drawRects))
1661 return false;
1662 }
1663
1664 return true;
1665}

◆ exitCode()

int SdlContext::exitCode ( ) const

Definition at line 934 of file sdl_context.cpp.

935{
936 return _exitCode;
937}

◆ getAadAuthHelper()

std::shared_ptr< SdlAadAuthHelper > & SdlContext::getAadAuthHelper ( )

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

1788{
1789 return _aadAuthHelper;
1790}

◆ getClipboardChannelContext()

sdlClip & SdlContext::getClipboardChannelContext ( )

Definition at line 1028 of file sdl_context.cpp.

1029{
1030 return _clip;
1031}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )

Definition at line 1038 of file sdl_context.cpp.

1039{
1040 return _dialog;
1041}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID  id) const

Definition at line 979 of file sdl_context.cpp.

980{
981 return _displays.at(id);
982}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )

Definition at line 1018 of file sdl_context.cpp.

1019{
1020 return _disp;
1021}

◆ getDisplayIds()

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

Definition at line 984 of file sdl_context.cpp.

985{
986 std::vector<SDL_DisplayID> keys;
987 keys.reserve(_displays.size());
988 for (const auto& entry : _displays)
989 {
990 keys.push_back(entry.first);
991 }
992 return keys;
993}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )

Definition at line 1011 of file sdl_context.cpp.

1012{
1013 if (_windows.empty())
1014 return nullptr;
1015 return &_windows.begin()->second;
1016}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )

Definition at line 1023 of file sdl_context.cpp.

1024{
1025 return _input;
1026}

◆ getRailChannelContext()

SdlRail & SdlContext::getRailChannelContext ( )

Definition at line 1033 of file sdl_context.cpp.

1034{
1035 return _rail;
1036}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id)

Definition at line 1003 of file sdl_context.cpp.

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

◆ getWindowForId() [2/2]

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

Definition at line 995 of file sdl_context.cpp.

996{
997 auto it = _windows.find(id);
998 if (it == _windows.end())
999 return nullptr;
1000 return &it->second;
1001}

◆ getWLog()

wLog * SdlContext::getWLog ( )

Definition at line 1043 of file sdl_context.cpp.

1044{
1045 return _log;
1046}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const

Definition at line 1889 of file sdl_context.cpp.

1890{
1891 return _grabKeyboard;
1892}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const

Definition at line 1873 of file sdl_context.cpp.

1874{
1875 return _grabMouse;
1876}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event &  ev)

Definition at line 1462 of file sdl_context.cpp.

1463{
1464 if ((ev.type >= SDL_EVENT_DISPLAY_FIRST) && (ev.type <= SDL_EVENT_DISPLAY_LAST))
1465 {
1466 const auto& dev = ev.display;
1467 return handleEvent(dev);
1468 }
1469 if ((ev.type >= SDL_EVENT_WINDOW_FIRST) && (ev.type <= SDL_EVENT_WINDOW_LAST))
1470 {
1471 const auto& wev = ev.window;
1472 return handleEvent(wev);
1473 }
1474 switch (ev.type)
1475 {
1476 case SDL_EVENT_RENDER_TARGETS_RESET:
1477 case SDL_EVENT_RENDER_DEVICE_RESET:
1478 case SDL_EVENT_WILL_ENTER_FOREGROUND:
1479 return redraw();
1480 default:
1481 break;
1482 }
1483
1484 if (!isConnected())
1485 return true;
1486
1487 switch (ev.type)
1488 {
1489 case SDL_EVENT_FINGER_DOWN:
1490 case SDL_EVENT_FINGER_UP:
1491 case SDL_EVENT_FINGER_MOTION:
1492 {
1493 const auto& cev = ev.tfinger;
1494 return handleEvent(cev);
1495 }
1496 case SDL_EVENT_MOUSE_MOTION:
1497
1498 {
1499 const auto& cev = ev.motion;
1500 return handleEvent(cev);
1501 }
1502 case SDL_EVENT_MOUSE_BUTTON_DOWN:
1503 case SDL_EVENT_MOUSE_BUTTON_UP:
1504 {
1505 const auto& cev = ev.button;
1506 return handleEvent(cev);
1507 }
1508 case SDL_EVENT_MOUSE_WHEEL:
1509 {
1510 const auto& cev = ev.wheel;
1511 return handleEvent(cev);
1512 }
1513 case SDL_EVENT_CLIPBOARD_UPDATE:
1514 {
1515 const auto& cev = ev.clipboard;
1516 return getClipboardChannelContext().handleEvent(cev);
1517 }
1518 case SDL_EVENT_KEY_DOWN:
1519 case SDL_EVENT_KEY_UP:
1520 {
1521 const auto& cev = ev.key;
1522 return getInputChannelContext().handleEvent(cev);
1523 }
1524 default:
1525 return true;
1526 }
1527}

◆ hasCursor()

bool SdlContext::hasCursor ( ) const

Definition at line 76 of file sdl_context.cpp.

77{
78 return _cursor_visible;
79}

◆ isConnected()

bool SdlContext::isConnected ( ) const

Definition at line 1736 of file sdl_context.cpp.

1737{
1738 return _connected;
1739}

◆ join()

int SdlContext::join ( )

Definition at line 102 of file sdl_context.cpp.

103{
104 /* We do not want to use freerdp_abort_connect_context here.
105 * It would change the exit code and we do not want that. */
106 HANDLE event = freerdp_abort_event(context());
107 if (!SetEvent(event))
108 return -1;
109
110 _thread.join();
111 return 0;
112}

◆ lock()

CriticalSection & SdlContext::lock ( )

Definition at line 1566 of file sdl_context.cpp.

1567{
1568 return _critical;
1569}

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )

Definition at line 927 of file sdl_context.cpp.

928{
929 for (auto& w : _windows)
930 w.second.minimize();
931 return true;
932}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t  index) const

Definition at line 1829 of file sdl_context.cpp.

1830{
1831 if (index >= _monitorIds.size())
1832 {
1833 return -1;
1834 }
1835 return _monitorIds.at(index);
1836}

◆ monitorIds()

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

Definition at line 1824 of file sdl_context.cpp.

1825{
1826 return _monitorIds;
1827}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint &  pos)

Definition at line 1048 of file sdl_context.cpp.

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

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const

Definition at line 939 of file sdl_context.cpp.

940{
941 return _sdlPixelFormat;
942}

◆ pixelToScreen() [1/2]

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

Definition at line 1426 of file sdl_context.cpp.

1427{
1428 auto w = getWindowForId(id);
1429 if (!w)
1430 {
1431 if (_rail.enabled() && _rail.ownsWindow(id))
1432 return pos;
1433 return {};
1434 }
1435
1436 /* Ignore errors here, sometimes SDL has no renderer */
1437 auto renderer = w->renderer();
1438 if (!renderer)
1439 return pos;
1440
1441 SDL_FPoint rpos{};
1442 if (!SDL_RenderCoordinatesToWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1443 return {};
1444 return applyLocalScaling(rpos);
1445}

◆ pixelToScreen() [2/2]

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

Definition at line 1447 of file sdl_context.cpp.

1448{
1449 const auto fpos = pixelToScreen(id, SDL_FPoint{ pos.x, pos.y });
1450 const auto size = pixelToScreen(id, SDL_FPoint{ pos.w, pos.h });
1451 SDL_FRect r{ fpos.x, fpos.y, size.x, size.y };
1452 if (round)
1453 {
1454 r.w = std::ceil(r.w);
1455 r.h = std::ceil(r.h);
1456 r.x = std::floor(r.x);
1457 r.y = std::floor(r.y);
1458 }
1459 return r;
1460}

◆ pointers()

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

Definition at line 1571 of file sdl_context.cpp.

1572{
1573 return _valid_pointers;
1574}

◆ pop()

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

Definition at line 1844 of file sdl_context.cpp.

1845{
1846 std::unique_lock lock(_queue_mux);
1847 if (_queue.empty())
1848 {
1849 return {};
1850 }
1851 auto val = std::move(_queue.front());
1852 _queue.pop();
1853 return val;
1854}

◆ push()

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

Definition at line 1838 of file sdl_context.cpp.

1839{
1840 std::unique_lock lock(_queue_mux);
1841 _queue.emplace(std::move(rects));
1842}

◆ redraw()

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

Definition at line 1717 of file sdl_context.cpp.

1718{
1719 if (!_connected)
1720 return true;
1721
1722 /* In RAIL mode, hiding the desktop window must not suppress server output. */
1723 if (suppress && _rail.enabled())
1724 return true;
1725
1726 auto gdi = context()->gdi;
1727 WINPR_ASSERT(gdi);
1728 return gdi_send_suppress_output(gdi, suppress);
1729}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID  id)

Definition at line 954 of file sdl_context.cpp.

955{
956 for (auto& w : _windows)
957 {
958 if (w.second.displayIndex() == id)
959 _windows.erase(w.first);
960 }
961 return true;
962}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )

Definition at line 1773 of file sdl_context.cpp.

1774{
1775 WLog_Print(getWLog(), WLOG_TRACE, "restore cursor: %d", _cursorType);
1776 switch (_cursorType)
1777 {
1778 case CURSOR_NULL:
1779 if (!SDL_HideCursor())
1780 {
1781 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
1782 return false;
1783 }
1784
1785 setHasCursor(false);
1786 return true;
1787
1788 case CURSOR_DEFAULT:
1789 {
1790 auto def = SDL_GetDefaultCursor();
1791 if (!SDL_SetCursor(def))
1792 {
1793 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
1794 static_cast<void*>(def));
1795 return false;
1796 }
1797 if (!SDL_ShowCursor())
1798 {
1799 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
1800 return false;
1801 }
1802 setHasCursor(true);
1803 return true;
1804 }
1805 case CURSOR_IMAGE:
1806 setHasCursor(true);
1807 return sdl_Pointer_Set_Process(this);
1808 default:
1809 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
1810 sdl::utils::toString(_cursorType).c_str());
1811 return false;
1812 }
1813}

◆ screenToPixel()

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

Definition at line 1403 of file sdl_context.cpp.

1404{
1405 auto w = getWindowForId(id);
1406 if (!w)
1407 {
1408 /* RAIL windows are server-authoritative 1:1 (no local scaling) and not in _windows. */
1409 if (_rail.enabled() && _rail.ownsWindow(id))
1410 return pos;
1411 return {};
1412 }
1413
1414 /* Ignore errors here, sometimes SDL has no renderer */
1415 auto renderer = w->renderer();
1416 if (!renderer)
1417 return pos;
1418
1419 SDL_FPoint rpos{};
1420 if (!SDL_RenderCoordinatesFromWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1421 return {};
1422 removeLocalScaling(rpos.x, rpos.y);
1423 return rpos;
1424}

◆ setConnected()

void SdlContext::setConnected ( bool  val)

Definition at line 1731 of file sdl_context.cpp.

1732{
1733 _connected = val;
1734}

◆ setCredentialsRead()

void SdlContext::setCredentialsRead ( )

Definition at line 1591 of file sdl_context.cpp.

1592{
1593 _credentialsRead = true;
1594}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( const rdpPointer *  cursor)

Definition at line 1758 of file sdl_context.cpp.

1759{
1760 std::unique_lock lock(_critical);
1761 if (!contains(cursor))
1762 return true;
1763
1764 _cursor = { sdl_Pointer_Copy(cursor), sdl_PointerFreeCopyAll };
1765 return setCursor(CURSOR_IMAGE);
1766}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType  type)

Definition at line 1752 of file sdl_context.cpp.

1753{
1754 _cursorType = type;
1755 return restoreCursor();
1756}

◆ setFullscreen()

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

Definition at line 1856 of file sdl_context.cpp.

1857{
1858 for (const auto& window : _windows)
1859 {
1860 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
1861 forceOriginalDisplay))
1862 return false;
1863 }
1864 _fullscreen = enter;
1865 return true;
1866}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool  enter)

Definition at line 1899 of file sdl_context.cpp.

1900{
1901 _grabKeyboard = enter;
1902 return true;
1903}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool  enter)

Definition at line 1883 of file sdl_context.cpp.

1884{
1885 _grabMouse = enter;
1886 return true;
1887}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool  val)

Definition at line 71 of file sdl_context.cpp.

72{
73 this->_cursor_visible = val;
74}

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 81 of file sdl_context.cpp.

82{
83 auto wmclass = freerdp_settings_get_string(_context->settings, FreeRDP_WmClass);
84 if (!wmclass || (strlen(wmclass) == 0))
85 wmclass = SDL_CLIENT_UUID;
86
87 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING, wmclass);
88 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING, SDL_CLIENT_NAME);
89 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_VERSION_STRING, SDL_CLIENT_VERSION);
90 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_CREATOR_STRING, SDL_CLIENT_VENDOR);
91 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_COPYRIGHT_STRING, SDL_CLIENT_COPYRIGHT);
92 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_URL_STRING, SDL_CLIENT_URL);
93 SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_TYPE_STRING, SDL_CLIENT_TYPE);
94}
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 1868 of file sdl_context.cpp.

1869{
1870 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1871}

◆ setMonitorIds()

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

Definition at line 1815 of file sdl_context.cpp.

1816{
1817 _monitorIds.clear();
1818 for (auto id : ids)
1819 {
1820 _monitorIds.push_back(id);
1821 }
1822}

◆ setResizeable()

bool SdlContext::setResizeable ( bool  enable)

Definition at line 1905 of file sdl_context.cpp.

1906{
1907 const auto settings = context()->settings;
1908 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1909 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1910 bool use = (dyn && enable) || smart;
1911
1912 for (const auto& window : _windows)
1913 {
1914 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1915 return false;
1916 }
1917 _resizeable = use;
1918
1919 return true;
1920}

◆ shallAbort()

bool SdlContext::shallAbort ( bool  ignoreDialogs = false)

Definition at line 122 of file sdl_context.cpp.

123{
124 std::unique_lock lock(_critical);
125 if (freerdp_shall_disconnect_context(context()))
126 {
127 if (ignoreDialogs)
128 return true;
129 if (_rdpThreadRunning)
130 return false;
131 return !getDialog().isRunning();
132 }
133 return false;
134}

◆ start()

int SdlContext::start ( )

Definition at line 96 of file sdl_context.cpp.

97{
98 _thread = std::thread(rdpThreadRun, this);
99 return 0;
100}

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )

Definition at line 1937 of file sdl_context.cpp.

1938{
1939 return setFullscreen(!fullscreen());
1940}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )

Definition at line 1894 of file sdl_context.cpp.

1895{
1896 return setGrabKeyboard(!grabKeyboard());
1897}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )

Definition at line 1878 of file sdl_context.cpp.

1879{
1880 return setGrabMouse(!grabMouse());
1881}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )

Definition at line 1927 of file sdl_context.cpp.

1928{
1929 return setResizeable(!resizeable());
1930}

◆ update_fullscreen()

BOOL SdlContext::update_fullscreen ( BOOL  enter)

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

1732{
1733 std::scoped_lock lock(critical);
1734 for (const auto& window : windows)
1735 {
1736 if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_FULLSCREEN, &window.second, enter))
1737 return FALSE;
1738 }
1739 fullscreen = enter;
1740 return TRUE;
1741}

◆ update_minimize()

BOOL SdlContext::update_minimize ( )

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

1744{
1745 std::scoped_lock lock(critical);
1746 return sdl_push_user_event(SDL_USEREVENT_WINDOW_MINIMIZE);
1747}

◆ update_resizeable()

BOOL SdlContext::update_resizeable ( BOOL  enable)

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

1750{
1751 std::scoped_lock lock(critical);
1752
1753 const auto settings = context()->settings;
1754 const BOOL dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1755 const BOOL smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1756 BOOL use = (dyn && enable) || smart;
1757
1758 for (const auto& window : windows)
1759 {
1760 if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_RESIZEABLE, &window.second, use))
1761 return FALSE;
1762 }
1763 resizeable = use;
1764
1765 return TRUE;
1766}

◆ updateWindow()

bool SdlContext::updateWindow ( SDL_WindowID  id)

Definition at line 458 of file sdl_context.cpp.

459{
460 if (freerdp_settings_get_bool(_context->settings, FreeRDP_Fullscreen) ||
461 freerdp_settings_get_bool(_context->settings, FreeRDP_UseMultimon))
462 return true;
463
464 auto& w = _windows.at(id);
465 auto m = w.monitor(true);
466 auto r = w.rect();
467 m.width = r.w;
468 m.height = r.h;
469 m.attributes.physicalWidth = static_cast<UINT32>(r.w);
470 m.attributes.physicalHeight = static_cast<UINT32>(r.h);
471 w.setMonitor(m);
472 return true;
473}

◆ updateWindowList()

bool SdlContext::updateWindowList ( )

Definition at line 440 of file sdl_context.cpp.

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

◆ critical

CriticalSection SdlContext::critical

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

◆ disp

sdlDispContext SdlContext::disp

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

◆ exit_code

int SdlContext::exit_code = -1

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

◆ fullscreen

bool SdlContext::fullscreen = false

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

◆ grab_kbd

bool SdlContext::grab_kbd = false

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

◆ grab_kbd_enabled

bool SdlContext::grab_kbd_enabled = true

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

◆ grab_mouse

bool SdlContext::grab_mouse = false

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

◆ initialize

WinPREvent SdlContext::initialize

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

◆ initialized

WinPREvent SdlContext::initialized

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

◆ input

sdlInput SdlContext::input

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

◆ log

wLog* SdlContext::log

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

◆ primary

SDLSurfacePtr SdlContext::primary

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

◆ primary_format

SDLPixelFormatPtr SdlContext::primary_format

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

◆ rdp_thread_running

std::atomic<bool> SdlContext::rdp_thread_running

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

◆ resizeable

bool SdlContext::resizeable = false

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

◆ sdl_pixel_format

Uint32 SdlContext::sdl_pixel_format = 0

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

◆ thread

std::thread SdlContext::thread

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

◆ update_complete

WinPREvent SdlContext::update_complete

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

◆ windows

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

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

◆ windows_created

WinPREvent SdlContext::windows_created

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


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