2 * ion/ioncore/saveload.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * See the included file LICENSE for details.
13 #include <libtu/objp.h>
14 #include <libextl/readconfig.h>
15 #include <libextl/extl.h>
29 static bool loading_layout=FALSE;
30 static bool layout_load_error=FALSE;
33 /*{{{ Session management module support */
36 static SMAddCallback *add_cb;
37 static SMCfgCallback *cfg_cb;
38 static SMPHolderCallback *ph_cb;
39 static bool clientwin_was_missing=FALSE;
42 void ioncore_set_sm_callbacks(SMAddCallback *add, SMCfgCallback *cfg)
49 void ioncore_get_sm_callbacks(SMAddCallback **add, SMCfgCallback **cfg)
56 void ioncore_set_sm_pholder_callback(SMPHolderCallback *phcb)
62 void ioncore_clientwin_load_missing()
64 clientwin_was_missing=TRUE;
71 /*{{{ Load support functions */
74 WRegion *create_region_load(WWindow *par, const WFitParams *fp,
77 char *objclass=NULL, *name=NULL;
78 WRegionLoadCreateFn* fn=NULL;
79 WRegClassInfo *info=NULL;
82 char *grouped_name=NULL;
84 if(!extl_table_gets_s(tab, "type", &objclass))
90 info=ioncore_lookup_regclass(objclass, FALSE);
95 warn(TR("Unknown class \"%s\", cannot create region."),
97 layout_load_error=loading_layout;
103 clientwin_was_missing=FALSE;
105 reg=fn(par, fp, tab);
108 if(clientwin_was_missing && add_cb!=NULL && ph_cb!=NULL){
109 WPHolder *ph=ph_cb();
112 destroy_obj((Obj*)ph);
116 if(!OBJ_IS(reg, WClientWin)){
117 if(extl_table_gets_s(tab, "name", &name)){
118 region_set_name(reg, name);
133 /*{{{ Save support functions */
136 bool region_supports_save(WRegion *reg)
138 return HAS_DYN(reg, region_get_configuration);
142 ExtlTab region_get_base_configuration(WRegion *reg)
147 tab=extl_create_table();
149 extl_table_sets_s(tab, "type", OBJ_TYPESTR(reg));
151 name=region_name(reg);
153 if(name!=NULL && !OBJ_IS(reg, WClientWin))
154 extl_table_sets_s(tab, "name", name);
160 static bool get_config_clientwins=TRUE;
163 ExtlTab region_get_configuration(WRegion *reg)
165 ExtlTab tab=extl_table_none();
166 if(get_config_clientwins || !OBJ_IS(reg, WClientWin)){
167 CALL_DYN_RET(tab, ExtlTab, region_get_configuration, reg, (reg));
174 * Get configuration tree. If \var{clientwins} is unset, client windows
177 EXTL_EXPORT_AS(WRegion, get_configuration)
178 ExtlTab region_get_configuration_extl(WRegion *reg, bool clientwins)
182 get_config_clientwins=clientwins;
184 tab=region_get_configuration(reg);
186 get_config_clientwins=TRUE;
195 /*{{{ save_workspaces, load_workspaces */
198 static const char backup_msg[]=DUMMY_TR(
199 "There were errors loading layout. Backing up current layout savefile as\n"
201 "If you are _not_ running under a session manager and wish to restore your\n"
202 "old layout, copy this backup file over the layout savefile found in the\n"
203 "same directory while Ion is not running and after having fixed your other\n"
204 "configuration files that are causing this problem. (Maybe a missing\n"
208 bool ioncore_init_layout()
215 ok=extl_read_savefile("saved_layout", &tab);
218 layout_load_error=FALSE;
220 FOR_ALL_SCREENS(scr){
221 ExtlTab scrtab=extl_table_none();
224 /* Potential Xinerama or such support should set the screen ID
225 * of the root window to less than zero, and number its own
226 * fake screens up from 0.
232 scrok=extl_table_geti_t(tab, screen_id(scr), &scrtab);
234 n+=(TRUE==screen_init_layout(scr, scrtab));
237 extl_unref_table(scrtab);
240 loading_layout=FALSE;
242 if(layout_load_error){
244 char tm[]="saved_layout.backup-YYYYMMDDHHMMSS\0\0\0\0";
247 strftime(tm+20, 15, "%Y%m%d%H%M%S", localtime(&t));
248 backup=extl_get_savefile(tm);
250 warn(TR("Unable to get file for layout backup."));
253 if(access(backup, F_OK)==0){
254 warn(TR("Backup file %s already exists."), backup);
258 warn(TR(backup_msg), backup);
259 if(!extl_serialise(backup, tab))
260 warn(TR("Failed backup."));
265 warn(TR("Unable to initialise layout on any screen."));
273 bool ioncore_save_layout()
276 ExtlTab tab=extl_create_table();
279 if(tab==extl_table_none())
282 FOR_ALL_SCREENS(scr){
289 scrtab=region_get_configuration((WRegion*)scr);
291 if(scrtab==extl_table_none()){
292 warn(TR("Unable to get configuration for screen %d."),
295 extl_table_seti_t(tab, screen_id(scr), scrtab);
296 extl_unref_table(scrtab);
300 ret=extl_write_savefile("saved_layout", tab);
302 extl_unref_table(tab);
305 warn(TR("Unable to save layout."));