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 448 of file SDL2/sdl_disp.cpp.

448 : _sdl(sdl)
449{
450 SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO);
451
452 WINPR_ASSERT(_sdl);
453 WINPR_ASSERT(_sdl->context()->settings);
454 WINPR_ASSERT(_sdl->context()->pubSub);
455
456 auto settings = _sdl->context()->settings;
457 auto pubSub = _sdl->context()->pubSub;
458
459 _lastSentWidth = _targetWidth =
460 WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth));
461 _lastSentHeight = _targetHeight =
462 WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
463 if (PubSub_SubscribeActivated(pubSub, sdlDispContext::OnActivated) < 0)
464 throw std::exception();
465 if (PubSub_SubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset) < 0)
466 throw std::exception();
467 addTimer();
468}
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 470 of file SDL2/sdl_disp.cpp.

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

Member Function Documentation

◆ handle_window_event()

BOOL sdlDispContext::handle_window_event ( const SDL_WindowEvent *  ev)

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

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

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

◆ handleEvent() [2/2]

bool sdlDispContext::handleEvent ( const SDL_WindowEvent &  ev)

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

371{
372 auto window = _sdl->getWindowForId(ev.windowID);
373 if (!window)
374 return true;
375
376 auto bordered = freerdp_settings_get_bool(_sdl->context()->settings, FreeRDP_Decorations);
377 window->setBordered(bordered);
378
379 switch (ev.type)
380 {
381 case SDL_EVENT_WINDOW_HIDDEN:
382 case SDL_EVENT_WINDOW_MINIMIZED:
383 return _sdl->redraw(true);
384 case SDL_EVENT_WINDOW_ENTER_FULLSCREEN:
385 return updateMonitor(ev.windowID);
386 case SDL_EVENT_WINDOW_LEAVE_FULLSCREEN:
387 return updateMonitor(ev.windowID);
388
389 case SDL_EVENT_WINDOW_EXPOSED:
390 case SDL_EVENT_WINDOW_SHOWN:
391 case SDL_EVENT_WINDOW_MAXIMIZED:
392 case SDL_EVENT_WINDOW_RESTORED:
393 if (!_sdl->redraw())
394 return false;
395
396 /* fallthrough */
397 WINPR_FALLTHROUGH
398 case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
399 case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
400 case SDL_EVENT_WINDOW_RESIZED:
401 return updateMonitor(ev.windowID);
402 case SDL_EVENT_WINDOW_MOUSE_LEAVE:
403 WINPR_ASSERT(_sdl);
404 return _sdl->getInputChannelContext().keyboard_grab(ev.windowID, false);
405 case SDL_EVENT_WINDOW_MOUSE_ENTER:
406 WINPR_ASSERT(_sdl);
407 if (!_sdl->getInputChannelContext().keyboard_grab(ev.windowID, true))
408 return false;
409 return _sdl->getInputChannelContext().keyboard_focus_in();
410 case SDL_EVENT_WINDOW_FOCUS_GAINED:
411 return _sdl->getInputChannelContext().keyboard_focus_in();
412
413 default:
414 return true;
415 }
416}

◆ init()

bool sdlDispContext::init ( DispClientContext *  disp)

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

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

◆ uninit()

bool sdlDispContext::uninit ( DispClientContext *  disp)

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

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

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