From: Dana Jansens Date: Wed, 30 Jul 2003 20:01:35 +0000 (+0000) Subject: restore saved session data for applications X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=9c1438f17b84ef096faec0b8d52dd7d39c2c50c5;p=chaz%2Fopenbox restore saved session data for applications --- diff --git a/openbox/client.c b/openbox/client.c index 0c6a5a6e..27854756 100644 --- a/openbox/client.c +++ b/openbox/client.c @@ -8,6 +8,7 @@ #include "prop.h" #include "extensions.h" #include "frame.h" +#include "session.h" #include "event.h" #include "grab.h" #include "focus.h" @@ -43,6 +44,7 @@ static void client_showhide(ObClient *self); static void client_change_allowed_actions(ObClient *self); static void client_change_state(ObClient *self); static void client_apply_startup_state(ObClient *self); +static void client_restore_session_state(ObClient *self); void client_startup() { @@ -232,6 +234,8 @@ void client_manage(Window window) self->obwin.type = Window_Client; self->window = window; client_get_all(self); + client_restore_session_state(self); + client_change_state(self); /* remove the client's border (and adjust re gravity) */ client_toggle_border(self, FALSE); @@ -455,6 +459,38 @@ void client_unmanage(ObClient *self) client_set_list(); } +static void client_restore_session_state(ObClient *self) +{ + ObSessionState *s; + + g_message("looking for %s", self->name); + + s = session_state_find(self); + g_message("returned %p %d", s, self->positioned); + if (!(s)) return; + + g_message("restoring state for %s", s->name); + + g_message("%d %d %d %d", s->x, s->y, s->w, s->h); + RECT_SET(self->area, s->x, s->y, s->w, s->h); + XResizeWindow(ob_display, self->window, s->w, s->h); + self->positioned = TRUE; + g_message("desktop %d", s->desktop); + self->desktop = s->desktop == DESKTOP_ALL ? s->desktop : + MIN(screen_num_desktops - 1, s->desktop); + self->shaded = s->shaded; + self->iconic = s->iconic; + self->skip_pager = s->skip_pager; + self->skip_taskbar = s->skip_taskbar; + self->fullscreen = s->fullscreen; + self->above = s->above; + self->below = s->below; + self->max_horz = s->max_horz; + self->max_vert = s->max_vert; + + session_state_free(s); +} + void client_move_onscreen(ObClient *self, gboolean rude) { int x = self->area.x; @@ -624,8 +660,6 @@ static void client_get_all(ObClient *self) client_update_class(self); client_update_strut(self); client_update_icons(self); - - client_change_state(self); } static void client_get_area(ObClient *self) @@ -926,7 +960,10 @@ void client_update_normal_hints(ObClient *self) /* get the hints from the window */ if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) { - self->positioned = !!(size.flags & (PPosition|USPosition)); + /* don't let apps tell me where to put transient windows, but only if + they have a valid parent */ + self->positioned = !!(size.flags & (PPosition|USPosition)) && + !self->transient_for; if (size.flags & PWinGravity) { self->gravity = size.win_gravity; @@ -1864,11 +1901,6 @@ void client_configure_full(ObClient *self, ObCorner anchor, self->border_width; event.xconfigure.y = self->frame->area.y + self->frame->size.top - self->border_width; - g_message("x %d cx %d y %d cy %d", - self->area.x, - event.xconfigure.x, - self->area.y, - event.xconfigure.y); event.xconfigure.width = w; event.xconfigure.height = h; event.xconfigure.border_width = 0; diff --git a/openbox/prop.c b/openbox/prop.c index 3724f1a7..47e5a538 100644 --- a/openbox/prop.c +++ b/openbox/prop.c @@ -31,6 +31,8 @@ void prop_startup() CREATE(wm_window_role, "WM_WINDOW_ROLE"); CREATE(motif_wm_hints, "_MOTIF_WM_HINTS"); + CREATE(sm_client_id, "SM_CLIENT_ID"); + CREATE(net_supported, "_NET_SUPPORTED"); CREATE(net_client_list, "_NET_CLIENT_LIST"); CREATE(net_client_list_stacking, "_NET_CLIENT_LIST_STACKING"); diff --git a/openbox/prop.h b/openbox/prop.h index 58ff570a..4ed6d721 100644 --- a/openbox/prop.h +++ b/openbox/prop.h @@ -33,6 +33,9 @@ typedef struct Atoms { Atom wm_window_role; Atom motif_wm_hints; + /* SM atoms */ + Atom sm_client_id; + /* NETWM atoms */ /* root window properties */ diff --git a/openbox/session.c b/openbox/session.c index 95028ec2..58b07ca5 100644 --- a/openbox/session.c +++ b/openbox/session.c @@ -30,6 +30,7 @@ static SmcConn sm_conn; static gchar *save_file; static gint sm_argc; static gchar **sm_argv; +static GSList *sm_saved_state; static gboolean session_save(); @@ -214,12 +215,11 @@ void session_shutdown() } } -static void sm_save_yourself(SmcConn conn, SmPointer data, int save_type, - Bool shutdown, int interact_style, Bool fast) +static void sm_save_yourself_phase2(SmcConn conn, SmPointer data) { gboolean success; - ob_debug("got SAVE YOURSELF from session manager\n"); + ob_debug("got SAVE YOURSELF PHASE 2 from session manager\n"); success = session_save(); save_commands(); @@ -227,6 +227,17 @@ static void sm_save_yourself(SmcConn conn, SmPointer data, int save_type, SmcSaveYourselfDone(conn, success); } +static void sm_save_yourself(SmcConn conn, SmPointer data, int save_type, + Bool shutdown, int interact_style, Bool fast) +{ + ob_debug("got SAVE YOURSELF from session manager\n"); + + if (!SmcRequestSaveYourselfPhase2(conn, sm_save_yourself_phase2, data)) { + ob_debug("SAVE YOURSELF PHASE 2 failed\n"); + SmcSaveYourselfDone(conn, FALSE); + } +} + static void sm_die(SmcConn conn, SmPointer data) { ob_exit(); @@ -273,10 +284,14 @@ static gboolean session_save() gint32 *dimensions; gint prex, prey, prew, preh; ObClient *c = it->data; + gchar *client_id, *t; if (!client_normal(c)) continue; + if (!PROP_GETS(c->window, sm_client_id, locale, &client_id)) + continue; + prex = c->area.x; prey = c->area.y; prew = c->area.width; @@ -292,14 +307,20 @@ static gboolean session_save() g_free(dimensions); } - fprintf(f, "\n", - g_markup_escape_text("XXX", -1)); - fprintf(f, "\t%s\n", - g_markup_escape_text(c->name, -1)); - fprintf(f, "\t%s\n", - g_markup_escape_text(c->class, -1)); - fprintf(f, "\t%s\n", - g_markup_escape_text(c->role, -1)); + fprintf(f, "\n", client_id); + + t = g_markup_escape_text(c->name, -1); + fprintf(f, "\t%s\n", t); + g_free(t); + + t = g_markup_escape_text(c->class, -1); + fprintf(f, "\t%s\n", t); + g_free(t); + + t = g_markup_escape_text(c->role, -1); + fprintf(f, "\t%s\n", t); + g_free(t); + fprintf(f, "\t%d\n", c->desktop); fprintf(f, "\t%d\n", prex); fprintf(f, "\t%d\n", prey); @@ -324,6 +345,8 @@ static gboolean session_save() if (c->max_vert) fprintf(f, "\t\n"); fprintf(f, "\n\n"); + + g_free(client_id); } fprintf(f, "\n"); @@ -339,6 +362,55 @@ static gboolean session_save() return success; } +void session_state_free(ObSessionState *state) +{ + if (state) { + g_free(state->id); + g_free(state->name); + g_free(state->class); + g_free(state->role); + + g_free(state); + } +} + +static gboolean session_state_cmp(const ObSessionState *s, const ObClient *c) +{ + gchar *client_id; + + if (!PROP_GETS(c->window, sm_client_id, locale, &client_id)) + return FALSE; + g_print("\nsaved %s\nnow %s\n", s->id, client_id); + if (strcmp(s->id, client_id)) { + g_free(client_id); + return FALSE; + } + g_free(client_id); + g_print("\nsaved %s\nnow %s\n", s->name, c->name); + if (strcmp(s->name, c->name)) + return FALSE; + g_print("\nsaved %s\nnow %s\n", s->class, c->class); + if (strcmp(s->class, c->class)) + return FALSE; + g_print("\nsaved %s\nnow %s\n", s->role, c->role); + if (strcmp(s->role, c->role)) + return FALSE; + return TRUE; +} + +ObSessionState* session_state_find(ObClient *c) +{ + GSList *it; + + for (it = sm_saved_state; it; it = g_slist_next(it)) + if (session_state_cmp(it->data, c)) { + ObSessionState *s = it->data; + sm_saved_state = g_slist_remove(sm_saved_state, s); + return s; + } + return NULL; +} + void session_load(char *path) { xmlDocPtr doc; @@ -354,64 +426,72 @@ void session_load(char *path) node = parse_find_node("window", node->xmlChildrenNode); while (node) { - gchar *id, *name, *class, *role; - guint desktop; - gint x, y, w, h; - gboolean shaded, iconic, skip_pager, skip_taskbar, fullscreen; - gboolean above, below, max_horz, max_vert; + ObSessionState *state; + + state = g_new0(ObSessionState, 1); - if (!parse_attr_string("id", node, &id)) + if (!parse_attr_string("id", node, &state->id)) goto session_load_bail; if (!(n = parse_find_node("name", node->xmlChildrenNode))) goto session_load_bail; - name = parse_string(doc, n); + state->name = parse_string(doc, n); if (!(n = parse_find_node("class", node->xmlChildrenNode))) goto session_load_bail; - class = parse_string(doc, n); + state->class = parse_string(doc, n); if (!(n = parse_find_node("role", node->xmlChildrenNode))) goto session_load_bail; - role = parse_string(doc, n); + state->role = parse_string(doc, n); if (!(n = parse_find_node("desktop", node->xmlChildrenNode))) goto session_load_bail; - desktop = parse_int(doc, n); + state->desktop = parse_int(doc, n); if (!(n = parse_find_node("x", node->xmlChildrenNode))) goto session_load_bail; - x = parse_int(doc, n); + state->x = parse_int(doc, n); if (!(n = parse_find_node("y", node->xmlChildrenNode))) goto session_load_bail; - y = parse_int(doc, n); + state->y = parse_int(doc, n); if (!(n = parse_find_node("width", node->xmlChildrenNode))) goto session_load_bail; - w = parse_int(doc, n); + state->w = parse_int(doc, n); if (!(n = parse_find_node("height", node->xmlChildrenNode))) goto session_load_bail; - h = parse_int(doc, n); - - shaded = parse_find_node("shaded", node->xmlChildrenNode) != NULL; - iconic = parse_find_node("iconic", node->xmlChildrenNode) != NULL; - skip_pager = parse_find_node("skip_pager", node->xmlChildrenNode) - != NULL; - skip_taskbar = parse_find_node("skip_taskbar", node->xmlChildrenNode) - != NULL; - fullscreen = parse_find_node("fullscreen", node->xmlChildrenNode) - != NULL; - above = parse_find_node("above", node->xmlChildrenNode) != NULL; - below = parse_find_node("below", node->xmlChildrenNode) != NULL; - max_horz = parse_find_node("max_horz", node->xmlChildrenNode) != NULL; - max_vert = parse_find_node("max_vert", node->xmlChildrenNode) != NULL; + state->h = parse_int(doc, n); + + state->shaded = + parse_find_node("shaded", node->xmlChildrenNode) != NULL; + state->iconic = + parse_find_node("iconic", node->xmlChildrenNode) != NULL; + state->skip_pager = + parse_find_node("skip_pager", node->xmlChildrenNode) != NULL; + state->skip_taskbar = + parse_find_node("skip_taskbar", node->xmlChildrenNode) != NULL; + state->fullscreen = + parse_find_node("fullscreen", node->xmlChildrenNode) != NULL; + state->above = + parse_find_node("above", node->xmlChildrenNode) != NULL; + state->below = + parse_find_node("below", node->xmlChildrenNode) != NULL; + state->max_horz = + parse_find_node("max_horz", node->xmlChildrenNode) != NULL; + state->max_vert = + parse_find_node("max_vert", node->xmlChildrenNode) != NULL; - g_message("read session window %s", name); + g_message("read session window %s", state->name); - /* XXX save this */ + /* save this */ + g_message("saved state for %s %s", state->name, state->id); + sm_saved_state = g_slist_prepend(sm_saved_state, state); + goto session_load_ok; session_load_bail: + session_state_free(state); + + session_load_ok: node = parse_find_node("window", node->next); } xmlFreeDoc(doc); - - unlink(path); } #endif diff --git a/openbox/session.h b/openbox/session.h index 0e7aa97e..5247d690 100644 --- a/openbox/session.h +++ b/openbox/session.h @@ -1,8 +1,26 @@ #ifndef __ob__session_h #define __ob__session_h +#include + +struct _ObClient; + +typedef struct _ObSessionState ObSessionState; + +struct _ObSessionState { + gchar *id, *name, *class, *role; + guint desktop; + gint x, y, w, h; + gboolean shaded, iconic, skip_pager, skip_taskbar, fullscreen; + gboolean above, below, max_horz, max_vert; +}; + + void session_load(char *path); void session_startup(int argc, char **argv); void session_shutdown(); +ObSessionState* session_state_find(struct _ObClient *c); +void session_state_free(ObSessionState *state); + #endif