From 4d7a7d9d4c59b9ac5a369f4733aa819a2d01e83d Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 28 Jul 2003 05:20:50 +0000 Subject: [PATCH] save the commands on startup --- openbox/session.c | 108 +++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 44 deletions(-) diff --git a/openbox/session.c b/openbox/session.c index 9ee9f04d..637c77ff 100644 --- a/openbox/session.c +++ b/openbox/session.c @@ -30,6 +30,9 @@ static SmcConn sm_conn; static gchar *save_file; static gint sm_argc; static gchar **sm_argv; + +static gboolean session_save(); + static void sm_save_yourself(SmcConn conn, SmPointer data, int save_type, Bool shutdown, int interact_style, Bool fast); static void sm_die(SmcConn conn, SmPointer data); @@ -79,10 +82,17 @@ static void save_commands() } } - prop_res.vals[j].value = "--sm-save-file"; - prop_res.vals[j++].length = strlen("--sm-save-file"); - prop_res.vals[j].value = save_file; - prop_res.vals[j++].length = strlen(save_file); + if (save_file) { + prop_res.vals[j].value = "--sm-save-file"; + prop_res.vals[j++].length = strlen("--sm-save-file"); + prop_res.vals[j].value = save_file; + prop_res.vals[j++].length = strlen(save_file); + } else { + prop_res.vals[j].value = "--sm-client-id"; + prop_res.vals[j++].length = strlen("--sm-client-id"); + prop_res.vals[j].value = ob_sm_id; + prop_res.vals[j++].length = strlen(ob_sm_id); + } props[0] = &prop_res; props[1] = &prop_cmd; @@ -173,6 +183,8 @@ void session_startup(int argc, char **argv) g_free(val_uid.value); + save_commands(); + ob_debug("Connected to session manager with id %s\n", ob_sm_id); } } @@ -204,14 +216,40 @@ void session_shutdown() static void sm_save_yourself(SmcConn conn, SmPointer data, int save_type, Bool shutdown, int interact_style, Bool fast) +{ + gboolean success; + + ob_debug("got SAVE YOURSELF from session manager\n"); + + success = session_save(); + save_commands(); + + SmcSaveYourselfDone(conn, success); +} + +static void sm_die(SmcConn conn, SmPointer data) +{ + ob_exit(); + ob_debug("got DIE from session manager\n"); +} + +static void sm_save_complete(SmcConn conn, SmPointer data) +{ + ob_debug("got SAVE COMPLETE from session manager\n"); +} + +static void sm_shutdown_cancelled(SmcConn conn, SmPointer data) +{ + ob_debug("got SHUTDOWN CANCELLED from session manager\n"); +} + +static gboolean session_save() { gchar *filename; FILE *f; GList *it; gboolean success = TRUE; - ob_debug("got SAVE YOURSELF from session manager\n"); - /* this algo is from metacity */ filename = g_strdup_printf("%d-%d-%u.obs", (int) time(NULL), @@ -254,38 +292,38 @@ static void sm_save_yourself(SmcConn conn, SmPointer data, int save_type, g_free(dimensions); } - fprintf(f, "\t\n", + fprintf(f, "\n", g_markup_escape_text("XXX", -1)); - fprintf(f, "\t\t%s\n", + fprintf(f, "\t%s\n", g_markup_escape_text(c->name, -1)); - fprintf(f, "\t\t%s\n", + fprintf(f, "\t%s\n", g_markup_escape_text(c->class, -1)); - fprintf(f, "\t\t%s\n", + fprintf(f, "\t%s\n", g_markup_escape_text(c->role, -1)); - fprintf(f, "\t\t%d\n", c->desktop); - fprintf(f, "\t\t%d\n", prex); - fprintf(f, "\t\t%d\n", prey); - fprintf(f, "\t\t%d\n", prew); - fprintf(f, "\t\t%d\n", preh); + fprintf(f, "\t%d\n", c->desktop); + fprintf(f, "\t%d\n", prex); + fprintf(f, "\t%d\n", prey); + fprintf(f, "\t%d\n", prew); + fprintf(f, "\t%d\n", preh); if (c->shaded) - fprintf(f, "\t\t\n"); + fprintf(f, "\t\n"); if (c->iconic) - fprintf(f, "\t\t\n"); + fprintf(f, "\t\n"); if (c->skip_pager) - fprintf(f, "\t\t\n"); + fprintf(f, "\t\n"); if (c->skip_taskbar) - fprintf(f, "\t\t\n"); + fprintf(f, "\t\n"); if (c->fullscreen) - fprintf(f, "\t\t\n"); + fprintf(f, "\t\n"); if (c->above) - fprintf(f, "\t\t\n"); + fprintf(f, "\t\n"); if (c->below) - fprintf(f, "\t\t\n"); + fprintf(f, "\t\n"); if (c->max_horz) - fprintf(f, "\t\t\n"); + fprintf(f, "\t\n"); if (c->max_vert) - fprintf(f, "\t\t\n"); - fprintf(f, "\t\n\n"); + fprintf(f, "\t\n"); + fprintf(f, "\n\n"); } fprintf(f, "\n"); @@ -298,25 +336,7 @@ static void sm_save_yourself(SmcConn conn, SmPointer data, int save_type, fclose(f); } - save_commands(); - - SmcSaveYourselfDone(conn, success); -} - -static void sm_die(SmcConn conn, SmPointer data) -{ - ob_exit(); - ob_debug("got DIE from session manager\n"); -} - -static void sm_save_complete(SmcConn conn, SmPointer data) -{ - ob_debug("got SAVE COMPLETE from session manager\n"); -} - -static void sm_shutdown_cancelled(SmcConn conn, SmPointer data) -{ - ob_debug("got SHUTDOWN CANCELLED from session manager\n"); + return success; } void session_load(char *path) -- 2.45.2