]> Dogcows Code - chaz/openbox/blobdiff - openbox/session.c
when restoring the session, dont restore windows which appear more than once in the...
[chaz/openbox] / openbox / session.c
index b07f16942418cbbbc56f2e71a9571d288a516d63..5a084ab60ae62d0dfaecb46a29a9949b6c21edfb 100644 (file)
@@ -102,9 +102,11 @@ void session_startup(gint argc, gchar **argv)
     }
 
     if (ob_sm_save_file != NULL) {
-        ob_debug_type(OB_DEBUG_SM, "Loading from session file %s\n",
-                      ob_sm_save_file);
-        session_load_file(ob_sm_save_file);
+        if (ob_sm_restore) {
+            ob_debug_type(OB_DEBUG_SM, "Loading from session file %s\n",
+                          ob_sm_save_file);
+            session_load_file(ob_sm_save_file);
+        }
     } else {
         gchar *filename;
 
@@ -613,6 +615,7 @@ static void session_load_file(const gchar *path)
 {
     xmlDocPtr doc;
     xmlNodePtr node, n;
+    GList *it, *inext;
 
     if (!parse_load(path, "openbox_session", &doc, &node))
         return;
@@ -687,6 +690,50 @@ static void session_load_file(const gchar *path)
         session_state_free(state);
     }
 
+    /* Remove any duplicates.  This means that if two windows (or more) are
+       saved with the same session state, we won't restore a session for any
+       of them because we don't know what window to put what on. AHEM FIREFOX.
+
+       This is going to be an O(2^n) kind of operation unfortunately.
+    */
+    for (it = session_saved_state; it; it = inext) {
+        GList *jt, *jnext;
+        gboolean founddup = FALSE;
+        ObSessionState *s1 = it->data;
+
+        inext = g_list_next(it);
+
+        for (jt = g_list_next(it); jt; jt = jnext) {
+            ObSessionState *s2 = jt->data;
+            gboolean match;
+
+            jnext = g_list_next(jt);
+
+            if (s1->id && s2->id)
+                match = strcmp(s1->id, s2->id) == 0;
+            else if (s1->command && s2->command)
+                match = strcmp(s1->command, s2->command) == 0;
+            else
+                match = FALSE;
+
+            if (match &&
+                !strcmp(s1->name, s2->name) &&
+                !strcmp(s1->class, s2->class) &&
+                !strcmp(s1->role, s2->role))
+            {
+                session_state_free(s2);
+                session_saved_state =
+                    g_list_delete_link(session_saved_state, jt);
+                founddup = TRUE;
+            }
+        }
+
+        if (founddup) {
+            session_state_free(s1);
+            session_saved_state = g_list_delete_link(session_saved_state, it);
+        }
+    }
+
     xmlFreeDoc(doc);
 }
 
This page took 0.025886 seconds and 4 git commands to generate.