- g_warning("Failed to connect to session manager: %s", sm_err);
- else {
- SmPropValue val_prog;
- SmPropValue val_uid;
- SmPropValue val_hint;
- SmPropValue val_pri;
- SmPropValue val_pid;
- SmProp prop_prog = { SmProgram, SmARRAY8, 1, };
- SmProp prop_uid = { SmUserID, SmARRAY8, 1, };
- SmProp prop_hint = { SmRestartStyleHint, SmCARD8, 1, };
- SmProp prop_pid = { SmProcessID, SmARRAY8, 1, };
- SmProp prop_pri = { "_GSM_Priority", SmCARD8, 1, };
- SmProp *props[6];
- gulong hint, pri;
- gchar pid[32];
-
- val_prog.value = argv[0];
- val_prog.length = strlen(argv[0]);
-
- val_uid.value = g_strdup(g_get_user_name());
- val_uid.length = strlen(val_uid.value);
-
- hint = SmRestartImmediately;
- val_hint.value = &hint;
- val_hint.length = 1;
-
- sprintf(pid, "%ld", (long)getpid());
- val_pid.value = pid;
- val_pid.length = strlen(pid);
-
- /* priority with gnome-session-manager, low to run before other apps */
- pri = 20;
- val_pri.value = &pri;
- val_pri.length = 1;
-
- prop_prog.vals = &val_prog;
- prop_uid.vals = &val_uid;
- prop_hint.vals = &val_hint;
- prop_pid.vals = &val_pid;
- prop_pri.vals = &val_pri;
-
- props[0] = &prop_prog;
- props[1] = &prop_uid;
- props[2] = &prop_hint;
- props[3] = &prop_pid;
- props[4] = &prop_pri;
-
- SmcSetProperties(sm_conn, 5, props);
-
- g_free(val_uid.value);
-
- ob_debug("Connected to session manager with id %s\n", ob_sm_id);
+ ob_debug("Failed to connect to session manager: %s\n", sm_err);
+ return sm_conn != NULL;
+}
+
+static void session_setup_program()
+{
+ SmPropValue vals = {
+ .value = sm_argv[0],
+ .length = strlen(sm_argv[0]) + 1
+ };
+ SmProp prop = {
+ .name = g_strdup(SmProgram),
+ .type = g_strdup(SmARRAY8),
+ .num_vals = 1,
+ .vals = &vals
+ };
+ SmProp *list = ∝
+ ob_debug_type(OB_DEBUG_SM, "Setting program: %s\n", sm_argv[0]);
+ SmcSetProperties(sm_conn, 1, &list);
+ g_free(prop.name);
+ g_free(prop.type);
+}
+
+static void session_setup_user()
+{
+ char *user = g_strdup(g_get_user_name());
+
+ SmPropValue vals = {
+ .value = user,
+ .length = strlen(user) + 1
+ };
+ SmProp prop = {
+ .name = g_strdup(SmUserID),
+ .type = g_strdup(SmARRAY8),
+ .num_vals = 1,
+ .vals = &vals
+ };
+ SmProp *list = ∝
+ ob_debug_type(OB_DEBUG_SM, "Setting user: %s\n", user);
+ SmcSetProperties(sm_conn, 1, &list);
+ g_free(prop.name);
+ g_free(prop.type);
+ g_free(user);
+}
+
+static void session_setup_restart_style(gboolean restart)
+{
+ gchar restart_hint = restart ? SmRestartImmediately : SmRestartIfRunning;
+
+ SmPropValue vals = {
+ .value = &restart_hint,
+ .length = 1
+ };
+ SmProp prop = {
+ .name = g_strdup(SmRestartStyleHint),
+ .type = g_strdup(SmCARD8),
+ .num_vals = 1,
+ .vals = &vals
+ };
+ SmProp *list = ∝
+ ob_debug_type(OB_DEBUG_SM, "Setting restart: %d\n", restart);
+ SmcSetProperties(sm_conn, 1, &list);
+ g_free(prop.name);
+ g_free(prop.type);
+}
+
+static void session_setup_pid()
+{
+ gchar *pid = g_strdup_printf("%ld", (glong) getpid());
+
+ SmPropValue vals = {
+ .value = pid,
+ .length = strlen(pid) + 1
+ };
+ SmProp prop = {
+ .name = g_strdup(SmProcessID),
+ .type = g_strdup(SmARRAY8),
+ .num_vals = 1,
+ .vals = &vals
+ };
+ SmProp *list = ∝
+ ob_debug_type(OB_DEBUG_SM, "Setting pid: %s\n", pid);
+ SmcSetProperties(sm_conn, 1, &list);
+ g_free(prop.name);
+ g_free(prop.type);
+ g_free(pid);
+}
+
+/*! This is a gnome-session-manager extension */
+static void session_setup_priority()
+{
+ gchar priority = 20; /* 20 is a lower prioity to run before other apps */
+
+ SmPropValue vals = {
+ .value = &priority,
+ .length = 1
+ };
+ SmProp prop = {
+ .name = g_strdup("_GSM_Priority"),
+ .type = g_strdup(SmCARD8),
+ .num_vals = 1,
+ .vals = &vals
+ };
+ SmProp *list = ∝
+ ob_debug_type(OB_DEBUG_SM, "Setting priority: %d\n", priority);
+ SmcSetProperties(sm_conn, 1, &list);
+ g_free(prop.name);
+ g_free(prop.type);
+}
+
+static void session_setup_clone_command()
+{
+ gint i;
+
+ SmPropValue *vals = g_new(SmPropValue, sm_argc);
+ SmProp prop = {
+ .name = g_strdup(SmCloneCommand),
+ .type = g_strdup(SmLISTofARRAY8),
+ .num_vals = sm_argc,
+ .vals = vals
+ };
+ SmProp *list = ∝
+
+ ob_debug_type(OB_DEBUG_SM, "Setting clone command: (%d)\n", sm_argc);
+ for (i = 0; i < sm_argc; ++i) {
+ vals[i].value = sm_argv[i];
+ vals[i].length = strlen(sm_argv[i]) + 1;
+ ob_debug_type(OB_DEBUG_SM, " %s\n", vals[i].value);
+ }
+
+ SmcSetProperties(sm_conn, 1, &list);
+ g_free(prop.name);
+ g_free(prop.type);
+ g_free(vals);
+}
+
+static void session_setup_restart_command()
+{
+ gint i;
+
+ SmPropValue *vals = g_new(SmPropValue, sm_argc + 4);
+ SmProp prop = {
+ .name = g_strdup(SmRestartCommand),
+ .type = g_strdup(SmLISTofARRAY8),
+ .num_vals = sm_argc + 4,
+ .vals = vals
+ };
+ SmProp *list = ∝
+
+ ob_debug_type(OB_DEBUG_SM, "Setting restart command: (%d)\n", sm_argc+4);
+ for (i = 0; i < sm_argc; ++i) {
+ vals[i].value = sm_argv[i];
+ vals[i].length = strlen(sm_argv[i]) + 1;
+ ob_debug_type(OB_DEBUG_SM, " %s\n", vals[i].value);