aboutsummaryrefslogtreecommitdiffstats
path: root/dzen.h
blob: 1f266be2834a78d4d4998f507255871ca23348f0 (plain) (blame)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* 
 * (C)opyright MMVII Robert Manea <rob dot manea  at gmail dot com>
 * See LICENSE file for license details.
 */

#include <X11/Xlib.h>
#include <X11/Xutil.h>
//#include <X11/keysym.h>
#include <pthread.h>

#define FONT	    "-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*"
#define BGCOLOR		"#ab0b0b"
#define FGCOLOR		"#efefef"

//#define BUF_SIZE    4096
#define BUF_SIZE    1024

/* gui data structures */
enum { ColFG, ColBG, ColLast };

typedef struct DZEN Dzen;
typedef struct Fnt Fnt;
typedef struct TW TWIN;
typedef struct SW SWIN;

struct Fnt {
    XFontStruct *xfont;
    XFontSet set;
    int ascent;
    int descent;
    int height;
};

/* title window */
struct TW {
    int x, y, width, height;
    int screen;
    char *fnt;
    char *bg;
    char *fg;

    Window win;
    Drawable drawable;
    Bool autohide;
    Bool ishidden;
};

/* slave window */
struct SW {
    int x, y, width, height;
    int screen;
    char *fnt;
    char *bg;
    char *fg;

    Window win;
    Window *line;
    Drawable drawable;

    char *tbuf[BUF_SIZE];
    int tcnt;
    int max_lines;
    int first_line_vis;
    int last_line_vis;
    int sel_line;

    Bool ismenu;
    Bool issticky;
    Bool ispersistent;
    Bool ismapped;
};

/* TODO: Remove unused variables */
struct DZEN {
    int x, y, w, h;
    Bool running;
    unsigned long norm[ColLast];

    TWIN title_win;
    SWIN slave_win;

    /* to be removed */
    char *fnt;
    char *bg;
    char *fg;
    int mw, mh;
    /*---------------*/

    Display *dpy;
    int screen;
    unsigned int depth;

    Visual *visual;
    GC gc, rgc;
    Fnt font;

    /* position */
    int hy, hw;
    int cur_line;

    pthread_t read_thread;
    pthread_mutex_t mt;

    int ret_val;
};

extern Dzen dzen;

/* draw.c */
extern void drawtext(const char *text,
        int reverse,
        int line);	                        
extern unsigned long getcolor(const char *colstr);	/* returns color of colstr */
extern void setfont(const char *fontstr);		    /* sets global font */
extern unsigned int textw(const char *text);		/* returns width of text in px */

/* util.c */
extern void *emalloc(unsigned int size);		/* allocates memory, exits on error */
extern void eprint(const char *errstr, ...);	/* prints errstr and exits with 1 */
extern char *estrdup(const char *str);			/* duplicates str, exits on allocation error */
extern void spawn(const char *arg);             /* execute arg */