summaryrefslogtreecommitdiff
path: root/src/dwminfo.c
blob: 8e04b4344ee355eca3c6e568d3d405b999d32ffe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "signal.h"
#include "text.h"

#include <stdio.h>
#include <unistd.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>

struct state {
    Display * display;
    Window window;
    struct text * text;
};

static int
init_state(struct state * s)
{
    s->display = XOpenDisplay(NULL);
    s->window = XDefaultRootWindow(s->display);
    s->text = text_new();
    return 0;
}

static void
deinit_state(struct state * s)
{
    XCloseDisplay(s->display);
    text_free(s->text);
}

static void
update_status(struct state * s)
{
    text_update(s->text);
    XStoreName(s->display, s->window, s->text->value);
    XSync(s->display, 1);
}

static void
run_loop(struct state * s)
{
    while(signal_running) {
        update_status(s);
        usleep(1000 * 500);
    }
}

int main(void)
{
    struct state s;

    signal_setup_actions();

    init_state(&s);
    run_loop(&s);
    deinit_state(&s);

    return 0;
}