22#include <freerdp/config.h>
32#include <winpr/assert.h>
35#include <freerdp/log.h>
37#define TAG CLIENT_TAG("sdl")
39#include "sdl_monitor.hpp"
40#include "sdl_context.hpp"
54 MONITOR_INFO* monitors;
60int sdl_list_monitors([[maybe_unused]]
SdlContext* sdl)
62 SDL_Init(SDL_INIT_VIDEO);
65 auto ids = SDL_GetDisplays(&nmonitors);
67 printf(
"listing %d monitors:\n", nmonitors);
68 for (
int i = 0; i < nmonitors; i++)
72 const auto brc = SDL_GetDisplayBounds(
id, &rect);
73 const char* name = SDL_GetDisplayName(
id);
77 printf(
" %s [%u] [%s] %dx%d\t+%d+%d\n", (i == 0) ?
"*" :
" ", id, name, rect.w, rect.h,
85[[nodiscard]]
static BOOL sdl_apply_mon_max_size(
SdlContext* sdl, UINT32* pMaxWidth,
93 WINPR_ASSERT(pMaxWidth);
94 WINPR_ASSERT(pMaxHeight);
96 auto settings = sdl->context()->settings;
97 WINPR_ASSERT(settings);
101 auto monitor =
static_cast<const rdpMonitor*
>(
102 freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x));
104 left = std::min(monitor->x, left);
105 top = std::min(monitor->y, top);
106 right = std::max(monitor->x + monitor->width, right);
107 bottom = std::max(monitor->y + monitor->height, bottom);
110 const int32_t w = right - left;
111 const int32_t h = bottom - top;
113 *pMaxWidth = WINPR_ASSERTING_INT_CAST(uint32_t, w);
114 *pMaxHeight = WINPR_ASSERTING_INT_CAST(uint32_t, h);
118[[nodiscard]]
static BOOL sdl_apply_max_size(
SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
121 WINPR_ASSERT(pMaxWidth);
122 WINPR_ASSERT(pMaxHeight);
124 auto settings = sdl->context()->settings;
125 WINPR_ASSERT(settings);
132 auto monitor =
static_cast<const rdpMonitor*
>(
133 freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x));
137 *pMaxWidth = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->width);
138 *pMaxHeight = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->height);
143 SDL_GetDisplayUsableBounds(monitor->orig_screen, &rect);
144 *pMaxWidth = WINPR_ASSERTING_INT_CAST(uint32_t, rect.w);
145 *pMaxHeight = WINPR_ASSERTING_INT_CAST(uint32_t, rect.h);
150 SDL_GetDisplayUsableBounds(monitor->orig_screen, &rect);
152 *pMaxWidth = WINPR_ASSERTING_INT_CAST(uint32_t, rect.w);
153 *pMaxHeight = WINPR_ASSERTING_INT_CAST(uint32_t, rect.h);
156 *pMaxWidth = (WINPR_ASSERTING_INT_CAST(uint32_t, rect.w) *
161 *pMaxHeight = (WINPR_ASSERTING_INT_CAST(uint32_t, rect.h) *
175[[nodiscard]]
static BOOL sdl_apply_display_properties(
SdlContext* sdl)
179 rdpSettings* settings = sdl->context()->settings;
180 WINPR_ASSERT(settings);
182 std::vector<rdpMonitor> monitors;
188 if (sdl->monitorIds().empty())
190 const auto id = sdl->monitorIds().front();
191 auto monitor = sdl->getDisplay(
id);
192 monitor.is_primary =
true;
195 monitors.emplace_back(monitor);
201 for (
const auto&
id : sdl->monitorIds())
203 const auto monitor = sdl->getDisplay(
id);
204 monitors.emplace_back(monitor);
210[[nodiscard]]
static BOOL sdl_detect_single_window(
SdlContext* sdl, UINT32* pMaxWidth,
214 WINPR_ASSERT(pMaxWidth);
215 WINPR_ASSERT(pMaxHeight);
217 rdpSettings* settings = sdl->context()->settings;
218 WINPR_ASSERT(settings);
229 SDL_DisplayID
id = 0;
230 const auto& ids = sdl->monitorIds();
235 sdl->setMonitorIds({
id });
238 if (!sdl_apply_display_properties(sdl))
240 return sdl_apply_max_size(sdl, pMaxWidth, pMaxHeight);
242 return sdl_apply_mon_max_size(sdl, pMaxWidth, pMaxHeight);
245BOOL sdl_detect_monitors(
SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
248 WINPR_ASSERT(pMaxWidth);
249 WINPR_ASSERT(pMaxHeight);
251 rdpSettings* settings = sdl->context()->settings;
252 WINPR_ASSERT(settings);
254 const auto& ids = sdl->getDisplayIds();
259 sdl->setMonitorIds(ids);
262 sdl->setMonitorIds({ ids.front() });
271 "Found %" PRIu32
" monitor IDs, but only have %" PRIuz
" monitors connected",
276 std::vector<SDL_DisplayID> used;
277 for (
size_t x = 0; x < nr; x++)
279 auto cur =
static_cast<const UINT32*
>(
280 freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorIds, x));
283 SDL_DisplayID
id = *cur;
286 if (std::find(ids.begin(), ids.end(),
id) == ids.end())
288 WLog_ERR(TAG,
"Supplied monitor ID[%" PRIuz
"]=%" PRIu32
" is invalid", x,
id);
293 if (std::find(used.begin(), used.end(),
id) != used.end())
295 WLog_ERR(TAG,
"Duplicate monitor ID[%" PRIuz
"]=%" PRIu32
" detected", x,
id);
300 sdl->setMonitorIds(used);
303 if (!sdl_apply_display_properties(sdl))
306 auto size =
static_cast<uint32_t
>(sdl->monitorIds().size());
310 return sdl_detect_single_window(sdl, pMaxWidth, pMaxHeight);
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 val)
Sets a UINT32 settings value.
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_monitor_def_array_sorted(rdpSettings *settings, const rdpMonitor *monitors, size_t count)
Sort monitor array according to:
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.