]> git.decadent.org.uk Git - ion3.git/blobdiff - mod_sp/main.c
Imported Upstream version 20090110
[ion3.git] / mod_sp / main.c
index b827ae2fa55c5571ce6838474e074f90355d07ac..637912cb999c7cf5321378f7acf393ab8dfd4522 100644 (file)
@@ -1,12 +1,9 @@
 /*
  * ion/mod_sp/main.c
  *
- * Copyright (c) Tuomo Valkonen 2004-2006
+ * Copyright (c) Tuomo Valkonen 2004-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 <string.h>
 #include <ioncore/saveload.h>
 #include <ioncore/screen.h>
 #include <ioncore/mplex.h>
+#include <ioncore/stacking.h>
 #include <ioncore/ioncore.h>
 #include <ioncore/global.h>
 #include <ioncore/framep.h>
 #include <ioncore/frame.h>
 #include <ioncore/names.h>
+#include <ioncore/group.h>
+#include <ioncore/group-ws.h>
 
 #include "main.h"
 #include "exports.h"
@@ -43,6 +43,7 @@ char mod_sp_ion_api_version[]=ION_API_VERSION;
 
 
 #define SP_NAME  "*scratchpad*"
+#define SPWS_NAME  "*scratchws*"
 
 
 /*}}}*/
@@ -58,34 +59,69 @@ static WRegion *create_frame_scratchpad(WWindow *parent, const WFitParams *fp,
 }
 
 
-static WFrame *create(WMPlex *mplex, int flags)
+static WRegion *create_scratchws(WWindow *parent, const WFitParams *fp, 
+                                 void *unused)
 {
-    WFrame *sp;
-    WMPlexAttachParams par;
-    int sw=REGION_GEOM(mplex).w, sh=REGION_GEOM(mplex).h;
+    WRegion *reg;
+    WRegionAttachData data;
+    WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
+    WGroupWS *ws;
+    
+    ws=create_groupws(parent, fp);
+    
+    if(ws==NULL)
+        return NULL;
+        
+    region_set_name((WRegion*)ws, SPWS_NAME);
+    
+    data.type=REGION_ATTACH_NEW;
+    data.u.n.fn=create_frame_scratchpad;
+    data.u.n.param=NULL;
+    
+    par.szplcy_set=TRUE;
+    par.szplcy=SIZEPOLICY_FREE_GLUE;
+    
+    par.geom_set=TRUE;
+    par.geom.w=minof(fp->g.w, CF_SCRATCHPAD_DEFAULT_W);
+    par.geom.h=minof(fp->g.h, CF_SCRATCHPAD_DEFAULT_H);
+    par.geom.x=(fp->g.w-par.geom.w)/2;
+    par.geom.y=(fp->g.h-par.geom.h)/2;
+    
+    par.level_set=TRUE;
+    par.level=STACKING_LEVEL_MODAL1+1;
+    
+    par.bottom=TRUE;
+    
+    reg=group_do_attach(&ws->grp, &par, &data);
 
+    if(reg==NULL){
+        destroy_obj((Obj*)ws);
+        return NULL;
+    }
+     
+    region_set_name((WRegion*)reg, SP_NAME);
+    
+    return (WRegion*)ws;
+}
+
+
+static WRegion *create(WMPlex *mplex, int flags)
+{
+    WRegion *sp;
+    WMPlexAttachParams par=MPLEXATTACHPARAMS_INIT;
+    
     par.flags=(flags
                |MPLEX_ATTACH_UNNUMBERED
-               |MPLEX_ATTACH_MODAL
                |MPLEX_ATTACH_SIZEPOLICY
-               |MPLEX_ATTACH_GEOM);
-    par.szplcy=SIZEPOLICY_FREE_GLUE;
-    
-    par.geom.w=minof(sw, CF_SCRATCHPAD_DEFAULT_W);
-    par.geom.h=minof(sh, CF_SCRATCHPAD_DEFAULT_H);
-    par.geom.x=(sw-par.geom.w)/2;
-    par.geom.y=(sh-par.geom.h)/2;
+               |MPLEX_ATTACH_PSEUDOMODAL);
+    par.szplcy=SIZEPOLICY_FULL_EXACT;
 
-    sp=(WFrame*)mplex_do_attach_new((WMPlex*)mplex, &par,
-                                    create_frame_scratchpad,
-                                    NULL);
+    sp=mplex_do_attach_new((WMPlex*)mplex, &par,
+                           create_scratchws,
+                           NULL);
     
-
-    if(sp==NULL){
+    if(sp==NULL)
         warn(TR("Unable to create scratchpad."));
-    }
-    
-    region_set_name((WRegion*)sp, SP_NAME);
     
     return sp;
 }
@@ -99,16 +135,19 @@ static bool is_scratchpad(WRegion *reg)
     if(nm==NULL)
         return FALSE;
     
-    if(inst_off<0)
-        return (strcmp(nm, SP_NAME)==0);
-    else
-        return (strncmp(nm, SP_NAME, inst_off)==0);
+    return (inst_off<0
+            ? (strcmp(nm, SP_NAME)==0 || 
+               strcmp(nm, SPWS_NAME)==0)
+            : (strncmp(nm, SP_NAME, inst_off)==0 ||
+               strncmp(nm, SPWS_NAME, inst_off)==0));
 }
 
 
 /*EXTL_DOC
  * Change displayed status of some scratchpad on \var{mplex} if one is 
- * found. The parameter \var{how} is one of (set/unset/toggle).
+ * found. The parameter \var{how} is one of 
+ * \codestr{set}, \codestr{unset}, or \codestr{toggle}.
+ * The resulting status is returned.
  */
 EXTL_EXPORT
 bool mod_sp_set_shown_on(WMPlex *mplex, const char *how)
@@ -116,11 +155,11 @@ bool mod_sp_set_shown_on(WMPlex *mplex, const char *how)
     int setpar=libtu_setparam_invert(libtu_string_to_setparam(how));
     WMPlexIterTmp tmp;
     WRegion *reg;
-    bool found=FALSE;
+    bool found=FALSE, res=FALSE;
     
     FOR_ALL_MANAGED_BY_MPLEX(mplex, reg, tmp){
         if(is_scratchpad(reg)){
-            mplex_set_hidden(mplex, reg, setpar);
+            res=!mplex_set_hidden(mplex, reg, setpar);
             found=TRUE;
         }
     }
@@ -129,15 +168,18 @@ bool mod_sp_set_shown_on(WMPlex *mplex, const char *how)
         int sp=libtu_string_to_setparam(how);
         if(sp==SETPARAM_SET || sp==SETPARAM_TOGGLE)
             found=(create(mplex, 0)!=NULL);
+            res=found;
     }
     
-    return found;
+    return res;
 }
 
 
 /*EXTL_DOC
  * Toggle displayed status of \var{sp}.
- * The parameter \var{how} is one of (set/unset/toggle).
+ * The parameter \var{how} is one of 
+ * \codestr{set}, \codestr{unset}, or \codestr{toggle}.
+ * The resulting status is returned.
  */
 EXTL_EXPORT
 bool mod_sp_set_shown(WFrame *sp, const char *how)