Skip to content

Commit

Permalink
(Wayland) Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Jun 20, 2023
1 parent 103982f commit 6a14737
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 112 deletions.
13 changes: 6 additions & 7 deletions gfx/common/egl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,25 +300,24 @@ void egl_destroy(egl_ctx_data_t *egl)
* If we screw up, any TTY will not restore.
*/

egl->ctx = EGL_NO_CONTEXT;
egl->hw_ctx = EGL_NO_CONTEXT;
egl->surf = EGL_NO_SURFACE;
egl->dpy = EGL_NO_DISPLAY;
egl->config = 0;
egl->ctx = EGL_NO_CONTEXT;
egl->hw_ctx = EGL_NO_CONTEXT;
egl->surf = EGL_NO_SURFACE;
egl->dpy = EGL_NO_DISPLAY;
egl->config = 0;
g_egl_inited = false;

frontend_driver_destroy_signal_handler_state();
}

void egl_bind_hw_render(egl_ctx_data_t *egl, bool enable)
{
egl->use_hw_ctx = enable;
egl->use_hw_ctx = enable;

if (egl->dpy == EGL_NO_DISPLAY)
return;
if (egl->surf == EGL_NO_SURFACE)
return;

_egl_make_current(egl->dpy, egl->surf,
egl->surf,
enable ? egl->hw_ctx : egl->ctx);
Expand Down
135 changes: 65 additions & 70 deletions gfx/common/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#define DEFAULT_WINDOWED_WIDTH 640
#define DEFAULT_WINDOWED_HEIGHT 480

// Icon is 16x15 scaled by 16
/* Icon is 16x15 scaled by 16 */
#define SPLASH_WINDOW_WIDTH 240
#define SPLASH_WINDOW_HEIGHT 256

Expand Down Expand Up @@ -89,7 +89,7 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
int32_t width, int32_t height, struct wl_array *states)
{
const uint32_t *state;
bool floating = true;
bool floating = true;

wl->fullscreen = false;
wl->maximized = false;
Expand All @@ -100,23 +100,23 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
{
case XDG_TOPLEVEL_STATE_FULLSCREEN:
wl->fullscreen = true;
floating = false;
floating = false;
break;
case XDG_TOPLEVEL_STATE_MAXIMIZED:
wl->maximized = true;
floating = false;
wl->maximized = true;
floating = false;
break;
case XDG_TOPLEVEL_STATE_TILED_LEFT:
case XDG_TOPLEVEL_STATE_TILED_RIGHT:
case XDG_TOPLEVEL_STATE_TILED_TOP:
case XDG_TOPLEVEL_STATE_TILED_BOTTOM:
floating = false;
floating = false;
break;
case XDG_TOPLEVEL_STATE_RESIZING:
wl->resize = true;
wl->resize = true;
break;
case XDG_TOPLEVEL_STATE_ACTIVATED:
wl->activated = true;
wl->activated = true;
break;
}
}
Expand All @@ -127,14 +127,14 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
height = wl->floating_height;
}

if ( width > 0
&& height > 0)
if ( (width > 0)
&& (height > 0))
{
wl->width = width;
wl->height = height;
wl->width = width;
wl->height = height;
wl->buffer_width = wl->width * wl->buffer_scale;
wl->buffer_height = wl->height * wl->buffer_scale;
wl->resize = true;
wl->resize = true;
if (wl->viewport)
update_viewport(wl);
}
Expand All @@ -147,11 +147,7 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl,
}

void xdg_toplevel_handle_close(void *data,
struct xdg_toplevel *xdg_toplevel)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
command_event(CMD_EVENT_QUIT, NULL);
}
struct xdg_toplevel *xdg_toplevel) { command_event(CMD_EVENT_QUIT, NULL); }

#ifdef HAVE_LIBDECOR_H
void libdecor_frame_handle_configure_common(struct libdecor_frame *frame,
Expand Down Expand Up @@ -218,23 +214,18 @@ void libdecor_frame_handle_configure_common(struct libdecor_frame *frame,
}

void libdecor_frame_handle_close(struct libdecor_frame *frame,
void *data)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
command_event(CMD_EVENT_QUIT, NULL);
}

void *data) { command_event(CMD_EVENT_QUIT, NULL); }
void libdecor_frame_handle_commit(struct libdecor_frame *frame,
void *data)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
}
void *data) { }
#endif


void gfx_ctx_wl_get_video_size_common(gfx_ctx_wayland_data_t *wl,
void gfx_ctx_wl_get_video_size_common(void *data,
unsigned *width, unsigned *height)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
if (!wl)
return;
if (!wl->reported_display_size)
{
display_output_t *od;
Expand Down Expand Up @@ -361,44 +352,48 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)
wl->wl_pointer = NULL;
wl->wl_keyboard = NULL;

wl->width = 0;
wl->height = 0;
wl->buffer_width = 0;
wl->buffer_height = 0;
wl->width = 0;
wl->height = 0;
wl->buffer_width = 0;
wl->buffer_height = 0;
}

void gfx_ctx_wl_update_title_common(gfx_ctx_wayland_data_t *wl)
void gfx_ctx_wl_update_title_common(void *data)
{
char title[128];
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;

title[0] = '\0';

video_driver_get_window_title(title, sizeof(title));

#ifdef HAVE_LIBDECOR_H
if (wl->libdecor)
if (wl)
{
if (wl && title[0])
wl->libdecor_frame_set_title(wl->libdecor_frame, title);
}
else
#ifdef HAVE_LIBDECOR_H
if (wl->libdecor)
{
if (title[0])
wl->libdecor_frame_set_title(wl->libdecor_frame, title);
}
else
#endif
{
if (wl && title[0])
{
if (wl->deco)
zxdg_toplevel_decoration_v1_set_mode(wl->deco,
ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
xdg_toplevel_set_title(wl->xdg_toplevel, title);
if (title[0])
{
if (wl->deco)
zxdg_toplevel_decoration_v1_set_mode(wl->deco,
ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
xdg_toplevel_set_title(wl->xdg_toplevel, title);
}
}
}
}

bool gfx_ctx_wl_get_metrics_common(void *data,
enum display_metric_types type, float *value)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
display_output_t *od;
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
output_info_t *oi = wl ? wl->current_output : NULL;

if (!oi)
Expand All @@ -419,8 +414,8 @@ bool gfx_ctx_wl_get_metrics_common(void *data,
break;

case DISPLAY_METRIC_DPI:
*value = (float)oi->width * 25.4f /
(float)oi->physical_width;
*value = (float)oi->width * 25.4f
/ (float)oi->physical_width;
break;

default:
Expand Down Expand Up @@ -745,11 +740,12 @@ bool gfx_ctx_wl_init_common(
/* Bind SHM based wl_buffer to wl_surface until the vulkan surface is ready.
* This shows the window which assigns us a display (wl_output)
* which is usefull for HiDPI and auto selecting a display for fullscreen. */
if (video_monitor_index == 0 && wl_list_length (&wl->all_outputs) > 1) {
if (video_monitor_index == 0 && wl_list_length (&wl->all_outputs) > 1)
{
if (!wl_draw_splash_screen(wl))
RARCH_ERR("[Wayland]: Failed to draw splash screen\n");

// Make sure splash screen is on screen and sized
/* Make sure splash screen is on screen and sized */
#ifdef HAVE_LIBDECOR_H
if (wl->libdecor)
{
Expand Down Expand Up @@ -842,7 +838,7 @@ bool gfx_ctx_wl_set_video_mode_common_fullscreen(gfx_ctx_wayland_data_t *wl,

if (video_monitor_index <= 0 && wl->current_output != NULL)
{
oi = wl->current_output;
oi = wl->current_output;
output = oi->output;
RARCH_LOG("[Wayland]: Auto fullscreen on display \"%s\" \"%s\"\n", oi->make, oi->model);
}
Expand Down Expand Up @@ -892,32 +888,31 @@ bool gfx_ctx_wl_suppress_screensaver(void *data, bool state)

if (!wl->idle_inhibit_manager)
return false;
if (state == (!!wl->idle_inhibitor))
return true;

if (state)
{
RARCH_LOG("[Wayland]: Enabling idle inhibitor\n");
struct zwp_idle_inhibit_manager_v1 *mgr = wl->idle_inhibit_manager;
wl->idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(mgr, wl->surface);
}
else
if (state != (!!wl->idle_inhibitor))
{
RARCH_LOG("[Wayland]: Disabling the idle inhibitor\n");
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
wl->idle_inhibitor = NULL;
if (state)
{
RARCH_LOG("[Wayland]: Enabling idle inhibitor\n");
struct zwp_idle_inhibit_manager_v1 *mgr = wl->idle_inhibit_manager;
wl->idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(mgr, wl->surface);
}
else
{
RARCH_LOG("[Wayland]: Disabling the idle inhibitor\n");
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
wl->idle_inhibitor = NULL;
}
}

return true;
}

float gfx_ctx_wl_get_refresh_rate(void *data)
{
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;

if (!wl || !wl->current_output)
return false;

return (float) wl->current_output->refresh_rate / 1000.0f;
return (float)wl->current_output->refresh_rate / 1000.0f;
}

bool gfx_ctx_wl_has_focus(void *data)
Expand Down Expand Up @@ -961,8 +956,8 @@ static void shm_buffer_handle_release(void *data,
}

#if 0
static void xdg_surface_handle_configure(void *data, struct xdg_surface *surface,
uint32_t serial)
static void xdg_surface_handle_configure(void *data,
struct xdg_surface *surface, uint32_t serial)
{
xdg_surface_ack_configure(surface, serial);
}
Expand Down
6 changes: 3 additions & 3 deletions gfx/common/wayland_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ void libdecor_frame_handle_commit(struct libdecor_frame *frame,
void *data);
#endif

void gfx_ctx_wl_get_video_size_common(gfx_ctx_wayland_data_t *wl,
unsigned *width, unsigned *height);
void gfx_ctx_wl_get_video_size_common(void *data, unsigned *width,
unsigned *height);

void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl);

void gfx_ctx_wl_update_title_common(gfx_ctx_wayland_data_t *wl);
void gfx_ctx_wl_update_title_common(void *data);

bool gfx_ctx_wl_get_metrics_common(void *data,
enum display_metric_types type, float *value);
Expand Down
Loading

0 comments on commit 6a14737

Please sign in to comment.