pinosaur
/
dwmblocks.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b7d1970
)
Only open X server once rather than open and close after every writeout.
author
aidan
<aidan@Edward.localdomain>
Wed, 9 Sep 2020 19:10:49 +0000
(13:10 -0600)
committer
aidan
<aidan@Edward.localdomain>
Wed, 9 Sep 2020 19:10:49 +0000
(13:10 -0600)
dwmblocks.c
patch
|
blob
|
history
diff --git
a/dwmblocks.c
b/dwmblocks.c
index
ef25785
..
64ad7a3
100644
(file)
--- a/
dwmblocks.c
+++ b/
dwmblocks.c
@@
-39,6
+39,10
@@
void pstdout();
#ifndef NO_X
void setroot();
static void (*writestatus) () = setroot;
#ifndef NO_X
void setroot();
static void (*writestatus) () = setroot;
+static int setupX();
+static Display *dpy;
+static int screen;
+static Window root;
#else
static void (*writestatus) () = pstdout;
#endif
#else
static void (*writestatus) () = pstdout;
#endif
@@
-76,8
+80,7
@@
void getcmd(const Block *block, char *output)
void getcmds(int time)
{
const Block* current;
void getcmds(int time)
{
const Block* current;
- for (unsigned int i = 0; i < LENGTH(blocks); i++)
- {
+ for (unsigned int i = 0; i < LENGTH(blocks); i++) {
current = blocks + i;
if ((current->interval != 0 && time % current->interval == 0) || time == -1)
getcmd(current,statusbar[i]);
current = blocks + i;
if ((current->interval != 0 && time % current->interval == 0) || time == -1)
getcmd(current,statusbar[i]);
@@
-87,8
+90,7
@@
void getcmds(int time)
void getsigcmds(unsigned int signal)
{
const Block *current;
void getsigcmds(unsigned int signal)
{
const Block *current;
- for (unsigned int i = 0; i < LENGTH(blocks); i++)
- {
+ for (unsigned int i = 0; i < LENGTH(blocks); i++) {
current = blocks + i;
if (current->signal == signal)
getcmd(current,statusbar[i]);
current = blocks + i;
if (current->signal == signal)
getcmd(current,statusbar[i]);
@@
-103,8
+105,7
@@
void setupsignals()
signal(i, dummysighandler);
#endif
signal(i, dummysighandler);
#endif
- for (unsigned int i = 0; i < LENGTH(blocks); i++)
- {
+ for (unsigned int i = 0; i < LENGTH(blocks); i++) {
if (blocks[i].signal > 0)
signal(SIGMINUS+blocks[i].signal, sighandler);
}
if (blocks[i].signal > 0)
signal(SIGMINUS+blocks[i].signal, sighandler);
}
@@
-124,22
+125,22
@@
int getstatus(char *str, char *last)
#ifndef NO_X
void setroot()
{
#ifndef NO_X
void setroot()
{
- 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;
+ XStoreName(dpy, root, statusstr[0]);
+ XFlush(dpy);
+}
+
+int setupX()
+{
dpy = XOpenDisplay(NULL);
if (!dpy) {
dpy = XOpenDisplay(NULL);
if (!dpy) {
- fprintf(stderr, "Failed to open display\n");
- statusContinue = 0;
- returnStatus = 1;
- return;
+ fprintf(stderr, "dwmblocks: Failed to open display\n");
+ return 0;
}
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
}
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
- XStoreName(dpy, root, statusstr[0]);
- XCloseDisplay(dpy);
+ return 1;
}
#endif
}
#endif
@@
-157,8
+158,7
@@
void statusloop()
setupsignals();
int i = 0;
getcmds(-1);
setupsignals();
int i = 0;
getcmds(-1);
- while (1)
- {
+ while (1) {
getcmds(i++);
writestatus();
if (!statusContinue)
getcmds(i++);
writestatus();
if (!statusContinue)
@@
-188,17
+188,23
@@
void termhandler()
int main(int argc, char** argv)
{
int main(int argc, char** argv)
{
- for (int i = 0; i < argc; i++) //Handle command line arguments
- {
+ for (int i = 0; i < argc; i++) {//Handle command line arguments
if (!strcmp("-d",argv[i]))
strncpy(delim, argv[++i], delimLen);
else if (!strcmp("-p",argv[i]))
writestatus = pstdout;
}
if (!strcmp("-d",argv[i]))
strncpy(delim, argv[++i], delimLen);
else if (!strcmp("-p",argv[i]))
writestatus = pstdout;
}
+#ifndef NO_X
+ if (!setupX())
+ return 1;
+#endif
delimLen = MIN(delimLen, strlen(delim));
delim[delimLen++] = '\0';
signal(SIGTERM, termhandler);
signal(SIGINT, termhandler);
statusloop();
delimLen = MIN(delimLen, strlen(delim));
delim[delimLen++] = '\0';
signal(SIGTERM, termhandler);
signal(SIGINT, termhandler);
statusloop();
- return returnStatus;
+#ifndef NO_X
+ XCloseDisplay(dpy);
+#endif
+ return 0;
}
}