Initial commit
This commit is contained in:
19
patch/alpha.c
Normal file
19
patch/alpha.c
Normal file
@@ -0,0 +1,19 @@
|
||||
float
|
||||
clamp(float value, float lower, float upper) {
|
||||
if (value < lower)
|
||||
return lower;
|
||||
if (value > upper)
|
||||
return upper;
|
||||
return value;
|
||||
}
|
||||
|
||||
void
|
||||
changealpha(const Arg *arg)
|
||||
{
|
||||
if ((alpha > 0 && arg->f < 0) || (alpha < 1 && arg->f > 0))
|
||||
alpha += arg->f;
|
||||
alpha = clamp(alpha, 0.0, 1.0);
|
||||
xloadcols();
|
||||
redraw();
|
||||
}
|
||||
|
||||
2
patch/alpha.h
Normal file
2
patch/alpha.h
Normal file
@@ -0,0 +1,2 @@
|
||||
static float clamp(float value, float lower, float upper);
|
||||
static void changealpha(const Arg *);
|
||||
192
patch/boxdraw.c
Normal file
192
patch/boxdraw.c
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright 2018 Avi Halachmi (:avih) avihpit@yahoo.com https://github.com/avih
|
||||
* MIT/X Consortium License
|
||||
*/
|
||||
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
/* Rounded non-negative integers division of n / d */
|
||||
#define DIV(n, d) (((n) + (d) / 2) / (d))
|
||||
|
||||
static Display *xdpy;
|
||||
static Colormap xcmap;
|
||||
static XftDraw *xd;
|
||||
static Visual *xvis;
|
||||
|
||||
static void drawbox(int, int, int, int, XftColor *, XftColor *, ushort);
|
||||
static void drawboxlines(int, int, int, int, XftColor *, ushort);
|
||||
|
||||
/* public API */
|
||||
|
||||
void
|
||||
boxdraw_xinit(Display *dpy, Colormap cmap, XftDraw *draw, Visual *vis)
|
||||
{
|
||||
xdpy = dpy; xcmap = cmap; xd = draw, xvis = vis;
|
||||
}
|
||||
|
||||
int
|
||||
isboxdraw(Rune u)
|
||||
{
|
||||
Rune block = u & ~0xff;
|
||||
return (boxdraw && block == 0x2500 && boxdata[(uint8_t)u]) ||
|
||||
(boxdraw_braille && block == 0x2800);
|
||||
}
|
||||
|
||||
/* the "index" is actually the entire shape data encoded as ushort */
|
||||
ushort
|
||||
boxdrawindex(const Glyph *g)
|
||||
{
|
||||
if (boxdraw_braille && (g->u & ~0xff) == 0x2800)
|
||||
return BRL | (uint8_t)g->u;
|
||||
if (boxdraw_bold && (g->mode & ATTR_BOLD))
|
||||
return BDB | boxdata[(uint8_t)g->u];
|
||||
return boxdata[(uint8_t)g->u];
|
||||
}
|
||||
|
||||
void
|
||||
drawboxes(int x, int y, int cw, int ch, XftColor *fg, XftColor *bg,
|
||||
const XftGlyphFontSpec *specs, int len)
|
||||
{
|
||||
for ( ; len-- > 0; x += cw, specs++)
|
||||
drawbox(x, y, cw, ch, fg, bg, (ushort)specs->glyph);
|
||||
}
|
||||
|
||||
/* implementation */
|
||||
|
||||
void
|
||||
drawbox(int x, int y, int w, int h, XftColor *fg, XftColor *bg, ushort bd)
|
||||
{
|
||||
ushort cat = bd & ~(BDB | 0xff); /* mask out bold and data */
|
||||
if (bd & (BDL | BDA)) {
|
||||
/* lines (light/double/heavy/arcs) */
|
||||
drawboxlines(x, y, w, h, fg, bd);
|
||||
|
||||
} else if (cat == BBD) {
|
||||
/* lower (8-X)/8 block */
|
||||
int d = DIV((uint8_t)bd * h, 8);
|
||||
XftDrawRect(xd, fg, x, y + d, w, h - d);
|
||||
|
||||
} else if (cat == BBU) {
|
||||
/* upper X/8 block */
|
||||
XftDrawRect(xd, fg, x, y, w, DIV((uint8_t)bd * h, 8));
|
||||
|
||||
} else if (cat == BBL) {
|
||||
/* left X/8 block */
|
||||
XftDrawRect(xd, fg, x, y, DIV((uint8_t)bd * w, 8), h);
|
||||
|
||||
} else if (cat == BBR) {
|
||||
/* right (8-X)/8 block */
|
||||
int d = DIV((uint8_t)bd * w, 8);
|
||||
XftDrawRect(xd, fg, x + d, y, w - d, h);
|
||||
|
||||
} else if (cat == BBQ) {
|
||||
/* Quadrants */
|
||||
int w2 = DIV(w, 2), h2 = DIV(h, 2);
|
||||
if (bd & TL)
|
||||
XftDrawRect(xd, fg, x, y, w2, h2);
|
||||
if (bd & TR)
|
||||
XftDrawRect(xd, fg, x + w2, y, w - w2, h2);
|
||||
if (bd & BL)
|
||||
XftDrawRect(xd, fg, x, y + h2, w2, h - h2);
|
||||
if (bd & BR)
|
||||
XftDrawRect(xd, fg, x + w2, y + h2, w - w2, h - h2);
|
||||
|
||||
} else if (bd & BBS) {
|
||||
/* Shades - data is 1/2/3 for 25%/50%/75% alpha, respectively */
|
||||
int d = (uint8_t)bd;
|
||||
XftColor xfc;
|
||||
XRenderColor xrc = { .alpha = 0xffff };
|
||||
|
||||
xrc.red = DIV(fg->color.red * d + bg->color.red * (4 - d), 4);
|
||||
xrc.green = DIV(fg->color.green * d + bg->color.green * (4 - d), 4);
|
||||
xrc.blue = DIV(fg->color.blue * d + bg->color.blue * (4 - d), 4);
|
||||
|
||||
XftColorAllocValue(xdpy, xvis, xcmap, &xrc, &xfc);
|
||||
XftDrawRect(xd, &xfc, x, y, w, h);
|
||||
XftColorFree(xdpy, xvis, xcmap, &xfc);
|
||||
|
||||
} else if (cat == BRL) {
|
||||
/* braille, each data bit corresponds to one dot at 2x4 grid */
|
||||
int w1 = DIV(w, 2);
|
||||
int h1 = DIV(h, 4), h2 = DIV(h, 2), h3 = DIV(3 * h, 4);
|
||||
|
||||
if (bd & 1) XftDrawRect(xd, fg, x, y, w1, h1);
|
||||
if (bd & 2) XftDrawRect(xd, fg, x, y + h1, w1, h2 - h1);
|
||||
if (bd & 4) XftDrawRect(xd, fg, x, y + h2, w1, h3 - h2);
|
||||
if (bd & 8) XftDrawRect(xd, fg, x + w1, y, w - w1, h1);
|
||||
if (bd & 16) XftDrawRect(xd, fg, x + w1, y + h1, w - w1, h2 - h1);
|
||||
if (bd & 32) XftDrawRect(xd, fg, x + w1, y + h2, w - w1, h3 - h2);
|
||||
if (bd & 64) XftDrawRect(xd, fg, x, y + h3, w1, h - h3);
|
||||
if (bd & 128) XftDrawRect(xd, fg, x + w1, y + h3, w - w1, h - h3);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
drawboxlines(int x, int y, int w, int h, XftColor *fg, ushort bd)
|
||||
{
|
||||
/* s: stem thickness. width/8 roughly matches underscore thickness. */
|
||||
/* We draw bold as 1.5 * normal-stem and at least 1px thicker. */
|
||||
/* doubles draw at least 3px, even when w or h < 3. bold needs 6px. */
|
||||
int mwh = MIN(w, h);
|
||||
int base_s = MAX(1, DIV(mwh, 8));
|
||||
int bold = (bd & BDB) && mwh >= 6; /* possibly ignore boldness */
|
||||
int s = bold ? MAX(base_s + 1, DIV(3 * base_s, 2)) : base_s;
|
||||
int w2 = DIV(w - s, 2), h2 = DIV(h - s, 2);
|
||||
/* the s-by-s square (x + w2, y + h2, s, s) is the center texel. */
|
||||
/* The base length (per direction till edge) includes this square. */
|
||||
|
||||
int light = bd & (LL | LU | LR | LD);
|
||||
int double_ = bd & (DL | DU | DR | DD);
|
||||
|
||||
if (light) {
|
||||
/* d: additional (negative) length to not-draw the center */
|
||||
/* texel - at arcs and avoid drawing inside (some) doubles */
|
||||
int arc = bd & BDA;
|
||||
int multi_light = light & (light - 1);
|
||||
int multi_double = double_ & (double_ - 1);
|
||||
/* light crosses double only at DH+LV, DV+LH (ref. shapes) */
|
||||
int d = arc || (multi_double && !multi_light) ? -s : 0;
|
||||
|
||||
if (bd & LL)
|
||||
XftDrawRect(xd, fg, x, y + h2, w2 + s + d, s);
|
||||
if (bd & LU)
|
||||
XftDrawRect(xd, fg, x + w2, y, s, h2 + s + d);
|
||||
if (bd & LR)
|
||||
XftDrawRect(xd, fg, x + w2 - d, y + h2, w - w2 + d, s);
|
||||
if (bd & LD)
|
||||
XftDrawRect(xd, fg, x + w2, y + h2 - d, s, h - h2 + d);
|
||||
}
|
||||
|
||||
/* double lines - also align with light to form heavy when combined */
|
||||
if (double_) {
|
||||
/*
|
||||
* going clockwise, for each double-ray: p is additional length
|
||||
* to the single-ray nearer to the previous direction, and n to
|
||||
* the next. p and n adjust from the base length to lengths
|
||||
* which consider other doubles - shorter to avoid intersections
|
||||
* (p, n), or longer to draw the far-corner texel (n).
|
||||
*/
|
||||
int dl = bd & DL, du = bd & DU, dr = bd & DR, dd = bd & DD;
|
||||
if (dl) {
|
||||
int p = dd ? -s : 0, n = du ? -s : dd ? s : 0;
|
||||
XftDrawRect(xd, fg, x, y + h2 + s, w2 + s + p, s);
|
||||
XftDrawRect(xd, fg, x, y + h2 - s, w2 + s + n, s);
|
||||
}
|
||||
if (du) {
|
||||
int p = dl ? -s : 0, n = dr ? -s : dl ? s : 0;
|
||||
XftDrawRect(xd, fg, x + w2 - s, y, s, h2 + s + p);
|
||||
XftDrawRect(xd, fg, x + w2 + s, y, s, h2 + s + n);
|
||||
}
|
||||
if (dr) {
|
||||
int p = du ? -s : 0, n = dd ? -s : du ? s : 0;
|
||||
XftDrawRect(xd, fg, x + w2 - p, y + h2 - s, w - w2 + p, s);
|
||||
XftDrawRect(xd, fg, x + w2 - n, y + h2 + s, w - w2 + n, s);
|
||||
}
|
||||
if (dd) {
|
||||
int p = dr ? -s : 0, n = dl ? -s : dr ? s : 0;
|
||||
XftDrawRect(xd, fg, x + w2 + s, y + h2 - p, s, h - h2 + p);
|
||||
XftDrawRect(xd, fg, x + w2 - s, y + h2 - n, s, h - h2 + n);
|
||||
}
|
||||
}
|
||||
}
|
||||
214
patch/boxdraw.h
Normal file
214
patch/boxdraw.h
Normal file
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* Copyright 2018 Avi Halachmi (:avih) avihpit@yahoo.com https://github.com/avih
|
||||
* MIT/X Consortium License
|
||||
*/
|
||||
|
||||
/*
|
||||
* U+25XX codepoints data
|
||||
*
|
||||
* References:
|
||||
* http://www.unicode.org/charts/PDF/U2500.pdf
|
||||
* http://www.unicode.org/charts/PDF/U2580.pdf
|
||||
*
|
||||
* Test page:
|
||||
* https://github.com/GNOME/vte/blob/master/doc/boxes.txt
|
||||
*/
|
||||
|
||||
/* Each shape is encoded as 16-bits. Higher bits are category, lower are data */
|
||||
/* Categories (mutually exclusive except BDB): */
|
||||
/* For convenience, BDL/BDA/BBS/BDB are 1 bit each, the rest are enums */
|
||||
#define BDL (1<<8) /* Box Draw Lines (light/double/heavy) */
|
||||
#define BDA (1<<9) /* Box Draw Arc (light) */
|
||||
|
||||
#define BBD (1<<10) /* Box Block Down (lower) X/8 */
|
||||
#define BBL (2<<10) /* Box Block Left X/8 */
|
||||
#define BBU (3<<10) /* Box Block Upper X/8 */
|
||||
#define BBR (4<<10) /* Box Block Right X/8 */
|
||||
#define BBQ (5<<10) /* Box Block Quadrants */
|
||||
#define BRL (6<<10) /* Box Braille (data is lower byte of U28XX) */
|
||||
|
||||
#define BBS (1<<14) /* Box Block Shades */
|
||||
#define BDB (1<<15) /* Box Draw is Bold */
|
||||
|
||||
/* (BDL/BDA) Light/Double/Heavy x Left/Up/Right/Down/Horizontal/Vertical */
|
||||
/* Heavy is light+double (literally drawing light+double align to form heavy) */
|
||||
#define LL (1<<0)
|
||||
#define LU (1<<1)
|
||||
#define LR (1<<2)
|
||||
#define LD (1<<3)
|
||||
#define LH (LL+LR)
|
||||
#define LV (LU+LD)
|
||||
|
||||
#define DL (1<<4)
|
||||
#define DU (1<<5)
|
||||
#define DR (1<<6)
|
||||
#define DD (1<<7)
|
||||
#define DH (DL+DR)
|
||||
#define DV (DU+DD)
|
||||
|
||||
#define HL (LL+DL)
|
||||
#define HU (LU+DU)
|
||||
#define HR (LR+DR)
|
||||
#define HD (LD+DD)
|
||||
#define HH (HL+HR)
|
||||
#define HV (HU+HD)
|
||||
|
||||
/* (BBQ) Quadrants Top/Bottom x Left/Right */
|
||||
#define TL (1<<0)
|
||||
#define TR (1<<1)
|
||||
#define BL (1<<2)
|
||||
#define BR (1<<3)
|
||||
|
||||
/* Data for U+2500 - U+259F except dashes/diagonals */
|
||||
static const unsigned short boxdata[256] = {
|
||||
/* light lines */
|
||||
[0x00] = BDL + LH, /* light horizontal */
|
||||
[0x02] = BDL + LV, /* light vertical */
|
||||
[0x0c] = BDL + LD + LR, /* light down and right */
|
||||
[0x10] = BDL + LD + LL, /* light down and left */
|
||||
[0x14] = BDL + LU + LR, /* light up and right */
|
||||
[0x18] = BDL + LU + LL, /* light up and left */
|
||||
[0x1c] = BDL + LV + LR, /* light vertical and right */
|
||||
[0x24] = BDL + LV + LL, /* light vertical and left */
|
||||
[0x2c] = BDL + LH + LD, /* light horizontal and down */
|
||||
[0x34] = BDL + LH + LU, /* light horizontal and up */
|
||||
[0x3c] = BDL + LV + LH, /* light vertical and horizontal */
|
||||
[0x74] = BDL + LL, /* light left */
|
||||
[0x75] = BDL + LU, /* light up */
|
||||
[0x76] = BDL + LR, /* light right */
|
||||
[0x77] = BDL + LD, /* light down */
|
||||
|
||||
/* heavy [+light] lines */
|
||||
[0x01] = BDL + HH,
|
||||
[0x03] = BDL + HV,
|
||||
[0x0d] = BDL + HR + LD,
|
||||
[0x0e] = BDL + HD + LR,
|
||||
[0x0f] = BDL + HD + HR,
|
||||
[0x11] = BDL + HL + LD,
|
||||
[0x12] = BDL + HD + LL,
|
||||
[0x13] = BDL + HD + HL,
|
||||
[0x15] = BDL + HR + LU,
|
||||
[0x16] = BDL + HU + LR,
|
||||
[0x17] = BDL + HU + HR,
|
||||
[0x19] = BDL + HL + LU,
|
||||
[0x1a] = BDL + HU + LL,
|
||||
[0x1b] = BDL + HU + HL,
|
||||
[0x1d] = BDL + HR + LV,
|
||||
[0x1e] = BDL + HU + LD + LR,
|
||||
[0x1f] = BDL + HD + LR + LU,
|
||||
[0x20] = BDL + HV + LR,
|
||||
[0x21] = BDL + HU + HR + LD,
|
||||
[0x22] = BDL + HD + HR + LU,
|
||||
[0x23] = BDL + HV + HR,
|
||||
[0x25] = BDL + HL + LV,
|
||||
[0x26] = BDL + HU + LD + LL,
|
||||
[0x27] = BDL + HD + LU + LL,
|
||||
[0x28] = BDL + HV + LL,
|
||||
[0x29] = BDL + HU + HL + LD,
|
||||
[0x2a] = BDL + HD + HL + LU,
|
||||
[0x2b] = BDL + HV + HL,
|
||||
[0x2d] = BDL + HL + LD + LR,
|
||||
[0x2e] = BDL + HR + LL + LD,
|
||||
[0x2f] = BDL + HH + LD,
|
||||
[0x30] = BDL + HD + LH,
|
||||
[0x31] = BDL + HD + HL + LR,
|
||||
[0x32] = BDL + HR + HD + LL,
|
||||
[0x33] = BDL + HH + HD,
|
||||
[0x35] = BDL + HL + LU + LR,
|
||||
[0x36] = BDL + HR + LU + LL,
|
||||
[0x37] = BDL + HH + LU,
|
||||
[0x38] = BDL + HU + LH,
|
||||
[0x39] = BDL + HU + HL + LR,
|
||||
[0x3a] = BDL + HU + HR + LL,
|
||||
[0x3b] = BDL + HH + HU,
|
||||
[0x3d] = BDL + HL + LV + LR,
|
||||
[0x3e] = BDL + HR + LV + LL,
|
||||
[0x3f] = BDL + HH + LV,
|
||||
[0x40] = BDL + HU + LH + LD,
|
||||
[0x41] = BDL + HD + LH + LU,
|
||||
[0x42] = BDL + HV + LH,
|
||||
[0x43] = BDL + HU + HL + LD + LR,
|
||||
[0x44] = BDL + HU + HR + LD + LL,
|
||||
[0x45] = BDL + HD + HL + LU + LR,
|
||||
[0x46] = BDL + HD + HR + LU + LL,
|
||||
[0x47] = BDL + HH + HU + LD,
|
||||
[0x48] = BDL + HH + HD + LU,
|
||||
[0x49] = BDL + HV + HL + LR,
|
||||
[0x4a] = BDL + HV + HR + LL,
|
||||
[0x4b] = BDL + HV + HH,
|
||||
[0x78] = BDL + HL,
|
||||
[0x79] = BDL + HU,
|
||||
[0x7a] = BDL + HR,
|
||||
[0x7b] = BDL + HD,
|
||||
[0x7c] = BDL + HR + LL,
|
||||
[0x7d] = BDL + HD + LU,
|
||||
[0x7e] = BDL + HL + LR,
|
||||
[0x7f] = BDL + HU + LD,
|
||||
|
||||
/* double [+light] lines */
|
||||
[0x50] = BDL + DH,
|
||||
[0x51] = BDL + DV,
|
||||
[0x52] = BDL + DR + LD,
|
||||
[0x53] = BDL + DD + LR,
|
||||
[0x54] = BDL + DR + DD,
|
||||
[0x55] = BDL + DL + LD,
|
||||
[0x56] = BDL + DD + LL,
|
||||
[0x57] = BDL + DL + DD,
|
||||
[0x58] = BDL + DR + LU,
|
||||
[0x59] = BDL + DU + LR,
|
||||
[0x5a] = BDL + DU + DR,
|
||||
[0x5b] = BDL + DL + LU,
|
||||
[0x5c] = BDL + DU + LL,
|
||||
[0x5d] = BDL + DL + DU,
|
||||
[0x5e] = BDL + DR + LV,
|
||||
[0x5f] = BDL + DV + LR,
|
||||
[0x60] = BDL + DV + DR,
|
||||
[0x61] = BDL + DL + LV,
|
||||
[0x62] = BDL + DV + LL,
|
||||
[0x63] = BDL + DV + DL,
|
||||
[0x64] = BDL + DH + LD,
|
||||
[0x65] = BDL + DD + LH,
|
||||
[0x66] = BDL + DD + DH,
|
||||
[0x67] = BDL + DH + LU,
|
||||
[0x68] = BDL + DU + LH,
|
||||
[0x69] = BDL + DH + DU,
|
||||
[0x6a] = BDL + DH + LV,
|
||||
[0x6b] = BDL + DV + LH,
|
||||
[0x6c] = BDL + DH + DV,
|
||||
|
||||
/* (light) arcs */
|
||||
[0x6d] = BDA + LD + LR,
|
||||
[0x6e] = BDA + LD + LL,
|
||||
[0x6f] = BDA + LU + LL,
|
||||
[0x70] = BDA + LU + LR,
|
||||
|
||||
/* Lower (Down) X/8 block (data is 8 - X) */
|
||||
[0x81] = BBD + 7, [0x82] = BBD + 6, [0x83] = BBD + 5, [0x84] = BBD + 4,
|
||||
[0x85] = BBD + 3, [0x86] = BBD + 2, [0x87] = BBD + 1, [0x88] = BBD + 0,
|
||||
|
||||
/* Left X/8 block (data is X) */
|
||||
[0x89] = BBL + 7, [0x8a] = BBL + 6, [0x8b] = BBL + 5, [0x8c] = BBL + 4,
|
||||
[0x8d] = BBL + 3, [0x8e] = BBL + 2, [0x8f] = BBL + 1,
|
||||
|
||||
/* upper 1/2 (4/8), 1/8 block (X), right 1/2, 1/8 block (8-X) */
|
||||
[0x80] = BBU + 4, [0x94] = BBU + 1,
|
||||
[0x90] = BBR + 4, [0x95] = BBR + 7,
|
||||
|
||||
/* Quadrants */
|
||||
[0x96] = BBQ + BL,
|
||||
[0x97] = BBQ + BR,
|
||||
[0x98] = BBQ + TL,
|
||||
[0x99] = BBQ + TL + BL + BR,
|
||||
[0x9a] = BBQ + TL + BR,
|
||||
[0x9b] = BBQ + TL + TR + BL,
|
||||
[0x9c] = BBQ + TL + TR + BR,
|
||||
[0x9d] = BBQ + TR,
|
||||
[0x9e] = BBQ + BL + TR,
|
||||
[0x9f] = BBQ + BL + TR + BR,
|
||||
|
||||
/* Shades, data is an alpha value in 25% units (1/4, 1/2, 3/4) */
|
||||
[0x91] = BBS + 1, [0x92] = BBS + 2, [0x93] = BBS + 3,
|
||||
|
||||
/* U+2504 - U+250B, U+254C - U+254F: unsupported (dashes) */
|
||||
/* U+2571 - U+2573: unsupported (diagonals) */
|
||||
};
|
||||
98
patch/font2.c
Normal file
98
patch/font2.c
Normal file
@@ -0,0 +1,98 @@
|
||||
int
|
||||
xloadsparefont(FcPattern *pattern, int flags)
|
||||
{
|
||||
FcPattern *match;
|
||||
FcResult result;
|
||||
|
||||
match = FcFontMatch(NULL, pattern, &result);
|
||||
if (!match) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(frc[frclen].font = XftFontOpenPattern(xw.dpy, match))) {
|
||||
FcPatternDestroy(match);
|
||||
return 1;
|
||||
}
|
||||
|
||||
frc[frclen].flags = flags;
|
||||
/* Believe U+0000 glyph will present in each default font */
|
||||
frc[frclen].unicodep = 0;
|
||||
frclen++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
xloadsparefonts(void)
|
||||
{
|
||||
FcPattern *pattern;
|
||||
double fontval;
|
||||
int fc;
|
||||
char **fp;
|
||||
|
||||
if (frclen != 0)
|
||||
die("can't embed spare fonts. cache isn't empty");
|
||||
|
||||
/* Calculate count of spare fonts */
|
||||
fc = sizeof(font2) / sizeof(*font2);
|
||||
if (fc == 0)
|
||||
return;
|
||||
|
||||
/* Allocate memory for cache entries. */
|
||||
if (frccap < 4 * fc) {
|
||||
frccap += 4 * fc - frccap;
|
||||
frc = xrealloc(frc, frccap * sizeof(Fontcache));
|
||||
}
|
||||
|
||||
for (fp = font2; fp - font2 < fc; ++fp) {
|
||||
|
||||
if (**fp == '-')
|
||||
pattern = XftXlfdParse(*fp, False, False);
|
||||
else
|
||||
pattern = FcNameParse((FcChar8 *)*fp);
|
||||
|
||||
if (!pattern)
|
||||
die("can't open spare font %s\n", *fp);
|
||||
|
||||
if (defaultfontsize > 0 && defaultfontsize != usedfontsize) {
|
||||
if (FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
|
||||
FcResultMatch) {
|
||||
fontval *= usedfontsize / defaultfontsize;
|
||||
FcPatternDel(pattern, FC_PIXEL_SIZE);
|
||||
FcPatternDel(pattern, FC_SIZE);
|
||||
FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontval);
|
||||
} else if (FcPatternGetDouble(pattern, FC_SIZE, 0, &fontval) ==
|
||||
FcResultMatch) {
|
||||
fontval *= usedfontsize / defaultfontsize;
|
||||
FcPatternDel(pattern, FC_PIXEL_SIZE);
|
||||
FcPatternDel(pattern, FC_SIZE);
|
||||
FcPatternAddDouble(pattern, FC_SIZE, fontval);
|
||||
}
|
||||
}
|
||||
|
||||
FcPatternAddBool(pattern, FC_SCALABLE, 1);
|
||||
|
||||
FcConfigSubstitute(NULL, pattern, FcMatchPattern);
|
||||
XftDefaultSubstitute(xw.dpy, xw.scr, pattern);
|
||||
|
||||
if (xloadsparefont(pattern, FRC_NORMAL))
|
||||
die("can't open spare font %s\n", *fp);
|
||||
|
||||
FcPatternDel(pattern, FC_SLANT);
|
||||
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
|
||||
if (xloadsparefont(pattern, FRC_ITALIC))
|
||||
die("can't open spare font %s\n", *fp);
|
||||
|
||||
FcPatternDel(pattern, FC_WEIGHT);
|
||||
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
|
||||
if (xloadsparefont(pattern, FRC_ITALICBOLD))
|
||||
die("can't open spare font %s\n", *fp);
|
||||
|
||||
FcPatternDel(pattern, FC_SLANT);
|
||||
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
|
||||
if (xloadsparefont(pattern, FRC_BOLD))
|
||||
die("can't open spare font %s\n", *fp);
|
||||
|
||||
FcPatternDestroy(pattern);
|
||||
}
|
||||
}
|
||||
2
patch/font2.h
Normal file
2
patch/font2.h
Normal file
@@ -0,0 +1,2 @@
|
||||
static int xloadsparefont(FcPattern *, int);
|
||||
static void xloadsparefonts(void);
|
||||
29
patch/keyboardselect_reflow.txt
Normal file
29
patch/keyboardselect_reflow.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
Shortcuts in keyboard selection mode:
|
||||
|
||||
h, j, k, l: move cursor left/down/up/right (also with arrow keys)
|
||||
H, M, L: move cursor to the top/middle/bottom of the screen
|
||||
Home, End: move cursor to the top/bottom of the screen
|
||||
Backspace or 0, $ or A: move cursor to the beginning/end of the line
|
||||
^ or I: move cursor to the beginning of the indented line
|
||||
!: move cursor to the middle of the row
|
||||
_: move cursor to the right edge of the screen
|
||||
*: move cursor to the center of the screen
|
||||
w, W jump forward to the start of a word
|
||||
e, E jump forward to the end of a word
|
||||
b, B jump backward to the start of a word
|
||||
g, G: go to the first/last line
|
||||
z: center the screen on the cursor
|
||||
PgUp or K, PgDown or J: scroll the page up/down
|
||||
/, ?: activate input mode and search up/down
|
||||
n, N: repeat last search and search forward/backward
|
||||
f, F: jump forward/backward to the given character
|
||||
t, T: jump forward/backward to before the given character
|
||||
; or r repeat previous f, t, F or T movement and move forward
|
||||
, or R repeat previous f, t, F or T movement and move backward
|
||||
v: toggle selection mode
|
||||
V: toggle line selection mode
|
||||
s: toggle regular/rectangular selection type
|
||||
y: yank (copy) selected text
|
||||
0 - 9: set the quantifier
|
||||
Return: quit keyboard_select, yank and keep the highlight of the selection
|
||||
Escape, q: quit keyboard_select/exit input mode/exit selection mode/reset quantifier
|
||||
229
patch/keyboardselect_st.c
Normal file
229
patch/keyboardselect_st.c
Normal file
@@ -0,0 +1,229 @@
|
||||
void set_notifmode(int type, KeySym ksym)
|
||||
{
|
||||
static char *lib[] = { " MOVE ", " SEL "};
|
||||
static Glyph *g, *deb, *fin;
|
||||
static int col, bot;
|
||||
|
||||
if (ksym == -1) {
|
||||
free(g);
|
||||
col = term.col, bot = term.bot;
|
||||
g = xmalloc(col * sizeof(Glyph));
|
||||
memcpy(g, term.line[bot], col * sizeof(Glyph));
|
||||
|
||||
} else if (ksym == -2)
|
||||
memcpy(term.line[bot], g, col * sizeof(Glyph));
|
||||
|
||||
if ( type < 2 ) {
|
||||
char *z = lib[type];
|
||||
for (deb = &term.line[bot][col - 6], fin = &term.line[bot][col]; deb < fin; z++, deb++)
|
||||
deb->mode = ATTR_REVERSE,
|
||||
deb->u = *z,
|
||||
deb->fg = defaultfg, deb->bg = defaultbg;
|
||||
} else if (type < 5)
|
||||
memcpy(term.line[bot], g, col * sizeof(Glyph));
|
||||
else {
|
||||
for (deb = &term.line[bot][0], fin = &term.line[bot][col]; deb < fin; deb++)
|
||||
deb->mode = ATTR_REVERSE,
|
||||
deb->u = ' ',
|
||||
deb->fg = defaultfg, deb->bg = defaultbg;
|
||||
term.line[bot][0].u = ksym;
|
||||
}
|
||||
|
||||
term.dirty[bot] = 1;
|
||||
drawregion(0, bot, col, bot + 1);
|
||||
}
|
||||
|
||||
Glyph getglyph(Term term, int y, int x)
|
||||
{
|
||||
Glyph g;
|
||||
int realy = y - term.scr;
|
||||
if(realy >= 0) {
|
||||
g = term.line[realy][x];
|
||||
} else {
|
||||
realy = term.histi - term.scr + y + 1;
|
||||
g = term.hist[realy][x];
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
void select_or_drawcursor(int selectsearch_mode, int type)
|
||||
{
|
||||
int done = 0;
|
||||
|
||||
if (selectsearch_mode & 1) {
|
||||
selextend(term.c.x, term.c.y, type, done);
|
||||
xsetsel(getsel());
|
||||
} else {
|
||||
xdrawcursor(term.c.x, term.c.y, getglyph(term, term.c.y, term.c.x),
|
||||
term.ocx, term.ocy, getglyph(term, term.ocy, term.ocx));
|
||||
}
|
||||
}
|
||||
|
||||
void search(int selectsearch_mode, Rune *target, int ptarget, int incr, int type, TCursor *cu)
|
||||
{
|
||||
Rune *r;
|
||||
int i, bound = (term.col * cu->y + cu->x) * (incr > 0) + incr;
|
||||
|
||||
for (i = term.col * term.c.y + term.c.x + incr; i != bound; i += incr) {
|
||||
for (r = target; r - target < ptarget; r++) {
|
||||
if (*r == term.line[(i + r - target) / term.col][(i + r - target) % term.col].u) {
|
||||
if (r - target == ptarget - 1)
|
||||
break;
|
||||
} else {
|
||||
r = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (r != NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i != bound) {
|
||||
term.c.y = i / term.col, term.c.x = i % term.col;
|
||||
select_or_drawcursor(selectsearch_mode, type);
|
||||
}
|
||||
}
|
||||
|
||||
int trt_kbdselect(KeySym ksym, char *buf, int len)
|
||||
{
|
||||
static TCursor cu;
|
||||
static Rune target[64];
|
||||
static int type = 1, ptarget, in_use;
|
||||
static int sens, quant;
|
||||
static char selectsearch_mode;
|
||||
int i, bound, *xy;
|
||||
|
||||
if (selectsearch_mode & 2) {
|
||||
if (ksym == XK_Return) {
|
||||
selectsearch_mode ^= 2;
|
||||
set_notifmode(selectsearch_mode, -2);
|
||||
if (ksym == XK_Escape)
|
||||
ptarget = 0;
|
||||
return 0;
|
||||
} else if (ksym == XK_BackSpace) {
|
||||
if (!ptarget)
|
||||
return 0;
|
||||
term.line[term.bot][ptarget--].u = ' ';
|
||||
} else if (len < 1) {
|
||||
return 0;
|
||||
} else if (ptarget == term.col || ksym == XK_Escape) {
|
||||
return 0;
|
||||
} else {
|
||||
utf8decode(buf, &target[ptarget++], len);
|
||||
term.line[term.bot][ptarget].u = target[ptarget - 1];
|
||||
}
|
||||
|
||||
if (ksym != XK_BackSpace)
|
||||
search(selectsearch_mode, &target[0], ptarget, sens, type, &cu);
|
||||
|
||||
term.dirty[term.bot] = 1;
|
||||
drawregion(0, term.bot, term.col, term.bot + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (ksym) {
|
||||
case -1:
|
||||
in_use = 1;
|
||||
cu.x = term.c.x, cu.y = term.c.y;
|
||||
set_notifmode(0, ksym);
|
||||
return MODE_KBDSELECT;
|
||||
case XK_s:
|
||||
if (selectsearch_mode & 1)
|
||||
selclear();
|
||||
else
|
||||
selstart(term.c.x, term.c.y, 0);
|
||||
set_notifmode(selectsearch_mode ^= 1, ksym);
|
||||
break;
|
||||
case XK_t:
|
||||
selextend(term.c.x, term.c.y, type ^= 3, i = 0); /* 2 fois */
|
||||
selextend(term.c.x, term.c.y, type, i = 0);
|
||||
break;
|
||||
case XK_slash:
|
||||
case XK_KP_Divide:
|
||||
case XK_question:
|
||||
ksym &= XK_question; /* Divide to slash */
|
||||
sens = (ksym == XK_slash) ? -1 : 1;
|
||||
ptarget = 0;
|
||||
set_notifmode(15, ksym);
|
||||
selectsearch_mode ^= 2;
|
||||
break;
|
||||
case XK_Escape:
|
||||
if (!in_use)
|
||||
break;
|
||||
selclear();
|
||||
case XK_Return:
|
||||
set_notifmode(4, ksym);
|
||||
term.c.x = cu.x, term.c.y = cu.y;
|
||||
select_or_drawcursor(selectsearch_mode = 0, type);
|
||||
in_use = quant = 0;
|
||||
return MODE_KBDSELECT;
|
||||
case XK_n:
|
||||
case XK_N:
|
||||
if (ptarget)
|
||||
search(selectsearch_mode, &target[0], ptarget, (ksym == XK_n) ? -1 : 1, type, &cu);
|
||||
break;
|
||||
case XK_BackSpace:
|
||||
term.c.x = 0;
|
||||
select_or_drawcursor(selectsearch_mode, type);
|
||||
break;
|
||||
case XK_dollar:
|
||||
term.c.x = term.col - 1;
|
||||
select_or_drawcursor(selectsearch_mode, type);
|
||||
break;
|
||||
case XK_Home:
|
||||
term.c.x = 0, term.c.y = 0;
|
||||
select_or_drawcursor(selectsearch_mode, type);
|
||||
break;
|
||||
case XK_End:
|
||||
term.c.x = cu.x, term.c.y = cu.y;
|
||||
select_or_drawcursor(selectsearch_mode, type);
|
||||
break;
|
||||
case XK_Page_Up:
|
||||
case XK_Page_Down:
|
||||
term.c.y = (ksym == XK_Prior ) ? 0 : cu.y;
|
||||
select_or_drawcursor(selectsearch_mode, type);
|
||||
break;
|
||||
case XK_exclam:
|
||||
term.c.x = term.col >> 1;
|
||||
select_or_drawcursor(selectsearch_mode, type);
|
||||
break;
|
||||
case XK_asterisk:
|
||||
case XK_KP_Multiply:
|
||||
term.c.x = term.col >> 1;
|
||||
case XK_underscore:
|
||||
term.c.y = cu.y >> 1;
|
||||
select_or_drawcursor(selectsearch_mode, type);
|
||||
break;
|
||||
default:
|
||||
if (ksym >= XK_0 && ksym <= XK_9) { /* 0-9 keyboard */
|
||||
quant = (quant * 10) + (ksym ^ XK_0);
|
||||
return 0;
|
||||
} else if (ksym >= XK_KP_0 && ksym <= XK_KP_9) { /* 0-9 numpad */
|
||||
quant = (quant * 10) + (ksym ^ XK_KP_0);
|
||||
return 0;
|
||||
} else if (ksym == XK_k || ksym == XK_h)
|
||||
i = ksym & 1;
|
||||
else if (ksym == XK_l || ksym == XK_j)
|
||||
i = ((ksym & 6) | 4) >> 1;
|
||||
else if ((XK_Home & ksym) != XK_Home || (i = (ksym ^ XK_Home) - 1) > 3)
|
||||
break;
|
||||
|
||||
xy = (i & 1) ? &term.c.y : &term.c.x;
|
||||
sens = (i & 2) ? 1 : -1;
|
||||
bound = (i >> 1 ^ 1) ? 0 : (i ^ 3) ? term.col - 1 : term.bot;
|
||||
|
||||
if (quant == 0)
|
||||
quant++;
|
||||
|
||||
if (*xy == bound && ((sens < 0 && bound == 0) || (sens > 0 && bound > 0)))
|
||||
break;
|
||||
|
||||
*xy += quant * sens;
|
||||
if (*xy < 0 || ( bound > 0 && *xy > bound))
|
||||
*xy = bound;
|
||||
|
||||
select_or_drawcursor(selectsearch_mode, type);
|
||||
}
|
||||
quant = 0;
|
||||
return 0;
|
||||
}
|
||||
2
patch/keyboardselect_st.h
Normal file
2
patch/keyboardselect_st.h
Normal file
@@ -0,0 +1,2 @@
|
||||
void toggle_winmode(int);
|
||||
int trt_kbdselect(KeySym, char *, int);
|
||||
7
patch/keyboardselect_x.c
Normal file
7
patch/keyboardselect_x.c
Normal file
@@ -0,0 +1,7 @@
|
||||
void toggle_winmode(int flag) {
|
||||
win.mode ^= flag;
|
||||
}
|
||||
|
||||
void keyboard_select(const Arg *dummy) {
|
||||
win.mode ^= trt_kbdselect(-1, NULL, 0);
|
||||
}
|
||||
2
patch/keyboardselect_x.h
Normal file
2
patch/keyboardselect_x.h
Normal file
@@ -0,0 +1,2 @@
|
||||
void toggle_winmode(int);
|
||||
void keyboard_select(const Arg *);
|
||||
43
patch/scrollback.c
Normal file
43
patch/scrollback.c
Normal file
@@ -0,0 +1,43 @@
|
||||
void
|
||||
kscrolldown(const Arg* a)
|
||||
{
|
||||
int n = a->i;
|
||||
|
||||
if (n < 0)
|
||||
n = term.row + n;
|
||||
|
||||
if (n > term.scr)
|
||||
n = term.scr;
|
||||
|
||||
if (term.scr > 0) {
|
||||
term.scr -= n;
|
||||
selscroll(0, -n);
|
||||
tfulldirt();
|
||||
}
|
||||
|
||||
scroll_images(-1*n);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
kscrollup(const Arg* a)
|
||||
{
|
||||
int n = a->i;
|
||||
if (n < 0)
|
||||
n = term.row + n;
|
||||
|
||||
if (term.scr + n > term.histn)
|
||||
n = term.histn - term.scr;
|
||||
|
||||
if (!n)
|
||||
return;
|
||||
|
||||
if (term.scr <= HISTSIZE-n) {
|
||||
term.scr += n;
|
||||
selscroll(0, n);
|
||||
tfulldirt();
|
||||
}
|
||||
|
||||
scroll_images(n);
|
||||
|
||||
}
|
||||
15
patch/scrollback.h
Normal file
15
patch/scrollback.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#define TLINE(y) ((y) < term.scr ? term.hist[((y) + term.histi - \
|
||||
term.scr + HISTSIZE + 1) % HISTSIZE] : \
|
||||
term.line[(y) - term.scr])
|
||||
|
||||
void kscrolldown(const Arg *);
|
||||
void kscrollup(const Arg *);
|
||||
|
||||
typedef struct {
|
||||
uint b;
|
||||
uint mask;
|
||||
void (*func)(const Arg *);
|
||||
const Arg arg;
|
||||
} MouseKey;
|
||||
|
||||
extern MouseKey mkeys[];
|
||||
3
patch/st_include.c
Normal file
3
patch/st_include.c
Normal file
@@ -0,0 +1,3 @@
|
||||
/* Patches */
|
||||
#include "keyboardselect_st.c"
|
||||
#include "scrollback.c"
|
||||
3
patch/st_include.h
Normal file
3
patch/st_include.h
Normal file
@@ -0,0 +1,3 @@
|
||||
/* Patches */
|
||||
#include "keyboardselect_st.h"
|
||||
#include "scrollback.h"
|
||||
23
patch/utils.h
Normal file
23
patch/utils.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/// Dynamic memory-chunk, with (1) datatype size, (2/3) initialized / allocated chunk, (4) content
|
||||
typedef struct { uint8_t const elSize; uint32_t init, alloc; char* content; } DynamicArray;
|
||||
#define UTF8_ARRAY {4, 0, 0, NULL}
|
||||
|
||||
static inline int p_alloc(DynamicArray *s, uint32_t amount) {
|
||||
uint32_t const diff=s->init+s->elSize*amount-s->alloc, nas=s->alloc+max(diff,15)*s->elSize;
|
||||
if (s->alloc < s->init + s->elSize * amount) {
|
||||
char* tmp = realloc(s->content, nas);
|
||||
if (!tmp) return 0;
|
||||
s->alloc = nas, s->content = tmp;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
static inline char *view(DynamicArray * s, uint32_t i) { return s->content + i*s->elSize; }
|
||||
static inline char *end(DynamicArray *s, uint32_t i) { return s->content +s->init-(i+1)*s->elSize; }
|
||||
static inline uint32_t getU32(DynamicArray* s, uint32_t i, int b) { return *((uint32_t*) (b ?view(s,i) :end(s,i))); }
|
||||
static char *expand(DynamicArray *s) { if (!p_alloc(s, 1)) return NULL; s->init += s->elSize; return end(s, 0); }
|
||||
static inline void pop(DynamicArray* s) { s->init -= s->elSize; }
|
||||
static inline void empty(DynamicArray* s) { s->init = 0; }
|
||||
static inline int size(DynamicArray const * s) { return s->init / s->elSize; }
|
||||
static inline void assign(DynamicArray* s, DynamicArray const *o) {
|
||||
if (p_alloc(s, size(o))) memcpy(s->content, o->content, (s->init=o->init));
|
||||
}
|
||||
5
patch/x_include.c
Normal file
5
patch/x_include.c
Normal file
@@ -0,0 +1,5 @@
|
||||
/* Patches */
|
||||
#include "alpha.c"
|
||||
#include "boxdraw.c"
|
||||
#include "font2.c"
|
||||
#include "keyboardselect_x.c"
|
||||
5
patch/x_include.h
Normal file
5
patch/x_include.h
Normal file
@@ -0,0 +1,5 @@
|
||||
/* Patches */
|
||||
#include "alpha.h"
|
||||
#include "boxdraw.h"
|
||||
#include "font2.h"
|
||||
#include "keyboardselect_x.h"
|
||||
Reference in New Issue
Block a user