699205d
diff -ur ClanLib-0.6.5/Sources/Display/Display/X11/display_xwindow.cpp ClanLib-0.6.5.new/Sources/Display/Display/X11/display_xwindow.cpp
699205d
--- ClanLib-0.6.5/Sources/Display/Display/X11/display_xwindow.cpp	2002-08-14 21:33:36.000000000 +0200
699205d
+++ ClanLib-0.6.5.new/Sources/Display/Display/X11/display_xwindow.cpp	2019-11-05 15:30:21.875867133 +0100
699205d
@@ -303,8 +303,13 @@
699205d
 	
699205d
 	if (fullscreen)
699205d
 	{
699205d
-		XSetInputFocus(m_dpy, m_win, RevertToParent, CurrentTime);
699205d
+		// Wait for it to be mapped
699205d
+		XEvent event;
699205d
+		do {
699205d
+			XMaskEvent(m_dpy, StructureNotifyMask, &event);
699205d
+		} while ( (event.type != MapNotify) || (event.xmap.event != m_win) );
699205d
 		XGrabPointer(m_dpy, m_win, true, 0, GrabModeAsync, GrabModeAsync, m_win, None, CurrentTime);
699205d
+		XGrabKeyboard(m_dpy, m_win, true, GrabModeAsync, GrabModeAsync, CurrentTime);
699205d
 	}
699205d
 
699205d
 	m_target = create_target();
699205d
diff -ur ClanLib-0.6.5/Sources/Display/Display/X11/display_xwindow.h ClanLib-0.6.5.new/Sources/Display/Display/X11/display_xwindow.h
699205d
--- ClanLib-0.6.5/Sources/Display/Display/X11/display_xwindow.h	2019-11-05 13:45:37.613392627 +0100
699205d
+++ ClanLib-0.6.5.new/Sources/Display/Display/X11/display_xwindow.h	2019-11-05 15:27:57.419753032 +0100
699205d
@@ -106,6 +106,23 @@
699205d
 		XDefineCursor(get_display(), get_window(), cursor);
699205d
 	}
699205d
 	
699205d
+	bool has_focus() {
699205d
+		// Assume we have focus if we are fullscreen, this is necessary
699205d
+		// for correct operation under Xwayland, where our focus check fails
699205d
+		if (is_fullscreen())
699205d
+			return true;
699205d
+
699205d
+		// get_window() returns NULL if in DGA mode.
699205d
+		if (get_window() == 0)
699205d
+			return true;
699205d
+
699205d
+		// Check if window has focus right now:
699205d
+		Window focus_win;
699205d
+		int focus_state;
699205d
+		XGetInputFocus(get_display(), &focus_win, &focus_state);
699205d
+		return get_window() == focus_win;
699205d
+	}
699205d
+
699205d
 protected:
699205d
 	virtual void get_real_resolution(int* width, int* height);
699205d
 	void fill_modelist();
699205d
diff -ur ClanLib-0.6.5/Sources/Display/Input/X11/keyboard_x11.cpp ClanLib-0.6.5.new/Sources/Display/Input/X11/keyboard_x11.cpp
699205d
--- ClanLib-0.6.5/Sources/Display/Input/X11/keyboard_x11.cpp	2019-11-05 13:45:37.625392719 +0100
699205d
+++ ClanLib-0.6.5.new/Sources/Display/Input/X11/keyboard_x11.cpp	2019-11-05 15:25:55.666814019 +0100
699205d
@@ -117,17 +117,7 @@
699205d
 
699205d
 void CL_XWindowKeyboard::keep_alive()
699205d
 {
699205d
-	// Check if window has focus right now:
699205d
-	Window focus_win;
699205d
-	int focus_state;
699205d
-	XGetInputFocus(
699205d
-		card->get_display(),
699205d
-		&focus_win,
699205d
-		&focus_state);
699205d
-		
699205d
-	// get_window() returns NULL if in DGA mode.
699205d
-	if (card->get_window() == 0 ||
699205d
-		card->get_window() == focus_win)
699205d
+	if (card->has_focus())
699205d
 	{
699205d
 		XQueryKeymap(card->get_display(), keys_return);
699205d
 	}
699205d
diff -ur ClanLib-0.6.5/Sources/Display/Input/X11/mouse_x11.cpp ClanLib-0.6.5.new/Sources/Display/Input/X11/mouse_x11.cpp
699205d
--- ClanLib-0.6.5/Sources/Display/Input/X11/mouse_x11.cpp	2002-05-17 10:47:58.000000000 +0200
699205d
+++ ClanLib-0.6.5.new/Sources/Display/Input/X11/mouse_x11.cpp	2019-11-05 15:27:37.402598649 +0100
699205d
@@ -124,14 +124,6 @@
699205d
 	axes[0].center = (card->get_width())/2.0;
699205d
 	axes[1].center = (card->get_height())/2.0;
699205d
 
699205d
-	// Check if window has focus right now:
699205d
-	Window focus_win;
699205d
-	int focus_state;
699205d
-	XGetInputFocus(
699205d
-		card->get_display(),
699205d
-		&focus_win,
699205d
-		&focus_state);
699205d
-
699205d
 	XQueryPointer(card->get_display(),
699205d
 		      card->get_window(),
699205d
 		      &root,
699205d
@@ -149,8 +141,7 @@
699205d
 	if (win_x >= cursor->get_max_x()) win_x = (int)cursor->get_max_x() - 1;
699205d
 	if (win_y >= cursor->get_max_y()) win_y = (int)cursor->get_max_y() - 1;
699205d
 
699205d
-	// get_window() returns NULL if in DGA mode.	
699205d
-	if (card->get_window() == 0 || card->get_window() == focus_win)
699205d
+	if (card->has_focus())
699205d
 	{
699205d
 		axes[0].pos = cursor->x;
699205d
 		axes[1].pos = cursor->y;
699205d
diff -ur ClanLib-0.6.5/Sources/GL/GLX/displaycard_glx.cpp ClanLib-0.6.5.new/Sources/GL/GLX/displaycard_glx.cpp
699205d
--- ClanLib-0.6.5/Sources/GL/GLX/displaycard_glx.cpp	2019-11-05 15:43:10.695796640 +0100
699205d
+++ ClanLib-0.6.5.new/Sources/GL/GLX/displaycard_glx.cpp	2019-11-05 15:46:37.803393768 +0100
699205d
@@ -252,8 +252,13 @@
699205d
 
699205d
 	if (fullscreen)
699205d
 	{
699205d
-		XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
699205d
+		// Wait for it to be mapped
699205d
+		XEvent event;
699205d
+		do {
699205d
+			XMaskEvent(dpy, StructureNotifyMask, &event);
699205d
+		} while ( (event.type != MapNotify) || (event.xmap.event != win) );
699205d
 		XGrabPointer(dpy, win, true, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime);
699205d
+		XGrabKeyboard(dpy, win, true, GrabModeAsync, GrabModeAsync, CurrentTime);
699205d
 	}
699205d
 
699205d
 	// Listen for keystrokes...
699205d
diff -ur ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/alsa.cpp ClanLib-0.6.5.new/Sources/Sound/Sound/ClanSound/alsa.cpp
699205d
--- ClanLib-0.6.5/Sources/Sound/Sound/ClanSound/alsa.cpp	2019-11-05 14:30:21.576099991 +0100
699205d
+++ ClanLib-0.6.5.new/Sources/Sound/Sound/ClanSound/alsa.cpp	2019-11-05 12:17:12.086830277 +0100
699205d
@@ -47,6 +47,7 @@
699205d
 	snd_pcm_hw_params_t *hwparams;
699205d
 	unsigned int mixing_frequency = 22050;
699205d
 	
699205d
+	handle = NULL;
699205d
 	rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
699205d
 	if (rc < 0)
699205d
 	{