Also log the loglevel
[notion/jeffpc.git] / mod_sp / main.c
blobf0cf5d63f70afbc2e78d7a8add277fad8bfef63f
1 /*
2 * ion/mod_sp/main.c
4 * Copyright (c) Tuomo Valkonen 2004-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <string.h>
11 #include <libtu/map.h>
12 #include <libtu/minmax.h>
13 #include <libextl/readconfig.h>
14 #include <libmainloop/hooks.h>
16 #include <ioncore/saveload.h>
17 #include <ioncore/screen.h>
18 #include <ioncore/mplex.h>
19 #include <ioncore/stacking.h>
20 #include <ioncore/ioncore.h>
21 #include <ioncore/global.h>
22 #include <ioncore/framep.h>
23 #include <ioncore/frame.h>
24 #include <ioncore/names.h>
25 #include <ioncore/group.h>
26 #include <ioncore/group-ws.h>
28 #include "main.h"
29 #include "exports.h"
32 /*{{{ Module information */
34 #include "../version.h"
36 char mod_sp_ion_api_version[]=NOTION_API_VERSION;
39 /*}}}*/
42 /*{{{ Bindmaps, config, etc. */
45 #define SP_NAME "*scratchpad*"
46 #define SPWS_NAME "*scratchws*"
49 /*}}}*/
52 /*{{{ Exports */
55 static WRegion *create_frame_scratchpad(WWindow *parent, const WFitParams *fp,
56 void *unused)
58 return (WRegion*)create_frame(parent, fp, FRAME_MODE_UNKNOWN);
62 static WRegion *create_scratchws(WWindow *parent, const WFitParams *fp,
63 void *unused)
65 WRegion *reg;
66 WRegionAttachData data;
67 WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
68 WGroupWS *ws;
70 ws=create_groupws(parent, fp);
72 if(ws==NULL)
73 return NULL;
75 region_set_name((WRegion*)ws, SPWS_NAME);
77 data.type=REGION_ATTACH_NEW;
78 data.u.n.fn=create_frame_scratchpad;
79 data.u.n.param=NULL;
81 par.szplcy_set=TRUE;
82 par.szplcy=SIZEPOLICY_FREE_GLUE;
84 par.geom_set=TRUE;
85 par.geom.w=minof(fp->g.w, CF_SCRATCHPAD_DEFAULT_W);
86 par.geom.h=minof(fp->g.h, CF_SCRATCHPAD_DEFAULT_H);
87 par.geom.x=(fp->g.w-par.geom.w)/2;
88 par.geom.y=(fp->g.h-par.geom.h)/2;
90 par.level_set=TRUE;
91 par.level=STACKING_LEVEL_MODAL1+1;
93 par.bottom=TRUE;
95 reg=group_do_attach(&ws->grp, &par, &data);
97 if(reg==NULL){
98 destroy_obj((Obj*)ws);
99 return NULL;
102 region_set_name((WRegion*)reg, SP_NAME);
104 return (WRegion*)ws;
108 static WRegion *create(WMPlex *mplex, int flags)
110 WRegion *sp;
111 WMPlexAttachParams par=MPLEXATTACHPARAMS_INIT;
113 par.flags=(flags
114 |MPLEX_ATTACH_UNNUMBERED
115 |MPLEX_ATTACH_SIZEPOLICY
116 |MPLEX_ATTACH_PSEUDOMODAL);
117 par.szplcy=SIZEPOLICY_FULL_EXACT;
119 sp=mplex_do_attach_new(mplex, &par,
120 create_scratchws,
121 NULL);
123 if(sp==NULL)
124 warn(TR("Unable to create scratchpad."));
126 return sp;
130 static bool is_scratchpad(WRegion *reg)
132 char *nm=reg->ni.name;
133 int inst_off=reg->ni.inst_off;
135 if(nm==NULL)
136 return FALSE;
138 return (inst_off<0
139 ? (strcmp(nm, SP_NAME)==0 ||
140 strcmp(nm, SPWS_NAME)==0)
141 : (strncmp(nm, SP_NAME, inst_off)==0 ||
142 strncmp(nm, SPWS_NAME, inst_off)==0));
145 /*EXTL_DOC
146 * Is \var{reg} a scratchpad?
148 EXTL_SAFE
149 EXTL_EXPORT
150 bool mod_sp_is_scratchpad(WRegion *reg)
152 return is_scratchpad(reg);
155 /*EXTL_DOC
156 * Attempt to create a scratchpad on \var{scr}.
158 EXTL_EXPORT
159 bool mod_sp_create_scratchpad(WScreen *scr)
161 WMPlexIterTmp tmp;
162 WRegion *reg;
164 FOR_ALL_MANAGED_BY_MPLEX((WMPlex*)scr, reg, tmp){
165 if(is_scratchpad(reg))
166 return TRUE;
169 return create(&scr->mplex, MPLEX_ATTACH_HIDDEN)!=NULL;
172 /*EXTL_DOC
173 * Change displayed status of some scratchpad on \var{mplex} if one is
174 * found. The parameter \var{how} is one of
175 * \codestr{set}, \codestr{unset}, or \codestr{toggle}.
176 * The resulting status is returned.
178 EXTL_EXPORT
179 bool mod_sp_set_shown_on(WMPlex *mplex, const char *how)
181 int setpar=libtu_setparam_invert(libtu_string_to_setparam(how));
182 WMPlexIterTmp tmp;
183 WRegion *reg;
184 bool found=FALSE, res=FALSE;
186 FOR_ALL_MANAGED_BY_MPLEX(mplex, reg, tmp){
187 if(is_scratchpad(reg)){
188 res=!mplex_set_hidden(mplex, reg, setpar);
189 found=TRUE;
193 if(!found){
194 int sp=libtu_string_to_setparam(how);
195 if(sp==SETPARAM_SET || sp==SETPARAM_TOGGLE)
196 found=(create(mplex, 0)!=NULL);
197 res=found;
200 return res;
204 /*EXTL_DOC
205 * Toggle displayed status of \var{sp}.
206 * The parameter \var{how} is one of
207 * \codestr{set}, \codestr{unset}, or \codestr{toggle}.
208 * The resulting status is returned.
210 EXTL_EXPORT
211 bool mod_sp_set_shown(WFrame *sp, const char *how)
213 if(sp!=NULL){
214 int setpar=libtu_setparam_invert(libtu_string_to_setparam(how));
215 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(sp), WMPlex);
216 if(mplex!=NULL)
217 return mplex_set_hidden(mplex, (WRegion*)sp, setpar);
220 return FALSE;
224 /*}}}*/
227 /*{{{ Init & deinit */
230 void mod_sp_deinit()
232 mod_sp_unregister_exports();
236 static void check_and_create()
238 WMPlexIterTmp tmp;
239 WScreen *scr;
240 WRegion *reg;
242 /* No longer needed, free the memory the list uses. */
243 hook_remove(ioncore_post_layout_setup_hook, check_and_create);
245 FOR_ALL_SCREENS(scr){
246 FOR_ALL_MANAGED_BY_MPLEX((WMPlex*)scr, reg, tmp){
247 if(is_scratchpad(reg))
248 return;
251 create(&scr->mplex, MPLEX_ATTACH_HIDDEN);
256 bool mod_sp_init()
258 if(!mod_sp_register_exports())
259 return FALSE;
261 extl_read_config("cfg_sp", NULL, FALSE);
263 if(ioncore_g.opmode==IONCORE_OPMODE_INIT){
264 hook_add(ioncore_post_layout_setup_hook, check_and_create);
265 }else{
266 check_and_create();
269 return TRUE;
273 /*}}}*/