mirror of
https://github.com/mintycube/dwmblocks.git
synced 2024-10-22 14:05:47 +02:00
Refactor X11 part
This commit is contained in:
parent
65bfd0eef5
commit
cdc992cc41
23
main.c
23
main.c
@ -163,18 +163,23 @@ void debug() {
|
|||||||
write(STDOUT_FILENO, "\n", 1);
|
write(STDOUT_FILENO, "\n", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int setupX() {
|
||||||
|
dpy = XOpenDisplay(NULL);
|
||||||
|
if (!dpy)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
screen = DefaultScreen(dpy);
|
||||||
|
root = RootWindow(dpy, screen);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void setRoot() {
|
void setRoot() {
|
||||||
// Only set root if text has changed
|
// Only set root if text has changed
|
||||||
if (!getStatus(statusBar[0], statusBar[1]))
|
if (!getStatus(statusBar[0], statusBar[1]))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Display* d = XOpenDisplay(NULL);
|
|
||||||
if (d)
|
|
||||||
dpy = d;
|
|
||||||
screen = DefaultScreen(dpy);
|
|
||||||
root = RootWindow(dpy, screen);
|
|
||||||
XStoreName(dpy, root, statusBar[0]);
|
XStoreName(dpy, root, statusBar[0]);
|
||||||
XCloseDisplay(dpy);
|
XFlush(dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void signalHandler() {
|
void signalHandler() {
|
||||||
@ -284,6 +289,11 @@ void init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(const int argc, const char* argv[]) {
|
int main(const int argc, const char* argv[]) {
|
||||||
|
if (setupX()) {
|
||||||
|
fprintf(stderr, "dwmblocks: Failed to open display\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
writeStatus = setRoot;
|
writeStatus = setRoot;
|
||||||
for (int i = 0; i < argc; i++)
|
for (int i = 0; i < argc; i++)
|
||||||
if (!strcmp("-d", argv[i]))
|
if (!strcmp("-d", argv[i]))
|
||||||
@ -292,6 +302,7 @@ int main(const int argc, const char* argv[]) {
|
|||||||
init();
|
init();
|
||||||
statusLoop();
|
statusLoop();
|
||||||
|
|
||||||
|
XCloseDisplay(dpy);
|
||||||
close(epollFD);
|
close(epollFD);
|
||||||
close(signalFD);
|
close(signalFD);
|
||||||
for (int i = 0; i < LEN(pipes); i++)
|
for (int i = 0; i < LEN(pipes); i++)
|
||||||
|
Loading…
Reference in New Issue
Block a user