]> git.decadent.org.uk Git - ion3.git/blobdiff - ioncore/detach.c
[svn-upgrade] Integrating new upstream version, ion3 (20070506)
[ion3.git] / ioncore / detach.c
index c93ca0cb2154b28d76c195e3811e8c9d73d37a55..72c74060e4d6d1278b4866147c5b7e2b36e55fa3 100644 (file)
@@ -3,10 +3,7 @@
  *
  * Copyright (c) Tuomo Valkonen 1999-2007. 
  *
- * 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>
 #include <libtu/minmax.h>
 
 #include <ioncore/common.h>
+#include <ioncore/global.h>
 #include <ioncore/mplex.h>
 #include <ioncore/focus.h>
 #include <ioncore/group.h>
 #include <ioncore/group-ws.h>
 #include <ioncore/framedpholder.h>
 #include <ioncore/return.h>
+#include <ioncore/sizehint.h>
+#include <ioncore/resize.h>
 
 
 static void get_relative_geom(WRectangle *g, WRegion *reg, WRegion *mgr)
@@ -38,7 +38,8 @@ static void get_relative_geom(WRectangle *g, WRegion *reg, WRegion *mgr)
 }
 
 
-bool ioncore_do_detach(WRegion *reg, WGroup *grp, WFrameMode framemode)
+static bool ioncore_do_detach(WRegion *reg, WGroup *grp, WFrameMode framemode,
+                              uint framelevel)
 {
     WGroupAttachParams ap=GROUPATTACHPARAMS_INIT;
     WRegionAttachData data;
@@ -68,6 +69,9 @@ bool ioncore_do_detach(WRegion *reg, WGroup *grp, WFrameMode framemode)
         
         ap.geom_weak_set=TRUE;
         ap.geom_weak=0;
+
+        ap.level_set=TRUE;
+        ap.level=framelevel+1;
         
         get_relative_geom(&fpa.inner_geom, reg, (WRegion*)grp);
 
@@ -81,8 +85,8 @@ bool ioncore_do_detach(WRegion *reg, WGroup *grp, WFrameMode framemode)
             ap.szplcy=st->szplcy;
             ap.szplcy_set=TRUE;
             
-            ap.level=maxof(st->level, STACKING_LEVEL_NORMAL);
             ap.level_set=TRUE;
+            ap.level=maxof(st->level, STACKING_LEVEL_NORMAL);
         }
         
         ap.geom_set=TRUE;
@@ -120,14 +124,19 @@ static WRegion *check_mplex(WRegion *reg, WFrameMode *mode)
 }
 
 
-static WGroup *find_group(WRegion *reg)
+static WGroup *find_group(WRegion *reg, uint *level)
 {
     WRegion *mgr=REGION_MANAGER(reg);
     
     while(mgr!=NULL){
+        reg=mgr;
         mgr=REGION_MANAGER(mgr);
-        if(OBJ_IS(mgr, WGroup))
+        if(OBJ_IS(mgr, WGroup)){
+            WStacking *st=ioncore_find_stacking((WRegion*)reg);
+            if(st!=NULL)
+                *level=st->level;
             break;
+        }
     }
     
     return (WGroup*)mgr;
@@ -140,10 +149,11 @@ bool ioncore_detach(WRegion *reg, int sp)
     WFrameMode mode;
     WGroup *grp;
     bool set, nset;
+    uint level=STACKING_LEVEL_NORMAL;
     
-    reg=region_group_if_bottom(reg);
+    reg=region_groupleader_of(reg);
     
-    grp=find_group(check_mplex(reg, &mode));
+    grp=find_group(check_mplex(reg, &mode), &level);
     
     /* reg is only considered detached if there's no higher-level group
      * to attach to, thus causing 'toggle' to cycle.
@@ -155,7 +165,7 @@ bool ioncore_detach(WRegion *reg, int sp)
         return set;
 
     if(!set){
-        return ioncore_do_detach(reg, grp, mode);
+        return ioncore_do_detach(reg, grp, mode, level);
     }else{
         WPHolder *ph=region_get_return(reg);
         
@@ -174,11 +184,12 @@ bool ioncore_detach(WRegion *reg, int sp)
 
 /*EXTL_DOC
  * Detach or reattach \var{reg}, depending on whether \var{how}
- * is 'set'/'unset'/'toggle'. (Detaching means making \var{reg} 
- * managed by its nearest ancestor \type{WGroup}, framed if \var{reg} is
- * not itself \type{WFrame}. Reattaching means making it managed where
- * it used to be managed, if a return-placeholder exists.)
- * If \var{reg} is the 'bottom' of some group, the whole group is
+ * is \codestr{set}, \codestr{unset} or \codestr{toggle}. (Detaching 
+ * means making \var{reg} managed by its nearest ancestor \type{WGroup},
+ * framed if \var{reg} is not itself \type{WFrame}. Reattaching means 
+ * making it managed where it used to be managed, if a return-placeholder
+ * exists.)
+ * If \var{reg} is the `bottom' of some group, the whole group is
  * detached. If \var{reg} is a \type{WWindow}, it is put into a 
  * frame.
  */
@@ -192,3 +203,44 @@ bool ioncore_detach_extl(WRegion *reg, const char *how)
 }
 
 
+void do_unsqueeze(WRegion *reg)
+{
+    WSizeHints h;
+    WRegion *mgr=REGION_MANAGER(reg);
+    
+    if(OBJ_IS(reg, WScreen))
+        return;
+    
+    region_size_hints(reg, &h);
+
+    if(!h.min_set)
+        return;
+        
+    if(h.min_width<=REGION_GEOM(reg).w && 
+       h.min_height<=REGION_GEOM(reg).h){
+        return;
+    }
+    
+    ioncore_detach(reg, SETPARAM_SET);
+        
+    if(REGION_MANAGER(reg)==mgr)
+        return;
+    
+    do_unsqueeze(reg);
+}
+
+
+/*EXTL_DOC
+ * Try to detach \var{reg} if it fits poorly in its 
+ * current location. This function does not do anything,
+ * unless \var{override} is set or the \var{unsqueeze} option
+ * of \fnref{ioncore.set} is set.
+ */
+EXTL_EXPORT
+void ioncore_unsqueeze(WRegion *reg, bool override)
+{
+    if(ioncore_g.unsqueeze_enabled || override)
+        do_unsqueeze(region_groupleader_of(reg));
+}
+
+