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)
 

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

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 1770 of file SDL2/sdl_freerdp.cpp.

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

References freerdp_settings_get_bool().

Here is the call graph for this function:

Member Function Documentation

◆ addDisplayWindow()

bool SdlContext::addDisplayWindow ( SDL_DisplayID  id)

Definition at line 935 of file sdl_context.cpp.

936{
937 const auto flags =
938 SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
939 auto title = sdl::utils::windowTitle(context()->settings);
940 auto w = SdlWindow::create(id, title, flags);
941 _windows.emplace(w.id(), std::move(w));
942 return true;
943}

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 113 of file sdl_context.cpp.

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

◆ common()

rdpClientContext * SdlContext::common ( ) const

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

1785{
1786 return reinterpret_cast<rdpClientContext*>(_context);
1787}

◆ context()

rdpContext * SdlContext::context ( ) const

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

1780{
1781 return _context;
1782}

◆ createWindows()

bool SdlContext::createWindows ( )

Definition at line 358 of file sdl_context.cpp.

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

◆ cursor()

rdpPointer * SdlContext::cursor ( ) const

Definition at line 1515 of file sdl_context.cpp.

1516{
1517 return _cursor.get();
1518}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )

Definition at line 955 of file sdl_context.cpp.

956{
957 int count = 0;
958 auto display = SDL_GetDisplays(&count);
959 if (!display)
960 return false;
961 for (int x = 0; x < count; x++)
962 {
963 const auto id = display[x];
964 addOrUpdateDisplay(id);
965 }
966 SDL_free(display);
967 return true;
968}

◆ drawToWindow()

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

Definition at line 874 of file sdl_context.cpp.

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

◆ drawToWindows()

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

Definition at line 1411 of file sdl_context.cpp.

1412{
1413 for (auto& window : _windows)
1414 {
1415 if (!drawToWindow(window.second, rects))
1416 return FALSE;
1417 }
1418
1419 return TRUE;
1420}

◆ exitCode()

int SdlContext::exitCode ( ) const

Definition at line 925 of file sdl_context.cpp.

926{
927 return _exitCode;
928}

◆ getClipboardChannelContext()

sdlClip & SdlContext::getClipboardChannelContext ( )

Definition at line 1019 of file sdl_context.cpp.

1020{
1021 return _clip;
1022}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )

Definition at line 1024 of file sdl_context.cpp.

1025{
1026 return _dialog;
1027}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID  id) const

Definition at line 970 of file sdl_context.cpp.

971{
972 return _displays.at(id);
973}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )

Definition at line 1009 of file sdl_context.cpp.

1010{
1011 return _disp;
1012}

◆ getDisplayIds()

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

Definition at line 975 of file sdl_context.cpp.

976{
977 std::vector<SDL_DisplayID> keys;
978 keys.reserve(_displays.size());
979 for (const auto& entry : _displays)
980 {
981 keys.push_back(entry.first);
982 }
983 return keys;
984}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )

Definition at line 1002 of file sdl_context.cpp.

1003{
1004 if (_windows.empty())
1005 return nullptr;
1006 return &_windows.begin()->second;
1007}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )

Definition at line 1014 of file sdl_context.cpp.

1015{
1016 return _input;
1017}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id)

Definition at line 994 of file sdl_context.cpp.

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

◆ getWindowForId() [2/2]

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

Definition at line 986 of file sdl_context.cpp.

987{
988 auto it = _windows.find(id);
989 if (it == _windows.end())
990 return nullptr;
991 return &it->second;
992}

◆ getWLog()

wLog * SdlContext::getWLog ( )

Definition at line 1029 of file sdl_context.cpp.

1030{
1031 return _log;
1032}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const

Definition at line 1636 of file sdl_context.cpp.

1637{
1638 return _grabKeyboard;
1639}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const

Definition at line 1620 of file sdl_context.cpp.

1621{
1622 return _grabMouse;
1623}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event &  ev)

Definition at line 1332 of file sdl_context.cpp.

1333{
1334 if ((ev.type >= SDL_EVENT_DISPLAY_FIRST) && (ev.type <= SDL_EVENT_DISPLAY_LAST))
1335 {
1336 const auto& dev = ev.display;
1337 return handleEvent(dev);
1338 }
1339 if ((ev.type >= SDL_EVENT_WINDOW_FIRST) && (ev.type <= SDL_EVENT_WINDOW_LAST))
1340 {
1341 const auto& wev = ev.window;
1342 return handleEvent(wev);
1343 }
1344 switch (ev.type)
1345 {
1346 case SDL_EVENT_RENDER_TARGETS_RESET:
1347 case SDL_EVENT_RENDER_DEVICE_RESET:
1348 case SDL_EVENT_WILL_ENTER_FOREGROUND:
1349 return redraw();
1350 default:
1351 break;
1352 }
1353
1354 if (!isConnected())
1355 return true;
1356
1357 switch (ev.type)
1358 {
1359 case SDL_EVENT_FINGER_DOWN:
1360 case SDL_EVENT_FINGER_UP:
1361 case SDL_EVENT_FINGER_MOTION:
1362 {
1363 const auto& cev = ev.tfinger;
1364 return handleEvent(cev);
1365 }
1366 case SDL_EVENT_MOUSE_MOTION:
1367
1368 {
1369 const auto& cev = ev.motion;
1370 return handleEvent(cev);
1371 }
1372 case SDL_EVENT_MOUSE_BUTTON_DOWN:
1373 case SDL_EVENT_MOUSE_BUTTON_UP:
1374 {
1375 const auto& cev = ev.button;
1376 return handleEvent(cev);
1377 }
1378 case SDL_EVENT_MOUSE_WHEEL:
1379 {
1380 const auto& cev = ev.wheel;
1381 return handleEvent(cev);
1382 }
1383 case SDL_EVENT_CLIPBOARD_UPDATE:
1384 {
1385 const auto& cev = ev.clipboard;
1386 return getClipboardChannelContext().handleEvent(cev);
1387 }
1388 case SDL_EVENT_KEY_DOWN:
1389 case SDL_EVENT_KEY_UP:
1390 {
1391 const auto& cev = ev.key;
1392 return getInputChannelContext().handleEvent(cev);
1393 }
1394 default:
1395 return true;
1396 }
1397}

◆ hasCursor()

bool SdlContext::hasCursor ( ) const

Definition at line 75 of file sdl_context.cpp.

76{
77 return _cursor_visible;
78}

◆ isConnected()

bool SdlContext::isConnected ( ) const

Definition at line 1487 of file sdl_context.cpp.

1488{
1489 return _connected;
1490}

◆ join()

int SdlContext::join ( )

Definition at line 101 of file sdl_context.cpp.

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

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )

Definition at line 918 of file sdl_context.cpp.

919{
920 for (auto& w : _windows)
921 w.second.minimize();
922 return true;
923}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t  index) const

Definition at line 1576 of file sdl_context.cpp.

1577{
1578 if (index >= _monitorIds.size())
1579 {
1580 return -1;
1581 }
1582 return _monitorIds.at(index);
1583}

◆ monitorIds()

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

Definition at line 1571 of file sdl_context.cpp.

1572{
1573 return _monitorIds;
1574}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint &  pos)

Definition at line 1034 of file sdl_context.cpp.

1035{
1036 auto window = SDL_GetMouseFocus();
1037 if (!window)
1038 return true;
1039
1040 const auto id = SDL_GetWindowID(window);
1041 const auto spos = pixelToScreen(id, pos);
1042 SDL_WarpMouseInWindow(window, spos.x, spos.y);
1043 return true;
1044}

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const

Definition at line 930 of file sdl_context.cpp.

931{
932 return _sdlPixelFormat;
933}

◆ pixelToScreen() [1/2]

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

Definition at line 1300 of file sdl_context.cpp.

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

◆ pixelToScreen() [2/2]

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

Definition at line 1317 of file sdl_context.cpp.

1318{
1319 const auto fpos = pixelToScreen(id, SDL_FPoint{ pos.x, pos.y });
1320 const auto size = pixelToScreen(id, SDL_FPoint{ pos.w, pos.h });
1321 SDL_FRect r{ fpos.x, fpos.y, size.x, size.y };
1322 if (round)
1323 {
1324 r.w = std::ceil(r.w);
1325 r.h = std::ceil(r.h);
1326 r.x = std::floor(r.x);
1327 r.y = std::floor(r.y);
1328 }
1329 return r;
1330}

◆ pop()

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

Definition at line 1591 of file sdl_context.cpp.

1592{
1593 std::unique_lock lock(_queue_mux);
1594 if (_queue.empty())
1595 {
1596 return {};
1597 }
1598 auto val = std::move(_queue.front());
1599 _queue.pop();
1600 return val;
1601}

◆ push()

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

Definition at line 1585 of file sdl_context.cpp.

1586{
1587 std::unique_lock lock(_queue_mux);
1588 _queue.emplace(std::move(rects));
1589}

◆ redraw()

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

Definition at line 1472 of file sdl_context.cpp.

1473{
1474 if (!_connected)
1475 return true;
1476
1477 auto gdi = context()->gdi;
1478 WINPR_ASSERT(gdi);
1479 return gdi_send_suppress_output(gdi, suppress);
1480}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID  id)

Definition at line 945 of file sdl_context.cpp.

946{
947 for (auto& w : _windows)
948 {
949 if (w.second.displayIndex() == id)
950 _windows.erase(w.first);
951 }
952 return true;
953}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )

Definition at line 1520 of file sdl_context.cpp.

1521{
1522 WLog_Print(getWLog(), WLOG_DEBUG, "restore cursor: %d", _cursorType);
1523 switch (_cursorType)
1524 {
1525 case CURSOR_NULL:
1526 if (!SDL_HideCursor())
1527 {
1528 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
1529 return false;
1530 }
1531
1532 setHasCursor(false);
1533 return true;
1534
1535 case CURSOR_DEFAULT:
1536 {
1537 auto def = SDL_GetDefaultCursor();
1538 if (!SDL_SetCursor(def))
1539 {
1540 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
1541 static_cast<void*>(def));
1542 return false;
1543 }
1544 if (!SDL_ShowCursor())
1545 {
1546 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
1547 return false;
1548 }
1549 setHasCursor(true);
1550 return true;
1551 }
1552 case CURSOR_IMAGE:
1553 setHasCursor(true);
1554 return sdl_Pointer_Set_Process(this);
1555 default:
1556 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
1557 sdl::utils::toString(_cursorType).c_str());
1558 return false;
1559 }
1560}

◆ screenToPixel()

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

Definition at line 1282 of file sdl_context.cpp.

1283{
1284 auto w = getWindowForId(id);
1285 if (!w)
1286 return {};
1287
1288 /* Ignore errors here, sometimes SDL has no renderer */
1289 auto renderer = SDL_GetRenderer(w->window());
1290 if (!renderer)
1291 return pos;
1292
1293 SDL_FPoint rpos{};
1294 if (!SDL_RenderCoordinatesFromWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1295 return {};
1296 removeLocalScaling(rpos.x, rpos.y);
1297 return rpos;
1298}

◆ setConnected()

void SdlContext::setConnected ( bool  val)

Definition at line 1482 of file sdl_context.cpp.

1483{
1484 _connected = val;
1485}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( const rdpPointer *  cursor)

Definition at line 1509 of file sdl_context.cpp.

1510{
1511 _cursor = { sdl_Pointer_Copy(cursor), sdl_Pointer_FreeCopy };
1512 return setCursor(CURSOR_IMAGE);
1513}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType  type)

Definition at line 1503 of file sdl_context.cpp.

1504{
1505 _cursorType = type;
1506 return restoreCursor();
1507}

◆ setFullscreen()

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

Definition at line 1603 of file sdl_context.cpp.

1604{
1605 for (const auto& window : _windows)
1606 {
1607 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
1608 forceOriginalDisplay))
1609 return false;
1610 }
1611 _fullscreen = enter;
1612 return true;
1613}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool  enter)

Definition at line 1646 of file sdl_context.cpp.

1647{
1648 _grabKeyboard = enter;
1649 return true;
1650}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool  enter)

Definition at line 1630 of file sdl_context.cpp.

1631{
1632 _grabMouse = enter;
1633 return true;
1634}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool  val)

Definition at line 70 of file sdl_context.cpp.

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

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 80 of file sdl_context.cpp.

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

1616{
1617 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1618}

◆ setMonitorIds()

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

Definition at line 1562 of file sdl_context.cpp.

1563{
1564 _monitorIds.clear();
1565 for (auto id : ids)
1566 {
1567 _monitorIds.push_back(id);
1568 }
1569}

◆ setResizeable()

bool SdlContext::setResizeable ( bool  enable)

Definition at line 1652 of file sdl_context.cpp.

1653{
1654 const auto settings = context()->settings;
1655 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1656 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1657 bool use = (dyn && enable) || smart;
1658
1659 for (const auto& window : _windows)
1660 {
1661 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1662 return false;
1663 }
1664 _resizeable = use;
1665
1666 return true;
1667}

◆ shallAbort()

bool SdlContext::shallAbort ( bool  ignoreDialogs = false)

Definition at line 121 of file sdl_context.cpp.

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

◆ start()

int SdlContext::start ( )

Definition at line 95 of file sdl_context.cpp.

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

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )

Definition at line 1684 of file sdl_context.cpp.

1685{
1686 return setFullscreen(!fullscreen());
1687}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )

Definition at line 1641 of file sdl_context.cpp.

1642{
1643 return setGrabKeyboard(!grabKeyboard());
1644}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )

Definition at line 1625 of file sdl_context.cpp.

1626{
1627 return setGrabMouse(!grabMouse());
1628}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )

Definition at line 1674 of file sdl_context.cpp.

1675{
1676 return setResizeable(!resizeable());
1677}

◆ update_fullscreen()

BOOL SdlContext::update_fullscreen ( BOOL  enter)

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

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

◆ update_minimize()

BOOL SdlContext::update_minimize ( )

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

1746{
1747 std::scoped_lock lock(critical);
1748 return sdl_push_user_event(SDL_USEREVENT_WINDOW_MINIMIZE);
1749}

◆ update_resizeable()

BOOL SdlContext::update_resizeable ( BOOL  enable)

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

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

◆ updateWindow()

bool SdlContext::updateWindow ( SDL_WindowID  id)

Definition at line 449 of file sdl_context.cpp.

450{
451 if (freerdp_settings_get_bool(_context->settings, FreeRDP_Fullscreen) ||
452 freerdp_settings_get_bool(_context->settings, FreeRDP_UseMultimon))
453 return true;
454
455 auto& w = _windows.at(id);
456 auto m = w.monitor(true);
457 auto r = w.rect();
458 m.width = r.w;
459 m.height = r.h;
460 m.attributes.physicalWidth = static_cast<UINT32>(r.w);
461 m.attributes.physicalHeight = static_cast<UINT32>(r.h);
462 w.setMonitor(m);
463 return true;
464}

◆ updateWindowList()

bool SdlContext::updateWindowList ( )

Definition at line 438 of file sdl_context.cpp.

439{
440 std::vector<rdpMonitor> list;
441 list.reserve(_windows.size());
442 for (const auto& win : _windows)
443 list.push_back(win.second.monitor(_windows.size() == 1));
444
445 return freerdp_settings_set_monitor_def_array_sorted(context()->settings, list.data(),
446 list.size());
447}
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: