put back --sm-client-id argument, needed for including us in a default

2002-03-13  Havoc Pennington  <hp@pobox.com>

	* src/main.c (main): put back --sm-client-id argument, needed
	for including us in a default session
This commit is contained in:
Havoc Pennington 2002-03-14 04:36:02 +00:00 committed by Havoc Pennington
parent 9e2cfcd699
commit 42936562de
5 changed files with 68 additions and 28 deletions

View File

@ -1,3 +1,8 @@
2002-03-13 Havoc Pennington <hp@pobox.com>
* src/main.c (main): put back --sm-client-id argument, needed
for including us in a default session
2002-03-13 Havoc Pennington <hp@pobox.com> 2002-03-13 Havoc Pennington <hp@pobox.com>
* src/session.c (meta_session_init): don't save a file here, only * src/session.c (meta_session_init): don't save a file here, only

View File

@ -88,10 +88,10 @@ PKG_CHECK_MODULES(METACITY, gtk+-2.0 >= 1.3.13 gconf-2.0 >= 1.1.7)
PKG_CHECK_MODULES(METACITY_MESSAGE, gtk+-2.0 >= 1.3.13) PKG_CHECK_MODULES(METACITY_MESSAGE, gtk+-2.0 >= 1.3.13)
PKG_CHECK_MODULES(METACITY_WINDOW_DEMO, gtk+-2.0 >= 1.3.13) PKG_CHECK_MODULES(METACITY_WINDOW_DEMO, gtk+-2.0 >= 1.3.13)
CFLAGS="$METACITY_CFLAGS $CFLAGS"
AC_PATH_XTRA AC_PATH_XTRA
CFLAGS="$METACITY_CFLAGS $CFLAGS $X_CFLAGS"
METACITY_LIBS="$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS $METACITY_LIBS" METACITY_LIBS="$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS $METACITY_LIBS"
found_sm=false found_sm=false

View File

@ -138,6 +138,28 @@ main (int argc, char **argv)
} }
else if (strcmp (arg, "--display") == 0) else if (strcmp (arg, "--display") == 0)
; /* wait for next arg */ ; /* wait for next arg */
else if (strstr (arg, "--sm-client-id=") == arg)
{
const char *id;
if (client_id)
meta_fatal ("Can't specify client ID twice\n");
id = strchr (arg, '=');
++id;
client_id = g_strdup (id);
}
else if (prev_arg &&
strcmp (prev_arg, "--sm-client-id") == 0)
{
if (client_id)
meta_fatal ("Can't specify client ID twice\n");
client_id = g_strdup (arg);
}
else if (strcmp (arg, "--sm-client-id") == 0)
; /* wait for next arg */
else if (strstr (arg, "--sm-save-file=") == arg) else if (strstr (arg, "--sm-save-file=") == arg)
{ {
const char *file; const char *file;
@ -168,6 +190,9 @@ main (int argc, char **argv)
++i; ++i;
} }
if (save_file && client_id)
meta_fatal ("Can't specify both SM save file and SM client id\n");
meta_main_loop = g_main_loop_new (NULL, FALSE); meta_main_loop = g_main_loop_new (NULL, FALSE);
if (display_name == NULL && if (display_name == NULL &&
@ -243,7 +268,7 @@ main (int argc, char **argv)
* info * info
*/ */
if (!disable_sm) if (!disable_sm)
meta_session_init (save_file); meta_session_init (client_id, save_file);
if (!meta_display_open (NULL)) if (!meta_display_open (NULL))
meta_exit (META_EXIT_ERROR); meta_exit (META_EXIT_ERROR);

View File

@ -28,7 +28,8 @@
#ifndef HAVE_SM #ifndef HAVE_SM
void void
meta_session_init (const char *save_file) meta_session_init (const char *client_id,
const char *save_file)
{ {
meta_topic (META_DEBUG_SM, "Compiled without session management support\n"); meta_topic (META_DEBUG_SM, "Compiled without session management support\n");
} }
@ -68,8 +69,7 @@ static void new_ice_connection (IceConn connection, IcePointer client_data,
Bool opening, IcePointer *watch_data); Bool opening, IcePointer *watch_data);
static void save_state (void); static void save_state (void);
static void load_state (const char *previous_save_file); static char* load_state (const char *previous_save_file);
static const char* get_previous_id (void);
static void regenerate_save_file (void); static void regenerate_save_file (void);
static const char* full_save_file (void); static const char* full_save_file (void);
static const char* base_save_file (void); static const char* base_save_file (void);
@ -208,21 +208,27 @@ static gpointer session_connection = NULL;
static ClientState current_state = STATE_DISCONNECTED; static ClientState current_state = STATE_DISCONNECTED;
void void
meta_session_init (const char *previous_save_file) meta_session_init (const char *previous_client_id,
const char *previous_save_file)
{ {
/* Some code here from twm */ /* Some code here from twm */
char buf[256]; char buf[256];
unsigned long mask; unsigned long mask;
SmcCallbacks callbacks; SmcCallbacks callbacks;
const char *previous_id; char *saved_client_id;
meta_topic (META_DEBUG_SM, "Initializing session with save file '%s'\n", meta_topic (META_DEBUG_SM, "Initializing session with save file '%s'\n",
previous_save_file ? previous_save_file : "(none)"); previous_save_file ? previous_save_file : "(none)");
if (previous_save_file) if (previous_save_file)
load_state (previous_save_file); {
saved_client_id = load_state (previous_save_file);
previous_id = get_previous_id (); /* from the file if any, null otherwise */ previous_client_id = saved_client_id;
}
else
{
saved_client_id = NULL;
}
ice_init (); ice_init ();
@ -254,14 +260,15 @@ meta_session_init (const char *previous_save_file)
SmProtoMinor, SmProtoMinor,
mask, mask,
&callbacks, &callbacks,
(char*) previous_id, (char*) previous_client_id,
&client_id, &client_id,
255, buf); 255, buf);
if (session_connection == NULL) if (session_connection == NULL)
{ {
meta_warning ("Failed to open connection to session manager: %s\n", buf); meta_warning ("Failed to open connection to session manager: %s\n", buf);
return;
goto out;
} }
else else
{ {
@ -270,7 +277,7 @@ meta_session_init (const char *previous_save_file)
meta_topic (META_DEBUG_SM, "Obtained session ID '%s'\n", client_id); meta_topic (META_DEBUG_SM, "Obtained session ID '%s'\n", client_id);
} }
if (previous_id && strcmp (previous_id, client_id) == 0) if (previous_client_id && strcmp (previous_client_id, client_id) == 0)
current_state = STATE_IDLE; current_state = STATE_IDLE;
else else
current_state = STATE_REGISTERING; current_state = STATE_REGISTERING;
@ -338,6 +345,9 @@ meta_session_init (const char *previous_save_file)
SmcSetProperties (session_connection, 6, props); SmcSetProperties (session_connection, 6, props);
} }
out:
g_free (saved_client_id);
} }
static void static void
@ -925,7 +935,7 @@ typedef enum
typedef struct typedef struct
{ {
MetaWindowSessionInfo *info; MetaWindowSessionInfo *info;
char *previous_id;
} ParseData; } ParseData;
static void session_info_free (MetaWindowSessionInfo *info); static void session_info_free (MetaWindowSessionInfo *info);
@ -956,9 +966,8 @@ static GMarkupParser metacity_session_parser = {
}; };
static GSList *window_info_list = NULL; static GSList *window_info_list = NULL;
static char* previous_id = NULL;
static void static char*
load_state (const char *previous_save_file) load_state (const char *previous_save_file)
{ {
GMarkupParseContext *context; GMarkupParseContext *context;
@ -983,7 +992,7 @@ load_state (const char *previous_save_file)
session_file, error->message); session_file, error->message);
g_error_free (error); g_error_free (error);
g_free (session_file); g_free (session_file);
return; return NULL;
} }
meta_topic (META_DEBUG_SM, "Parsing saved session file %s\n", session_file); meta_topic (META_DEBUG_SM, "Parsing saved session file %s\n", session_file);
@ -991,6 +1000,7 @@ load_state (const char *previous_save_file)
session_file = NULL; session_file = NULL;
parse_data.info = NULL; parse_data.info = NULL;
parse_data.previous_id = NULL;
context = g_markup_parse_context_new (&metacity_session_parser, context = g_markup_parse_context_new (&metacity_session_parser,
0, &parse_data, NULL); 0, &parse_data, NULL);
@ -1020,9 +1030,14 @@ load_state (const char *previous_save_file)
if (parse_data.info) if (parse_data.info)
session_info_free (parse_data.info); session_info_free (parse_data.info);
g_free (parse_data.previous_id);
parse_data.previous_id = NULL;
out: out:
g_free (text); g_free (text);
return parse_data.previous_id;
} }
/* FIXME this isn't very robust against bogus session files */ /* FIXME this isn't very robust against bogus session files */
@ -1052,7 +1067,7 @@ start_element_handler (GMarkupParseContext *context,
name = attribute_names[i]; name = attribute_names[i];
val = attribute_values[i]; val = attribute_values[i];
if (previous_id) if (pd->previous_id)
{ {
g_set_error (error, g_set_error (error,
G_MARKUP_ERROR, G_MARKUP_ERROR,
@ -1063,7 +1078,7 @@ start_element_handler (GMarkupParseContext *context,
if (strcmp (name, "id") == 0) if (strcmp (name, "id") == 0)
{ {
previous_id = decode_text_from_utf8 (val); pd->previous_id = decode_text_from_utf8 (val);
} }
else else
{ {
@ -1297,12 +1312,6 @@ text_handler (GMarkupParseContext *context,
*/ */
} }
static const char*
get_previous_id (void)
{
return previous_id;
}
static gboolean static gboolean
both_null_or_matching (const char *a, both_null_or_matching (const char *a,
const char *b) const char *b)

View File

@ -60,7 +60,8 @@ struct _MetaWindowSessionInfo
const MetaWindowSessionInfo* meta_window_lookup_saved_state (MetaWindow *window); const MetaWindowSessionInfo* meta_window_lookup_saved_state (MetaWindow *window);
void meta_window_release_saved_state (const MetaWindowSessionInfo *info); void meta_window_release_saved_state (const MetaWindowSessionInfo *info);
void meta_session_init (const char *save_file); void meta_session_init (const char *client_id,
const char *save_file);
#endif #endif