aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2022-09-24 00:25:00 +0200
committerThomas Voss <thomasvoss@live.com> 2022-09-24 00:25:00 +0200
commit4563949de32e17ab26e4f7d6307cd7521cedfcf9 (patch)
treecfeef6c7eb62c8eaca47093aaf912269ccc79a73
parent3e243f31d8a261004f3e311c7ec5cb278d892a18 (diff)
Add support for my current WM, sway(1)HEADv1.0master
-rw-r--r--Makefile9
-rw-r--r--README.md26
-rw-r--r--mstatus.165
-rw-r--r--mstatus.c29
4 files changed, 96 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index b4ba764..fe6c48f 100644
--- a/Makefile
+++ b/Makefile
@@ -3,16 +3,19 @@
target = mstatus
CC = cc
-CFLAGS = -O3 -std=c11 -pedantic -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes
+CFLAGS = -O3 -std=c11 -pedantic -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Werror
LDFLAGS = -lX11
PREFIX = /usr/local
+HAS_DWM = false
+
all: ${target}
${target}: mstatus.c
- ${CC} ${CFLAGS} ${LDFLAGS} -o $@ $<
+ ${HAS_DWM} \
+ && ${CC} ${CFLAGS} ${LDFLAGS} -DHAS_DWM -o $@ $< \
+ || ${CC} ${CFLAGS} -o $@ $<
-.PHONY: clean install uninstall
clean:
rm -f ${target} ${objects}
diff --git a/README.md b/README.md
index 161293a..9477526 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,34 @@
+<!-- vi: tw=80
+ -->
+
mstatus
=======
-`mstatus` is a minimal status bar for the DWM window manager. The status bar is comprised of a
-series of blocks which can be added, modified, and deleted by sending simple commands to a file.
+`mstatus` is a minimal status bar intended for the DWM window manager but which
+also works on other window managers; I use it on Sway, for instance. The status
+bar is comprised of a sequence of “blocks” which can be created, modifed, and
+removed at will by writing commands to a named pipe.
-For usage instructions see the `mstatus(1)` manual page.
+For usage instructions see the `mstatus(1)` manual page. This can either be
+done by running `man -l mstatus.1`, or `man mstatus` if you have already
+installed the program. Online documentation is also available [here][1]
Installation
============
-Assuming you have cloned the repo, you can install the status bar and manual page in two commands.
+Assuming you have cloned the repo, you can install the status bar and manual
+page in two commands.
```sh
$ make
$ make install # Will require root permissions
```
+
+If you are installing `mstatus` for usage in DWM, then the installation is
+slightly different:
+
+```sh
+$ make HAS_DWM=true
+$ make install # Will require root permissions
+```
+
+[1]: https://thomasvoss.com/man/mstatus.1.html
diff --git a/mstatus.1 b/mstatus.1
index 475ca24..672dba1 100644
--- a/mstatus.1
+++ b/mstatus.1
@@ -1,23 +1,37 @@
-.Dd $Mdocdate: 2 August 2021 $
-.Dt MSTATUS 1 URM
-.Os DWM
+.\" vi: tw=80
+.\"
+.\" BSD Zero Clause License
+.\"
+.\" Copyright (c) 2022 Thomas Voss
+.\"
+.\" Permission to use, copy, modify, and/or distribute this software for any
+.\" purpose with or without fee is hereby granted.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+.\" AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+.\" OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+.\" PERFORMANCE OF THIS SOFTWARE.
+.Dd $Mdocdate: September 23 2022 $
+.Dt MSTATUS 1
+.Os
.Sh NAME
.Nm mstatus
-.Nd a modular status bar for DWM
+.Nd a modular status bar
.Sh SYNOPSIS
.Nm
.Op Fl r
.Op Fl s Ar seperator
.Sh DESCRIPTION
.Nm
-is a modular status bar for the
-.Xr dwm 1
-window manager.
+is a modular status bar.
The
.Nm
-status bar is comprised of a series of blocks which can be programmatically added, removed, and
-updated.
-These blocks appear side by side on the status bar seperated by a the string
+status bar is comprised of a series of blocks which can be programmatically
+added, removed, and updated.
+These blocks appear side by side on the status bar seperated by the string
.Dq " | " ,
although this can be configured with the
.Fl s
@@ -47,14 +61,16 @@ then
.Nm
will attempt to create/update a block instead.
.Pp
-Next, you can optionally provide a number which represents the block you want to act upon.
+Next, you can optionally provide a number which represents the block you want
+to act upon.
As an example, the command
.Dq \-10
signals that you would like to remove block 10 from the status bar.
The command
.Dq 4
on the other hand signals that you would like to create/update block 4.
-If no block number is specified, then the specified action will be executed on block 1.
+If no block number is specified, then the specified action will be executed on
+block 1.
It is important to note that the command
.Dq 0
will be ignored as there is no block 0, however the command
@@ -63,8 +79,8 @@ is special in that it deletes all the blocks from the status bar.
.Pp
Finally, after you have provided the optional
.Sq \-
-flag and have selected the block to act upon, you can provide any string which will be displayed in
-the selected block.
+flag and have selected the block to act upon, you can provide any string which
+will be displayed in the selected block.
If the
.Sq \-
flag was specified then this string will be simply ignored.
@@ -96,14 +112,19 @@ Replace the entire status bar with
.Ex -std
.Sh NOTES
.Nm
-always allocates enough memory to be able to hold as many blocks as the number of the rightmost
-block.
-This means that if you created a block in slots 1 and 2, memory will be allocated for 2 blocks,
-however if you create a block in slots 1, 2, and 300, then memory will be allocated for 300 blocks.
-It is for this reason that you should avoid creating blocks in very high slots without reason.
-Luckily if deleting the block in slot 300 from the above example, the memory for slots 3 to 300 will
-all be freed.
+always allocates enough memory to be able to hold as many blocks as the number
+of the rightmost block.
+This means that if you created a block in slots 1 and 2, memory will be
+allocated for 2 blocks, however if you create a block in slots 1, 2, and 300,
+then memory will be allocated for 300 blocks.
+It is for this reason that you should avoid creating blocks in very high slots
+without reason.
+Luckily if deleting the block in slot 300 from the above example, the memory
+for slots 3 to 300 will all be freed.
.Sh BUGS
As of the initial 1.0 version you cannot have a block which begins with a digit.
.Sh SEE ALSO
-.Xr dwm 1
+.Xr dwm 1 ,
+.Xr sway 1
+.Sh AUTHORS
+.An Thomas Voss Aq Mt thomasvoss@live.com
diff --git a/mstatus.c b/mstatus.c
index f95f993..9e68eb3 100644
--- a/mstatus.c
+++ b/mstatus.c
@@ -15,7 +15,9 @@
#include <syslog.h>
#include <unistd.h>
-#include <X11/Xlib.h>
+#ifdef HAS_DWM
+ #include <X11/Xlib.h>
+#endif
#define CTOI(x) ((x) ^ 48)
@@ -34,13 +36,16 @@ struct {
static noreturn void usage(void);
static noreturn void die(const char *);
-static void xfork(void);
static void *xrealloc(void *, size_t);
static void xfree(char **);
static void write_status(struct Block);
static bool process(char *, struct Block *);
static void create_fifo(char *);
+
+#ifdef HAS_DWM
static void daemonize(void);
+static void xfork(void);
+#endif
void
usage(void)
@@ -58,6 +63,7 @@ die(const char *s)
exit(EXIT_FAILURE);
}
+#ifdef HAS_DWM
void
xfork(void)
{
@@ -67,6 +73,7 @@ xfork(void)
if (pid != 0)
exit(EXIT_SUCCESS);
}
+#endif
void *
xrealloc(void *ptr, size_t size)
@@ -163,12 +170,16 @@ update_bar:;
if (rflag)
strcat(buf, " ");
+#ifdef HAS_DWM
/* Xlib magic to set the DWM status */
Display *dpy = XOpenDisplay(NULL);
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
(void) XStoreName(dpy, root, buf);
(void) XCloseDisplay(dpy);
+#else
+ puts(buf);
+#endif
}
bool
@@ -221,6 +232,7 @@ create_fifo:
syslog(LOG_INFO, "Created input FIFO '%s'", fifo_path);
}
+#ifdef HAS_DWM
void
daemonize(void)
{
@@ -242,6 +254,7 @@ daemonize(void)
syslog(LOG_INFO, "Daemonized '%s'", argv0);
}
+#endif
int
main(int argc, char **argv)
@@ -263,10 +276,18 @@ main(int argc, char **argv)
}
}
- openlog(argv0, LOG_PID | LOG_CONS, LOG_DAEMON);
+ openlog(argv0, LOG_PID | LOG_CONS,
+#ifdef HAS_DWM
+ LOG_DAEMON
+#else
+ LOG_USER
+#endif
+ );
char fifo_path[PATH_MAX];
create_fifo(fifo_path);
+#ifdef HAS_DWM
daemonize();
+#endif
char *line = NULL;
size_t len = 0;
@@ -281,7 +302,7 @@ main(int argc, char **argv)
if (line[--nr] == '\n')
line[nr] = '\0';
- syslog(LOG_INFO, "Recieved command '%s'", line);
+ syslog(LOG_DEBUG, "Recieved command '%s'", line);
struct Block b;
if (!process(line, &b))