diff --git a/shell/ev-application.c b/shell/ev-application.c
index fc7a0e9..380130e 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -634,7 +634,8 @@ ev_application_open_uri_in_window (EvApplication  *application,
 				   guint           timestamp)
 {
 #ifdef GDK_WINDOWING_X11
-	GdkWindow *gdk_window;
+	GdkDisplay *display = gdk_screen_get_display (screen);
+	GdkWindow  *gdk_window;
 #endif
 
 	if (screen) {
@@ -650,16 +651,19 @@ ev_application_open_uri_in_window (EvApplication  *application,
 		gtk_widget_realize (GTK_WIDGET (ev_window));
 
 #ifdef GDK_WINDOWING_X11
-	gdk_window = gtk_widget_get_window (GTK_WIDGET (ev_window));
+	if (GDK_IS_X11_DISPLAY(display)) {
+		gdk_window = gtk_widget_get_window (GTK_WIDGET (ev_window));
 
-	if (timestamp <= 0)
-		timestamp = gdk_x11_get_server_time (gdk_window);
-	gdk_x11_window_set_user_time (gdk_window, timestamp);
+		if (timestamp <= 0)
+			timestamp = gdk_x11_get_server_time (gdk_window);
+		gdk_x11_window_set_user_time (gdk_window, timestamp);
 
-	gtk_window_present (GTK_WINDOW (ev_window));
-#else
-	gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
+		gtk_window_present (GTK_WINDOW (ev_window));
+	} else
 #endif /* GDK_WINDOWING_X11 */
+	{
+		gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
+	}
 }
 
 static void
@@ -733,9 +737,10 @@ ev_application_open_window (EvApplication *application,
 			    GdkScreen     *screen,
 			    guint32        timestamp)
 {
-	GtkWidget *new_window = ev_window_new ();
+	GtkWidget  *new_window = ev_window_new ();
 #ifdef GDK_WINDOWING_X11
-	GdkWindow *gdk_window;
+	GdkDisplay *display = gdk_screen_get_display (screen);
+	GdkWindow  *gdk_window;
 #endif
 
 	if (screen) {
@@ -747,16 +752,19 @@ ev_application_open_window (EvApplication *application,
 		gtk_widget_realize (new_window);
 
 #ifdef GDK_WINDOWING_X11
-	gdk_window = gtk_widget_get_window (GTK_WIDGET (new_window));
+	if (GDK_IS_X11_DISPLAY(display)) {
+		gdk_window = gtk_widget_get_window (GTK_WIDGET (new_window));
 
-	if (timestamp <= 0)
-		timestamp = gdk_x11_get_server_time (gdk_window);
-	gdk_x11_window_set_user_time (gdk_window, timestamp);
+		if (timestamp <= 0)
+			timestamp = gdk_x11_get_server_time (gdk_window);
+		gdk_x11_window_set_user_time (gdk_window, timestamp);
 
-	gtk_window_present (GTK_WINDOW (new_window));
-#else
-	gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
+		gtk_window_present (GTK_WINDOW (new_window));
+	} else
 #endif /* GDK_WINDOWING_X11 */
+	{
+		gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
+	}
 }
 
 #ifdef ENABLE_DBUS
