From 0c228f0e0cae7039bd321f539652e9044250895d Mon Sep 17 00:00:00 2001 From: BearOso Date: Sat, 12 Oct 2024 17:06:07 -0500 Subject: [PATCH] Gtk: Use a Wayland check function. --- gtk/src/gtk_compat.h | 4 ++++ gtk/src/gtk_display.cpp | 2 +- gtk/src/gtk_display_driver_opengl.cpp | 30 +++++++-------------------- gtk/src/gtk_display_driver_vulkan.cpp | 10 ++++----- gtk/src/gtk_s9xwindow.cpp | 10 ++++----- 5 files changed, 21 insertions(+), 35 deletions(-) diff --git a/gtk/src/gtk_compat.h b/gtk/src/gtk_compat.h index f48fecf6..c642bd09 100644 --- a/gtk/src/gtk_compat.h +++ b/gtk/src/gtk_compat.h @@ -20,6 +20,10 @@ #ifdef GDK_WINDOWING_WAYLAND #include +inline bool is_wayland() +{ + return GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default()); +} #endif #ifdef GDK_WINDOWING_X11 diff --git a/gtk/src/gtk_display.cpp b/gtk/src/gtk_display.cpp index d59090c0..2d9601d1 100644 --- a/gtk/src/gtk_display.cpp +++ b/gtk/src/gtk_display.cpp @@ -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"; diff --git a/gtk/src/gtk_display_driver_opengl.cpp b/gtk/src/gtk_display_driver_opengl.cpp index bd8e4d6c..4baf4d18 100644 --- a/gtk/src/gtk_display_driver_opengl.cpp +++ b/gtk/src/gtk_display_driver_opengl.cpp @@ -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(); } diff --git a/gtk/src/gtk_display_driver_vulkan.cpp b/gtk/src/gtk_display_driver_vulkan.cpp index 266811ad..02a91a97 100644 --- a/gtk/src/gtk_display_driver_vulkan.cpp +++ b/gtk/src/gtk_display_driver_vulkan.cpp @@ -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(); #ifdef GDK_WINDOWING_WAYLAND - if (GDK_IS_WAYLAND_WINDOW(drawing_area->get_window()->gobj())) + if (is_wayland()) { wayland_surface = std::make_unique(); 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 } \ No newline at end of file diff --git a/gtk/src/gtk_s9xwindow.cpp b/gtk/src/gtk_s9xwindow.cpp index 1fb3dd0f..58b900b2 100644 --- a/gtk/src/gtk_s9xwindow.cpp +++ b/gtk/src/gtk_s9xwindow.cpp @@ -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;