From 267c002975a9ae6683ea3612b209266c9aa606c2 Mon Sep 17 00:00:00 2001 From: Simon Wells Date: Sat, 23 Oct 2021 00:38:37 +1300 Subject: [PATCH] modify the spaceware code to also work on wayland use the recommended compile-time and run-time checks for x11 and wayland --- src/platform/guigtk.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/platform/guigtk.cpp b/src/platform/guigtk.cpp index 46a7df35..6afb9c72 100644 --- a/src/platform/guigtk.cpp +++ b/src/platform/guigtk.cpp @@ -33,7 +33,12 @@ #if defined(HAVE_SPACEWARE) # include -# include +# if defined(GDK_WINDOWING_X11) +# include +# endif +# if defined(GDK_WINDOWING_WAYLAND) +# include +# endif # if GTK_CHECK_VERSION(3, 20, 0) # include # else @@ -1047,7 +1052,7 @@ WindowRef CreateWindow(Window::Kind kind, WindowRef parentWindow) { void Open3DConnexion() {} void Close3DConnexion() {} -#if defined(HAVE_SPACEWARE) && defined(GDK_WINDOWING_X11) +#if defined(HAVE_SPACEWARE) && (defined(GDK_WINDOWING_X11) || defined(GDK_WINDOWING_WAYLAND)) static void ProcessSpnavEvent(WindowImplGtk *window, const spnav_event &spnavEvent, bool shiftDown, bool controlDown) { switch(spnavEvent.type) { case SPNAV_EVENT_MOTION: { @@ -1129,17 +1134,26 @@ void Request3DConnexionEventsForWindow(WindowRef window) { std::static_pointer_cast(window); Glib::RefPtr gdkWindow = windowImpl->gtkWindow.get_window(); - if(!GDK_IS_X11_DISPLAY(gdkWindow->get_display()->gobj())) { - return; +#if defined(GDK_WINDOWING_X11) + if(GDK_IS_X11_DISPLAY(gdkWindow->get_display()->gobj())) { + if(spnav_x11_open(gdk_x11_get_default_xdisplay(), + gdk_x11_window_get_xid(gdkWindow->gobj())) != -1) { + gdkWindow->add_filter(GdkSpnavFilter, windowImpl.get()); + } else if(spnav_open() != -1) { + g_io_add_watch(g_io_channel_unix_new(spnav_fd()), G_IO_IN, + ConsumeSpnavQueue, windowImpl.get()); + } } +#endif +#if defined(GDK_WINDOWING_WAYLAND) + if(GDK_IS_WAYLAND_DISPLAY(gdkWindow->get_display()->gobj())) { + if(spnav_open() != -1) { + g_io_add_watch(g_io_channel_unix_new(spnav_fd()), G_IO_IN, + ConsumeSpnavQueue, windowImpl.get()); + } + } +#endif - if(spnav_x11_open(gdk_x11_get_default_xdisplay(), - gdk_x11_window_get_xid(gdkWindow->gobj())) != -1) { - gdkWindow->add_filter(GdkSpnavFilter, windowImpl.get()); - } else if(spnav_open() != -1) { - g_io_add_watch(g_io_channel_unix_new(spnav_fd()), G_IO_IN, - ConsumeSpnavQueue, windowImpl.get()); - } } #else void Request3DConnexionEventsForWindow(WindowRef window) {}