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
 
SdlContext & operator= (const SdlContext &other)=delete
 
SdlContext & operator= (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
 
SdlContext & operator= (const SdlContext &other)=delete
 
SdlContext & operator= (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 SdlWindow * getWindowForId (SDL_WindowID id) const
 
SdlWindow * getWindowForId (SDL_WindowID id)
 
SdlWindow * getFirstWindow ()
 
bool addDisplayWindow (SDL_DisplayID id)
 
bool removeDisplayWindow (SDL_DisplayID id)
 
bool detectDisplays ()
 
rdpMonitor getDisplay (SDL_DisplayID id) const
 
std::vector< SDL_DisplayID > getDisplayIds () const
 
sdlDispContext & getDisplayChannelContext ()
 
sdlInput & getInputChannelContext ()
 
sdlClip & getClipboardChannelContext ()
 
SdlRail & getRailChannelContext ()
 
SdlConnectionDialogWrapper & getDialog ()
 
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_A * args ()
 
size_t argsCount () const
 
CriticalSection & lock ()
 
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, SdlWindow > windows
 
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< SDLConnectionDialog > connection_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 48 of file sdl_context.hpp.

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

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

1003{
1004 const auto flags =
1005 SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
1006 auto title = sdl::utils::windowTitle(context()->settings);
1007 auto w = SdlWindow::create(id, title, flags);
1008 _windows.emplace(w.id(), std::move(w));
1009 return true;
1010}

◆ args()

COMMAND_LINE_ARGUMENT_A * SdlContext::args ( )

Definition at line 1587 of file sdl_context.cpp.

1588{
1589 return _args.data();
1590}

◆ argsCount()

size_t SdlContext::argsCount ( ) const

Definition at line 1592 of file sdl_context.cpp.

1593{
1594 if (_args.size() <= 1)
1595 return 0;
1596 return _args.size() - 1;
1597}

◆ argumentHandler()

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

Definition at line 1599 of file sdl_context.cpp.

1600{
1601 auto sdl = static_cast<SdlContext*>(custom);
1602 if (!sdl)
1603 return -1;
1604
1605 if (arg->Name)
1606 {
1607 if (strcmp(arg->Name, sdl_allow_screensaver) == 0)
1608 {
1609 if (arg->Value != nullptr)
1610 {
1611 if (!SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"))
1612 {
1613 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
1614 "SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER) failed with %s",
1615 SDL_GetError());
1616 return -2;
1617 }
1618 }
1619 }
1620 else if (strcmp(arg->Name, sdl_connection_dialog) == 0)
1621 sdl->_connectionDialog = (arg->Value != nullptr);
1622 }
1623 return 0;
1624}

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 119 of file sdl_context.cpp.

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

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

1637{
1638 for (const auto& cur : _valid_pointers)
1639 {
1640 if (cur == ptr)
1641 return true;
1642 }
1643 return false;
1644}

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

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

1647{
1648 return _credentialsRead;
1649}

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const

Definition at line 1828 of file sdl_context.cpp.

1829{
1830 return _cursor.get();
1831}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )

Definition at line 1022 of file sdl_context.cpp.

1023{
1024 int count = 0;
1025 auto display = SDL_GetDisplays(&count);
1026 if (!display)
1027 return false;
1028 for (int x = 0; x < count; x++)
1029 {
1030 const auto id = display[x];
1031 addOrUpdateDisplay(id);
1032 }
1033 SDL_free(display);
1034 return true;
1035}

◆ drawToWindow()

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

Definition at line 941 of file sdl_context.cpp.

942{
943 if (!isConnected())
944 return true;
945
946 auto gdi = context()->gdi;
947 WINPR_ASSERT(gdi);
948
949 auto size = window.rect();
950
951 std::unique_lock lock(_critical);
952 auto surface = _primary.get();
953
954 if (useLocalScale())
955 {
956 window.setOffsetX(0);
957 window.setOffsetY(0);
958 if (gdi->width < size.w)
959 {
960 window.setOffsetX((size.w - gdi->width) / 2);
961 }
962 if (gdi->height < size.h)
963 {
964 window.setOffsetY((size.h - gdi->height) / 2);
965 }
966
967 _localScale = { static_cast<float>(size.w) / static_cast<float>(gdi->width),
968 static_cast<float>(size.h) / static_cast<float>(gdi->height) };
969 if (!window.drawScaledRects(surface, _localScale, rects))
970 return false;
971 }
972 else
973 {
974 SDL_Point offset{ 0, 0 };
975 if (freerdp_settings_get_bool(context()->settings, FreeRDP_UseMultimon))
976 offset = { window.offsetX(), window.offsetY() };
977 if (!window.drawRects(surface, offset, rects))
978 return false;
979 }
980
981 window.updateSurface();
982 return true;
983}

◆ drawToWindows()

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

Definition at line 1679 of file sdl_context.cpp.

1680{
1681 /* RAIL damage is per-window (_gfxDamage), not in the rects queue: repaint every tick. */
1682 if (_rail.enabled())
1683 {
1684 for (auto& window : _windows)
1685 {
1686 if ((SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN) == 0)
1687 SDL_HideWindow(window.second.window());
1688 }
1689
1690 std::unique_lock lock(_critical);
1691 _rail.paint(_primary.get(), pixelFormat(), rects);
1692 return true;
1693 }
1694
1695 /* Non-RAIL mode (e.g. Non-Monitored Desktop during UAC / Consent UI): show the desktop window.
1696 */
1697 bool firstShow = false;
1698 for (auto& window : _windows)
1699 {
1700 if (SDL_GetWindowFlags(window.second.window()) & SDL_WINDOW_HIDDEN)
1701 {
1702 SDL_ShowWindow(window.second.window());
1703 SDL_RaiseWindow(window.second.window());
1704 firstShow = true;
1705 }
1706 }
1707
1708 if (rects.empty() && !firstShow)
1709 return true;
1710
1711 std::vector<SDL_Rect> drawRects = rects;
1712 {
1713 std::unique_lock lock(_critical);
1714 if ((drawRects.empty() || firstShow) && _primary)
1715 drawRects = { { 0, 0, _primary->w, _primary->h } };
1716 }
1717
1718 for (auto& window : _windows)
1719 {
1720 if (!drawToWindow(window.second, drawRects))
1721 return false;
1722 }
1723
1724 return true;
1725}

◆ exitCode()

int SdlContext::exitCode ( ) const

Definition at line 992 of file sdl_context.cpp.

993{
994 return _exitCode;
995}

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

1087{
1088 return _clip;
1089}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )

Definition at line 1096 of file sdl_context.cpp.

1097{
1098 return _dialog;
1099}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID  id) const

Definition at line 1037 of file sdl_context.cpp.

1038{
1039 return _displays.at(id);
1040}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )

Definition at line 1076 of file sdl_context.cpp.

1077{
1078 return _disp;
1079}

◆ getDisplayIds()

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

Definition at line 1042 of file sdl_context.cpp.

1043{
1044 std::vector<SDL_DisplayID> keys;
1045 keys.reserve(_displays.size());
1046 for (const auto& entry : _displays)
1047 {
1048 keys.push_back(entry.first);
1049 }
1050 return keys;
1051}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )

Definition at line 1069 of file sdl_context.cpp.

1070{
1071 if (_windows.empty())
1072 return nullptr;
1073 return &_windows.begin()->second;
1074}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )

Definition at line 1081 of file sdl_context.cpp.

1082{
1083 return _input;
1084}

◆ getRailChannelContext()

SdlRail & SdlContext::getRailChannelContext ( )

Definition at line 1091 of file sdl_context.cpp.

1092{
1093 return _rail;
1094}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id)

Definition at line 1061 of file sdl_context.cpp.

1062{
1063 auto it = _windows.find(id);
1064 if (it == _windows.end())
1065 return nullptr;
1066 return &it->second;
1067}

◆ getWindowForId() [2/2]

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

Definition at line 1053 of file sdl_context.cpp.

1054{
1055 auto it = _windows.find(id);
1056 if (it == _windows.end())
1057 return nullptr;
1058 return &it->second;
1059}

◆ getWLog()

wLog * SdlContext::getWLog ( )

Definition at line 1101 of file sdl_context.cpp.

1102{
1103 return _log;
1104}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const

Definition at line 1949 of file sdl_context.cpp.

1950{
1951 return _grabKeyboard;
1952}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const

Definition at line 1933 of file sdl_context.cpp.

1934{
1935 return _grabMouse;
1936}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event &  ev)

Definition at line 1520 of file sdl_context.cpp.

1521{
1522 if ((ev.type >= SDL_EVENT_DISPLAY_FIRST) && (ev.type <= SDL_EVENT_DISPLAY_LAST))
1523 {
1524 const auto& dev = ev.display;
1525 return handleEvent(dev);
1526 }
1527 if ((ev.type >= SDL_EVENT_WINDOW_FIRST) && (ev.type <= SDL_EVENT_WINDOW_LAST))
1528 {
1529 const auto& wev = ev.window;
1530 return handleEvent(wev);
1531 }
1532 switch (ev.type)
1533 {
1534 case SDL_EVENT_RENDER_TARGETS_RESET:
1535 case SDL_EVENT_RENDER_DEVICE_RESET:
1536 case SDL_EVENT_WILL_ENTER_FOREGROUND:
1537 return redraw();
1538 default:
1539 break;
1540 }
1541
1542 if (!isConnected())
1543 return true;
1544
1545 switch (ev.type)
1546 {
1547 case SDL_EVENT_FINGER_DOWN:
1548 case SDL_EVENT_FINGER_UP:
1549 case SDL_EVENT_FINGER_MOTION:
1550 {
1551 const auto& cev = ev.tfinger;
1552 return handleEvent(cev);
1553 }
1554 case SDL_EVENT_MOUSE_MOTION:
1555
1556 {
1557 const auto& cev = ev.motion;
1558 return handleEvent(cev);
1559 }
1560 case SDL_EVENT_MOUSE_BUTTON_DOWN:
1561 case SDL_EVENT_MOUSE_BUTTON_UP:
1562 {
1563 const auto& cev = ev.button;
1564 return handleEvent(cev);
1565 }
1566 case SDL_EVENT_MOUSE_WHEEL:
1567 {
1568 const auto& cev = ev.wheel;
1569 return handleEvent(cev);
1570 }
1571 case SDL_EVENT_CLIPBOARD_UPDATE:
1572 {
1573 const auto& cev = ev.clipboard;
1574 return getClipboardChannelContext().handleEvent(cev);
1575 }
1576 case SDL_EVENT_KEY_DOWN:
1577 case SDL_EVENT_KEY_UP:
1578 {
1579 const auto& cev = ev.key;
1580 return getInputChannelContext().handleEvent(cev);
1581 }
1582 default:
1583 return true;
1584 }
1585}

◆ hasCursor()

bool SdlContext::hasCursor ( ) const

Definition at line 81 of file sdl_context.cpp.

82{
83 return _cursor_visible;
84}

◆ isConnected()

bool SdlContext::isConnected ( ) const

Definition at line 1796 of file sdl_context.cpp.

1797{
1798 return _connected;
1799}

◆ join()

int SdlContext::join ( )

Definition at line 107 of file sdl_context.cpp.

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

◆ lock()

CriticalSection & SdlContext::lock ( )

Definition at line 1626 of file sdl_context.cpp.

1627{
1628 return _critical;
1629}

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )

Definition at line 985 of file sdl_context.cpp.

986{
987 for (auto& w : _windows)
988 w.second.minimize();
989 return true;
990}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t  index) const

Definition at line 1889 of file sdl_context.cpp.

1890{
1891 if (index >= _monitorIds.size())
1892 {
1893 return -1;
1894 }
1895 return _monitorIds.at(index);
1896}

◆ monitorIds()

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

Definition at line 1884 of file sdl_context.cpp.

1885{
1886 return _monitorIds;
1887}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint &  pos)

Definition at line 1106 of file sdl_context.cpp.

1107{
1108 auto window = SDL_GetMouseFocus();
1109 if (!window)
1110 return true;
1111
1112 const auto id = SDL_GetWindowID(window);
1113 const auto spos = pixelToScreen(id, pos);
1114 SDL_WarpMouseInWindow(window, spos.x, spos.y);
1115 return true;
1116}

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const

Definition at line 997 of file sdl_context.cpp.

998{
999 return _sdlPixelFormat;
1000}

◆ pixelToScreen() [1/2]

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

Definition at line 1484 of file sdl_context.cpp.

1485{
1486 auto w = getWindowForId(id);
1487 if (!w)
1488 {
1489 if (_rail.enabled() && _rail.ownsWindow(id))
1490 return pos;
1491 return {};
1492 }
1493
1494 /* Ignore errors here, sometimes SDL has no renderer */
1495 auto renderer = w->renderer();
1496 if (!renderer)
1497 return pos;
1498
1499 SDL_FPoint rpos{};
1500 if (!SDL_RenderCoordinatesToWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1501 return {};
1502 return applyLocalScaling(rpos);
1503}

◆ pixelToScreen() [2/2]

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

Definition at line 1505 of file sdl_context.cpp.

1506{
1507 const auto fpos = pixelToScreen(id, SDL_FPoint{ pos.x, pos.y });
1508 const auto size = pixelToScreen(id, SDL_FPoint{ pos.w, pos.h });
1509 SDL_FRect r{ fpos.x, fpos.y, size.x, size.y };
1510 if (round)
1511 {
1512 r.w = std::ceil(r.w);
1513 r.h = std::ceil(r.h);
1514 r.x = std::floor(r.x);
1515 r.y = std::floor(r.y);
1516 }
1517 return r;
1518}

◆ pointers()

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

Definition at line 1631 of file sdl_context.cpp.

1632{
1633 return _valid_pointers;
1634}

◆ pop()

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

Definition at line 1904 of file sdl_context.cpp.

1905{
1906 std::unique_lock lock(_queue_mux);
1907 if (_queue.empty())
1908 {
1909 return {};
1910 }
1911 auto val = std::move(_queue.front());
1912 _queue.pop();
1913 return val;
1914}

◆ push()

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

Definition at line 1898 of file sdl_context.cpp.

1899{
1900 std::unique_lock lock(_queue_mux);
1901 _queue.emplace(std::move(rects));
1902}

◆ redraw()

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

Definition at line 1777 of file sdl_context.cpp.

1778{
1779 if (!_connected)
1780 return true;
1781
1782 /* In RAIL mode, hiding the desktop window must not suppress server output. */
1783 if (suppress && _rail.enabled())
1784 return true;
1785
1786 auto gdi = context()->gdi;
1787 WINPR_ASSERT(gdi);
1788 return gdi_send_suppress_output(gdi, suppress);
1789}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID  id)

Definition at line 1012 of file sdl_context.cpp.

1013{
1014 for (auto& w : _windows)
1015 {
1016 if (w.second.displayIndex() == id)
1017 _windows.erase(w.first);
1018 }
1019 return true;
1020}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )

Definition at line 1833 of file sdl_context.cpp.

1834{
1835 WLog_Print(getWLog(), WLOG_TRACE, "restore cursor: %d", _cursorType);
1836 switch (_cursorType)
1837 {
1838 case CURSOR_NULL:
1839 if (!SDL_HideCursor())
1840 {
1841 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
1842 return false;
1843 }
1844
1845 setHasCursor(false);
1846 return true;
1847
1848 case CURSOR_DEFAULT:
1849 {
1850 auto def = SDL_GetDefaultCursor();
1851 if (!SDL_SetCursor(def))
1852 {
1853 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
1854 static_cast<void*>(def));
1855 return false;
1856 }
1857 if (!SDL_ShowCursor())
1858 {
1859 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
1860 return false;
1861 }
1862 setHasCursor(true);
1863 return true;
1864 }
1865 case CURSOR_IMAGE:
1866 setHasCursor(true);
1867 return sdl_Pointer_Set_Process(this);
1868 default:
1869 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
1870 sdl::utils::toString(_cursorType).c_str());
1871 return false;
1872 }
1873}

◆ screenToPixel()

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

Definition at line 1461 of file sdl_context.cpp.

1462{
1463 auto w = getWindowForId(id);
1464 if (!w)
1465 {
1466 /* RAIL windows are server-authoritative 1:1 (no local scaling) and not in _windows. */
1467 if (_rail.enabled() && _rail.ownsWindow(id))
1468 return pos;
1469 return {};
1470 }
1471
1472 /* Ignore errors here, sometimes SDL has no renderer */
1473 auto renderer = w->renderer();
1474 if (!renderer)
1475 return pos;
1476
1477 SDL_FPoint rpos{};
1478 if (!SDL_RenderCoordinatesFromWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1479 return {};
1480 removeLocalScaling(rpos.x, rpos.y);
1481 return rpos;
1482}

◆ setConnected()

void SdlContext::setConnected ( bool  val)

Definition at line 1791 of file sdl_context.cpp.

1792{
1793 _connected = val;
1794}

◆ setCredentialsRead()

void SdlContext::setCredentialsRead ( )

Definition at line 1651 of file sdl_context.cpp.

1652{
1653 _credentialsRead = true;
1654}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( const rdpPointer *  cursor)

Definition at line 1818 of file sdl_context.cpp.

1819{
1820 std::unique_lock lock(_critical);
1821 if (!contains(cursor))
1822 return true;
1823
1824 _cursor = { sdl_Pointer_Copy(cursor), sdl_PointerFreeCopyAll };
1825 return setCursor(CURSOR_IMAGE);
1826}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType  type)

Definition at line 1812 of file sdl_context.cpp.

1813{
1814 _cursorType = type;
1815 return restoreCursor();
1816}

◆ setFullscreen()

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

Definition at line 1916 of file sdl_context.cpp.

1917{
1918 for (const auto& window : _windows)
1919 {
1920 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
1921 forceOriginalDisplay))
1922 return false;
1923 }
1924 _fullscreen = enter;
1925 return true;
1926}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool  enter)

Definition at line 1959 of file sdl_context.cpp.

1960{
1961 _grabKeyboard = enter;
1962 return true;
1963}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool  enter)

Definition at line 1943 of file sdl_context.cpp.

1944{
1945 _grabMouse = enter;
1946 return true;
1947}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool  val)

Definition at line 76 of file sdl_context.cpp.

77{
78 this->_cursor_visible = val;
79}

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 86 of file sdl_context.cpp.

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

1929{
1930 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1931}

◆ setMonitorIds()

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

Definition at line 1875 of file sdl_context.cpp.

1876{
1877 _monitorIds.clear();
1878 for (auto id : ids)
1879 {
1880 _monitorIds.push_back(id);
1881 }
1882}

◆ setResizeable()

bool SdlContext::setResizeable ( bool  enable)

Definition at line 1965 of file sdl_context.cpp.

1966{
1967 const auto settings = context()->settings;
1968 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1969 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1970 bool use = (dyn && enable) || smart;
1971
1972 for (const auto& window : _windows)
1973 {
1974 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1975 return false;
1976 }
1977 _resizeable = use;
1978
1979 return true;
1980}

◆ shallAbort()

bool SdlContext::shallAbort ( bool  ignoreDialogs = false)

Definition at line 127 of file sdl_context.cpp.

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

◆ start()

int SdlContext::start ( )

Definition at line 101 of file sdl_context.cpp.

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

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )

Definition at line 1997 of file sdl_context.cpp.

1998{
1999 return setFullscreen(!fullscreen());
2000}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )

Definition at line 1954 of file sdl_context.cpp.

1955{
1956 return setGrabKeyboard(!grabKeyboard());
1957}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )

Definition at line 1938 of file sdl_context.cpp.

1939{
1940 return setGrabMouse(!grabMouse());
1941}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )

Definition at line 1987 of file sdl_context.cpp.

1988{
1989 return setResizeable(!resizeable());
1990}

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

477{
478 /* In fullscreen the monitor kept the size measured with the probe window at startup and was
479 * never updated, so a session the server started at another size stayed that way. Only the
480 * window knows its real size, so ask it in fullscreen as well. */
481 if (freerdp_settings_get_bool(_context->settings, FreeRDP_UseMultimon))
482 return true;
483
484 auto& w = _windows.at(id);
485 auto m = w.monitor(true);
486 auto r = w.rect();
487 m.width = r.w;
488 m.height = r.h;
489 m.attributes.physicalWidth = static_cast<UINT32>(r.w);
490 m.attributes.physicalHeight = static_cast<UINT32>(r.h);
491 w.setMonitor(m);
492 return true;
493}

◆ updateWindowList()

bool SdlContext::updateWindowList ( )

Definition at line 458 of file sdl_context.cpp.

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