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

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

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

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#if defined(WITH_DEBUG_SDL_EVENTS)
342 SDL_Log("got windowEvent %s [0x%08" PRIx32 "]", sdl_window_event_str(ev->event).c_str(),
343 ev->event);
344#endif
345 auto bordered = freerdp_settings_get_bool(_sdl->context()->settings, FreeRDP_Decorations)
346 ? SDL_TRUE
347 : SDL_FALSE;
348
349 auto it = _sdl->windows.find(ev->windowID);
350 if (it != _sdl->windows.end())
351 it->second.setBordered(bordered);
352
353 switch (ev->event)
354 {
355 case SDL_WINDOWEVENT_HIDDEN:
356 case SDL_WINDOWEVENT_MINIMIZED:
357 return gdi_send_suppress_output(_sdl->context()->gdi, TRUE);
358
359 case SDL_WINDOWEVENT_EXPOSED:
360 case SDL_WINDOWEVENT_SHOWN:
361 case SDL_WINDOWEVENT_MAXIMIZED:
362 case SDL_WINDOWEVENT_RESTORED:
363 return gdi_send_suppress_output(_sdl->context()->gdi, FALSE);
364
365 case SDL_WINDOWEVENT_RESIZED:
366 case SDL_WINDOWEVENT_SIZE_CHANGED:
367 _targetWidth = ev->data1;
368 _targetHeight = ev->data2;
369 return addTimer();
370
371 case SDL_WINDOWEVENT_LEAVE:
372 WINPR_ASSERT(_sdl);
373 _sdl->input.keyboard_grab(ev->windowID, false);
374 return TRUE;
375 case SDL_WINDOWEVENT_ENTER:
376 WINPR_ASSERT(_sdl);
377 _sdl->input.keyboard_grab(ev->windowID, true);
378 return _sdl->input.keyboard_focus_in();
379 case SDL_WINDOWEVENT_FOCUS_GAINED:
380 case SDL_WINDOWEVENT_TAKE_FOCUS:
381 return _sdl->input.keyboard_focus_in();
382
383 default:
384 return TRUE;
385 }
386}
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 case SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED:
347 SDL_LogDebug(cat, "The display with id %u changed mode", ev.displayID);
348 return updateMonitors(ev.type, ev.displayID);
349 case SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED:
350 SDL_LogDebug(cat, "The display with id %u changed desktop mode", ev.displayID);
351 return updateMonitors(ev.type, ev.displayID);
352 default:
353 return true;
354 }
355}

◆ handleEvent() [2/2]

bool sdlDispContext::handleEvent ( const SDL_WindowEvent &  ev)

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

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

◆ init()

bool sdlDispContext::init ( DispClientContext *  disp)

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

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

◆ uninit()

bool sdlDispContext::uninit ( DispClientContext *  disp)

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

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

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