all repos — dwm @ 3aabc08ede9c6496720124be8ee34c8b39735239

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, Window win, unsigned int w, unsigned int h) {
  9	Draw *draw = (Draw *)calloc(1, sizeof(Draw));
 10	draw->w = w;
 11	draw->h = h;
 12	/* TODO: drawable creation */
 13	/* TODO: gc allocation */
 14	return draw;
 15}
 16
 17void
 18draw_resize(Draw *draw, unsigned int w, unsigned int h) {
 19	if(!draw)
 20		return;
 21	draw->w = w;
 22	draw->h = h;
 23	/* TODO: resize drawable */
 24}
 25
 26void
 27draw_free(Draw *draw) {
 28	/* TODO: deallocate DDCs */
 29	/* TODO: deallocate drawable */
 30	free(draw);
 31}
 32
 33DDC *
 34dc_create(Draw *draw) {
 35	DDC *dc = (DDC *)calloc(1, sizeof(DDC));
 36	dc->draw = draw;
 37	dc->next = draw->dc;
 38	draw->dc = dc;
 39	return dc;
 40}
 41
 42void
 43dc_free(DDC *dc) {
 44	DDC **tdc;
 45
 46	if(!dc)
 47		return;
 48	/* remove from dc list */
 49	for(tdc = &dc->draw->dc; *tdc && *tdc != dc; tdc = &(*tdc)->next);
 50	*tdc = dc->next;
 51	/* TODO: deallocate any resources of this dc, if needed */
 52	free(dc);
 53}
 54
 55Fnt *
 56font_create(const char *fontname) {
 57	Fnt *font = (Fnt *)calloc(1, sizeof(Fnt));
 58	/* TODO: allocate actual font */
 59	return font;
 60}
 61
 62void
 63font_free(Fnt *font) {
 64	if(!font)
 65		return;
 66	/* TODO: deallocate any font resources */
 67	free(font);
 68}
 69
 70Col *
 71col_create(const char *colname) {
 72	Col *col = (Col *)calloc(1, sizeof(Col));
 73	/* TODO: allocate color */
 74	return col;
 75}
 76
 77void
 78col_free(Col *col) {
 79	if(!col)
 80		return;
 81	/* TODO: deallocate any color resource */
 82	free(col);
 83}
 84
 85void
 86dc_setfont(DDC *dc, Fnt *font) {
 87	if(!dc || !font)
 88		return;
 89	dc->font = font;
 90}
 91
 92void
 93dc_setfg(DDC *dc, Col *col) {
 94	if(!dc || !col) 
 95		return;
 96	dc->fg = col;
 97}
 98
 99void
100dc_setbg(DDC *dc, Col *col) {
101	if(!dc || !col)
102		return;
103	dc->bg = col;
104}
105
106void
107dc_setfill(DDC *dc, Bool fill) {
108	if(!dc)
109		return;
110	dc->fill = fill;
111}
112
113void
114dc_drawrect(DDC *dc, int x, int y, unsigned int w, unsigned int h) {
115	if(!dc)
116		return;
117	/* TODO: draw the rectangle */
118}
119
120void
121dc_drawtext(DDC *dc, int x, int y, const char *text) {
122	if(!dc)
123		return;
124	/* TODO: draw the text */
125}
126
127void
128dc_map(DDC *dc, int x, int y, unsigned int w, unsigned int h) {
129	if(!dc)
130		return;
131	/* TODO: map the dc contents in the region */
132}
133
134void
135dc_getextents(DDC *dc, const char *text, TextExtents *extents) {
136	if(!dc || !extents)
137		return;
138	/* TODO: get extents */
139}