wayland: Fix primary selection handling when the protocol isn't supported

The primary selection protocol is optional, so the function pointers to the internal Wayland functions should only be set if the protocol is supported. This allows graceful fall-back to the generic SDL implementation in other cases.

Fixes the clipboard tests under Weston.
main
Frank Praznik 2023-10-12 11:54:18 -04:00
parent e152129787
commit 72034b9a07
2 changed files with 7 additions and 4 deletions

View File

@ -107,7 +107,7 @@ int Wayland_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text)
{ {
SDL_VideoData *video_data = _this->driverdata; SDL_VideoData *video_data = _this->driverdata;
SDL_WaylandPrimarySelectionDevice *primary_selection_device = NULL; SDL_WaylandPrimarySelectionDevice *primary_selection_device = NULL;
int status = 0; int status = -1;
if (video_data->input != NULL && video_data->input->primary_selection_device != NULL) { if (video_data->input != NULL && video_data->input->primary_selection_device != NULL) {
primary_selection_device = video_data->input->primary_selection_device; primary_selection_device = video_data->input->primary_selection_device;

View File

@ -230,9 +230,6 @@ static SDL_VideoDevice *Wayland_CreateDevice(void)
device->SetClipboardData = Wayland_SetClipboardData; device->SetClipboardData = Wayland_SetClipboardData;
device->GetClipboardData = Wayland_GetClipboardData; device->GetClipboardData = Wayland_GetClipboardData;
device->HasClipboardData = Wayland_HasClipboardData; device->HasClipboardData = Wayland_HasClipboardData;
device->SetPrimarySelectionText = Wayland_SetPrimarySelectionText;
device->GetPrimarySelectionText = Wayland_GetPrimarySelectionText;
device->HasPrimarySelectionText = Wayland_HasPrimarySelectionText;
device->StartTextInput = Wayland_StartTextInput; device->StartTextInput = Wayland_StartTextInput;
device->StopTextInput = Wayland_StopTextInput; device->StopTextInput = Wayland_StopTextInput;
device->SetTextInputRect = Wayland_SetTextInputRect; device->SetTextInputRect = Wayland_SetTextInputRect;
@ -912,6 +909,12 @@ int Wayland_VideoInit(SDL_VideoDevice *_this)
Wayland_InitKeyboard(_this); Wayland_InitKeyboard(_this);
if (data->primary_selection_device_manager) {
_this->SetPrimarySelectionText = Wayland_SetPrimarySelectionText;
_this->GetPrimarySelectionText = Wayland_GetPrimarySelectionText;
_this->HasPrimarySelectionText = Wayland_HasPrimarySelectionText;
}
data->initializing = SDL_FALSE; data->initializing = SDL_FALSE;
return 0; return 0;