Merge pull request #10471 from hardening/sdl3_build

[sdl3] fix build against last SDL3
This commit is contained in:
akallabeth 2024-08-12 16:10:25 +02:00 committed by GitHub
commit d4ecd16477
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 56 additions and 76 deletions

View File

@ -224,7 +224,7 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
{
auto& ev = reinterpret_cast<const SDL_KeyboardEvent&>(event);
update(_renderer);
switch (event.key.keysym.sym)
switch (event.key.key)
{
case SDLK_RETURN:
case SDLK_RETURN2:
@ -478,7 +478,7 @@ void SDLConnectionDialog::resetTimer()
_running = false;
}
Uint32 SDLConnectionDialog::timeout(Uint32 intervalMS, void* pvthis)
Uint32 SDLConnectionDialog::timeout(void* pvthis, SDL_TimerID timerID, Uint32 intervalMS)
{
auto ths = static_cast<SDLConnectionDialog*>(pvthis);
ths->hide();

View File

@ -84,7 +84,7 @@ class SDLConnectionDialog
void resetTimer();
private:
static Uint32 timeout(Uint32 intervalMS, void* _this);
static Uint32 timeout(void* pvthis, SDL_TimerID timerID, Uint32 intervalMS);
private:
struct widget_cfg_t

View File

@ -152,10 +152,10 @@ int SdlInputWidgetList::run(std::vector<std::string>& result)
{
case SDL_EVENT_KEY_UP:
{
auto it = std::remove(pressed.begin(), pressed.end(), event.key.keysym.sym);
auto it = std::remove(pressed.begin(), pressed.end(), event.key.key);
pressed.erase(it, pressed.end());
switch (event.key.keysym.sym)
switch (event.key.key)
{
case SDLK_BACKSPACE:
{
@ -180,7 +180,7 @@ int SdlInputWidgetList::run(std::vector<std::string>& result)
running = false;
res = INPUT_BUTTON_CANCEL;
break;
case SDLK_v:
case SDLK_V:
if (pressed.size() == 2)
{
if ((pressed[0] == SDLK_LCTRL) || (pressed[0] == SDLK_RCTRL))
@ -200,7 +200,7 @@ int SdlInputWidgetList::run(std::vector<std::string>& result)
}
break;
case SDL_EVENT_KEY_DOWN:
pressed.push_back(event.key.keysym.sym);
pressed.push_back(event.key.key);
break;
case SDL_EVENT_TEXT_INPUT:
{
@ -258,9 +258,9 @@ int SdlInputWidgetList::run(std::vector<std::string>& result)
if (LastActiveTextInput != CurrentActiveTextInput)
{
if (CurrentActiveTextInput < 0)
SDL_StopTextInput();
SDL_StopTextInput(_window);
else
SDL_StartTextInput();
SDL_StartTextInput(_window);
LastActiveTextInput = CurrentActiveTextInput;
}

View File

@ -67,7 +67,7 @@ int SdlSelectList::run()
switch (event.type)
{
case SDL_EVENT_KEY_DOWN:
switch (event.key.keysym.sym)
switch (event.key.key)
{
case SDLK_UP:
case SDLK_BACKSPACE:

View File

@ -251,13 +251,13 @@ bool SdlWidget::update_text(SDL_Renderer* renderer, const std::string& text, SDL
{
texture = _image;
dst = _rect;
int w = 0;
int h = 0;
auto rc = SDL_QueryTexture(_image, nullptr, nullptr, &w, &h);
auto propId = SDL_GetTextureProperties(_image);
int w = SDL_GetNumberProperty(propId, SDL_PROP_TEXTURE_WIDTH_NUMBER, -1);
int h = SDL_GetNumberProperty(propId, SDL_PROP_TEXTURE_HEIGHT_NUMBER, -1);
if (w < 0 || h < 0)
widget_log_error(-1, "SDL_GetTextureProperties");
src.w = w;
src.h = h;
if (rc < 0)
widget_log_error(rc, "SDL_QueryTexture");
}
else if (_wrap)
texture = render_text_wrapped(renderer, text, fgcolor, src, dst);

View File

@ -43,7 +43,7 @@ void sdl_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEve
{
auto clip = reinterpret_cast<CliprdrClientContext*>(e->pInterface);
WINPR_ASSERT(clip);
clip->custom = context;
sdl->clip.init(clip);
}
else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0)
{

View File

@ -195,7 +195,7 @@ void sdlDispContext::OnGraphicsReset(void* context, const GraphicsResetEventArgs
}
}
Uint32 sdlDispContext::OnTimer(Uint32 interval, void* param)
Uint32 sdlDispContext::OnTimer(void* param, SDL_TimerID timerID, Uint32 interval)
{
auto ctx = static_cast<sdlDispContext*>(param);
if (!ctx)
@ -372,7 +372,6 @@ BOOL sdlDispContext::handle_window_event(const SDL_WindowEvent* ev)
_sdl->input.keyboard_grab(ev->windowID, SDL_TRUE);
return _sdl->input.keyboard_focus_in();
case SDL_EVENT_WINDOW_FOCUS_GAINED:
case SDL_EVENT_WINDOW_TAKE_FOCUS:
return _sdl->input.keyboard_focus_in();
default:

View File

@ -57,7 +57,7 @@ class sdlDispContext
UINT32 maxMonitorAreaFactorA, UINT32 maxMonitorAreaFactorB);
static void OnActivated(void* context, const ActivatedEventArgs* e);
static void OnGraphicsReset(void* context, const GraphicsResetEventArgs* e);
static Uint32 SDLCALL OnTimer(Uint32 interval, void* param);
static Uint32 SDLCALL OnTimer(void* param, SDL_TimerID timerID, Uint32 interval);
private:
SdlContext* _sdl = nullptr;

View File

@ -48,6 +48,7 @@
#include <SDL3/SDL.h>
#include <SDL3/SDL_hints.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_oldnames.h>
#include "sdl_channels.hpp"
#include "sdl_freerdp.hpp"
@ -483,7 +484,6 @@ static void sdl_destroy_primary(SdlContext* sdl)
if (!sdl)
return;
sdl->primary.reset();
sdl->primary_format.reset();
}
/* Create a SDL surface from the GDI buffer */
@ -498,19 +498,17 @@ static BOOL sdl_create_primary(SdlContext* sdl)
sdl_destroy_primary(sdl);
sdl->primary =
SDLSurfacePtr(SDL_CreateSurfaceFrom(gdi->primary_buffer, static_cast<int>(gdi->width),
static_cast<int>(gdi->height),
static_cast<int>(gdi->stride), sdl->sdl_pixel_format),
SDLSurfacePtr(SDL_CreateSurfaceFrom(static_cast<int>(gdi->width),
static_cast<int>(gdi->height), sdl->sdl_pixel_format,
gdi->primary_buffer, static_cast<int>(gdi->stride)),
SDL_DestroySurface);
sdl->primary_format =
SDLPixelFormatPtr(SDL_CreatePixelFormat(sdl->sdl_pixel_format), SDL_DestroyPixelFormat);
if (!sdl->primary || !sdl->primary_format)
if (!sdl->primary)
return FALSE;
SDL_SetSurfaceBlendMode(sdl->primary.get(), SDL_BLENDMODE_NONE);
SDL_FillSurfaceRect(sdl->primary.get(), nullptr,
SDL_MapRGBA(sdl->primary_format.get(), 0, 0, 0, 0xff));
SDL_Rect surfaceRect = { 0, 0, gdi->width, gdi->height };
SDL_FillSurfaceRect(sdl->primary.get(), &surfaceRect,
SDL_MapSurfaceRGBA(sdl->primary.get(), 0, 0, 0, 0xff));
return TRUE;
}
@ -1029,16 +1027,16 @@ static int sdl_run(SdlContext* sdl)
window->second.fill();
window->second.updateSurface();
break;
case SDL_EVENT_WINDOW_MOVED:
{
auto r = window->second.rect();
auto id = window->second.id();
WLog_DBG(SDL_TAG, "%lu: %dx%d-%dx%d", id, r.x, r.y, r.w, r.h);
}
break;
default:
case SDL_EVENT_WINDOW_MOVED:
{
auto r = window->second.rect();
auto id = window->second.id();
WLog_DBG(SDL_TAG, "%lu: %dx%d-%dx%d", id, r.x, r.y, r.w, r.h);
}
break;
}
default:
break;
}
}
}
break;
@ -1645,7 +1643,7 @@ int main(int argc, char* argv[])
SDL_SetLogOutputFunction(winpr_LogOutputFunction, sdl);
auto level = WLog_GetLogLevel(sdl->log);
SDL_LogSetAllPriority(wloglevel2dl(level));
SDL_SetLogPriorities(wloglevel2dl(level));
auto context = sdl->context();
WINPR_ASSERT(context);
@ -1699,8 +1697,7 @@ BOOL SdlContext::update_resizeable(BOOL enable)
SdlContext::SdlContext(rdpContext* context)
: _context(context), log(WLog_Get(SDL_TAG)), update_complete(true), disp(this), clip(this),
input(this), primary(nullptr, SDL_DestroySurface),
primary_format(nullptr, SDL_DestroyPixelFormat), rdp_thread_running(false)
input(this), primary(nullptr, SDL_DestroySurface), rdp_thread_running(false)
{
WINPR_ASSERT(context);
grab_kbd_enabled = freerdp_settings_get_bool(context->settings, FreeRDP_GrabKeyboard);

View File

@ -42,7 +42,6 @@
#include "dialogs/sdl_connection_dialog.hpp"
using SDLSurfacePtr = std::unique_ptr<SDL_Surface, decltype(&SDL_DestroySurface)>;
using SDLPixelFormatPtr = std::unique_ptr<SDL_PixelFormat, decltype(&SDL_DestroyPixelFormat)>;
class SdlContext
{
@ -77,9 +76,8 @@ class SdlContext
sdlClip clip;
SDLSurfacePtr primary;
SDLPixelFormatPtr primary_format;
SDL_PixelFormatEnum sdl_pixel_format = SDL_PIXELFORMAT_UNKNOWN;
SDL_PixelFormat sdl_pixel_format = SDL_PIXELFORMAT_UNKNOWN;
std::unique_ptr<SDLConnectionDialog> connection_dialog;

View File

@ -23,6 +23,8 @@
#include "sdl_utils.hpp"
#include "sdl_prefs.hpp"
#include <SDL3/SDL_oldnames.h>
#include <map>
#include <freerdp/scancode.h>
@ -160,17 +162,13 @@ static const scancode_entry_t map[] = {
ENTRY(SDL_SCANCODE_PAGEUP, RDP_SCANCODE_PRIOR),
ENTRY(SDL_SCANCODE_END, RDP_SCANCODE_END),
ENTRY(SDL_SCANCODE_PAGEDOWN, RDP_SCANCODE_NEXT),
ENTRY(SDL_SCANCODE_AUDIONEXT, RDP_SCANCODE_MEDIA_NEXT_TRACK),
ENTRY(SDL_SCANCODE_AUDIOPREV, RDP_SCANCODE_MEDIA_PREV_TRACK),
ENTRY(SDL_SCANCODE_AUDIOSTOP, RDP_SCANCODE_MEDIA_STOP),
ENTRY(SDL_SCANCODE_AUDIOPLAY, RDP_SCANCODE_MEDIA_PLAY_PAUSE),
ENTRY(SDL_SCANCODE_AUDIOMUTE, RDP_SCANCODE_VOLUME_MUTE),
ENTRY(SDL_SCANCODE_MEDIASELECT, RDP_SCANCODE_LAUNCH_MEDIA_SELECT),
ENTRY(SDL_SCANCODE_MAIL, RDP_SCANCODE_LAUNCH_MAIL),
ENTRY(SDL_SCANCODE_APP1, RDP_SCANCODE_LAUNCH_APP1),
ENTRY(SDL_SCANCODE_APP2, RDP_SCANCODE_LAUNCH_APP2),
ENTRY(SDL_SCANCODE_MEDIA_NEXT_TRACK, RDP_SCANCODE_MEDIA_NEXT_TRACK),
ENTRY(SDL_SCANCODE_MEDIA_PREVIOUS_TRACK, RDP_SCANCODE_MEDIA_PREV_TRACK),
ENTRY(SDL_SCANCODE_MEDIA_STOP, RDP_SCANCODE_MEDIA_STOP),
ENTRY(SDL_SCANCODE_MEDIA_PLAY, RDP_SCANCODE_MEDIA_PLAY_PAUSE),
ENTRY(SDL_SCANCODE_MUTE, RDP_SCANCODE_VOLUME_MUTE),
ENTRY(SDL_SCANCODE_MEDIA_SELECT, RDP_SCANCODE_LAUNCH_MEDIA_SELECT),
ENTRY(SDL_SCANCODE_SYSREQ, RDP_SCANCODE_SYSREQ),
ENTRY(SDL_SCANCODE_WWW, RDP_SCANCODE_BROWSER_HOME),
ENTRY(SDL_SCANCODE_LEFTBRACKET, RDP_SCANCODE_OEM_4),
ENTRY(SDL_SCANCODE_RIGHTBRACKET, RDP_SCANCODE_OEM_6),
ENTRY(SDL_SCANCODE_APOSTROPHE, RDP_SCANCODE_OEM_7),
@ -276,19 +274,11 @@ static const scancode_entry_t map[] = {
ENTRY(SDL_SCANCODE_KP_OCTAL, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_KP_DECIMAL, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_KP_HEXADECIMAL, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_CALCULATOR, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_COMPUTER, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_AC_REFRESH, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_AC_BOOKMARKS, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_BRIGHTNESSDOWN, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_BRIGHTNESSUP, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_DISPLAYSWITCH, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_KBDILLUMTOGGLE, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_KBDILLUMDOWN, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_KBDILLUMUP, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_EJECT, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_AUDIOREWIND, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_AUDIOFASTFORWARD, RDP_SCANCODE_UNKNOWN)
ENTRY(SDL_SCANCODE_MEDIA_EJECT, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_MEDIA_REWIND, RDP_SCANCODE_UNKNOWN),
ENTRY(SDL_SCANCODE_MEDIA_FAST_FORWARD, RDP_SCANCODE_UNKNOWN)
#endif
};
@ -538,31 +528,31 @@ void sdlInput::remapInitialize()
BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
{
WINPR_ASSERT(ev);
const UINT32 rdp_scancode = sdl_scancode_to_rdp(ev->keysym.scancode);
const UINT32 rdp_scancode = sdl_scancode_to_rdp(ev->scancode);
const SDL_Keymod mods = SDL_GetModState();
if ((mods & _hotkeyModmask) == _hotkeyModmask)
{
if (ev->type == SDL_EVENT_KEY_DOWN)
{
if (ev->keysym.scancode == _hotkeyFullscreen)
if (ev->scancode == _hotkeyFullscreen)
{
_sdl->update_fullscreen(!_sdl->fullscreen);
return TRUE;
}
if (ev->keysym.scancode == _hotkeyResizable)
if (ev->scancode == _hotkeyResizable)
{
_sdl->update_resizeable(!_sdl->resizeable);
return TRUE;
}
if (ev->keysym.scancode == _hotkeyGrab)
if (ev->scancode == _hotkeyGrab)
{
_sdl->grab_kbd_enabled = !_sdl->grab_kbd_enabled;
keyboard_grab(ev->windowID, _sdl->grab_kbd ? SDL_FALSE : SDL_TRUE);
return TRUE;
}
if (ev->keysym.scancode == _hotkeyDisconnect)
if (ev->scancode == _hotkeyDisconnect)
{
freerdp_abort_connect_context(_sdl->context());
return TRUE;

View File

@ -26,7 +26,7 @@
#include "sdl_touch.hpp"
#include "sdl_utils.hpp"
#include <SDL_mouse.h>
#include <SDL3/SDL_mouse.h>
#define TAG CLIENT_TAG("SDL.pointer")

View File

@ -50,7 +50,6 @@ const char* sdl_event_type_str(Uint32 type)
EV_CASE_STR(SDL_EVENT_DISPLAY_REMOVED);
EV_CASE_STR(SDL_EVENT_DISPLAY_MOVED);
EV_CASE_STR(SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED);
EV_CASE_STR(SDL_EVENT_DISPLAY_HDR_STATE_CHANGED);
EV_CASE_STR(SDL_EVENT_WINDOW_SHOWN);
EV_CASE_STR(SDL_EVENT_WINDOW_HIDDEN);
EV_CASE_STR(SDL_EVENT_WINDOW_EXPOSED);
@ -65,7 +64,6 @@ const char* sdl_event_type_str(Uint32 type)
EV_CASE_STR(SDL_EVENT_WINDOW_FOCUS_GAINED);
EV_CASE_STR(SDL_EVENT_WINDOW_FOCUS_LOST);
EV_CASE_STR(SDL_EVENT_WINDOW_CLOSE_REQUESTED);
EV_CASE_STR(SDL_EVENT_WINDOW_TAKE_FOCUS);
EV_CASE_STR(SDL_EVENT_WINDOW_HIT_TEST);
EV_CASE_STR(SDL_EVENT_WINDOW_ICCPROF_CHANGED);
EV_CASE_STR(SDL_EVENT_WINDOW_DISPLAY_CHANGED);
@ -74,8 +72,6 @@ const char* sdl_event_type_str(Uint32 type)
EV_CASE_STR(SDL_EVENT_WINDOW_ENTER_FULLSCREEN);
EV_CASE_STR(SDL_EVENT_WINDOW_LEAVE_FULLSCREEN);
EV_CASE_STR(SDL_EVENT_WINDOW_DESTROYED);
EV_CASE_STR(SDL_EVENT_WINDOW_PEN_ENTER);
EV_CASE_STR(SDL_EVENT_WINDOW_PEN_LEAVE);
EV_CASE_STR(SDL_EVENT_KEY_DOWN);
EV_CASE_STR(SDL_EVENT_KEY_UP);

View File

@ -169,7 +169,7 @@ bool SdlWindow::fill(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
if (!surface)
return false;
SDL_Rect rect = { 0, 0, surface->w, surface->h };
auto color = SDL_MapRGBA(surface->format, r, g, b, a);
auto color = SDL_MapSurfaceRGBA(surface, r, g, b, a);
SDL_FillSurfaceRect(surface, &rect, color);
return true;