]> git.decadent.org.uk Git - ion3.git/blobdiff - ioncore/manage.c
Imported Upstream version 20090110
[ion3.git] / ioncore / manage.c
index 2eb6f38b8f97e02bb2cfb54402cc6c417867338a..9215804123b63c79444ee0fe394016b4b9b8db4f 100644 (file)
@@ -1,12 +1,9 @@
 /*
  * ion/ioncore/manage.c
  *
- * Copyright (c) Tuomo Valkonen 1999-2007
+ * Copyright (c) Tuomo Valkonen 1999-2009
  *
- * Ion is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
+ * See the included file LICENSE for details.
  */
 
 #include <libtu/objp.h>
@@ -74,8 +71,11 @@ static WPHolder *try_target(WClientWin *cwin, const WManageParams *param,
         
     if(r==NULL)
         return NULL;
-            
-    return region_prepare_manage(r, cwin, param, MANAGE_REDIR_PREFER_NO);
+    
+    if(!region_same_rootwin(r, (WRegion*)cwin))
+        return NULL;
+    
+    return region_prepare_manage(r, cwin, param, MANAGE_PRIORITY_NONE);
 }
 
 
@@ -118,7 +118,7 @@ static bool handle_target_winprops(WClientWin *cwin, const WManageParams *param,
                 
                 if(ph==NULL){
                     ph=region_prepare_manage(reg, cwin, param, 
-                                             MANAGE_REDIR_PREFER_YES);
+                                             MANAGE_PRIORITY_NONE);
                     
                     if(ph==NULL)
                         destroy_obj((Obj*)reg);
@@ -159,7 +159,7 @@ static bool try_fullscreen(WClientWin *cwin, WScreen *dflt,
     
     if(fs_scr!=NULL){
         WPHolder *fs_ph=region_prepare_manage((WRegion*)fs_scr, cwin, param,
-                                              MANAGE_REDIR_STRICT_NO);
+                                              MANAGE_PRIORITY_NOREDIR);
         
         if(fs_ph!=NULL){
             int swf=(param->switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
@@ -186,6 +186,7 @@ bool clientwin_do_manage_default(WClientWin *cwin,
     WPHolder *ph=NULL;
     int swf=(param->switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
     bool ok, uq=FALSE;
+    WRegion *createroot=NULL;
 
     /* Find a suitable screen */
     scr=clientwin_find_suitable_screen(cwin, param);
@@ -208,8 +209,8 @@ bool clientwin_do_manage_default(WClientWin *cwin,
     if(ph==NULL){
         /* Find a placeholder for non-fullscreen state */
         ph=region_prepare_manage((WRegion*)scr, cwin, param,
-                                 MANAGE_REDIR_PREFER_YES);
-
+                                 MANAGE_PRIORITY_NONE);
+        
         if(try_fullscreen(cwin, scr, param)){
             if(pholder_target(ph)!=(WRegion*)region_screen_of((WRegion*)cwin)){
                 WRegion *grp=region_groupleader_of((WRegion*)cwin);
@@ -226,15 +227,22 @@ bool clientwin_do_manage_default(WClientWin *cwin,
         return FALSE;
     
     /* Not in full-screen mode; use the placeholder to attach. */
-    
-    ok=pholder_attach(ph, swf, (WRegion*)cwin);
-    
+    {
+        WRegionAttachData data;
+        data.type=REGION_ATTACH_REPARENT;
+        data.u.reg=(WRegion*)cwin;
+    
+        createroot=pholder_do_attach(ph, 
+                                     swf|PHOLDER_ATTACH_RETURN_CREATEROOT,
+                                     &data);
+    }
+
     destroy_obj((Obj*)ph);
     
-    if(uq && ok)
-        ioncore_unsqueeze((WRegion*)cwin, FALSE);
+    if(uq && createroot!=NULL)
+        ioncore_unsqueeze(createroot, FALSE);
     
-    return ok;
+    return (createroot!=NULL);
 }
 
 
@@ -245,29 +253,25 @@ bool clientwin_do_manage_default(WClientWin *cwin,
 
 
 WPHolder *region_prepare_manage(WRegion *reg, const WClientWin *cwin,
-                                const WManageParams *param, int redir)
+                                const WManageParams *param, int priority)
 {
     WPHolder *ret=NULL;
     CALL_DYN_RET(ret, WPHolder*, region_prepare_manage, reg, 
-                 (reg, cwin, param, redir));
+                 (reg, cwin, param, priority));
     return ret;
 }
 
 
 WPHolder *region_prepare_manage_default(WRegion *reg, const WClientWin *cwin,
-                                        const WManageParams *param, int redir)
+                                        const WManageParams *param, int priority)
 {
-    WRegion *curr;
-    
-    if(redir==MANAGE_REDIR_STRICT_NO)
-        return NULL;
-    
-    curr=region_current(reg);
+    int cpriority=MANAGE_PRIORITY_SUB(priority, MANAGE_PRIORITY_NONE);
+    WRegion *curr=region_current(reg);
     
     if(curr==NULL)
         return NULL;
         
-    return region_prepare_manage(curr, cwin, param, MANAGE_REDIR_PREFER_YES);
+    return region_prepare_manage(curr, cwin, param, cpriority);
 }
 
 
@@ -298,10 +302,10 @@ WPHolder *region_prepare_manage_transient_default(WRegion *reg,
 
 
 bool region_manage_clientwin(WRegion *reg, WClientWin *cwin,
-                             const WManageParams *par, int redir)
+                             const WManageParams *par, int priority)
 {
     bool ret;
-    WPHolder *ph=region_prepare_manage(reg, cwin, par, redir);
+    WPHolder *ph=region_prepare_manage(reg, cwin, par, priority);
     int swf=(par->switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
     
     if(ph==NULL)
@@ -326,6 +330,7 @@ DECLSTRUCT(WRescueInfo){
     WRegion *get_rescue;
     bool failed_get;
     bool test;
+    int flags;
 };
 
 
@@ -345,6 +350,54 @@ bool region_rescue_child_clientwins(WRegion *reg, WRescueInfo *info)
 }
 
 
+WPHolder *rescueinfo_pholder(WRescueInfo *info)
+{
+    if(info->test)
+        return NULL;
+        
+    if(info->ph==NULL){
+        info->ph=region_get_rescue_pholder(info->get_rescue);
+        if(info->ph==NULL){
+            info->failed_get=TRUE;
+            return NULL;
+        }
+    }
+    
+    return info->ph;
+}
+
+
+/* Bah, unsplitissä oikestaan pitäisi tehä non-deep rescue */
+
+bool region_do_rescue_this(WRegion *tosave_, WRescueInfo *info, int ph_flags)
+{
+    WClientWin *cwin=OBJ_CAST(tosave_, WClientWin);
+    WRegion *tosave=NULL;
+    
+    if(cwin!=NULL){
+        if(cwin->flags&CLIENTWIN_UNMAP_RQ)
+            return TRUE;
+        tosave=(WRegion*)cwin;
+    }else if(info->flags&REGION_RESCUE_NODEEP){
+        tosave=tosave_;
+    }else{
+        /* Try to rescue whole groups. */
+        /*tosave=(WRegion*)OBJ_CAST(tosave_, WGroupCW);*/
+    }
+    
+    if(tosave==NULL){
+        return region_rescue_clientwins(tosave_, info);
+    }else{
+        int phf=(info->flags&REGION_RESCUE_PHFLAGS_OK ? ph_flags : 0);
+        WPHolder *ph=rescueinfo_pholder(info);
+        
+        return (ph==NULL
+                ? FALSE
+                : pholder_attach(info->ph, phf, tosave));
+    }
+}
+
+
 bool region_rescue_some_clientwins(WRegion *reg, WRescueInfo *info,
                                    WRegionIterator *iter, void *st)
 {
@@ -358,32 +411,14 @@ bool region_rescue_some_clientwins(WRegion *reg, WRescueInfo *info,
     
     while(TRUE){
         WRegion *tosave=iter(st);
-        WClientWin *cwin;
         
         if(tosave==NULL)
             break;
-        
-        cwin=OBJ_CAST(tosave, WClientWin);
-        
-        if(cwin==NULL){
-            if(!region_rescue_clientwins(tosave, info)){
-                fails++;
-                if(info->failed_get)
-                    break;
-            }
-        }else if(info->test){
+
+        if(!region_do_rescue_this(tosave, info, 0)){
             fails++;
-            break;
-        }else if(!(cwin->flags&CLIENTWIN_UNMAP_RQ)){
-            if(info->ph==NULL){
-                info->ph=region_get_rescue_pholder(info->get_rescue);
-                if(info->ph==NULL){
-                    info->failed_get=TRUE;
-                    break;
-                }
-            }
-            if(!pholder_attach(info->ph, 0, (WRegion*)cwin))
-                fails++;
+            if(info->failed_get)
+                break;
         }
     }
     
@@ -401,19 +436,20 @@ bool region_rescue_clientwins(WRegion *reg, WRescueInfo *info)
 }
 
 
-bool region_rescue(WRegion *reg, WPHolder *ph_param)
+bool region_rescue(WRegion *reg, WPHolder *ph, int flags)
 {
     WRescueInfo info;
     bool ret;
     
-    info.ph=ph_param;
+    info.ph=ph;
+    info.flags=flags;
     info.test=FALSE;
     info.get_rescue=reg;
     info.failed_get=FALSE;
     
     ret=region_rescue_clientwins(reg, &info);
     
-    if(info.ph!=ph_param)
+    if(info.ph!=ph)
         destroy_obj((Obj*)info.ph);
     
     return ret;
@@ -425,6 +461,7 @@ bool region_rescue_needed(WRegion *reg)
     WRescueInfo info;
     
     info.ph=NULL;
+    info.flags=0;
     info.test=TRUE;
     info.get_rescue=reg;
     info.failed_get=FALSE;