-
-bool restore_history(const char *file_path)
-{
- if (file_path == NULL) {
- return false;
- }
-
- FILE *snapshot = fopen(file_path, "r");
- if (snapshot == NULL) {
- perror("Restore history: fopen");
- return false;
- }
-
- char line[MAXLEN];
- char mnm[SMALEN];
- char dnm[SMALEN];
- xcb_window_t win;
-
- empty_history();
-
- while (fgets(line, sizeof(line), snapshot) != NULL) {
- if (sscanf(line, "%s %s %X", mnm, dnm, &win) == 3) {
- coordinates_t loc;
- if (win != XCB_NONE && !locate_window(win, &loc)) {
- warn("Can't locate window 0x%X.\n", win);
- continue;
- }
- node_t *n = (win == XCB_NONE ? NULL : loc.node);
- if (!locate_desktop(dnm, &loc)) {
- warn("Can't locate desktop '%s'.\n", dnm);
- continue;
- }
- desktop_t *d = loc.desktop;
- if (!locate_monitor(mnm, &loc)) {
- warn("Can't locate monitor '%s'.\n", mnm);
- continue;
- }
- monitor_t *m = loc.monitor;
- history_add(m, d, n);
- } else {
- warn("Can't parse history entry: '%s'\n", line);
- }
- }
-
- fclose(snapshot);
- return true;
-}
-
-bool restore_stack(const char *file_path)
-{
- if (file_path == NULL) {
- return false;
- }
-
- FILE *snapshot = fopen(file_path, "r");
- if (snapshot == NULL) {
- perror("Restore stack: fopen");
- return false;
- }
-
- char line[MAXLEN];
- xcb_window_t win;
-
- while (stack_head != NULL) {
- remove_stack(stack_head);
- }
-
- while (fgets(line, sizeof(line), snapshot) != NULL) {
- if (sscanf(line, "%X", &win) == 1) {
- coordinates_t loc;
- if (locate_window(win, &loc)) {
- stack_insert_after(stack_tail, loc.node);
- } else {
- warn("Can't locate window 0x%X.\n", win);
- }
- } else {
- warn("Can't parse stack entry: '%s'\n", line);
- }
- }
-
- fclose(snapshot);
- return true;
-}