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