Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Jackbox Wayland Pack #4309

Merged
merged 5 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 55 additions & 11 deletions src/video/wayland/SDL_waylandvideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@
static int
Wayland_VideoInit(_THIS);

static void
Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display);
static int
Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
Wayland_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);

static int
Wayland_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi, float * hdpi, float * vdpi);

static void
Wayland_VideoQuit(_THIS);
Expand Down Expand Up @@ -177,8 +178,8 @@ Wayland_CreateDevice(int devindex)
/* Set the function pointers */
device->VideoInit = Wayland_VideoInit;
device->VideoQuit = Wayland_VideoQuit;
device->SetDisplayMode = Wayland_SetDisplayMode;
device->GetDisplayModes = Wayland_GetDisplayModes;
device->GetDisplayBounds = Wayland_GetDisplayBounds;
device->GetDisplayDPI = Wayland_GetDisplayDPI;
device->GetWindowWMInfo = Wayland_GetWindowWMInfo;
device->SuspendScreenSaver = Wayland_SuspendScreenSaver;

Expand Down Expand Up @@ -208,6 +209,7 @@ Wayland_CreateDevice(int devindex)
device->SetWindowSize = Wayland_SetWindowSize;
device->SetWindowMinimumSize = Wayland_SetWindowMinimumSize;
device->SetWindowMaximumSize = Wayland_SetWindowMaximumSize;
device->SetWindowModalFor = Wayland_SetWindowModalFor;
device->SetWindowTitle = Wayland_SetWindowTitle;
device->DestroyWindow = Wayland_DestroyWindow;
device->SetWindowHitTest = Wayland_SetWindowHitTest;
Expand Down Expand Up @@ -251,6 +253,10 @@ display_handle_geometry(void *data,
{
SDL_WaylandOutputData *driverdata = data;

driverdata->x = x;
driverdata->y = y;
driverdata->physical_width = physical_width;
driverdata->physical_height = physical_height;
driverdata->placeholder.name = SDL_strdup(model);
driverdata->transform = transform;
}
Expand Down Expand Up @@ -309,9 +315,31 @@ display_handle_done(void *data,
if (driverdata->transform & WL_OUTPUT_TRANSFORM_90) {
mode.w = driverdata->height / driverdata->scale_factor;
mode.h = driverdata->width / driverdata->scale_factor;

driverdata->hdpi = driverdata->physical_height ?
(((float) driverdata->height) * 25.4f / driverdata->physical_height) :
0.0f;
driverdata->vdpi = driverdata->physical_width ?
(((float) driverdata->width) * 25.4f / driverdata->physical_width) :
0.0f;
driverdata->ddpi = SDL_ComputeDiagonalDPI(driverdata->height,
driverdata->width,
((float) driverdata->physical_height) / 25.4f,
((float) driverdata->physical_width) / 25.4f);
} else {
mode.w = driverdata->width / driverdata->scale_factor;
mode.h = driverdata->height / driverdata->scale_factor;

driverdata->hdpi = driverdata->physical_width ?
(((float) driverdata->width) * 25.4f / driverdata->physical_width) :
0.0f;
driverdata->vdpi = driverdata->physical_height ?
(((float) driverdata->height) * 25.4f / driverdata->physical_height) :
0.0f;
driverdata->ddpi = SDL_ComputeDiagonalDPI(driverdata->width,
driverdata->height,
((float) driverdata->physical_width) / 25.4f,
((float) driverdata->physical_height) / 25.4f);
}
mode.refresh_rate = driverdata->refresh / 1000; /* mHz to Hz */
mode.driverdata = driverdata->output;
Expand Down Expand Up @@ -500,17 +528,33 @@ Wayland_VideoInit(_THIS)
return 0;
}

static void
Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display)
static int
Wayland_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
{
// Nothing to do here, everything was already done in the wl_output
// callbacks.
SDL_WaylandOutputData *driverdata = (SDL_WaylandOutputData *)display->driverdata;
rect->x = driverdata->x;
rect->y = driverdata->y;
rect->w = display->current_mode.w;
rect->h = display->current_mode.h;
return 0;
}

static int
Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
Wayland_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi, float * hdpi, float * vdpi)
{
return SDL_Unsupported();
SDL_WaylandOutputData *driverdata = (SDL_WaylandOutputData *)sdl_display->driverdata;

if (ddpi) {
*ddpi = driverdata->ddpi;
}
if (hdpi) {
*hdpi = driverdata->hdpi;
}
if (vdpi) {
*vdpi = driverdata->vdpi;
}

return driverdata->ddpi != 0.0f ? 0 : SDL_SetError("Couldn't get DPI");
}

void
Expand Down
4 changes: 3 additions & 1 deletion src/video/wayland/SDL_waylandvideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ typedef struct {
typedef struct {
struct wl_output *output;
float scale_factor;
int width, height, refresh, transform;
int x, y, width, height, refresh, transform;
int physical_width, physical_height;
float ddpi, hdpi, vdpi;
SDL_VideoDisplay placeholder;
SDL_bool done;
} SDL_WaylandOutputData;
Expand Down
24 changes: 24 additions & 0 deletions src/video/wayland/SDL_waylandwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,27 @@ Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
return 0; /* just succeed, the real work is done elsewhere. */
}

int
Wayland_SetWindowModalFor(_THIS, SDL_Window *modal_window, SDL_Window *parent_window)
{
const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
SDL_WindowData *modal_data = modal_window->driverdata;
SDL_WindowData *parent_data = parent_window->driverdata;

if (viddata->shell.xdg) {
xdg_toplevel_set_parent(modal_data->shell_surface.xdg.roleobj.toplevel,
parent_data->shell_surface.xdg.roleobj.toplevel);
} else if (viddata->shell.zxdg) {
zxdg_toplevel_v6_set_parent(modal_data->shell_surface.zxdg.roleobj.toplevel,
parent_data->shell_surface.zxdg.roleobj.toplevel);
} else {
return SDL_Unsupported();
}

WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
return 0;
}

void Wayland_ShowWindow(_THIS, SDL_Window *window)
{
SDL_WaylandOutputData *driverdata = (SDL_WaylandOutputData *) SDL_GetDisplayForWindow(window)->driverdata;
Expand Down Expand Up @@ -681,8 +702,11 @@ Wayland_RestoreWindow(_THIS, SDL_Window * window)
SDL_WindowData *wind = window->driverdata;
const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;

/* Note that xdg-shell does NOT provide a way to unset minimize! */
if (viddata->shell.xdg) {
xdg_toplevel_unset_maximized(wind->shell_surface.xdg.roleobj.toplevel);
} else if (viddata->shell.zxdg) {
zxdg_toplevel_v6_unset_maximized(wind->shell_surface.zxdg.roleobj.toplevel);
} else {
wl_shell_surface_set_toplevel(wind->shell_surface.wl);
}
Expand Down
1 change: 1 addition & 0 deletions src/video/wayland/SDL_waylandwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extern int Wayland_CreateWindow(_THIS, SDL_Window *window);
extern void Wayland_SetWindowSize(_THIS, SDL_Window * window);
extern void Wayland_SetWindowMinimumSize(_THIS, SDL_Window * window);
extern void Wayland_SetWindowMaximumSize(_THIS, SDL_Window * window);
extern int Wayland_SetWindowModalFor(_THIS, SDL_Window * modal_window, SDL_Window * parent_window);
extern void Wayland_SetWindowTitle(_THIS, SDL_Window * window);
extern void Wayland_DestroyWindow(_THIS, SDL_Window *window);
extern void Wayland_SuspendScreenSaver(_THIS);
Expand Down