]> git.decadent.org.uk Git - ion3.git/blob - mod_sm/sm.c
[svn-inject] Installing original source of ion3
[ion3.git] / mod_sm / sm.c
1 /*
2  * ion/mod_sm/sm.c
3  *
4  * Copyright (c) Tuomo Valkonen 2004-2006. 
5  *
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.
10  */
11
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include <libtu/misc.h>
16 #include <libtu/parser.h>
17 #include <libtu/tokenizer.h>
18
19 #include <ioncore/common.h>
20 #include <ioncore/global.h>
21 #include <ioncore/clientwin.h>
22 #include <ioncore/saveload.h>
23 #include <ioncore/property.h>
24 #include <libextl/readconfig.h>
25 #include <ioncore/manage.h>
26 #include <ioncore/ioncore.h>
27 #include <ioncore/exec.h>
28 #include "sm_matchwin.h"
29 #include "sm_session.h"
30 #include "exports.h"
31
32
33 /*{{{ Module information */
34
35
36 #include "../version.h"
37
38 char mod_sm_ion_api_version[]=ION_API_VERSION;
39
40
41 /*}}}*/
42
43
44 /*{{{ Manage callback */
45
46
47 static bool sm_do_manage(WClientWin *cwin, const WManageParams *param)
48 {
49     int transient_mode=TRANSIENT_MODE_OFF;
50     WPHolder *ph;
51     bool ret;
52     
53     if(param->tfor!=NULL)
54         return FALSE;
55     
56     ph=mod_sm_match_cwin_to_saved(cwin);
57     if(ph==NULL)
58         return FALSE;
59     
60     ret=pholder_attach(ph, 0, (WRegion*)cwin);
61     
62     destroy_obj((Obj*)ph);
63     
64     return ret;
65 }
66
67
68 /*}}}*/
69
70
71 /*{{{ Init/deinit */
72
73
74 static void mod_sm_set_sessiondir()
75 {
76     const char *smdir=NULL, *id=NULL;
77     char *tmp;
78     bool ok=FALSE;
79     
80     smdir=getenv("SM_SAVE_DIR");
81     id=getenv("GNOME_DESKTOP_SESSION_ID");
82
83     /* Running under SM, try to use a directory specific
84      * to the session.
85      */
86     if(smdir!=NULL){
87         tmp=scat(smdir, "/ion3"); /* TODO: pwm<=>ion! */
88     }else if(id!=NULL){
89         tmp=scat("gnome-session-", id);
90         if(tmp!=NULL){
91             char *p=tmp;
92             while(1){
93                 p=strpbrk(p, "/ :?*");
94                 if(p==NULL)
95                     break;
96                 *p='-';
97                 p++;
98             }
99         }
100     }else{
101         tmp=scopy("default-session-sm");
102     }
103         
104     if(tmp!=NULL){
105         ok=extl_set_sessiondir(tmp);
106         free(tmp);
107     }
108     
109     if(!ok)
110         warn(TR("Failed to set session directory."));
111 }
112
113
114
115 void mod_sm_deinit()
116 {
117     ioncore_set_smhook(NULL);
118
119     hook_remove(clientwin_do_manage_alt, (WHookDummy*)sm_do_manage);
120
121     ioncore_set_sm_callbacks(NULL, NULL);
122     
123     mod_sm_unregister_exports();
124     
125     mod_sm_close();
126 }
127
128
129 int mod_sm_init()
130 {
131     if(ioncore_g.sm_client_id!=NULL)
132         mod_sm_set_ion_id(ioncore_g.sm_client_id);
133     
134     if(!mod_sm_init_session())
135         goto err;
136
137     if(extl_sessiondir()==NULL)
138         mod_sm_set_sessiondir();
139     
140     if(!mod_sm_register_exports())
141         goto err;
142
143     ioncore_set_sm_callbacks(mod_sm_add_match, mod_sm_get_configuration);
144     
145     hook_add(clientwin_do_manage_alt, (WHookDummy*)sm_do_manage);
146
147     ioncore_set_smhook(mod_sm_smhook);
148     
149     return TRUE;
150     
151 err:
152     mod_sm_deinit();
153     return FALSE;
154 }
155
156
157 /*}}}*/
158