diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index b150bf3..76914f1 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -1824,9 +1824,14 @@ gtk_grab_add (GtkWidget *widget)
 {
   GtkWindowGroup *group;
   GtkWidget *old_grab_widget;
-  
+  GtkWidget *toplevel;
+
   g_return_if_fail (widget != NULL);
-  
+
+  toplevel = gtk_widget_get_toplevel (widget);
+  if (toplevel && gdk_window_get_window_type (toplevel->window) == GDK_WINDOW_OFFSCREEN)
+    return;
+
   if (!gtk_widget_has_grab (widget) && GTK_WIDGET_IS_SENSITIVE (widget))
     {
       GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_GRAB);
