This is to make it easier to build dwmblocks without xlib so you can
use it on wayland or other x wms.
#include<string.h>
#include<unistd.h>
#include<signal.h>
#include<string.h>
#include<unistd.h>
#include<signal.h>
#ifdef __OpenBSD__
#define SIGPLUS SIGUSR1+1
#define SIGMINUS SIGUSR1-1
#ifdef __OpenBSD__
#define SIGPLUS SIGUSR1+1
#define SIGMINUS SIGUSR1-1
void setupsignals();
void sighandler(int signum);
int getstatus(char *str, char *last);
void setupsignals();
void sighandler(int signum);
int getstatus(char *str, char *last);
void statusloop();
void termhandler();
void statusloop();
void termhandler();
+void pstdout();
+#ifndef NO_X
+void setroot();
+static void (*writestatus) () = setroot;
+#else
+static void (*writestatus) () = pstdout;
+#endif
-static Display *dpy;
-static int screen;
-static Window root;
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
static char statusstr[2][STATUSLENGTH];
static int statusContinue = 1;
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
static char statusstr[2][STATUSLENGTH];
static int statusContinue = 1;
-static void (*writestatus) () = setroot;
+static int returnStatus = 0;
//opens process *cmd and stores output in *output
void getcmd(const Block *block, char *output)
//opens process *cmd and stores output in *output
void getcmd(const Block *block, char *output)
return strcmp(str, last);//0 if they are the same
}
return strcmp(str, last);//0 if they are the same
}
+ static Display *dpy;
+ static int screen;
+ static Window root;
if (!getstatus(statusstr[0], statusstr[1]))//Only set root if text has changed.
return;
if (!getstatus(statusstr[0], statusstr[1]))//Only set root if text has changed.
return;
- Display *d = XOpenDisplay(NULL);
- if (d) {
- dpy = d;
+ dpy = XOpenDisplay(NULL);
+ if (!dpy) {
+ fprintf(stderr, "Failed to open display\n");
+ statusContinue = 0;
+ returnStatus = 1;
+ return;
}
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
XStoreName(dpy, root, statusstr[0]);
XCloseDisplay(dpy);
}
}
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
XStoreName(dpy, root, statusstr[0]);
XCloseDisplay(dpy);
}
setupsignals();
int i = 0;
getcmds(-1);
setupsignals();
int i = 0;
getcmds(-1);
{
getcmds(i++);
writestatus();
{
getcmds(i++);
writestatus();
+ if (!statusContinue)
+ break;
signal(SIGTERM, termhandler);
signal(SIGINT, termhandler);
statusloop();
signal(SIGTERM, termhandler);
signal(SIGINT, termhandler);
statusloop();