4 * Copyright (c) Tuomo Valkonen 2004-2007.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
14 #include <libtu/map.h>
15 #include <libtu/minmax.h>
16 #include <libextl/readconfig.h>
17 #include <libmainloop/hooks.h>
19 #include <ioncore/saveload.h>
20 #include <ioncore/screen.h>
21 #include <ioncore/mplex.h>
22 #include <ioncore/ioncore.h>
23 #include <ioncore/global.h>
24 #include <ioncore/framep.h>
25 #include <ioncore/frame.h>
26 #include <ioncore/names.h>
32 /*{{{ Module information */
34 #include "../version.h"
36 char mod_sp_ion_api_version[]=ION_API_VERSION;
42 /*{{{ Bindmaps, config, etc. */
45 #define SP_NAME "*scratchpad*"
54 static WRegion *create_frame_scratchpad(WWindow *parent, const WFitParams *fp,
57 return (WRegion*)create_frame(parent, fp, FRAME_MODE_UNKNOWN);
61 static WFrame *create(WMPlex *mplex, int flags)
64 WMPlexAttachParams par;
65 int sw=REGION_GEOM(mplex).w, sh=REGION_GEOM(mplex).h;
68 |MPLEX_ATTACH_UNNUMBERED
70 |MPLEX_ATTACH_SIZEPOLICY
72 par.szplcy=SIZEPOLICY_FREE_GLUE;
74 par.geom.w=minof(sw, CF_SCRATCHPAD_DEFAULT_W);
75 par.geom.h=minof(sh, CF_SCRATCHPAD_DEFAULT_H);
76 par.geom.x=(sw-par.geom.w)/2;
77 par.geom.y=(sh-par.geom.h)/2;
79 sp=(WFrame*)mplex_do_attach_new((WMPlex*)mplex, &par,
80 create_frame_scratchpad,
85 warn(TR("Unable to create scratchpad."));
88 region_set_name((WRegion*)sp, SP_NAME);
94 static bool is_scratchpad(WRegion *reg)
96 char *nm=reg->ni.name;
97 int inst_off=reg->ni.inst_off;
103 return (strcmp(nm, SP_NAME)==0);
105 return (strncmp(nm, SP_NAME, inst_off)==0);
110 * Change displayed status of some scratchpad on \var{mplex} if one is
111 * found. The parameter \var{how} is one of (set/unset/toggle).
114 bool mod_sp_set_shown_on(WMPlex *mplex, const char *how)
116 int setpar=libtu_setparam_invert(libtu_string_to_setparam(how));
121 FOR_ALL_MANAGED_BY_MPLEX(mplex, reg, tmp){
122 if(is_scratchpad(reg)){
123 mplex_set_hidden(mplex, reg, setpar);
129 int sp=libtu_string_to_setparam(how);
130 if(sp==SETPARAM_SET || sp==SETPARAM_TOGGLE)
131 found=(create(mplex, 0)!=NULL);
139 * Toggle displayed status of \var{sp}.
140 * The parameter \var{how} is one of (set/unset/toggle).
143 bool mod_sp_set_shown(WFrame *sp, const char *how)
146 int setpar=libtu_setparam_invert(libtu_string_to_setparam(how));
147 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(sp), WMPlex);
149 return mplex_set_hidden(mplex, (WRegion*)sp, setpar);
159 /*{{{ Init & deinit */
164 mod_sp_unregister_exports();
168 static void check_and_create()
174 /* No longer needed, free the memory the list uses. */
175 hook_remove(ioncore_post_layout_setup_hook, check_and_create);
177 FOR_ALL_SCREENS(scr){
178 FOR_ALL_MANAGED_BY_MPLEX((WMPlex*)scr, reg, tmp){
179 if(is_scratchpad(reg))
183 create(&scr->mplex, MPLEX_ATTACH_HIDDEN);
190 if(!mod_sp_register_exports())
193 extl_read_config("cfg_sp", NULL, FALSE);
195 if(ioncore_g.opmode==IONCORE_OPMODE_INIT){
196 hook_add(ioncore_post_layout_setup_hook, check_and_create);