FreeRDP
Loading...
Searching...
No Matches
SDL3/sdl_channels.cpp
1
19
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
67 freerdp_client_OnChannelConnectedEventHandler(context, e);
68 if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0)
69 {
70 /* After the common handler wires the GFX pipeline, override UpdateWindowFromSurface
71 * to route window-mapped surfaces to RAIL. */
72 auto gfx = reinterpret_cast<RdpgfxClientContext*>(e->pInterface);
73 auto ctx = static_cast<rdpContext*>(context);
74 if (gfx && freerdp_settings_get_bool(ctx->settings, FreeRDP_RemoteApplicationMode))
75 gfx->UpdateWindowFromSurface = SdlRail::UpdateWindowFromSurface;
76 }
77}
78
79void sdl_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e)
80{
81 auto sdl = get_context(context);
82
83 WINPR_ASSERT(sdl);
84 WINPR_ASSERT(e);
85
86 /* Never connected (failed connect). */
87 if (!e->pInterface)
88 return;
89
90 // TODO: Set resizeable depending on disp channel and /dynamic-resolution
91 if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0)
92 {
93 auto rail = reinterpret_cast<RailClientContext*>(e->pInterface);
94 sdl->getRailChannelContext().uninit(rail);
95 rail->custom = nullptr;
96 }
97 else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
98 {
99 auto clip = reinterpret_cast<CliprdrClientContext*>(e->pInterface);
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 if (!sdl->getDisplayChannelContext().uninit(disp))
108 WLog_Print(sdl->getWLog(), WLOG_WARN, "Failed to uninitialize display channel");
109 disp->custom = nullptr;
110 }
111
112 freerdp_client_OnChannelDisconnectedEventHandler(context, e);
113}
114
115void sdl_OnUserNotificationEventHandler(void* context, const UserNotificationEventArgs* e)
116{
117 WINPR_UNUSED(context);
118 WINPR_ASSERT(e);
119 WINPR_ASSERT(e->e.Sender);
120
121 if (strcmp(e->e.Sender, RDPEWA_CHANNEL_NAME) != 0)
122 return;
123
124 if (e->cancelPreviousNotification)
125 return;
126
127 struct userdata
128 {
129 std::string sender;
130 std::string message;
131 uint32_t timeoutMS = 0;
132 };
133
134 auto ud = new struct userdata;
135 if (e->message)
136 ud->message = e->message;
137 if (e->e.Sender)
138 ud->sender = e->e.Sender;
139 ud->timeoutMS = e->timeoutMS;
140
141 SDL_RunOnMainThread(
142 [](void* userdata)
143 {
144 auto ed = static_cast<struct userdata*>(userdata);
145 assert(ed);
146 auto parent = SDL_GetMouseFocus();
147 if (!parent)
148 parent = SDL_GetKeyboardFocus();
149 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, ed->sender.c_str(),
150 ed->message.c_str(), parent);
151 delete ed;
152 },
153 ud, false);
154}
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.