Implemented SDL_SetWindowMouseRect() on Wayland

This commit is contained in:
Ethan Lee 2021-11-09 01:30:00 -05:00
parent 18e69827aa
commit ae67c7d2da
5 changed files with 59 additions and 24 deletions

View file

@ -1153,15 +1153,35 @@ Wayland_MinimizeWindow(_THIS, SDL_Window * window)
WAYLAND_wl_display_flush(viddata->display);
}
void
Wayland_SetWindowMouseRect(_THIS, SDL_Window *window)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
/* This may look suspiciously like SetWindowGrab, despite SetMouseRect not
* implicitly doing a grab. And you're right! Wayland doesn't let us mess
* around with mouse focus whatsoever, so it just happens to be that the
* work that we can do in these two functions ends up being the same.
*
* Just know that this call lets you confine with a rect, SetWindowGrab
* lets you confine without a rect.
*/
if (SDL_RectEmpty(&window->mouse_rect) && !(window->flags & SDL_WINDOW_MOUSE_GRABBED)) {
Wayland_input_unconfine_pointer(data->input, window);
} else {
Wayland_input_confine_pointer(data->input, window);
}
}
void
Wayland_SetWindowMouseGrab(_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);
Wayland_input_confine_pointer(data->input, window);
} else if (SDL_RectEmpty(&window->mouse_rect)) {
Wayland_input_unconfine_pointer(data->input, window);
}
}