FreeRDP
Loading...
Searching...
No Matches
SDL3/sdl_channels.cpp
1
20#include <freerdp/config.h>
21
22#include <winpr/assert.h>
23
24#include <freerdp/client/rail.h>
25#include <freerdp/client/cliprdr.h>
26#include <freerdp/client/disp.h>
27#include <freerdp/client/rdpgfx.h>
28#include <freerdp/channels/rdpgfx.h>
29#include <freerdp/channels/rdpewa.h>
30
31#include "sdl_channels.hpp"
32#include "sdl_context.hpp"
33#include "sdl_disp.hpp"
34
35void sdl_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e)
36{
37 auto sdl = get_context(context);
38
39 WINPR_ASSERT(sdl);
40 WINPR_ASSERT(e);
41
42 if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0)
43 {
44 auto rail = reinterpret_cast<RailClientContext*>(e->pInterface);
45 WINPR_ASSERT(rail);
46
47 if (!sdl->getRailChannelContext().init(rail))
48 WLog_Print(sdl->getWLog(), WLOG_WARN, "Failed to initialize RAIL channel");
49 }
50 else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
51 {
52 auto clip = reinterpret_cast<CliprdrClientContext*>(e->pInterface);
53 WINPR_ASSERT(clip);
54
55 if (!sdl->getClipboardChannelContext().init(clip))
56 WLog_Print(sdl->getWLog(), WLOG_WARN, "Failed to initialize clipboard channel");
57 }
58 else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0)
59 {
60 auto disp = reinterpret_cast<DispClientContext*>(e->pInterface);
61 WINPR_ASSERT(disp);
62
63 if (!sdl->getDisplayChannelContext().init(disp))
64 WLog_Print(sdl->getWLog(), WLOG_WARN, "Failed to initialize display channel");
65 }
66 else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0)
67 {
68 /* After the common handler wires the GFX pipeline, override UpdateWindowFromSurface
69 * to route window-mapped surfaces to RAIL. */
70 freerdp_client_OnChannelConnectedEventHandler(context, e);
71 auto gfx = reinterpret_cast<RdpgfxClientContext*>(e->pInterface);
72 auto ctx = static_cast<rdpContext*>(context);
73 if (gfx && freerdp_settings_get_bool(ctx->settings, FreeRDP_RemoteApplicationMode))
74 gfx->UpdateWindowFromSurface = SdlRail::UpdateWindowFromSurface;
75 }
76 else
77 freerdp_client_OnChannelConnectedEventHandler(context, e);
78}
79
80void sdl_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e)
81{
82 auto sdl = get_context(context);
83
84 WINPR_ASSERT(sdl);
85 WINPR_ASSERT(e);
86
87 // TODO: Set resizeable depending on disp channel and /dynamic-resolution
88 if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0)
89 {
90 auto rail = reinterpret_cast<RailClientContext*>(e->pInterface);
91 WINPR_ASSERT(rail);
92 sdl->getRailChannelContext().uninit(rail);
93 rail->custom = nullptr;
94 }
95 else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
96 {
97 auto clip = reinterpret_cast<CliprdrClientContext*>(e->pInterface);
98 WINPR_ASSERT(clip);
99
100 if (!sdl->getClipboardChannelContext().uninit(clip))
101 WLog_Print(sdl->getWLog(), WLOG_WARN, "Failed to uninitialize clipboard channel");
102 clip->custom = nullptr;
103 }
104 else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0)
105 {
106 auto disp = reinterpret_cast<DispClientContext*>(e->pInterface);
107 WINPR_ASSERT(disp);
108
109 if (!sdl->getDisplayChannelContext().uninit(disp))
110 WLog_Print(sdl->getWLog(), WLOG_WARN, "Failed to uninitialize display channel");
111 disp->custom = nullptr;
112 }
113 else
114 freerdp_client_OnChannelDisconnectedEventHandler(context, e);
115}
116
117void sdl_OnUserNotificationEventHandler(void* context, const UserNotificationEventArgs* e)
118{
119 WINPR_UNUSED(context);
120 WINPR_ASSERT(e);
121 WINPR_ASSERT(e->e.Sender);
122
123 if (strcmp(e->e.Sender, RDPEWA_CHANNEL_NAME) != 0)
124 return;
125
126 if (e->cancelPreviousNotification)
127 return;
128
129 struct userdata
130 {
131 std::string sender;
132 std::string message;
133 uint32_t timeoutMS = 0;
134 };
135
136 auto ud = new struct userdata;
137 if (e->message)
138 ud->message = e->message;
139 if (e->e.Sender)
140 ud->sender = e->e.Sender;
141 ud->timeoutMS = e->timeoutMS;
142
143 SDL_RunOnMainThread(
144 [](void* userdata)
145 {
146 auto ed = static_cast<struct userdata*>(userdata);
147 assert(ed);
148 auto parent = SDL_GetMouseFocus();
149 if (!parent)
150 parent = SDL_GetKeyboardFocus();
151 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, ed->sender.c_str(),
152 ed->message.c_str(), parent);
153 delete ed;
154 },
155 ud, false);
156}
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.