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

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

930{
931 const auto flags =
932 SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS;
933 auto title = sdl::utils::windowTitle(context()->settings);
934 auto w = SdlWindow::create(id, title, flags);
935 _windows.emplace(w.id(), std::move(w));
936 return true;
937}

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 112 of file sdl_context.cpp.

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

◆ common()

rdpClientContext * SdlContext::common ( ) const

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

1780{
1781 return reinterpret_cast<rdpClientContext*>(_context);
1782}

◆ context()

rdpContext * SdlContext::context ( ) const

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

1775{
1776 return _context;
1777}

◆ createWindows()

bool SdlContext::createWindows ( )

Definition at line 352 of file sdl_context.cpp.

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

1494{
1495 return _cursor.get();
1496}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )

Definition at line 949 of file sdl_context.cpp.

950{
951 int count = 0;
952 auto display = SDL_GetDisplays(&count);
953 if (!display)
954 return false;
955 for (int x = 0; x < count; x++)
956 {
957 const auto id = display[x];
958 addOrUpdateDisplay(id);
959 }
960 SDL_free(display);
961 return true;
962}

◆ drawToWindow()

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

Definition at line 868 of file sdl_context.cpp.

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

◆ drawToWindows()

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

Definition at line 1389 of file sdl_context.cpp.

1390{
1391 for (auto& window : _windows)
1392 {
1393 if (!drawToWindow(window.second, rects))
1394 return FALSE;
1395 }
1396
1397 return TRUE;
1398}

◆ exitCode()

int SdlContext::exitCode ( ) const

Definition at line 919 of file sdl_context.cpp.

920{
921 return _exitCode;
922}

◆ getClipboardChannelContext()

sdlClip & SdlContext::getClipboardChannelContext ( )

Definition at line 1013 of file sdl_context.cpp.

1014{
1015 return _clip;
1016}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )

Definition at line 1018 of file sdl_context.cpp.

1019{
1020 return _dialog;
1021}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID  id) const

Definition at line 964 of file sdl_context.cpp.

965{
966 return _displays.at(id);
967}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )

Definition at line 1003 of file sdl_context.cpp.

1004{
1005 return _disp;
1006}

◆ getDisplayIds()

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

Definition at line 969 of file sdl_context.cpp.

970{
971 std::vector<SDL_DisplayID> keys;
972 keys.reserve(_displays.size());
973 for (const auto& entry : _displays)
974 {
975 keys.push_back(entry.first);
976 }
977 return keys;
978}

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )

Definition at line 996 of file sdl_context.cpp.

997{
998 if (_windows.empty())
999 return nullptr;
1000 return &_windows.begin()->second;
1001}

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )

Definition at line 1008 of file sdl_context.cpp.

1009{
1010 return _input;
1011}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id)

Definition at line 988 of file sdl_context.cpp.

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

◆ getWindowForId() [2/2]

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

Definition at line 980 of file sdl_context.cpp.

981{
982 auto it = _windows.find(id);
983 if (it == _windows.end())
984 return nullptr;
985 return &it->second;
986}

◆ getWLog()

wLog * SdlContext::getWLog ( )

Definition at line 1023 of file sdl_context.cpp.

1024{
1025 return _log;
1026}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const

Definition at line 1614 of file sdl_context.cpp.

1615{
1616 return _grabKeyboard;
1617}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const

Definition at line 1598 of file sdl_context.cpp.

1599{
1600 return _grabMouse;
1601}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event &  ev)

Definition at line 1310 of file sdl_context.cpp.

1311{
1312 if ((ev.type >= SDL_EVENT_DISPLAY_FIRST) && (ev.type <= SDL_EVENT_DISPLAY_LAST))
1313 {
1314 const auto& dev = ev.display;
1315 return handleEvent(dev);
1316 }
1317 if ((ev.type >= SDL_EVENT_WINDOW_FIRST) && (ev.type <= SDL_EVENT_WINDOW_LAST))
1318 {
1319 const auto& wev = ev.window;
1320 return handleEvent(wev);
1321 }
1322 switch (ev.type)
1323 {
1324 case SDL_EVENT_RENDER_TARGETS_RESET:
1325 case SDL_EVENT_RENDER_DEVICE_RESET:
1326 case SDL_EVENT_WILL_ENTER_FOREGROUND:
1327 return redraw();
1328 default:
1329 break;
1330 }
1331
1332 if (!isConnected())
1333 return true;
1334
1335 switch (ev.type)
1336 {
1337 case SDL_EVENT_FINGER_DOWN:
1338 case SDL_EVENT_FINGER_UP:
1339 case SDL_EVENT_FINGER_MOTION:
1340 {
1341 const auto& cev = ev.tfinger;
1342 return handleEvent(cev);
1343 }
1344 case SDL_EVENT_MOUSE_MOTION:
1345
1346 {
1347 const auto& cev = ev.motion;
1348 return handleEvent(cev);
1349 }
1350 case SDL_EVENT_MOUSE_BUTTON_DOWN:
1351 case SDL_EVENT_MOUSE_BUTTON_UP:
1352 {
1353 const auto& cev = ev.button;
1354 return handleEvent(cev);
1355 }
1356 case SDL_EVENT_MOUSE_WHEEL:
1357 {
1358 const auto& cev = ev.wheel;
1359 return handleEvent(cev);
1360 }
1361 case SDL_EVENT_CLIPBOARD_UPDATE:
1362 {
1363 const auto& cev = ev.clipboard;
1364 return getClipboardChannelContext().handleEvent(cev);
1365 }
1366 case SDL_EVENT_KEY_DOWN:
1367 case SDL_EVENT_KEY_UP:
1368 {
1369 const auto& cev = ev.key;
1370 return getInputChannelContext().handleEvent(cev);
1371 }
1372 default:
1373 return true;
1374 }
1375}

◆ hasCursor()

bool SdlContext::hasCursor ( ) const

Definition at line 74 of file sdl_context.cpp.

75{
76 return _cursor_visible;
77}

◆ isConnected()

bool SdlContext::isConnected ( ) const

Definition at line 1465 of file sdl_context.cpp.

1466{
1467 return _connected;
1468}

◆ join()

int SdlContext::join ( )

Definition at line 100 of file sdl_context.cpp.

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

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )

Definition at line 912 of file sdl_context.cpp.

913{
914 for (auto& w : _windows)
915 w.second.minimize();
916 return true;
917}

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t  index) const

Definition at line 1554 of file sdl_context.cpp.

1555{
1556 if (index >= _monitorIds.size())
1557 {
1558 return -1;
1559 }
1560 return _monitorIds.at(index);
1561}

◆ monitorIds()

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

Definition at line 1549 of file sdl_context.cpp.

1550{
1551 return _monitorIds;
1552}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint &  pos)

Definition at line 1028 of file sdl_context.cpp.

1029{
1030 auto window = SDL_GetMouseFocus();
1031 if (!window)
1032 return true;
1033
1034 const auto id = SDL_GetWindowID(window);
1035 const auto spos = pixelToScreen(id, pos);
1036 SDL_WarpMouseInWindow(window, spos.x, spos.y);
1037 return true;
1038}

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const

Definition at line 924 of file sdl_context.cpp.

925{
926 return _sdlPixelFormat;
927}

◆ pixelToScreen() [1/2]

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

Definition at line 1286 of file sdl_context.cpp.

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

◆ pixelToScreen() [2/2]

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

Definition at line 1303 of file sdl_context.cpp.

1304{
1305 const auto fpos = pixelToScreen(id, SDL_FPoint{ pos.x, pos.y });
1306 const auto size = pixelToScreen(id, SDL_FPoint{ pos.w, pos.h });
1307 return { fpos.x, fpos.y, size.x, size.y };
1308}

◆ pop()

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

Definition at line 1569 of file sdl_context.cpp.

1570{
1571 std::unique_lock lock(_queue_mux);
1572 if (_queue.empty())
1573 {
1574 return {};
1575 }
1576 auto val = std::move(_queue.front());
1577 _queue.pop();
1578 return val;
1579}

◆ push()

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

Definition at line 1563 of file sdl_context.cpp.

1564{
1565 std::unique_lock lock(_queue_mux);
1566 _queue.emplace(std::move(rects));
1567}

◆ redraw()

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

Definition at line 1450 of file sdl_context.cpp.

1451{
1452 if (!_connected)
1453 return true;
1454
1455 auto gdi = context()->gdi;
1456 WINPR_ASSERT(gdi);
1457 return gdi_send_suppress_output(gdi, suppress);
1458}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID  id)

Definition at line 939 of file sdl_context.cpp.

940{
941 for (auto& w : _windows)
942 {
943 if (w.second.displayIndex() == id)
944 _windows.erase(w.first);
945 }
946 return true;
947}

◆ restoreCursor()

bool SdlContext::restoreCursor ( )

Definition at line 1498 of file sdl_context.cpp.

1499{
1500 WLog_Print(getWLog(), WLOG_DEBUG, "restore cursor: %d", _cursorType);
1501 switch (_cursorType)
1502 {
1503 case CURSOR_NULL:
1504 if (!SDL_HideCursor())
1505 {
1506 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
1507 return false;
1508 }
1509
1510 setHasCursor(false);
1511 return true;
1512
1513 case CURSOR_DEFAULT:
1514 {
1515 auto def = SDL_GetDefaultCursor();
1516 if (!SDL_SetCursor(def))
1517 {
1518 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
1519 static_cast<void*>(def));
1520 return false;
1521 }
1522 if (!SDL_ShowCursor())
1523 {
1524 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
1525 return false;
1526 }
1527 setHasCursor(true);
1528 return true;
1529 }
1530 case CURSOR_IMAGE:
1531 setHasCursor(true);
1532 return sdl_Pointer_Set_Process(this);
1533 default:
1534 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
1535 sdl::utils::toString(_cursorType).c_str());
1536 return false;
1537 }
1538}

◆ screenToPixel()

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

Definition at line 1268 of file sdl_context.cpp.

1269{
1270 auto w = getWindowForId(id);
1271 if (!w)
1272 return {};
1273
1274 /* Ignore errors here, sometimes SDL has no renderer */
1275 auto renderer = SDL_GetRenderer(w->window());
1276 if (!renderer)
1277 return pos;
1278
1279 SDL_FPoint rpos{};
1280 if (!SDL_RenderCoordinatesFromWindow(renderer, pos.x, pos.y, &rpos.x, &rpos.y))
1281 return {};
1282 removeLocalScaling(rpos.x, rpos.y);
1283 return rpos;
1284}

◆ setConnected()

void SdlContext::setConnected ( bool  val)

Definition at line 1460 of file sdl_context.cpp.

1461{
1462 _connected = val;
1463}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( const rdpPointer *  cursor)

Definition at line 1487 of file sdl_context.cpp.

1488{
1489 _cursor = { sdl_Pointer_Copy(cursor), sdl_Pointer_FreeCopy };
1490 return setCursor(CURSOR_IMAGE);
1491}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( CursorType  type)

Definition at line 1481 of file sdl_context.cpp.

1482{
1483 _cursorType = type;
1484 return restoreCursor();
1485}

◆ setFullscreen()

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

Definition at line 1581 of file sdl_context.cpp.

1582{
1583 for (const auto& window : _windows)
1584 {
1585 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
1586 forceOriginalDisplay))
1587 return false;
1588 }
1589 _fullscreen = enter;
1590 return true;
1591}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool  enter)

Definition at line 1624 of file sdl_context.cpp.

1625{
1626 _grabKeyboard = enter;
1627 return true;
1628}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool  enter)

Definition at line 1608 of file sdl_context.cpp.

1609{
1610 _grabMouse = enter;
1611 return true;
1612}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool  val)

Definition at line 69 of file sdl_context.cpp.

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

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 79 of file sdl_context.cpp.

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

1594{
1595 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1596}

◆ setMonitorIds()

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

Definition at line 1540 of file sdl_context.cpp.

1541{
1542 _monitorIds.clear();
1543 for (auto id : ids)
1544 {
1545 _monitorIds.push_back(id);
1546 }
1547}

◆ setResizeable()

bool SdlContext::setResizeable ( bool  enable)

Definition at line 1630 of file sdl_context.cpp.

1631{
1632 const auto settings = context()->settings;
1633 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1634 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1635 bool use = (dyn && enable) || smart;
1636
1637 for (const auto& window : _windows)
1638 {
1639 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1640 return false;
1641 }
1642 _resizeable = use;
1643
1644 return true;
1645}

◆ shallAbort()

bool SdlContext::shallAbort ( bool  ignoreDialogs = false)

Definition at line 120 of file sdl_context.cpp.

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

◆ start()

int SdlContext::start ( )

Definition at line 94 of file sdl_context.cpp.

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

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )

Definition at line 1662 of file sdl_context.cpp.

1663{
1664 return setFullscreen(!fullscreen());
1665}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )

Definition at line 1619 of file sdl_context.cpp.

1620{
1621 return setGrabKeyboard(!grabKeyboard());
1622}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )

Definition at line 1603 of file sdl_context.cpp.

1604{
1605 return setGrabMouse(!grabMouse());
1606}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )

Definition at line 1652 of file sdl_context.cpp.

1653{
1654 return setResizeable(!resizeable());
1655}

◆ update_fullscreen()

BOOL SdlContext::update_fullscreen ( BOOL  enter)

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

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

◆ update_minimize()

BOOL SdlContext::update_minimize ( )

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

1741{
1742 std::scoped_lock lock(critical);
1743 return sdl_push_user_event(SDL_USEREVENT_WINDOW_MINIMIZE);
1744}

◆ update_resizeable()

BOOL SdlContext::update_resizeable ( BOOL  enable)

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

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

◆ updateWindow()

bool SdlContext::updateWindow ( SDL_WindowID  id)

Definition at line 443 of file sdl_context.cpp.

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

◆ updateWindowList()

bool SdlContext::updateWindowList ( )

Definition at line 432 of file sdl_context.cpp.

433{
434 std::vector<rdpMonitor> list;
435 list.reserve(_windows.size());
436 for (const auto& win : _windows)
437 list.push_back(win.second.monitor(_windows.size() == 1));
438
439 return freerdp_settings_set_monitor_def_array_sorted(context()->settings, list.data(),
440 list.size());
441}
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: