wayland: add support for SDL_SetWindowGrab

This commit is contained in:
Tudor Brindus 2020-04-17 13:55:44 -04:00
parent b47f577a9d
commit 1a291ab118
5 changed files with 75 additions and 0 deletions

View File

@ -65,6 +65,7 @@ struct SDL_WaylandInput {
struct wl_keyboard *keyboard; struct wl_keyboard *keyboard;
SDL_WaylandDataDevice *data_device; SDL_WaylandDataDevice *data_device;
struct zwp_relative_pointer_v1 *relative_pointer; struct zwp_relative_pointer_v1 *relative_pointer;
struct zwp_confined_pointer_v1 *confined_pointer;
SDL_WindowData *pointer_focus; SDL_WindowData *pointer_focus;
SDL_WindowData *keyboard_focus; SDL_WindowData *keyboard_focus;
@ -1263,6 +1264,64 @@ int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input)
return 0; return 0;
} }
static void
confined_pointer_confined(void *data,
struct zwp_confined_pointer_v1 *confined_pointer)
{
}
static void
confined_pointer_unconfined(void *data,
struct zwp_confined_pointer_v1 *confined_pointer)
{
}
static const struct zwp_confined_pointer_v1_listener confined_pointer_listener = {
confined_pointer_confined,
confined_pointer_unconfined,
};
int Wayland_input_confine_pointer(SDL_Window *window, struct SDL_WaylandInput *input)
{
SDL_WindowData *w = window->driverdata;
SDL_VideoData *d = input->display;
struct zwp_confined_pointer_v1 *confined_pointer;
if (!d->pointer_constraints)
return -1;
if (!input->pointer)
return -1;
/* A confine may already be active, in which case we should destroy it and
* create a new one. */
if (input->confined_pointer)
Wayland_input_unconfine_pointer(input);
confined_pointer =
zwp_pointer_constraints_v1_confine_pointer(d->pointer_constraints,
w->surface,
input->pointer,
NULL,
ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
zwp_confined_pointer_v1_add_listener(confined_pointer,
&confined_pointer_listener,
window);
input->confined_pointer = confined_pointer;
return 0;
}
int Wayland_input_unconfine_pointer(struct SDL_WaylandInput *input)
{
if (input->confined_pointer) {
zwp_confined_pointer_v1_destroy(input->confined_pointer);
input->confined_pointer = NULL;
}
return 0;
}
#endif /* SDL_VIDEO_DRIVER_WAYLAND */ #endif /* SDL_VIDEO_DRIVER_WAYLAND */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@ -43,6 +43,9 @@ extern void Wayland_display_destroy_pointer_constraints(SDL_VideoData *d);
extern int Wayland_input_lock_pointer(struct SDL_WaylandInput *input); extern int Wayland_input_lock_pointer(struct SDL_WaylandInput *input);
extern int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input); extern int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input);
extern int Wayland_input_confine_pointer(SDL_Window *window, struct SDL_WaylandInput *input);
extern int Wayland_input_unconfine_pointer(struct SDL_WaylandInput *input);
extern void Wayland_display_add_relative_pointer_manager(SDL_VideoData *d, uint32_t id); extern void Wayland_display_add_relative_pointer_manager(SDL_VideoData *d, uint32_t id);
extern void Wayland_display_destroy_relative_pointer_manager(SDL_VideoData *d); extern void Wayland_display_destroy_relative_pointer_manager(SDL_VideoData *d);

View File

@ -184,6 +184,7 @@ Wayland_CreateDevice(int devindex)
device->ShowWindow = Wayland_ShowWindow; device->ShowWindow = Wayland_ShowWindow;
device->SetWindowFullscreen = Wayland_SetWindowFullscreen; device->SetWindowFullscreen = Wayland_SetWindowFullscreen;
device->MaximizeWindow = Wayland_MaximizeWindow; device->MaximizeWindow = Wayland_MaximizeWindow;
device->SetWindowGrab = Wayland_SetWindowGrab;
device->RestoreWindow = Wayland_RestoreWindow; device->RestoreWindow = Wayland_RestoreWindow;
device->SetWindowBordered = Wayland_SetWindowBordered; device->SetWindowBordered = Wayland_SetWindowBordered;
device->SetWindowSize = Wayland_SetWindowSize; device->SetWindowSize = Wayland_SetWindowSize;

View File

@ -628,6 +628,17 @@ Wayland_MaximizeWindow(_THIS, SDL_Window * window)
WAYLAND_wl_display_flush( viddata->display ); WAYLAND_wl_display_flush( viddata->display );
} }
void
Wayland_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
if (grabbed)
Wayland_input_confine_pointer(window, data->input);
else
Wayland_input_unconfine_pointer(data->input);
}
int Wayland_CreateWindow(_THIS, SDL_Window *window) int Wayland_CreateWindow(_THIS, SDL_Window *window)
{ {
SDL_WindowData *data; SDL_WindowData *data;

View File

@ -88,6 +88,7 @@ extern void Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
SDL_VideoDisplay * _display, SDL_VideoDisplay * _display,
SDL_bool fullscreen); SDL_bool fullscreen);
extern void Wayland_MaximizeWindow(_THIS, SDL_Window * window); extern void Wayland_MaximizeWindow(_THIS, SDL_Window * window);
extern void Wayland_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
extern void Wayland_RestoreWindow(_THIS, SDL_Window * window); extern void Wayland_RestoreWindow(_THIS, SDL_Window * window);
extern void Wayland_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered); extern void Wayland_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
extern int Wayland_CreateWindow(_THIS, SDL_Window *window); extern int Wayland_CreateWindow(_THIS, SDL_Window *window);