Released version 3-2014010901
[notion.git] / mod_sm / sm.c
blob8d8b941ebccd41d05df179fbf306402a724431ea
1 /*
2 * ion/mod_sm/sm.c
4 * Copyright (c) Tuomo Valkonen 2004-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <stdlib.h>
10 #include <string.h>
12 #include <libtu/misc.h>
13 #include <libtu/parser.h>
14 #include <libtu/tokenizer.h>
15 #include <libtu/util.h>
17 #include <ioncore/common.h>
18 #include <ioncore/global.h>
19 #include <ioncore/clientwin.h>
20 #include <ioncore/saveload.h>
21 #include <ioncore/property.h>
22 #include <libextl/readconfig.h>
23 #include <ioncore/manage.h>
24 #include <ioncore/ioncore.h>
25 #include <ioncore/exec.h>
26 #include "sm_matchwin.h"
27 #include "sm_session.h"
28 #include "exports.h"
31 /*{{{ Module information */
34 #include "../version.h"
36 char mod_sm_ion_api_version[]=NOTION_API_VERSION;
39 /*}}}*/
42 /*{{{ Manage callback */
45 static bool sm_do_manage(WClientWin *cwin, const WManageParams *param)
47 int transient_mode=TRANSIENT_MODE_OFF;
48 WPHolder *ph;
49 bool ret;
51 if(param->tfor!=NULL)
52 return FALSE;
54 ph=mod_sm_match_cwin_to_saved(cwin);
55 if(ph==NULL)
56 return FALSE;
58 ret=pholder_attach(ph, 0, (WRegion*)cwin);
60 destroy_obj((Obj*)ph);
62 return ret;
66 /*}}}*/
69 /*{{{ Init/deinit */
72 static void mod_sm_set_sessiondir()
74 const char *smdir=NULL, *id=NULL;
75 char *tmp;
76 bool ok=FALSE;
78 smdir=getenv("SM_SAVE_DIR");
79 id=getenv("GNOME_DESKTOP_SESSION_ID");
81 /* Running under SM, try to use a directory specific
82 * to the session.
84 if(smdir!=NULL){
85 tmp=scat3(smdir, "/", libtu_progbasename());
86 }else if(id!=NULL){
87 tmp=scat("gnome-session-", id);
88 if(tmp!=NULL){
89 char *p=tmp;
90 while(1){
91 p=strpbrk(p, "/ :?*");
92 if(p==NULL)
93 break;
94 *p='-';
95 p++;
98 }else{
99 tmp=scopy("default-session-sm");
102 if(tmp!=NULL){
103 ok=extl_set_sessiondir(tmp);
104 free(tmp);
107 if(!ok)
108 warn(TR("Failed to set session directory."));
113 void mod_sm_deinit()
115 ioncore_set_smhook(NULL);
117 hook_remove(clientwin_do_manage_alt, (WHookDummy*)sm_do_manage);
119 ioncore_set_sm_callbacks(NULL, NULL);
121 mod_sm_unregister_exports();
123 mod_sm_close();
127 int mod_sm_init()
129 if(ioncore_g.sm_client_id!=NULL)
130 mod_sm_set_ion_id(ioncore_g.sm_client_id);
132 if(!mod_sm_init_session())
133 goto err;
135 if(extl_sessiondir()==NULL)
136 mod_sm_set_sessiondir();
138 if(!mod_sm_register_exports())
139 goto err;
141 ioncore_set_sm_callbacks(mod_sm_add_match, mod_sm_get_configuration);
143 hook_add(clientwin_do_manage_alt, (WHookDummy*)sm_do_manage);
145 ioncore_set_smhook(mod_sm_smhook);
147 return TRUE;
149 err:
150 mod_sm_deinit();
151 return FALSE;
155 /*}}}*/