aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--config.h28
-rw-r--r--monsterwm.c26
3 files changed, 34 insertions, 21 deletions
diff --git a/README.md b/README.md
index 80ad59a..0e6a412 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,7 @@ Maintaining my version of monsterwm. Changes:
- merge rectangles into main
- add `ignore` to AppRules to allow, e.g., stalonetray without being managed
- print status for lemonbar periodically (and on every update event)
+- prevent running commands from writing to stdout (to preserve status)
→ tiny and monstrous!
---------------------
diff --git a/config.h b/config.h
index aca1e5d..2858473 100644
--- a/config.h
+++ b/config.h
@@ -43,8 +43,19 @@ static const AppRule rules[] = { \
* custom commands
* must always end with ', NULL };'
*/
-static const char *termcmd[] = { "alacritty", NULL };
-static const char *menucmd[] = { "run", NULL };
+static const char *termcmd[] = { "alacritty", NULL };
+static const char *menucmd[] = { "run", NULL };
+static const char *now_playing[] = { "now_playing", NULL };
+static const char *albumbler[] = { "albumbler.py", NULL };
+static const char* mpc_toggle[] = { "mpc", "toggle", NULL };
+static const char* lock[] = { "lock", NULL };
+
+#define XF86AudioLowerVolume 0x1008ff11
+#define XF86AudioRaiseVolume 0x1008ff13
+#define XF86AudioMute 0x1008ff12
+static const char *vol_dn[] = { "pactl", "set-sink-volume", "0", "-5%", NULL };
+static const char *vol_up[] = { "pactl", "set-sink-volume", "0", "+5%", NULL };
+static const char *vol_mt[] = { "pactl", "set-sink-mute", "0", "toggle", NULL };
#define DESKTOPCHANGE(K,N) \
{ MOD4, K, change_desktop, {.i = N} }, \
@@ -59,12 +70,17 @@ static Key keys[] = {
// Commands
{ MOD4, XK_t, spawn, {.com = termcmd} },
{ MOD4, XK_d, spawn, {.com = menucmd} },
- { MOD4, XK_space, spawn, SHCMD("mpc toggle") },
- { MOD4|SHIFT, XK_space, spawn, SHCMD("albumbler.py") },
- { MOD4, XK_h, spawn, SHCMD("lock") },
- { MOD4|SHIFT|CONTROL, XK_space, spawn, SHCMD("notify-send --app-name=Playing $(mpc current)")},
+ { MOD4, XK_space, spawn, {.com = mpc_toggle } },
+ { MOD4|SHIFT, XK_space, spawn, {.com = albumbler } },
+ { MOD4|SHIFT|CONTROL, XK_space, spawn, {.com = now_playing } },
+ { MOD4, XK_h, spawn, {.com = lock } },
{ MOD4|SHIFT|CONTROL, XK_q, quit, {.i = 0} }, /* quit with exit value 0 */
+ // Multimedia
+ { 0, XF86AudioLowerVolume, spawn, {.com = vol_dn } },
+ { 0, XF86AudioRaiseVolume, spawn, {.com = vol_up } },
+ { 0, XF86AudioMute, spawn, {.com = vol_mt } },
+
// Windows
{ MOD4, XK_n, next_win, {NULL} },
{ MOD4, XK_o, prev_win, {NULL} },
diff --git a/monsterwm.c b/monsterwm.c
index fdb68eb..85c0b75 100644
--- a/monsterwm.c
+++ b/monsterwm.c
@@ -1,5 +1,6 @@
/* see license for copyright and license */
#define _XOPEN_SOURCE
+#define _POSIX_C_SOURCE 200112L
#include <stdlib.h>
#include <stdio.h>
#include <err.h>
@@ -428,22 +429,15 @@ void write_status(void) {
printf("%%{r}");
now = time(NULL);
- putenv("TZ=PST8PDT");
- ptm = localtime(&now);
- strftime(buff, sizeof(buff), "%Z %H:%M", ptm);
- printf("%s | ", buff);
-
- putenv("TZ=America/Chicago");
- ptm = localtime(&now);
- strftime(buff, sizeof(buff), "%Z %H:%M", ptm);
- printf("%s | ", buff);
-
- putenv("TZ=UTC");
- ptm = localtime(&now);
- strftime(buff, sizeof(buff), "%Z %H:%M", ptm);
- printf("%s | ", buff);
+ char* const tzs[] = {"TZ=PST8PDT", "TZ=America/Chicago", "TZ=America/New_York", "TZ=UTC", "TZ=Europe/London"};
+ for (unsigned int i=0; i < LENGTH(tzs); i++) {
+ putenv(tzs[i]);
+ ptm = localtime(&now);
+ strftime(buff, sizeof(buff), "%Z %H:%M", ptm);
+ printf("%s | ", buff);
+ }
- putenv("TZ=Europe/Amsterdam");
+ unsetenv("TZ");
ptm = localtime(&now);
strftime(buff, sizeof(buff), "%Z %H:%M:%S %D", ptm);
printf("%s", buff);
@@ -1133,8 +1127,10 @@ void sigchld(__attribute__((unused)) int sig) {
void spawn(const Arg *arg) {
if (fork()) return;
if (dis) close(ConnectionNumber(dis));
+ freopen("/dev/null", "w", stdout); // don't nuke status
setsid();
execvp((char*)arg->com[0], (char**)arg->com);
+ freopen("/dev/tty", "w", stdout);
err(EXIT_SUCCESS, "execvp %s", (char *)arg->com[0]);
}