FreeRDP
Loading...
Searching...
No Matches
sdlDispContext Class Reference

#include <sdl_disp.hpp>

Public Member Functions

 sdlDispContext (SdlContext *sdl)
 
 sdlDispContext (const sdlDispContext &other)=delete
 
 sdlDispContext (sdlDispContext &&other)=delete
 
sdlDispContext & operator= (const sdlDispContext &other)=delete
 
sdlDispContext & operator= (sdlDispContext &&other)=delete
 
BOOL init (DispClientContext *disp)
 
BOOL uninit (DispClientContext *disp)
 
BOOL handle_window_event (const SDL_WindowEvent *ev)
 
 sdlDispContext (SdlContext *sdl)
 
 sdlDispContext (const sdlDispContext &other)=delete
 
 sdlDispContext (sdlDispContext &&other)=delete
 
sdlDispContext & operator= (const sdlDispContext &other)=delete
 
sdlDispContext & operator= (sdlDispContext &&other)=delete
 
bool init (DispClientContext *disp)
 
bool uninit (DispClientContext *disp)
 
bool handleEvent (const SDL_DisplayEvent &ev)
 
bool handleEvent (const SDL_WindowEvent &ev)
 

Detailed Description

FreeRDP: A Remote Desktop Protocol Implementation SDL Display Control Channel

Copyright 2023 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 29 of file SDL2/sdl_disp.hpp.

Constructor & Destructor Documentation

◆ sdlDispContext()

sdlDispContext::sdlDispContext ( SdlContext *  sdl)
explicit

Definition at line 449 of file SDL2/sdl_disp.cpp.

449 : _sdl(sdl)
450{
451 SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO);
452
453 WINPR_ASSERT(_sdl);
454 WINPR_ASSERT(_sdl->context()->settings);
455 WINPR_ASSERT(_sdl->context()->pubSub);
456
457 auto settings = _sdl->context()->settings;
458 auto pubSub = _sdl->context()->pubSub;
459
460 _lastSentWidth = _targetWidth =
461 WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth));
462 _lastSentHeight = _targetHeight =
463 WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
464 if (PubSub_SubscribeActivated(pubSub, sdlDispContext::OnActivated) < 0)
465 throw std::exception();
466 if (PubSub_SubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset) < 0)
467 throw std::exception();
468 addTimer();
469}
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.

◆ ~sdlDispContext()

sdlDispContext::~sdlDispContext ( )

Definition at line 471 of file SDL2/sdl_disp.cpp.

472{
473 wPubSub* pubSub = _sdl->context()->pubSub;
474 WINPR_ASSERT(pubSub);
475
476 PubSub_UnsubscribeActivated(pubSub, sdlDispContext::OnActivated);
477 PubSub_UnsubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset);
478 SDL_RemoveTimer(_timer);
479 SDL_Quit();
480}

Member Function Documentation

◆ handle_window_event()

BOOL sdlDispContext::handle_window_event ( const SDL_WindowEvent *  ev)

Definition at line 339 of file SDL2/sdl_disp.cpp.

340{
341 WINPR_ASSERT(ev);
342 WLog_Print(_sdl->log, WLOG_TRACE, "got windowEvent %s [0x%08" PRIx32 "]",
343 sdl_window_event_str(ev->event).c_str(), ev->event);
344 auto bordered = freerdp_settings_get_bool(_sdl->context()->settings, FreeRDP_Decorations)
345 ? SDL_TRUE
346 : SDL_FALSE;
347
348 auto it = _sdl->windows.find(ev->windowID);
349 if (it != _sdl->windows.end())
350 it->second.setBordered(bordered);
351
352 switch (ev->event)
353 {
354 case SDL_WINDOWEVENT_HIDDEN:
355 case SDL_WINDOWEVENT_MINIMIZED:
356 return gdi_send_suppress_output(_sdl->context()->gdi, TRUE);
357
358 case SDL_WINDOWEVENT_EXPOSED:
359 case SDL_WINDOWEVENT_SHOWN:
360 case SDL_WINDOWEVENT_MAXIMIZED:
361 case SDL_WINDOWEVENT_RESTORED:
362 return gdi_send_suppress_output(_sdl->context()->gdi, FALSE);
363
364 case SDL_WINDOWEVENT_RESIZED:
365 case SDL_WINDOWEVENT_SIZE_CHANGED:
366 _targetWidth = ev->data1;
367 _targetHeight = ev->data2;
368 return addTimer();
369
370 case SDL_WINDOWEVENT_LEAVE:
371 WINPR_ASSERT(_sdl);
372 _sdl->input.keyboard_grab(ev->windowID, false);
373 return TRUE;
374 case SDL_WINDOWEVENT_ENTER:
375 WINPR_ASSERT(_sdl);
376 _sdl->input.keyboard_grab(ev->windowID, true);
377 return _sdl->input.keyboard_focus_in();
378 case SDL_WINDOWEVENT_FOCUS_GAINED:
379 case SDL_WINDOWEVENT_TAKE_FOCUS:
380 return _sdl->input.keyboard_focus_in();
381
382 default:
383 return TRUE;
384 }
385}
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.

◆ handleEvent() [1/2]

bool sdlDispContext::handleEvent ( const SDL_DisplayEvent &  ev)

Definition at line 344 of file SDL3/sdl_disp.cpp.

345{
346 const auto cat = SDL_LOG_CATEGORY_APPLICATION;
347 switch (ev.type)
348 {
349 case SDL_EVENT_DISPLAY_ADDED:
350 SDL_LogDebug(cat, "A new display with id %u was connected", ev.displayID);
351 return updateMonitors(ev.type, ev.displayID);
352 case SDL_EVENT_DISPLAY_REMOVED:
353 SDL_LogDebug(cat, "The display with id %u was disconnected", ev.displayID);
354 return updateMonitors(ev.type, ev.displayID);
355 case SDL_EVENT_DISPLAY_ORIENTATION:
356 SDL_LogDebug(cat, "The orientation of display with id %u was changed", ev.displayID);
357 return updateMonitors(ev.type, ev.displayID);
358 case SDL_EVENT_DISPLAY_MOVED:
359 SDL_LogDebug(cat, "The display with id %u was moved", ev.displayID);
360 return updateMonitors(ev.type, ev.displayID);
361 case SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED:
362 SDL_LogDebug(cat, "The display with id %u changed scale", ev.displayID);
363 return updateMonitors(ev.type, ev.displayID);
364#if SDL_VERSION_ATLEAST(3, 3, 2)
365 case SDL_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED:
366 SDL_LogDebug(cat, "The display with id %u changed usable bounds", ev.displayID);
367 return updateMonitors(ev.type, ev.displayID);
368#endif
369 case SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED:
370 SDL_LogDebug(cat, "The display with id %u changed mode", ev.displayID);
371 return updateMonitors(ev.type, ev.displayID);
372 case SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED:
373 SDL_LogDebug(cat, "The display with id %u changed desktop mode", ev.displayID);
374 return updateMonitors(ev.type, ev.displayID);
375 default:
376 return true;
377 }
378}

◆ handleEvent() [2/2]

bool sdlDispContext::handleEvent ( const SDL_WindowEvent &  ev)

Definition at line 380 of file SDL3/sdl_disp.cpp.

381{
382 auto window = _sdl->getWindowForId(ev.windowID);
383 if (!window)
384 return true;
385
386 auto bordered = freerdp_settings_get_bool(_sdl->context()->settings, FreeRDP_Decorations);
387 window->setBordered(bordered);
388
389 switch (ev.type)
390 {
391 case SDL_EVENT_WINDOW_HIDDEN:
392 case SDL_EVENT_WINDOW_MINIMIZED:
393 /* Other monitors may still show the session. */
394 if (!_sdl->allWindowsHidden())
395 return true;
396 return _sdl->redraw(true);
397 case SDL_EVENT_WINDOW_ENTER_FULLSCREEN:
398 return updateMonitor(ev.windowID);
399 case SDL_EVENT_WINDOW_LEAVE_FULLSCREEN:
400 return updateMonitor(ev.windowID);
401
402 case SDL_EVENT_WINDOW_EXPOSED:
403 case SDL_EVENT_WINDOW_SHOWN:
404 case SDL_EVENT_WINDOW_MAXIMIZED:
405 case SDL_EVENT_WINDOW_RESTORED:
406 if (!_sdl->redraw())
407 return false;
408
409 /* fallthrough */
410 WINPR_FALLTHROUGH
411 case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
412 case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
413 case SDL_EVENT_WINDOW_RESIZED:
414 return updateMonitor(ev.windowID);
415 case SDL_EVENT_WINDOW_MOUSE_LEAVE:
416 WINPR_ASSERT(_sdl);
417 return _sdl->getInputChannelContext().keyboard_grab(ev.windowID, false);
418 case SDL_EVENT_WINDOW_MOUSE_ENTER:
419 WINPR_ASSERT(_sdl);
420 if (!_sdl->getInputChannelContext().keyboard_grab(ev.windowID, true))
421 return false;
422 return _sdl->getInputChannelContext().keyboard_focus_in();
423 case SDL_EVENT_WINDOW_FOCUS_GAINED:
424 return _sdl->getInputChannelContext().keyboard_focus_in();
425
426 default:
427 return true;
428 }
429}

◆ init()

bool sdlDispContext::init ( DispClientContext *  disp)

Definition at line 417 of file SDL2/sdl_disp.cpp.

418{
419 if (!disp)
420 return FALSE;
421
422 auto settings = _sdl->context()->settings;
423
424 if (!settings)
425 return FALSE;
426
427 _disp = disp;
428 disp->custom = this;
429
430 if (freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate))
431 {
432 disp->DisplayControlCaps = sdlDispContext::DisplayControlCaps;
433 }
434
435 _sdl->update_resizeable(TRUE);
436 return TRUE;
437}

◆ uninit()

bool sdlDispContext::uninit ( DispClientContext *  disp)

Definition at line 439 of file SDL2/sdl_disp.cpp.

440{
441 if (!disp)
442 return FALSE;
443
444 _disp = nullptr;
445 _sdl->update_resizeable(FALSE);
446 return TRUE;
447}

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