Remove polling. Add a switch to make the bar permanent.
This commit is contained in:
parent
fcf64daac8
commit
b1e71d2866
|
@ -6,6 +6,15 @@ A lightweight bar based on XCB (yay). Provides foreground/background color
|
||||||
switching along with text alignment (screw you dzen!), nothing less and
|
switching along with text alignment (screw you dzen!), nothing less and
|
||||||
nothing more.
|
nothing more.
|
||||||
|
|
||||||
|
Options
|
||||||
|
-------
|
||||||
|
bar accpets a couple of command line switches
|
||||||
|
|
||||||
|
```
|
||||||
|
-h Shows the help and bails out.
|
||||||
|
-p Make the bar permanent.
|
||||||
|
```
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
-------------
|
-------------
|
||||||
Change the config.h file and you're good to go!
|
Change the config.h file and you're good to go!
|
||||||
|
|
32
bar.c
32
bar.c
|
@ -2,7 +2,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <poll.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ draw (int x, int align, char *text)
|
||||||
void
|
void
|
||||||
parse (char *text)
|
parse (char *text)
|
||||||
{
|
{
|
||||||
char parsed_text[1000] = {0, };
|
char parsed_text[1024] = {0, };
|
||||||
|
|
||||||
char *p = text;
|
char *p = text;
|
||||||
char *q = parsed_text;
|
char *q = parsed_text;
|
||||||
|
@ -143,26 +142,31 @@ init (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (void)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct pollfd stdinpoll = { .fd = 0, .events = POLLIN | POLLHUP };
|
static char input[1024] = {0, };
|
||||||
static char input[1000] = {0, };
|
int permanent = 0;
|
||||||
|
char ch;
|
||||||
|
|
||||||
|
while ((ch = getopt (argc, argv, "ph")) != -1) {
|
||||||
|
switch (ch) {
|
||||||
|
case 'h':
|
||||||
|
printf ("usage: %s [-p | -h]\n\t-h Shows this help\n\t-p Don't close after the data ends\n", argv[0]); exit (0);
|
||||||
|
case 'p': permanent = 1; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
atexit (cleanup);
|
atexit (cleanup);
|
||||||
signal (SIGINT, sighandle);
|
signal (SIGINT, sighandle);
|
||||||
signal (SIGTERM, sighandle);
|
signal (SIGTERM, sighandle);
|
||||||
init ();
|
init ();
|
||||||
|
|
||||||
for (;;) {
|
while (fgets (input, sizeof(input), stdin)) {
|
||||||
if (poll (&stdinpoll, 1, -1) > 0) {
|
parse (input);
|
||||||
if (stdinpoll.revents & POLLHUP) break;
|
xcb_flush (c);
|
||||||
if (stdinpoll.revents & POLLIN) {
|
|
||||||
fgets (input, sizeof(input), stdin);
|
|
||||||
parse (input);
|
|
||||||
xcb_flush (c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
/* There's no more data, but the user still wants to see it */
|
||||||
|
while (permanent);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user