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
 
sdlDispContextoperator= (const sdlDispContext &other)=delete
 
sdlDispContextoperator= (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
 
sdlDispContextoperator= (const sdlDispContext &other)=delete
 
sdlDispContextoperator= (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 326 of file SDL3/sdl_disp.cpp.

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

◆ handleEvent() [2/2]

bool sdlDispContext::handleEvent ( const SDL_WindowEvent &  ev)

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

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

◆ 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: