commit c7509a6b5075a7e1f3b12a11a7d569068769b232
parent 01cc1c9cfbc2fba63c3a86ef2818c5994bfd2898
Author: ViliamKovac1223 <viliamkovac1223@gmail.com>
Date: Sat, 9 Jul 2022 19:05:37 +0200
[dwm] add patch for restoring clients to their tags after restart
Diffstat:
2 files changed, 135 insertions(+), 0 deletions(-)
diff --git a/dwm.suckless.org/patches/restoreafterrestart/dwm-restoreafterrestart-20220709-d3f93c7.diff b/dwm.suckless.org/patches/restoreafterrestart/dwm-restoreafterrestart-20220709-d3f93c7.diff
@@ -0,0 +1,101 @@
+From 9fd4a02b57aa8a764d8105d5f2f854372f4ef559 Mon Sep 17 00:00:00 2001
+From: ViliamKovac1223 <viliamkovac1223@gmail.com>
+Date: Sat, 9 Jul 2022 17:35:54 +0200
+Subject: [PATCH] add restore patch
+
+---
+ config.def.h | 2 ++
+ dwm.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 55 insertions(+)
+
+diff --git a/config.def.h b/config.def.h
+index 6ec4146..0b91976 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -1,5 +1,7 @@
+ /* See LICENSE file for copyright and license details. */
+
++#define SESSION_FILE "/tmp/dwm-session"
++
+ /* appearance */
+ static const unsigned int borderpx = 1; /* border pixel of windows */
+ static const unsigned int snap = 32; /* snap pixel */
+diff --git a/dwm.c b/dwm.c
+index 74cec7e..76b40a2 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -1255,11 +1255,63 @@ propertynotify(XEvent *e)
+ }
+ }
+
++void
++saveSession(void)
++{
++ FILE *fw = fopen(SESSION_FILE, "w");
++ for (Client *c = selmon->clients; c != NULL; c = c->next) { // get all the clients with their tags and write them to the file
++ fprintf(fw, "%lu %u\n", c->win, c->tags);
++ }
++ fclose(fw);
++}
++
++void
++restoreSession(void)
++{
++ // restore session
++ FILE *fr = fopen(SESSION_FILE, "r");
++ if (!fr)
++ return;
++
++ char *str = malloc(23 * sizeof(char)); // allocate enough space for excepted input from text file
++ while (fscanf(fr, "%[^\n] ", str) != EOF) { // read file till the end
++ long unsigned int winId;
++ unsigned int tagsForWin;
++ int check = sscanf(str, "%lu %u", &winId, &tagsForWin); // get data
++ if (check != 2) // break loop if data wasn't read correctly
++ break;
++
++ for (Client *c = selmon->clients; c ; c = c->next) { // add tags to every window by winId
++ if (c->win == winId) {
++ c->tags = tagsForWin;
++ break;
++ }
++ }
++ }
++
++ for (Client *c = selmon->clients; c ; c = c->next) { // refocus on windows
++ focus(c);
++ restack(c->mon);
++ }
++
++ for (Monitor *m = selmon; m; m = m->next) // rearrange all monitors
++ arrange(m);
++
++ free(str);
++ fclose(fr);
++
++ // delete a file
++ remove(SESSION_FILE);
++}
++
+ void
+ quit(const Arg *arg)
+ {
+ if(arg->i) restart = 1;
+ running = 0;
++
++ if (restart == 1)
++ saveSession();
+ }
+
+ Monitor *
+@@ -2173,6 +2225,7 @@ main(int argc, char *argv[])
+ die("pledge");
+ #endif /* __OpenBSD__ */
+ scan();
++ restoreSession();
+ run();
+ if(restart) execvp(argv[0], argv);
+ cleanup();
+--
+2.35.1
+
diff --git a/dwm.suckless.org/patches/restoreafterrestart/index.md b/dwm.suckless.org/patches/restoreafterrestart/index.md
@@ -0,0 +1,34 @@
+Restore after restart
+=====================
+
+Description
+-----------
+After restarting your dwm all your windows/clients are all in one tag, first tag.
+Well no more, This patch save tag of every window/client to the file and after dwm is restarted
+the file is read and used to get all the windows/clients in their previous tags.
+
+Configuration Options
+---------------------
+* `SESSION_FILE` - path to the file which is used to store tags to all windows/clients
+
+Notes
+-----
+This patch is supposed be used along the [restartsig](../restartsig/index.md), if you want use this patch with your own
+way how to restart dwm then put "saveSession()" before restarting dwm and put "restoreSession()" after
+dwm was restarted.
+Patch has been coded based on [this debate](https://bbs.archlinux.org/viewtopic.php?id=196975).
+This patch is also hosted on my [github](https://github.com/ViliamKovac1223/dwm-ViliamKovac1223-build/tree/main/patches).
+
+Download
+--------
+* [dwm-restoreafterrestart-20220709-d3f93c7.diff](dwm-restoreafterrestart-20220709-d3f93c7.diff)
+
+Authors
+-------
+* Viliam Kováč - viliamkovac1223@gmail.com
+
+Fake Internet money
+-------------------
+If you like my work and want to support me by some fake internet money, here is my monero address
+
+8722XFCUGajWxpdKQY4V2ije88Ti2v97VWLS9p9rvNTcWd7VisuKQzvQYNan37jYnv7thECLkrnbm6CKdA2jhdFFTLV8nav