reorganized (removed {brush,color,font}.c, merged into draw.c)

This commit is contained in:
Anselm R. Garbe 2006-10-12 18:26:30 +02:00
parent 2007c0194f
commit d675b11bad
6 changed files with 169 additions and 190 deletions

View File

@ -3,8 +3,8 @@
include config.mk
SRC = area.c bar.c brush.c client.c color.c column.c draw.c event.c \
font.c frame.c fs.c geom.c key.c mouse.c rule.c view.c wm.c
SRC = area.c bar.c client.c column.c draw.c event.c \
frame.c fs.c geom.c key.c mouse.c rule.c view.c wm.c
OBJ = ${SRC:.c=.o}
all: options wmiiwm

66
brush.c
View File

@ -1,66 +0,0 @@
/* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include "wm.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void
draw_tile(BlitzBrush *b) {
drawbg(b->blitz->dpy, b->drawable, b->gc, b->rect,
b->color, b->border);
}
void
draw_label(BlitzBrush *b, char *text) {
unsigned int x, y, w, h, len;
Bool shortened = False;
static char buf[2048];
XGCValues gcv;
draw_tile(b);
if(!text)
return;
shortened = 0;
strncpy(buf, text, sizeof(buf));
len = strlen(buf);
gcv.foreground = b->color.fg;
gcv.background = b->color.bg;
h = b->font->ascent + b->font->descent;
y = b->rect.y + b->rect.height / 2 - h / 2 + b->font->ascent;
/* shorten text if necessary */
while(len && (w = textwidth(b->font, buf)) > b->rect.width - h) {
buf[--len] = 0;
shortened = True;
}
if(w > b->rect.width)
return;
/* mark shortened info in the string */
if(shortened) {
if (len > 3)
buf[len - 3] = '.';
if (len > 2)
buf[len - 2] = '.';
if (len > 1)
buf[len - 1] = '.';
}
switch (b->align) {
case EAST:
x = b->rect.x + b->rect.width - (w + (b->font->height / 2));
break;
default:
x = b->rect.x + (b->font->height / 2);
break;
}
if(b->font->set) {
XChangeGC(b->blitz->dpy, b->gc, GCForeground | GCBackground, &gcv);
XmbDrawImageString(b->blitz->dpy, b->drawable, b->font->set, b->gc,
x, y, buf, len);
}
else {
gcv.font = b->font->xfont->fid;
XChangeGC(b->blitz->dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv);
XDrawImageString(b->blitz->dpy, b->drawable, b->gc, x, y, buf, len);
}
}

27
color.c
View File

@ -1,27 +0,0 @@
/* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include "wm.h"
#include <string.h>
static unsigned long
xloadcolor(Blitz *blitz, char *colstr) {
XColor color;
char col[8];
strncpy(col, colstr, sizeof(col));
col[7] = 0;
XAllocNamedColor(blitz->dpy,
DefaultColormap(blitz->dpy, blitz->screen), col, &color, &color);
return color.pixel;
}
int
loadcolor(Blitz *blitz, BlitzColor *c) {
if(!c->colstr || strlen(c->colstr) != 23)
return -1;
c->fg = xloadcolor(blitz, &c->colstr[0]);
c->bg = xloadcolor(blitz, &c->colstr[8]);
c->border = xloadcolor(blitz, &c->colstr[16]);
return 0;
}

159
draw.c
View File

@ -2,6 +2,143 @@
* See LICENSE file for license details.
*/
#include "wm.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
unsigned int
textwidth_l(BlitzFont *font, char *text, unsigned int len) {
if(font->set) {
XRectangle r;
XmbTextExtents(font->set, text, len, NULL, &r);
return r.width;
}
return XTextWidth(font->xfont, text, len);
}
unsigned int
textwidth(BlitzFont *font, char *text) {
return textwidth_l(font, text, strlen(text));
}
void
loadfont(Blitz *blitz, BlitzFont *font) {
char *fontname = font->fontstr;
char **missing = NULL, *def = "?";
int n;
setlocale(LC_ALL, "");
if(font->set)
XFreeFontSet(blitz->dpy, font->set);
font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
if(missing) {
while(n--)
fprintf(stderr, "liblitz: missing fontset: %s\n", missing[n]);
XFreeStringList(missing);
if(font->set) {
XFreeFontSet(blitz->dpy, font->set);
font->set = NULL;
}
}
if(font->set) {
XFontSetExtents *font_extents;
XFontStruct **xfonts;
char **font_names;
unsigned int i;
font->ascent = font->descent = 0;
font_extents = XExtentsOfFontSet(font->set);
n = XFontsOfFontSet(font->set, &xfonts, &font_names);
for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
if(font->ascent < (*xfonts)->ascent)
font->ascent = (*xfonts)->ascent;
if(font->descent < (*xfonts)->descent)
font->descent = (*xfonts)->descent;
xfonts++;
}
}
else {
if(font->xfont)
XFreeFont(blitz->dpy, font->xfont);
font->xfont = NULL;
font->xfont = XLoadQueryFont(blitz->dpy, fontname);
if (!font->xfont) {
fontname = "fixed";
font->xfont = XLoadQueryFont(blitz->dpy, fontname);
}
if (!font->xfont) {
fprintf(stderr, "%s", "liblitz: error, cannot load 'fixed' font\n");
exit(1);
}
font->ascent = font->xfont->ascent;
font->descent = font->xfont->descent;
}
font->height = font->ascent + font->descent;
}
unsigned int
labelh(BlitzFont *font) {
return font->height + 4;
}
void
draw_tile(BlitzBrush *b) {
drawbg(b->blitz->dpy, b->drawable, b->gc, b->rect,
b->color, b->border);
}
void
draw_label(BlitzBrush *b, char *text) {
unsigned int x, y, w, h, len;
Bool shortened = False;
static char buf[2048];
XGCValues gcv;
draw_tile(b);
if(!text)
return;
shortened = 0;
strncpy(buf, text, sizeof(buf));
len = strlen(buf);
gcv.foreground = b->color.fg;
gcv.background = b->color.bg;
h = b->font->ascent + b->font->descent;
y = b->rect.y + b->rect.height / 2 - h / 2 + b->font->ascent;
/* shorten text if necessary */
while(len && (w = textwidth(b->font, buf)) > b->rect.width - h) {
buf[--len] = 0;
shortened = True;
}
if(w > b->rect.width)
return;
/* mark shortened info in the string */
if(shortened) {
if (len > 3)
buf[len - 3] = '.';
if (len > 2)
buf[len - 2] = '.';
if (len > 1)
buf[len - 1] = '.';
}
switch (b->align) {
case EAST:
x = b->rect.x + b->rect.width - (w + (b->font->height / 2));
break;
default:
x = b->rect.x + (b->font->height / 2);
break;
}
if(b->font->set) {
XChangeGC(b->blitz->dpy, b->gc, GCForeground | GCBackground, &gcv);
XmbDrawImageString(b->blitz->dpy, b->drawable, b->font->set, b->gc,
x, y, buf, len);
}
else {
gcv.font = b->font->xfont->fid;
XChangeGC(b->blitz->dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv);
XDrawImageString(b->blitz->dpy, b->drawable, b->gc, x, y, buf, len);
}
}
void
drawbg(Display *dpy, Drawable drawable, GC gc, XRectangle rect,
@ -52,3 +189,25 @@ drawcursor(Display *dpy, Drawable drawable, GC gc,
s[4].x2 = x + 2;
XDrawSegments(dpy, drawable, gc, s, 5);
}
static unsigned long
xloadcolor(Blitz *blitz, char *colstr) {
XColor color;
char col[8];
strncpy(col, colstr, sizeof(col));
col[7] = 0;
XAllocNamedColor(blitz->dpy,
DefaultColormap(blitz->dpy, blitz->screen), col, &color, &color);
return color.pixel;
}
int
loadcolor(Blitz *blitz, BlitzColor *c) {
if(!c->colstr || strlen(c->colstr) != 23)
return -1;
c->fg = xloadcolor(blitz, &c->colstr[0]);
c->bg = xloadcolor(blitz, &c->colstr[8]);
c->border = xloadcolor(blitz, &c->colstr[16]);
return 0;
}

82
font.c
View File

@ -1,82 +0,0 @@
/* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include "wm.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
unsigned int
textwidth_l(BlitzFont *font, char *text, unsigned int len) {
if(font->set) {
XRectangle r;
XmbTextExtents(font->set, text, len, NULL, &r);
return r.width;
}
return XTextWidth(font->xfont, text, len);
}
unsigned int
textwidth(BlitzFont *font, char *text) {
return textwidth_l(font, text, strlen(text));
}
void
loadfont(Blitz *blitz, BlitzFont *font) {
char *fontname = font->fontstr;
char **missing = NULL, *def = "?";
int n;
setlocale(LC_ALL, "");
if(font->set)
XFreeFontSet(blitz->dpy, font->set);
font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
if(missing) {
while(n--)
fprintf(stderr, "liblitz: missing fontset: %s\n", missing[n]);
XFreeStringList(missing);
if(font->set) {
XFreeFontSet(blitz->dpy, font->set);
font->set = NULL;
}
}
if(font->set) {
XFontSetExtents *font_extents;
XFontStruct **xfonts;
char **font_names;
unsigned int i;
font->ascent = font->descent = 0;
font_extents = XExtentsOfFontSet(font->set);
n = XFontsOfFontSet(font->set, &xfonts, &font_names);
for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
if(font->ascent < (*xfonts)->ascent)
font->ascent = (*xfonts)->ascent;
if(font->descent < (*xfonts)->descent)
font->descent = (*xfonts)->descent;
xfonts++;
}
}
else {
if(font->xfont)
XFreeFont(blitz->dpy, font->xfont);
font->xfont = NULL;
font->xfont = XLoadQueryFont(blitz->dpy, fontname);
if (!font->xfont) {
fontname = "fixed";
font->xfont = XLoadQueryFont(blitz->dpy, fontname);
}
if (!font->xfont) {
fprintf(stderr, "%s", "liblitz: error, cannot load 'fixed' font\n");
exit(1);
}
font->ascent = font->xfont->ascent;
font->descent = font->xfont->descent;
}
font->height = font->ascent + font->descent;
}
unsigned int
labelh(BlitzFont *font) {
return font->height + 4;
}

21
wm.h
View File

@ -261,10 +261,6 @@ extern void draw_bar(WMScreen *s);
extern void resize_bar();
extern Bar *bar_of_name(Bar *b_link, const char *name);
/* brush.c */
extern void draw_label(BlitzBrush *b, char *text);
extern void draw_tile(BlitzBrush *b);
/* client.c */
extern Client *create_client(Window w, XWindowAttributes *wa);
extern void destroy_client(Client *c);
@ -293,9 +289,6 @@ extern void update_client_grab(Client *c, Bool is_sel);
extern void apply_rules(Client *c);
extern void apply_tags(Client *c, const char *tags);
/* color.c */
extern int loadcolor(Blitz *blitz, BlitzColor *c);
/* column.c */
extern void arrange_column(Area *a, Bool dirty);
extern void scale_column(Area *a, float h);
@ -305,10 +298,18 @@ extern char *str_of_column_mode(int mode);
extern Area *new_column(View *v, Area *pos, unsigned int w);
/* draw.c */
extern int loadcolor(Blitz *blitz, BlitzColor *c);
extern void draw_label(BlitzBrush *b, char *text);
extern void draw_tile(BlitzBrush *b);
extern void drawbg(Display *dpy, Drawable drawable, GC gc,
XRectangle rect, BlitzColor c, Bool border);
extern void drawcursor(Display *dpy, Drawable drawable, GC gc,
int x, int y, unsigned int h, BlitzColor c);
extern unsigned int textwidth(BlitzFont *font, char *text);
extern unsigned int textwidth_l(BlitzFont *font, char *text, unsigned int len);
extern void loadfont(Blitz *blitz, BlitzFont *font);
extern unsigned int labelh(BlitzFont *font);
/* event.c */
extern void check_x_event(IXPConn *c);
@ -322,12 +323,6 @@ extern void draw_frame(Frame *f);
extern void draw_frames();
extern void update_frame_widget_colors(Frame *f);
/* font.c */
extern unsigned int textwidth(BlitzFont *font, char *text);
extern unsigned int textwidth_l(BlitzFont *font, char *text, unsigned int len);
extern void loadfont(Blitz *blitz, BlitzFont *font);
extern unsigned int labelh(BlitzFont *font);
/* fs.c */
extern void fs_attach(P9Req *r);
extern void fs_clunk(P9Req *r);