]> git.lizzy.rs Git - bspwm.git/commitdiff
New message: 'restore_history'
authorBastien Dejean <nihilhill@gmail.com>
Wed, 8 May 2013 13:10:09 +0000 (15:10 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Wed, 8 May 2013 13:10:09 +0000 (15:10 +0200)
In addition, the message previously known as 'restore' is now called
'restore_layout'.

README.md
bash_completion
bspwm.1
examples/loop/autostart
examples/loop/pam_environment
examples/loop/sxhkdrc
examples/loop/wm_restart [deleted file]
messages.c
tree.c
tree.h

index a1aa773dc0d6ace13546bdca3c02bfbf1666869d..8bc1533e199dfa75668f1358eebe628dfb8ca6c6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -179,7 +179,9 @@ The following messages are handled:
 
 - `adopt_orphans` — Manage all the unmanaged windows remaining from a previous session.
 
-- `restore FILE_PATH` — Restore the layout of each desktop from the content of `FILE_PATH`.
+- `restore_layout FILE_PATH` — Restore the layout of each desktop from the content of `FILE_PATH`.
+
+- `restore_history FILE_PATH` — Restore the history of each desktop from the content of `FILE_PATH`.
 
 - `quit [EXIT_STATUS]` — Quit.
 
index 9121915b9a56cfb00c775980572a0841f903ae0d..c7a894583ee34c1f16e4d188749aedba94da5cba 100644 (file)
@@ -1,6 +1,6 @@
 _bspc()
 {
-    local messages='get set list list_desktops list_monitors list_windows list_rules list_history presel cancel ratio pad focus shift swap push pull cycle nearest circulate grab_pointer track_pointer ungrab_pointer toggle_fullscreen toggle_floating toggle_locked toggle_visibility close kill send_to drop_to send_to_monitor drop_to_monitor use use_monitor alternate alternate_desktop alternate_monitor add add_in rename_monitor rename cycle_monitor cycle_desktop layout cycle_layout rotate flip balance rule remove_rule put_status adopt_orphans restore quit'
+    local messages='get set list list_desktops list_monitors list_windows list_rules list_history presel cancel ratio pad focus shift swap push pull cycle nearest circulate grab_pointer track_pointer ungrab_pointer toggle_fullscreen toggle_floating toggle_locked toggle_visibility close kill send_to drop_to send_to_monitor drop_to_monitor use use_monitor alternate alternate_desktop alternate_monitor add add_in rename_monitor rename cycle_monitor cycle_desktop layout cycle_layout rotate flip balance rule remove_rule put_status adopt_orphans restore_layout restore_history quit'
 
     local settings='focused_border_color active_border_color normal_border_color presel_border_color focused_locked_border_color active_locked_border_color normal_locked_border_color urgent_border_color border_width window_gap split_ratio top_padding right_padding bottom_padding left_padding wm_name borderless_monocle gapless_monocle focus_follows_pointer adaptative_raise apply_shadow_property auto_alternate focus_by_distance'
 
diff --git a/bspwm.1 b/bspwm.1
index b9bb358657d5567e46e0cf03e511863445a23bcf..f5a0b1e9a547867ffe6dff75e413c0aaa87ef61e 100644 (file)
--- a/bspwm.1
+++ b/bspwm.1
@@ -252,9 +252,12 @@ Output the current state to the panel fifo.
 .BI adopt_orphans
 Manage all the unmanaged windows remaining from a previous session.
 .TP
-.BI restore " FILE_PATH"
+.BI restore_layout " FILE_PATH"
 Restore the layout of each desktop from the content of FILE_PATH.
 .TP
+.BI restore_history " FILE_PATH"
+Restore the history of each desktop from the content of FILE_PATH.
+.TP
 .BI quit " [EXIT_STATUS]"
 Quit.
 .SH SETTINGS
index 85fee549f032ca0d5a3448234675c794591ccaa7..8c749dcf54d8e5d76f0c737f1762e6513210339e 100755 (executable)
@@ -1,8 +1,13 @@
 #! /bin/sh
 
-if [ -e "$BSPWM_BACKUP" ] ; then
-    bspc restore "$BSPWM_BACKUP"
-    rm "$BSPWM_BACKUP"
+if [ -e "$BSPWM_LAYOUT" ] ; then
+    bspc restore_layout "$BSPWM_LAYOUT"
+    rm "$BSPWM_LAYOUT"
 else
     bspc adopt_orphans
 fi
+
+if [ -e "$BSPWM_HISTORY" ] ; then
+    bspc restore_history "$BSPWM_HISTORY"
+    rm "$BSPWM_HISTORY"
+fi
index ce01f1716537d8e4ca086294ad295170b04bf40d..234c4c8f9a5a0d674d9398b1d5b24d9be6b2845a 100644 (file)
@@ -1 +1,2 @@
-BSPWM_BACKUP=/tmp/bspwm-backup
+BSPWM_LAYOUT=/tmp/bspwm.layout
+BSPWM_HISTORY=/tmp/bspwm.history
index c6d364727bd96d89a920e4dc140a4c54c9659874..9dc3e6031d09f4070fdf080318a095065f8c8230 100644 (file)
@@ -1,2 +1,2 @@
 super + alt + {Escape,shift + Escape}
-    {wm_restart,bspc quit 1}
+    {bspc list_monitors > "$BSPWM_LAYOUT"; bspc list_history > "$BSPWM_HISTORY"; bspc quit,bspc quit 1}
diff --git a/examples/loop/wm_restart b/examples/loop/wm_restart
deleted file mode 100755 (executable)
index fd0f13e..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#! /bin/sh
-
-bspc list_monitors > "$BSPWM_BACKUP"
-bspc quit
index 5252bfd88594468152d09eb8f458076ac9669f8d..85c5fa624f787b120683cc2a1d01bd2202de1bd1 100644 (file)
@@ -442,9 +442,12 @@ void process_message(char *msg, char *rsp)
         put_status();
     } else if (strcmp(cmd, "adopt_orphans") == 0) {
         adopt_orphans();
-    } else if (strcmp(cmd, "restore") == 0) {
+    } else if (strcmp(cmd, "restore_layout") == 0) {
         char *arg = strtok(NULL, TOK_SEP);
-        restore(arg);
+        restore_layout(arg);
+    } else if (strcmp(cmd, "restore_history") == 0) {
+        char *arg = strtok(NULL, TOK_SEP);
+        restore_history(arg);
     } else if (strcmp(cmd, "quit") == 0) {
         char *arg = strtok(NULL, TOK_SEP);
         if (arg != NULL)
diff --git a/tree.c b/tree.c
index a412f2234eeb86ff560aa9ed56ff4e873e233838..57fedeb1690d49af67bdfe213e2e5dfab14cbf8a 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -996,7 +996,7 @@ void list(desktop_t *d, node_t *n, char *rsp, unsigned int depth)
     list(d, n->second_child, rsp, depth + 1);
 }
 
-void restore(char *file_path)
+void restore_layout(char *file_path)
 {
     if (file_path == NULL)
         return;
@@ -1128,3 +1128,43 @@ void restore(char *file_path)
         ewmh_update_current_desktop();
     }
 }
+
+void restore_history(char *file_path)
+{
+    if (file_path == NULL)
+        return;
+
+    FILE *snapshot = fopen(file_path, "r");
+    if (snapshot == NULL) {
+        warn("restore history: can't open file\n");
+        return;
+    }
+
+    char line[MAXLEN];
+    desktop_t *d = NULL;
+    unsigned int level;
+
+    while (fgets(line, sizeof(line), snapshot) != NULL) {
+        unsigned int i = strlen(line) - 1;
+        while (i > 0 && isspace(line[i]))
+            line[i--] = '\0';
+        level = 0;
+        while (level < strlen(line) && isspace(line[level]))
+            level++;
+        PRINTF("level %u: %s\n", level, line + level);
+        if (level == 0) {
+            desktop_location_t loc;
+            if (locate_desktop(line + level, &loc))
+                d = loc.desktop;
+        } else if (d != NULL) {
+            xcb_window_t win;
+            if (sscanf(line + level, "%X", &win) == 1) {
+                window_location_t loc;
+                if (locate_window(win, &loc))
+                    history_add(d->history, loc.node);
+            }
+        }
+    }
+
+    fclose(snapshot);
+}
diff --git a/tree.h b/tree.h
index d5e987e8b3b0b1ec826d1bf36414990f004681e1..7cc6d241c3389366062c8a1185513af1b0b69a5f 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -51,6 +51,7 @@ void list_history(char *);
 void list_monitors(list_option_t, char *);
 void list_desktops(monitor_t *, list_option_t, unsigned int, char *);
 void list(desktop_t *, node_t *, char *, unsigned int);
-void restore(char *);
+void restore_layout(char *);
+void restore_history(char *);
 
 #endif