all repos — dwm @ c0ba635c50dc53f06e4fc96392415b3d19b25826

fork of suckless dynamic window manager

draw.c (view raw)

  1/* See LICENSE file for copyright and license details. */
  2#include <stdlib.h>
  3#include <X11/Xlib.h>
  4
  5#include "draw.h"
  6
  7Draw *
  8draw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h) {
  9	Draw *draw = (Draw *)calloc(1, sizeof(Draw));
 10	draw->dpy = dpy;
 11	draw->screen = screen;
 12	draw->win = win;
 13	draw->w = w;
 14	draw->h = h;
 15	draw->drawable = XCreatePixmap(dpy, win, w, h, DefaultDepth(dpy, screen));
 16	draw->gc = XCreateGC(dpy, win, 0, NULL);
 17	XSetLineAttributes(dpy, draw->gc, 1, LineSolid, CapButt, JoinMiter);
 18	return draw;
 19}
 20
 21void
 22draw_resize(Draw *draw, unsigned int w, unsigned int h) {
 23	if(!draw)
 24		return;
 25	draw->w = w;
 26	draw->h = h;
 27	XFreePixmap(draw->dpy, draw->drawable);
 28	draw->drawable = XCreatePixmap(draw->dpy, draw->win, w, h, DefaultDepth(draw->dpy, draw->screen));
 29}
 30
 31void
 32draw_free(Draw *draw) {
 33	XFreePixmap(draw->dpy, draw->drawable);
 34	XFreeGC(draw->dpy, draw->gc);
 35	free(draw);
 36}
 37
 38Fnt *
 39font_create(const char *fontname) {
 40	Fnt *font = (Fnt *)calloc(1, sizeof(Fnt));
 41	/* TODO: allocate actual font */
 42	return font;
 43}
 44
 45void
 46font_free(Fnt *font) {
 47	if(!font)
 48		return;
 49	/* TODO: deallocate any font resources */
 50	free(font);
 51}
 52
 53Col *
 54col_create(const char *colname) {
 55	Col *col = (Col *)calloc(1, sizeof(Col));
 56	/* TODO: allocate color */
 57	return col;
 58}
 59
 60void
 61col_free(Col *col) {
 62	if(!col)
 63		return;
 64	/* TODO: deallocate any color resource */
 65	free(col);
 66}
 67
 68void
 69draw_setfont(Draw *draw, Fnt *font) {
 70	if(!draw || !font)
 71		return;
 72	draw->font = font;
 73}
 74
 75void
 76draw_setfg(Draw *draw, Col *col) {
 77	if(!draw || !col) 
 78		return;
 79	draw->fg = col;
 80}
 81
 82void
 83draw_setbg(Draw *draw, Col *col) {
 84	if(!draw || !col)
 85		return;
 86	draw->bg = col;
 87}
 88
 89void
 90draw_rect(Draw *draw, int x, int y, unsigned int w, unsigned int h) {
 91	if(!draw)
 92		return;
 93	/* TODO: draw the rectangle */
 94}
 95
 96void
 97draw_text(Draw *draw, int x, int y, const char *text) {
 98	if(!draw)
 99		return;
100	/* TODO: draw the text */
101}
102
103void
104draw_map(Draw *draw, int x, int y, unsigned int w, unsigned int h) {
105	if(!draw)
106		return;
107	/* TODO: map the draw contents in the region */
108}
109
110void
111draw_getextents(Draw *draw, const char *text, TextExtents *extents) {
112	if(!draw || !extents)
113		return;
114	/* TODO: get extents */
115}