modify the spaceware code to also work on wayland

use the recommended compile-time and run-time checks for x11 and wayland
pull/1137/head
Simon Wells 2021-10-23 00:38:37 +13:00 committed by phkahler
parent a45e84a2ff
commit 267c002975
1 changed files with 25 additions and 11 deletions

View File

@ -33,7 +33,12 @@
#if defined(HAVE_SPACEWARE)
# include <spnav.h>
# include <gdk/gdkx.h>
# if defined(GDK_WINDOWING_X11)
# include <gdk/gdkx.h>
# endif
# if defined(GDK_WINDOWING_WAYLAND)
# include <gdk/gdkwayland.h>
# endif
# if GTK_CHECK_VERSION(3, 20, 0)
# include <gdkmm/seat.h>
# 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<WindowImplGtk>(window);
Glib::RefPtr<Gdk::Window> 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) {}