aboutsummaryrefslogtreecommitdiffstats
path: root/dzen.h
blob: 4a4bf528e361becdcbabb2dc8bf758165cca5155 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* 
 * (C)opyright 2007-2009 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/Xresource.h>
#ifdef DZEN_XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
#ifdef DZEN_XFT
#include <X11/Xft/Xft.h>
#endif

#define FONT		"-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*"
#define BGCOLOR		"#111111"
#define FGCOLOR		"grey70"
#define ESC_CHAR    '^'

#define ALIGNCENTER 0
#define ALIGNLEFT   1
#define ALIGNRIGHT  2

#define MIN_BUF_SIZE   1024
#define MAX_LINE_LEN   8192

#define MAX_CLICKABLE_AREAS 256

#ifndef Button6
# define Button6 6
#endif

#ifndef Button7
# define Button7 7
#endif

enum { ColFG, ColBG, ColLast };

/* exapansion directions */
enum { noexpand, left, right, both };

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

struct Fnt {
	XFontStruct *xfont;
	XFontSet set;
	int ascent;
	int descent;
	int height;
#ifdef DZEN_XFT
	XftFont *xftfont;
	XGlyphInfo *extents;
	int width;
#endif
};

/* clickable areas */
typedef struct _CLICK_A {
    int active;
	int button;
	int start_x;
	int end_x;
	int start_y;
	int end_y;
	char cmd[1024];
} click_a;
extern click_a sens_areas[MAX_CLICKABLE_AREAS];
extern int sens_areas_cnt;
extern int xorig;


/* title window */
struct TW {
	int x, y, width, height;

	char *name;
	Window win;
	Drawable drawable;
	char alignment;
	int expand;
	int x_right_corner;
	Bool ishidden;
};

/* slave window */
struct SW {
	int x, y, width, height;

	char *name;
	Window win;
	Window *line;
	Drawable *drawable;

	/* input buffer */
	char **tbuf; 
	int tsize;
	int tcnt;
	/* line fg colors */
	unsigned long *tcol;

	int max_lines;
	int first_line_vis;
	int last_line_vis;
	int sel_line;

	char alignment;
	Bool ismenu;
	Bool ishmenu;
	Bool issticky;
	Bool ismapped;
};

struct DZEN {
	int x, y, w, h;
	Bool running;
	unsigned long norm[ColLast];

	TWIN title_win;
	SWIN slave_win;

	/* sensitive areas */
	Window sa_win;

	const char *fnt;
	const char *bg;
	const char *fg;
	int line_height;

	Display *dpy;
	int screen;
	unsigned int depth;

	Visual *visual;
	GC gc, rgc, tgc;
	Fnt font;
	Fnt fnpl[64];

	Bool ispersistent;
	Bool tsupdate;
	Bool colorize;
	unsigned long timeout;
	long cur_line;
	int ret_val;

	/* should always be 0 if DZEN_XINERAMA not defined */
	int xinescreen;
};

extern Dzen dzen;

void free_buffer(void);
void x_draw_body(void);

/* draw.c */
extern void drawtext(const char *text,
		int reverse,
		int line,
		int align);
extern char * parse_line(const char * text, 
		int linenr, 
		int align, 
		int reverse, 
		int nodraw);
extern 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 */
extern void drawheader(const char *text);
extern void drawbody(char *text);

/* 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 */

extern long colorcache_get(const char *name); /* gets a cached color */
extern void colorcache_set(const char *name, long value); /* sets a cached color */
#ifdef DZEN_XFT
extern int xftcolorcache_get(const char *name, XftColor *color); /* gets a cached color */
extern void xftcolorcache_set(const char *name, XftColor *color); /* sets a cached color */
#endif