More format and more improve :D
This commit is contained in:
parent
44f85c76ec
commit
6099f19a49
12 changed files with 633 additions and 628 deletions
81
src/drw.c
81
src/drw.c
|
@ -17,8 +17,7 @@ static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000
|
|||
static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
|
||||
|
||||
static long
|
||||
utf8decodebyte(const char c, size_t *i)
|
||||
{
|
||||
utf8decodebyte(const char c, size_t *i) {
|
||||
for (*i = 0; *i < (UTF_SIZ + 1); ++(*i))
|
||||
if (((unsigned char) c & utfmask[*i]) == utfbyte[*i])
|
||||
return (unsigned char) c & ~utfmask[*i];
|
||||
|
@ -26,18 +25,15 @@ utf8decodebyte(const char c, size_t *i)
|
|||
}
|
||||
|
||||
static size_t
|
||||
utf8validate(long *u, size_t i)
|
||||
{
|
||||
utf8validate(long *u, size_t i) {
|
||||
if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
|
||||
*u = UTF_INVALID;
|
||||
for (i = 1; *u > utfmax[i]; ++i)
|
||||
;
|
||||
for (i = 1; *u > utfmax[i]; ++i);
|
||||
return i;
|
||||
}
|
||||
|
||||
static size_t
|
||||
utf8decode(const char *c, long *u, size_t clen)
|
||||
{
|
||||
utf8decode(const char *c, long *u, size_t clen) {
|
||||
size_t i, j, len, type;
|
||||
long udecoded;
|
||||
|
||||
|
@ -61,8 +57,7 @@ utf8decode(const char *c, long *u, size_t clen)
|
|||
}
|
||||
|
||||
Drw *
|
||||
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
|
||||
{
|
||||
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) {
|
||||
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||
|
||||
drw->dpy = dpy;
|
||||
|
@ -78,8 +73,7 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
|
|||
}
|
||||
|
||||
void
|
||||
drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
||||
{
|
||||
drw_resize(Drw *drw, unsigned int w, unsigned int h) {
|
||||
if (!drw)
|
||||
return;
|
||||
|
||||
|
@ -91,8 +85,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
|||
}
|
||||
|
||||
void
|
||||
drw_free(Drw *drw)
|
||||
{
|
||||
drw_free(Drw *drw) {
|
||||
XFreePixmap(drw->dpy, drw->drawable);
|
||||
XFreeGC(drw->dpy, drw->gc);
|
||||
drw_fontset_free(drw->fonts);
|
||||
|
@ -103,8 +96,7 @@ drw_free(Drw *drw)
|
|||
* drw_fontset_create instead.
|
||||
*/
|
||||
static Fnt *
|
||||
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
|
||||
{
|
||||
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) {
|
||||
Fnt *font;
|
||||
XftFont *xfont = NULL;
|
||||
FcPattern *pattern = NULL;
|
||||
|
@ -143,8 +135,7 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
|
|||
}
|
||||
|
||||
static void
|
||||
xfont_free(Fnt *font)
|
||||
{
|
||||
xfont_free(Fnt *font) {
|
||||
if (!font)
|
||||
return;
|
||||
if (font->pattern)
|
||||
|
@ -154,8 +145,7 @@ xfont_free(Fnt *font)
|
|||
}
|
||||
|
||||
Fnt *
|
||||
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
|
||||
{
|
||||
drw_fontset_create(Drw *drw, const char *fonts[], size_t fontcount) {
|
||||
Fnt *cur, *ret = NULL;
|
||||
size_t i;
|
||||
|
||||
|
@ -172,8 +162,7 @@ drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
|
|||
}
|
||||
|
||||
void
|
||||
drw_fontset_free(Fnt *font)
|
||||
{
|
||||
drw_fontset_free(Fnt *font) {
|
||||
if (font) {
|
||||
drw_fontset_free(font->next);
|
||||
xfont_free(font);
|
||||
|
@ -181,8 +170,7 @@ drw_fontset_free(Fnt *font)
|
|||
}
|
||||
|
||||
void
|
||||
drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
|
||||
{
|
||||
drw_clr_create(Drw *drw, Clr *dest, const char *clrname) {
|
||||
if (!drw || !dest || !clrname)
|
||||
return;
|
||||
|
||||
|
@ -195,8 +183,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
|
|||
/* Wrapper to create color schemes. The caller has to call free(3) on the
|
||||
* returned color scheme when done using it. */
|
||||
Clr *
|
||||
drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
|
||||
{
|
||||
drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) {
|
||||
size_t i;
|
||||
Clr *ret;
|
||||
|
||||
|
@ -210,22 +197,19 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
|
|||
}
|
||||
|
||||
void
|
||||
drw_setfontset(Drw *drw, Fnt *set)
|
||||
{
|
||||
drw_setfontset(Drw *drw, Fnt *set) {
|
||||
if (drw)
|
||||
drw->fonts = set;
|
||||
}
|
||||
|
||||
void
|
||||
drw_setscheme(Drw *drw, Clr *scm)
|
||||
{
|
||||
drw_setscheme(Drw *drw, Clr *scm) {
|
||||
if (drw)
|
||||
drw->scheme = scm;
|
||||
}
|
||||
|
||||
void
|
||||
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert)
|
||||
{
|
||||
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) {
|
||||
if (!drw || !drw->scheme)
|
||||
return;
|
||||
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel);
|
||||
|
@ -236,8 +220,7 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int
|
|||
}
|
||||
|
||||
int
|
||||
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
|
||||
{
|
||||
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) {
|
||||
int i, ty, ellipsis_x = 0;
|
||||
unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len;
|
||||
XftDraw *d = NULL;
|
||||
|
@ -251,8 +234,13 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
|||
XftResult result;
|
||||
int charexists = 0, overflow = 0;
|
||||
/* keep track of a couple codepoints for which we have no match. */
|
||||
enum { nomatches_len = 64 };
|
||||
static struct { long codepoint[nomatches_len]; unsigned int idx; } nomatches;
|
||||
enum {
|
||||
nomatches_len = 64
|
||||
};
|
||||
static struct {
|
||||
long codepoint[nomatches_len];
|
||||
unsigned int idx;
|
||||
} nomatches;
|
||||
static unsigned int ellipsis_width = 0;
|
||||
|
||||
if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts)
|
||||
|
@ -366,8 +354,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
|||
if (match) {
|
||||
usedfont = xfont_create(drw, NULL, match);
|
||||
if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
|
||||
for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
|
||||
; /* NOP */
|
||||
for (curfont = drw->fonts; curfont->next; curfont = curfont->next); /* NOP */
|
||||
curfont->next = usedfont;
|
||||
} else {
|
||||
xfont_free(usedfont);
|
||||
|
@ -385,8 +372,7 @@ no_match:
|
|||
}
|
||||
|
||||
void
|
||||
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
|
||||
{
|
||||
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) {
|
||||
if (!drw)
|
||||
return;
|
||||
|
||||
|
@ -395,16 +381,14 @@ drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
|
|||
}
|
||||
|
||||
unsigned int
|
||||
drw_fontset_getwidth(Drw *drw, const char *text)
|
||||
{
|
||||
drw_fontset_getwidth(Drw *drw, const char *text) {
|
||||
if (!drw || !drw->fonts || !text)
|
||||
return 0;
|
||||
return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n)
|
||||
{
|
||||
drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n) {
|
||||
unsigned int tmp = 0;
|
||||
if (drw && drw->fonts && text && n)
|
||||
tmp = drw_text(drw, 0, 0, 0, 0, 0, text, n);
|
||||
|
@ -412,8 +396,7 @@ drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n)
|
|||
}
|
||||
|
||||
void
|
||||
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
|
||||
{
|
||||
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) {
|
||||
XGlyphInfo ext;
|
||||
|
||||
if (!font || !text)
|
||||
|
@ -427,8 +410,7 @@ drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w,
|
|||
}
|
||||
|
||||
Cur *
|
||||
drw_cur_create(Drw *drw, int shape)
|
||||
{
|
||||
drw_cur_create(Drw *drw, int shape) {
|
||||
Cur *cur;
|
||||
|
||||
if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
|
||||
|
@ -440,8 +422,7 @@ drw_cur_create(Drw *drw, int shape)
|
|||
}
|
||||
|
||||
void
|
||||
drw_cur_free(Drw *drw, Cur *cursor)
|
||||
{
|
||||
drw_cur_free(Drw *drw, Cur *cursor) {
|
||||
if (!cursor)
|
||||
return;
|
||||
|
||||
|
|
14
src/drw.h
14
src/drw.h
|
@ -12,7 +12,9 @@ typedef struct Fnt {
|
|||
struct Fnt *next;
|
||||
} Fnt;
|
||||
|
||||
enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
|
||||
enum {
|
||||
ColFg, ColBg, ColBorder
|
||||
}; /* Clr scheme index */
|
||||
typedef XftColor Clr;
|
||||
|
||||
typedef struct {
|
||||
|
@ -28,30 +30,40 @@ typedef struct {
|
|||
|
||||
/* Drawable abstraction */
|
||||
Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
|
||||
|
||||
void drw_resize(Drw *drw, unsigned int w, unsigned int h);
|
||||
|
||||
void drw_free(Drw *drw);
|
||||
|
||||
/* Fnt abstraction */
|
||||
Fnt *drw_fontset_create(Drw *drw, const char *fonts[], size_t fontcount);
|
||||
|
||||
void drw_fontset_free(Fnt *set);
|
||||
|
||||
unsigned int drw_fontset_getwidth(Drw *drw, const char *text);
|
||||
|
||||
unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n);
|
||||
|
||||
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
|
||||
|
||||
/* Colorscheme abstraction */
|
||||
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
|
||||
|
||||
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
|
||||
|
||||
/* Cursor abstraction */
|
||||
Cur *drw_cur_create(Drw *drw, int shape);
|
||||
|
||||
void drw_cur_free(Drw *drw, Cur *cursor);
|
||||
|
||||
/* Drawing context manipulation */
|
||||
void drw_setfontset(Drw *drw, Fnt *set);
|
||||
|
||||
void drw_setscheme(Drw *drw, Clr *scm);
|
||||
|
||||
/* Drawing functions */
|
||||
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
|
||||
|
||||
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
|
||||
|
||||
/* Map functions */
|
||||
|
|
13
src/dwm.c
13
src/dwm.c
|
@ -47,18 +47,6 @@
|
|||
#include "dwm.h"
|
||||
|
||||
/* macros */
|
||||
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
||||
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
|
||||
#define INTERSECT(x, y, w, h, m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
|
||||
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
|
||||
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]) || C->issticky)
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
|
||||
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
|
||||
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
|
||||
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||
|
||||
#define SYSTEM_TRAY_REQUEST_DOCK 0
|
||||
/* XEMBED messages */
|
||||
#define XEMBED_EMBEDDED_NOTIFY 0
|
||||
|
@ -70,7 +58,6 @@
|
|||
#define XEMBED_WINDOW_DEACTIVATE 2
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 0
|
||||
#define XEMBED_EMBEDDED_VERSION (VERSION_MAJOR << 16) | VERSION_MINOR
|
||||
|
||||
/* variables */
|
||||
static Systray *systray = NULL;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "../dwm.h"
|
||||
#include "../util.h"
|
||||
|
||||
void
|
||||
centeredmaster(Monitor *m)
|
||||
{
|
||||
centeredmaster(Monitor *m) {
|
||||
unsigned int i, n, h, mw, mx, my, oty, ety, tw;
|
||||
Client *c;
|
||||
|
||||
|
@ -54,8 +56,7 @@ centeredmaster(Monitor *m)
|
|||
}
|
||||
|
||||
void
|
||||
centeredfloatingmaster(Monitor *m)
|
||||
{
|
||||
centeredfloatingmaster(Monitor *m) {
|
||||
unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx;
|
||||
Client *c;
|
||||
|
||||
|
|
|
@ -7,4 +7,4 @@ static void centeredfloatingmaster(Monitor *m);
|
|||
#include "centeredmaster.c"
|
||||
|
||||
|
||||
#endif // !centeredmaster.h
|
||||
#endif // centeredmaster_H
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include "../dwm.h"
|
||||
|
||||
void
|
||||
fibonacci(Monitor *mon, int s) {
|
||||
unsigned int i, n, nx, ny, nw, nh;
|
||||
|
@ -30,8 +32,7 @@ fibonacci(Monitor *mon, int s) {
|
|||
ny += nh;
|
||||
else
|
||||
ny -= nh;
|
||||
}
|
||||
else if((i % 4) == 1)
|
||||
} else if ((i % 4) == 1)
|
||||
nx += nw;
|
||||
else if ((i % 4) == 2)
|
||||
ny += nh;
|
||||
|
@ -41,13 +42,11 @@ fibonacci(Monitor *mon, int s) {
|
|||
else
|
||||
nx -= nw;
|
||||
}
|
||||
if(i == 0)
|
||||
{
|
||||
if (i == 0) {
|
||||
if (n != 1)
|
||||
nw = mon->ww * mon->mfact;
|
||||
ny = mon->wy;
|
||||
}
|
||||
else if(i == 1)
|
||||
} else if (i == 1)
|
||||
nw = mon->ww - nw;
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include "../dwm.h"
|
||||
|
||||
void
|
||||
grid(Monitor *m) {
|
||||
unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "../dwm.h"
|
||||
#include "../util.h"
|
||||
|
||||
void
|
||||
monocle(Monitor *m)
|
||||
{
|
||||
monocle(Monitor *m) {
|
||||
unsigned int n = 0;
|
||||
Client *c;
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "../dwm.h"
|
||||
#include "../util.h"
|
||||
|
||||
void
|
||||
tile(Monitor *m)
|
||||
{
|
||||
tile(Monitor *m) {
|
||||
unsigned int i, n, h, mw, my, ty;
|
||||
Client *c;
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#include "dwm.h"
|
||||
#include "util.h"
|
||||
|
||||
static void
|
||||
movestack(const Arg *arg) {
|
||||
Client *c = NULL, *p = NULL, *pc = NULL, *i;
|
||||
|
@ -8,8 +11,7 @@ movestack(const Arg *arg) {
|
|||
if (!c)
|
||||
for (c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* find the client before selmon->sel */
|
||||
for (i = selmon->clients; i != selmon->sel; i = i->next)
|
||||
if (ISVISIBLE(i) && !i->isfloating)
|
||||
|
|
19
src/util.h
19
src/util.h
|
@ -1,8 +1,25 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
/* macros */
|
||||
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
||||
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
|
||||
#define INTERSECT(x, y, w, h, m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
|
||||
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
|
||||
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]) || C->issticky)
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
|
||||
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
|
||||
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
|
||||
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||
|
||||
#define XEMBED_EMBEDDED_VERSION (VERSION_MAJOR << 16) | VERSION_MINOR
|
||||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
|
||||
|
||||
void die(const char *fmt, ...);
|
||||
void *ecalloc(size_t nmemb, size_t size);
|
||||
|
||||
#endif // util_H
|
Loading…
Reference in a new issue