-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.c
57 lines (48 loc) · 1.42 KB
/
draw.c
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
#include <X11/Xft/Xft.h>
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "atlas.h"
#include "util.h"
/* Basic drawing context for color allocation */
Drw *drw_create(Display *dpy, int screen, Window root, unsigned int w,
unsigned int h) {
Drw *drw = ecalloc(1, sizeof(Drw));
drw->dpy = dpy;
drw->screen = screen;
drw->root = root;
drw->w = w;
drw->h = h;
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
drw->gc = XCreateGC(dpy, root, 0, NULL);
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
return drw;
}
void drw_free(Drw *drw) {
XFreePixmap(drw->dpy, drw->drawable);
XFreeGC(drw->dpy, drw->gc);
free(drw);
}
/* Color allocation for window borders */
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname) {
if (!drw || !dest || !clrname)
return;
if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
DefaultColormap(drw->dpy, drw->screen), clrname, dest))
die("error, cannot allocate color '%s'", clrname);
}
/* Create cursors */
Cur *drw_cur_create(Drw *drw, int shape) {
Cur *cur;
if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
return NULL;
cur->cursor = XCreateFontCursor(drw->dpy, shape);
return cur;
}
void drw_cur_free(Drw *drw, Cur *cursor) {
if (!cursor)
return;
XFreeCursor(drw->dpy, cursor->cursor);
free(cursor);
}