Gtk: Use a Wayland check function.

This commit is contained in:
BearOso 2024-10-12 17:06:07 -05:00
parent b19e31c83f
commit 0c228f0e0c
5 changed files with 21 additions and 35 deletions

View File

@ -20,6 +20,10 @@
#ifdef GDK_WINDOWING_WAYLAND
#include <gdk/gdkwayland.h>
inline bool is_wayland()
{
return GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default());
}
#endif
#ifdef GDK_WINDOWING_X11

View File

@ -912,7 +912,7 @@ static void S9xInitDriver()
{
// Only OpenGL is supported on Wayland
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default()))
if (is_wayland())
{
if (gui_config->display_driver != "vulkan")
gui_config->display_driver = "opengl";

View File

@ -346,13 +346,13 @@ void S9xOpenGLDisplayDriver::refresh()
void S9xOpenGLDisplayDriver::resize()
{
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(gdk_window))
if (is_wayland())
{
((WaylandEGLContext *)context)->resize(get_metrics(*drawing_area));
}
#endif
#ifdef GDK_WINDOWING_X11
if (GDK_IS_X11_WINDOW(gdk_window))
if (is_wayland())
{
context->resize();
}
@ -371,7 +371,7 @@ bool S9xOpenGLDisplayDriver::create_context()
GdkDisplay *gdk_display = drawing_area->get_display()->gobj();
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(gdk_window))
if (is_wayland())
{
wl_surface *surface = gdk_wayland_window_get_wl_surface(drawing_area->get_window()->gobj());
wl_display *display = gdk_wayland_display_get_wl_display(drawing_area->get_display()->gobj());
@ -381,7 +381,7 @@ bool S9xOpenGLDisplayDriver::create_context()
}
#endif
#ifdef GDK_WINDOWING_X11
if (GDK_IS_X11_WINDOW(gdk_window))
if (is_wayland())
{
if (!glx.attach(gdk_x11_display_get_xdisplay(gdk_display), gdk_x11_window_get_xid(gdk_window)))
return false;
@ -494,23 +494,7 @@ void S9xOpenGLDisplayDriver::deinit()
int S9xOpenGLDisplayDriver::query_availability()
{
GdkDisplay *gdk_display = gdk_display_get_default();
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_DISPLAY(gdk_display))
{
return 1;
}
#endif
#ifdef GDK_WINDOWING_X11
if (GDK_IS_X11_DISPLAY(gdk_display))
{
return 1;
}
#endif
return 0;
return 1;
}
bool S9xOpenGLDisplayDriver::is_ready()
@ -526,7 +510,7 @@ bool S9xOpenGLDisplayDriver::is_ready()
void S9xOpenGLDisplayDriver::shrink()
{
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(gdk_window))
if (is_wayland())
{
((WaylandEGLContext *)context)->shrink();
}
@ -536,7 +520,7 @@ void S9xOpenGLDisplayDriver::shrink()
void S9xOpenGLDisplayDriver::regrow()
{
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(gdk_window))
if (is_wayland())
{
((WaylandEGLContext *)context)->regrow();
}

View File

@ -90,7 +90,7 @@ void S9xVulkanDisplayDriver::refresh()
int new_width, new_height;
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(drawing_area->get_window()->gobj()))
if (is_wayland())
{
std::tie(new_width, new_height) = wayland_surface->get_size_for_metrics(get_metrics(*drawing_area));
context->swapchain->set_desired_size(new_width, new_height);
@ -110,7 +110,7 @@ void S9xVulkanDisplayDriver::refresh()
current_height = new_height;
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(drawing_area->get_window()->gobj()))
if (is_wayland())
wayland_surface->resize(get_metrics(*drawing_area));
#endif
}
@ -124,7 +124,7 @@ int S9xVulkanDisplayDriver::init()
context = std::make_unique<Vulkan::Context>();
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(drawing_area->get_window()->gobj()))
if (is_wayland())
{
wayland_surface = std::make_unique<WaylandSurface>();
wl_surface *surface = gdk_wayland_window_get_wl_surface(drawing_area->get_window()->gobj());
@ -270,7 +270,7 @@ bool S9xVulkanDisplayDriver::is_ready()
void S9xVulkanDisplayDriver::shrink()
{
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(drawing_area->get_window()->gobj()))
if (is_wayland())
wayland_surface->shrink();
#endif
}
@ -278,7 +278,7 @@ void S9xVulkanDisplayDriver::shrink()
void S9xVulkanDisplayDriver::regrow()
{
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_WINDOW(drawing_area->get_window()->gobj()))
if (is_wayland())
wayland_surface->regrow();
#endif
}

View File

@ -280,16 +280,14 @@ bool Snes9xWindow::button_press(GdkEventButton *event)
return false;
}
if (event->button >= 1 && event->button <= 3)
S9xReportButton(BINDING_MOUSE_BUTTON0 + event->button - 1, true);
S9xReportButton(BINDING_MOUSE_BUTTON0 + event->button - 1, true);
return false;
}
bool Snes9xWindow::button_release(GdkEventButton *event)
{
if (event->button >= 1 && event->button <= 3)
S9xReportButton(BINDING_MOUSE_BUTTON0 + event->button - 1, false);
S9xReportButton(BINDING_MOUSE_BUTTON0 + event->button - 1, false);
return false;
}
@ -1054,7 +1052,7 @@ Snes9xWindow::get_refresh_rate()
#endif
#ifdef GDK_WINDOWING_X11
if (GDK_IS_X11_DISPLAY(gdk_display))
if (is_wayland())
{
Window xid = gdk_x11_window_get_xid(gdk_window);
Display *dpy = gdk_x11_display_get_xdisplay(gdk_display);
@ -1063,7 +1061,7 @@ Snes9xWindow::get_refresh_rate()
#endif
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_DISPLAY(gdk_display))
if (is_wayland())
{
GdkMonitor *monitor = gdk_display_get_monitor_at_window(gdk_display, gdk_window);
refresh_rate = (double)gdk_monitor_get_refresh_rate(monitor) / 1000.0;