diff --git a/src/transients.c b/src/transients.c
index fbbde59a62df952cc41f5af6183f9a9855fb1dd4..6175a78631531b3001adee203725b300ef1dd87b 100644
--- a/src/transients.c
+++ b/src/transients.c
@@ -61,7 +61,10 @@ clientIsModal (Client * c)
     g_return_val_if_fail (c != NULL, FALSE);
 
     TRACE ("entering clientIsModal");
-
+    /* 
+       If the WM_TRANSIENT_FOR hint is set to another toplevel window, the dialog is modal for that window; 
+       if WM_TRANSIENT_FOR is not set or set to the root window the dialog is modal for its window group. 
+     */
     return (FLAG_TEST (c->flags, CLIENT_FLAG_STATE_MODAL) && (c->type & WINDOW_REGULAR_FOCUSABLE) &&
             (((c->transient_for != c->screen_info->xroot) && (c->transient_for != None) && (c->transient_for != c->window)) ||
              ((c->group_leader != None) && (c->group_leader != c->window))));
diff --git a/src/workspaces.c b/src/workspaces.c
index 891c31c4b280177624c07087c24f76e91fed7bb6..a921caa5a916d12874ec5cc7fc3394bfa89c9d20 100644
--- a/src/workspaces.c
+++ b/src/workspaces.c
@@ -305,9 +305,9 @@ workspaceSwitch (ScreenInfo *screen_info, int new_ws, Client * c2, gboolean upda
         }
         else if (c->win_workspace == new_ws)
         {
-            if (!FLAG_TEST (c->flags, CLIENT_FLAG_ICONIFIED))
+            if (!FLAG_TEST (c->flags, CLIENT_FLAG_ICONIFIED) && !FLAG_TEST (c->xfwm_flags, XFWM_FLAG_VISIBLE))
             {
-                if (!clientIsTransientOrModal (c))
+                if (!clientIsTransientOrModal (c) || !clientTransientOrModalHasAncestor (c, new_ws))
                 {
                     clientShow (c, FALSE);
                 }
@@ -329,7 +329,7 @@ workspaceSwitch (ScreenInfo *screen_info, int new_ws, Client * c2, gboolean upda
             }
             if (FLAG_TEST (c->xfwm_flags, XFWM_FLAG_VISIBLE) && !FLAG_TEST (c->flags, CLIENT_FLAG_STICKY))
             {
-                if (!clientIsTransientOrModal (c))
+                if (!clientIsTransientOrModal (c) || !clientTransientOrModalHasAncestor (c, new_ws))
                 {
                     clientHide (c, new_ws, FALSE);
                 }