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

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

◆ cleanup()

void SdlContext::cleanup ( )

Definition at line 111 of file sdl_context.cpp.

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

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

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

1470{
1471 return _cursor;
1472}

◆ detectDisplays()

bool SdlContext::detectDisplays ( )

Definition at line 947 of file sdl_context.cpp.

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

◆ drawToWindow()

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

Definition at line 867 of file sdl_context.cpp.

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

◆ drawToWindows()

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

Definition at line 1365 of file sdl_context.cpp.

1366{
1367 for (auto& window : _windows)
1368 {
1369 if (!drawToWindow(window.second, rects))
1370 return FALSE;
1371 }
1372
1373 return TRUE;
1374}

◆ exitCode()

int SdlContext::exitCode ( ) const

Definition at line 917 of file sdl_context.cpp.

918{
919 return _exitCode;
920}

◆ getClipboardChannelContext()

sdlClip & SdlContext::getClipboardChannelContext ( )

Definition at line 1011 of file sdl_context.cpp.

1012{
1013 return _clip;
1014}

◆ getDialog()

SdlConnectionDialogWrapper & SdlContext::getDialog ( )

Definition at line 1016 of file sdl_context.cpp.

1017{
1018 return _dialog;
1019}

◆ getDisplay()

rdpMonitor SdlContext::getDisplay ( SDL_DisplayID  id) const

Definition at line 962 of file sdl_context.cpp.

963{
964 return _displays.at(id);
965}

◆ getDisplayChannelContext()

sdlDispContext & SdlContext::getDisplayChannelContext ( )

Definition at line 1001 of file sdl_context.cpp.

1002{
1003 return _disp;
1004}

◆ getDisplayIds()

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

Definition at line 967 of file sdl_context.cpp.

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

◆ getFirstWindow()

SdlWindow * SdlContext::getFirstWindow ( )

Definition at line 994 of file sdl_context.cpp.

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

◆ getInputChannelContext()

sdlInput & SdlContext::getInputChannelContext ( )

Definition at line 1006 of file sdl_context.cpp.

1007{
1008 return _input;
1009}

◆ getWindowForId() [1/2]

SdlWindow * SdlContext::getWindowForId ( SDL_WindowID  id)

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}

◆ getWindowForId() [2/2]

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

Definition at line 978 of file sdl_context.cpp.

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

◆ getWLog()

wLog * SdlContext::getWLog ( )

Definition at line 1021 of file sdl_context.cpp.

1022{
1023 return _log;
1024}

◆ grabKeyboard()

bool SdlContext::grabKeyboard ( ) const

Definition at line 1590 of file sdl_context.cpp.

1591{
1592 return _grabKeyboard;
1593}

◆ grabMouse()

bool SdlContext::grabMouse ( ) const

Definition at line 1574 of file sdl_context.cpp.

1575{
1576 return _grabMouse;
1577}

◆ handleEvent()

bool SdlContext::handleEvent ( const SDL_Event &  ev)

Definition at line 1308 of file sdl_context.cpp.

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

◆ hasCursor()

bool SdlContext::hasCursor ( ) const

Definition at line 73 of file sdl_context.cpp.

74{
75 return _cursor_visible;
76}

◆ isConnected()

bool SdlContext::isConnected ( ) const

Definition at line 1441 of file sdl_context.cpp.

1442{
1443 return _connected;
1444}

◆ join()

int SdlContext::join ( )

Definition at line 99 of file sdl_context.cpp.

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

◆ minimizeAllWindows()

bool SdlContext::minimizeAllWindows ( )

Definition at line 910 of file sdl_context.cpp.

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

◆ monitorId()

int64_t SdlContext::monitorId ( uint32_t  index) const

Definition at line 1530 of file sdl_context.cpp.

1531{
1532 if (index >= _monitorIds.size())
1533 {
1534 return -1;
1535 }
1536 return _monitorIds.at(index);
1537}

◆ monitorIds()

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

Definition at line 1525 of file sdl_context.cpp.

1526{
1527 return _monitorIds;
1528}

◆ moveMouseTo()

bool SdlContext::moveMouseTo ( const SDL_FPoint &  pos)

Definition at line 1026 of file sdl_context.cpp.

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

◆ pixelFormat()

SDL_PixelFormat SdlContext::pixelFormat ( ) const

Definition at line 922 of file sdl_context.cpp.

923{
924 return _sdlPixelFormat;
925}

◆ pixelToScreen() [1/2]

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

Definition at line 1284 of file sdl_context.cpp.

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

◆ pixelToScreen() [2/2]

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

Definition at line 1301 of file sdl_context.cpp.

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

◆ pop()

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

Definition at line 1545 of file sdl_context.cpp.

1546{
1547 std::unique_lock lock(_queue_mux);
1548 if (_queue.empty())
1549 {
1550 return {};
1551 }
1552 auto val = std::move(_queue.front());
1553 _queue.pop();
1554 return val;
1555}

◆ push()

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

Definition at line 1539 of file sdl_context.cpp.

1540{
1541 std::unique_lock lock(_queue_mux);
1542 _queue.emplace(std::move(rects));
1543}

◆ redraw()

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

Definition at line 1426 of file sdl_context.cpp.

1427{
1428 if (!_connected)
1429 return true;
1430
1431 auto gdi = context()->gdi;
1432 WINPR_ASSERT(gdi);
1433 return gdi_send_suppress_output(gdi, suppress);
1434}

◆ removeDisplayWindow()

bool SdlContext::removeDisplayWindow ( SDL_DisplayID  id)

Definition at line 937 of file sdl_context.cpp.

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

◆ restoreCursor()

bool SdlContext::restoreCursor ( )

Definition at line 1474 of file sdl_context.cpp.

1475{
1476 WLog_Print(getWLog(), WLOG_DEBUG, "restore cursor: %d", _cursorType);
1477 switch (_cursorType)
1478 {
1479 case CURSOR_NULL:
1480 if (!SDL_HideCursor())
1481 {
1482 WLog_Print(getWLog(), WLOG_ERROR, "SDL_HideCursor failed");
1483 return false;
1484 }
1485
1486 setHasCursor(false);
1487 return true;
1488
1489 case CURSOR_DEFAULT:
1490 {
1491 auto def = SDL_GetDefaultCursor();
1492 if (!SDL_SetCursor(def))
1493 {
1494 WLog_Print(getWLog(), WLOG_ERROR, "SDL_SetCursor(default=%p) failed",
1495 static_cast<void*>(def));
1496 return false;
1497 }
1498 if (!SDL_ShowCursor())
1499 {
1500 WLog_Print(getWLog(), WLOG_ERROR, "SDL_ShowCursor failed");
1501 return false;
1502 }
1503 setHasCursor(true);
1504 return true;
1505 }
1506 case CURSOR_IMAGE:
1507 setHasCursor(true);
1508 return sdl_Pointer_Set_Process(this);
1509 default:
1510 WLog_Print(getWLog(), WLOG_ERROR, "Unknown cursorType %s",
1511 sdl::utils::toString(_cursorType).c_str());
1512 return false;
1513 }
1514}

◆ screenToPixel()

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

Definition at line 1266 of file sdl_context.cpp.

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

◆ setConnected()

void SdlContext::setConnected ( bool  val)

Definition at line 1436 of file sdl_context.cpp.

1437{
1438 _connected = val;
1439}

◆ setCursor() [1/2]

bool SdlContext::setCursor ( CursorType  type)

Definition at line 1457 of file sdl_context.cpp.

1458{
1459 _cursorType = type;
1460 return restoreCursor();
1461}

◆ setCursor() [2/2]

bool SdlContext::setCursor ( rdpPointer *  cursor)

Definition at line 1463 of file sdl_context.cpp.

1464{
1465 _cursor = cursor;
1466 return setCursor(CURSOR_IMAGE);
1467}

◆ setFullscreen()

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

Definition at line 1557 of file sdl_context.cpp.

1558{
1559 for (const auto& window : _windows)
1560 {
1561 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter,
1562 forceOriginalDisplay))
1563 return false;
1564 }
1565 _fullscreen = enter;
1566 return true;
1567}

◆ setGrabKeyboard()

bool SdlContext::setGrabKeyboard ( bool  enter)

Definition at line 1600 of file sdl_context.cpp.

1601{
1602 _grabKeyboard = enter;
1603 return true;
1604}

◆ setGrabMouse()

bool SdlContext::setGrabMouse ( bool  enter)

Definition at line 1584 of file sdl_context.cpp.

1585{
1586 _grabMouse = enter;
1587 return true;
1588}

◆ setHasCursor()

void SdlContext::setHasCursor ( bool  val)

Definition at line 68 of file sdl_context.cpp.

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

◆ setMetadata()

void SdlContext::setMetadata ( )

Definition at line 78 of file sdl_context.cpp.

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

1570{
1571 return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1572}

◆ setMonitorIds()

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

Definition at line 1516 of file sdl_context.cpp.

1517{
1518 _monitorIds.clear();
1519 for (auto id : ids)
1520 {
1521 _monitorIds.push_back(id);
1522 }
1523}

◆ setResizeable()

bool SdlContext::setResizeable ( bool  enable)

Definition at line 1606 of file sdl_context.cpp.

1607{
1608 const auto settings = context()->settings;
1609 const bool dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1610 const bool smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1611 bool use = (dyn && enable) || smart;
1612
1613 for (const auto& window : _windows)
1614 {
1615 if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1616 return false;
1617 }
1618 _resizeable = use;
1619
1620 return true;
1621}

◆ shallAbort()

bool SdlContext::shallAbort ( bool  ignoreDialogs = false)

Definition at line 119 of file sdl_context.cpp.

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

◆ start()

int SdlContext::start ( )

Definition at line 93 of file sdl_context.cpp.

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

◆ toggleFullscreen()

bool SdlContext::toggleFullscreen ( )

Definition at line 1638 of file sdl_context.cpp.

1639{
1640 return setFullscreen(!fullscreen());
1641}

◆ toggleGrabKeyboard()

bool SdlContext::toggleGrabKeyboard ( )

Definition at line 1595 of file sdl_context.cpp.

1596{
1597 return setGrabKeyboard(!grabKeyboard());
1598}

◆ toggleGrabMouse()

bool SdlContext::toggleGrabMouse ( )

Definition at line 1579 of file sdl_context.cpp.

1580{
1581 return setGrabMouse(!grabMouse());
1582}

◆ toggleResizeable()

bool SdlContext::toggleResizeable ( )

Definition at line 1628 of file sdl_context.cpp.

1629{
1630 return setResizeable(!resizeable());
1631}

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

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

◆ updateWindowList()

bool SdlContext::updateWindowList ( )

Definition at line 431 of file sdl_context.cpp.

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