save the stacking order of the windows, and sort the saved session data based on stacking when it is loaded. make the list public.

This commit is contained in:
Dana Jansens 2003-08-25 07:46:59 +00:00
parent 97e0908f16
commit 486c189d0b
2 changed files with 49 additions and 18 deletions

View file

@ -31,11 +31,12 @@ void session_state_free(ObSessionState *state) {}
#include <X11/SM/SMlib.h> #include <X11/SM/SMlib.h>
GList *session_saved_state;
static SmcConn sm_conn; static SmcConn sm_conn;
static gchar *save_file; static gchar *save_file;
static gint sm_argc; static gint sm_argc;
static gchar **sm_argv; static gchar **sm_argv;
static GSList *sm_saved_state;
static gboolean session_save(); static gboolean session_save();
@ -217,6 +218,12 @@ void session_shutdown()
SmcSetProperties(sm_conn, 1, props); SmcSetProperties(sm_conn, 1, props);
SmcCloseConnection(sm_conn, 0, NULL); SmcCloseConnection(sm_conn, 0, NULL);
while (session_saved_state) {
session_state_free(session_saved_state->data);
session_saved_state = g_list_delete_link(session_saved_state,
session_saved_state);
}
} }
} }
@ -281,16 +288,23 @@ static gboolean session_save()
g_warning("unable to save the session to %s: %s", g_warning("unable to save the session to %s: %s",
save_file, strerror(errno)); save_file, strerror(errno));
} else { } else {
guint stack_pos = 0;
fprintf(f, "<?xml version=\"1.0\"?>\n\n"); fprintf(f, "<?xml version=\"1.0\"?>\n\n");
fprintf(f, "<openbox_session id=\"%s\">\n\n", ob_sm_id); fprintf(f, "<openbox_session id=\"%s\">\n\n", ob_sm_id);
for (it = client_list; it; it = g_list_next(it)) { for (it = stacking_list; it; it = g_list_next(it)) {
guint num; guint num;
gint32 *dimensions; gint32 *dimensions;
gint prex, prey, prew, preh; gint prex, prey, prew, preh;
ObClient *c = it->data; ObClient *c;
gchar *client_id, *t; gchar *client_id, *t;
if (WINDOW_IS_CLIENT(it->data))
c = WINDOW_AS_CLIENT(it->data);
else
continue;
if (!client_normal(c)) if (!client_normal(c))
continue; continue;
@ -327,6 +341,7 @@ static gboolean session_save()
g_free(t); g_free(t);
fprintf(f, "\t<desktop>%d</desktop>\n", c->desktop); fprintf(f, "\t<desktop>%d</desktop>\n", c->desktop);
fprintf(f, "\t<stacking>%d</stacking>\n", stack_pos);
fprintf(f, "\t<x>%d</x>\n", prex); fprintf(f, "\t<x>%d</x>\n", prex);
fprintf(f, "\t<y>%d</y>\n", prey); fprintf(f, "\t<y>%d</y>\n", prey);
fprintf(f, "\t<width>%d</width>\n", prew); fprintf(f, "\t<width>%d</width>\n", prew);
@ -351,6 +366,8 @@ static gboolean session_save()
fprintf(f, "\t<max_vert />\n"); fprintf(f, "\t<max_vert />\n");
fprintf(f, "</window>\n\n"); fprintf(f, "</window>\n\n");
++stack_pos;
g_free(client_id); g_free(client_id);
} }
@ -379,41 +396,43 @@ void session_state_free(ObSessionState *state)
} }
} }
static gboolean session_state_cmp(ObSessionState *s, ObClient *c) gboolean session_state_cmp(ObSessionState *s, ObClient *c)
{ {
gchar *client_id; gchar *client_id;
if (!(client_id = client_get_sm_client_id(c))) if (!(client_id = client_get_sm_client_id(c)))
return FALSE; return FALSE;
g_print("\nsaved %s\nnow %s\n", s->id, client_id);
if (strcmp(s->id, client_id)) { if (strcmp(s->id, client_id)) {
g_free(client_id); g_free(client_id);
return FALSE; return FALSE;
} }
g_free(client_id); g_free(client_id);
g_print("saved %s\nnow %s\n", s->name, c->name);
if (strcmp(s->name, c->name)) if (strcmp(s->name, c->name))
return FALSE; return FALSE;
g_print("saved %s\nnow %s\n", s->class, c->class);
if (strcmp(s->class, c->class)) if (strcmp(s->class, c->class))
return FALSE; return FALSE;
g_print("saved %s\nnow %s\n\n", s->role, c->role);
if (strcmp(s->role, c->role)) if (strcmp(s->role, c->role))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
ObSessionState* session_state_find(ObClient *c) GList* session_state_find(ObClient *c)
{ {
GSList *it; GList *it;
for (it = sm_saved_state; it; it = g_slist_next(it)) for (it = session_saved_state; it; it = g_list_next(it)) {
if (session_state_cmp(it->data, c)) {
ObSessionState *s = it->data; ObSessionState *s = it->data;
sm_saved_state = g_slist_remove(sm_saved_state, s); if (!s->matched && session_state_cmp(s, c)) {
return s; s->matched = TRUE;
break;
} }
return NULL; }
return it;
}
static gint stack_sort(const ObSessionState *s1, const ObSessionState *s2)
{
return s1->stacking - s2->stacking;
} }
void session_load(char *path) void session_load(char *path)
@ -446,6 +465,9 @@ void session_load(char *path)
if (!(n = parse_find_node("role", node->xmlChildrenNode))) if (!(n = parse_find_node("role", node->xmlChildrenNode)))
goto session_load_bail; goto session_load_bail;
state->role = parse_string(doc, n); state->role = parse_string(doc, n);
if (!(n = parse_find_node("stacking", node->xmlChildrenNode)))
goto session_load_bail;
state->stacking = parse_int(doc, n);
if (!(n = parse_find_node("desktop", node->xmlChildrenNode))) if (!(n = parse_find_node("desktop", node->xmlChildrenNode)))
goto session_load_bail; goto session_load_bail;
state->desktop = parse_int(doc, n); state->desktop = parse_int(doc, n);
@ -482,7 +504,7 @@ void session_load(char *path)
parse_find_node("max_vert", node->xmlChildrenNode) != NULL; parse_find_node("max_vert", node->xmlChildrenNode) != NULL;
/* save this */ /* save this */
sm_saved_state = g_slist_prepend(sm_saved_state, state); session_saved_state = g_list_prepend(session_saved_state, state);
goto session_load_ok; goto session_load_ok;
session_load_bail: session_load_bail:
@ -493,6 +515,10 @@ void session_load(char *path)
node = parse_find_node("window", node->next); node = parse_find_node("window", node->next);
} }
/* sort them by their stacking order */
session_saved_state = g_list_sort(session_saved_state,
(GCompareFunc)stack_sort);
xmlFreeDoc(doc); xmlFreeDoc(doc);
} }

View file

@ -9,18 +9,23 @@ typedef struct _ObSessionState ObSessionState;
struct _ObSessionState { struct _ObSessionState {
gchar *id, *name, *class, *role; gchar *id, *name, *class, *role;
guint stacking;
guint desktop; guint desktop;
gint x, y, w, h; gint x, y, w, h;
gboolean shaded, iconic, skip_pager, skip_taskbar, fullscreen; gboolean shaded, iconic, skip_pager, skip_taskbar, fullscreen;
gboolean above, below, max_horz, max_vert; gboolean above, below, max_horz, max_vert;
gboolean matched;
}; };
extern GList *session_saved_state;
void session_load(char *path); void session_load(char *path);
void session_startup(int argc, char **argv); void session_startup(int argc, char **argv);
void session_shutdown(); void session_shutdown();
ObSessionState* session_state_find(struct _ObClient *c); GList* session_state_find(struct _ObClient *c);
gboolean session_state_cmp(ObSessionState *s, struct _ObClient *c);
void session_state_free(ObSessionState *state); void session_state_free(ObSessionState *state);
#endif #endif