Compare commits

..

9 Commits

12 changed files with 7919 additions and 2871 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.o
*.diff

View File

@@ -5,8 +5,12 @@
* *
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/ */
static char *font = "FiraCode Nerd Font Propo:pixelsize=13"; static char *font =
static int borderpx = 5; "JetBrainsMono NFP:pixelsize=15:antialias=true:autohint=true";
static char *font2[] = {
"Noto Color Emoji:pixelsize=15:antialias=true:autohint=true",
};
static int borderpx = 2;
/* /*
* What program is execed by st depends of these precedence rules: * What program is execed by st depends of these precedence rules:
@@ -16,7 +20,7 @@ static int borderpx = 5;
* 4: value of shell in /etc/passwd * 4: value of shell in /etc/passwd
* 5: value of shell in config.h * 5: value of shell in config.h
*/ */
static char *shell = "/bin/sh"; static char *shell = "/bin/bash";
char *utmp = NULL; char *utmp = NULL;
/* scroll program: to enable use a string like "scroll" */ /* scroll program: to enable use a string like "scroll" */
char *scroll = NULL; char *scroll = NULL;
@@ -96,37 +100,31 @@ unsigned int tabspaces = 8;
/* Terminal colors (16 first used in escape sequence) */ /* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = { static const char *colorname[] = {
/* 8 normal colors */ /* 8 normal colors */
"#323437", [0] = "#282828", /* hard contrast: #1d2021 / soft contrast: #32302f */
"#ff5454", [1] = "#cc241d", /* red */
"#8cc85f", [2] = "#98971a", /* green */
"#e3c78a", [3] = "#d79921", /* yellow */
"#80a0ff", [4] = "#458588", /* blue */
"#d183e8", [5] = "#b16286", /* magenta */
"#79dac8", [6] = "#689d6a", /* cyan */
"#a1aab8", [7] = "#a89984", /* white */
"#7c8f8f", [8] = "#928374", /* black */
"#ff5189", [9] = "#fb4934", /* red */
"#36c692", [10] = "#b8bb26", /* green */
"#bfbf97", [11] = "#fabd2f", /* yellow */
"#74b2ff", [12] = "#83a598", /* blue */
"#ae81ff", [13] = "#d3869b", /* magenta */
"#85dc85", [14] = "#8ec07c", /* cyan */
"#e2637f", [15] = "#ebdbb2", /* white */
[255] = 0, [255] = 0,
/* more colors can be added after 255 to use with DefaultXX */
"#272727",
"#f8f8f2",
"#080808",
"#eeeeee",
}; };
/* /*
* Default colors (colorname index) * Default colors (colorname index)
* foreground, background, cursor, reverse cursor * foreground, background, cursor, reverse cursor
*/ */
unsigned int defaultfg = 259; unsigned int defaultfg = 15;
unsigned int defaultbg = 256; unsigned int defaultbg = 0;
unsigned int defaultcs = 257; unsigned int defaultcs = 15;
static unsigned int defaultrcs = 257; static unsigned int defaultrcs = 257;
/* https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81 /* https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81
@@ -175,9 +173,10 @@ static uint forcemousemod = ShiftMask;
* Beware that overloading Button1 will disable the selection. * Beware that overloading Button1 will disable the selection.
*/ */
static MouseShortcut mshortcuts[] = { static MouseShortcut mshortcuts[] = {
/* mask button function argument release alt */ /* mask button function argument release */
{ XK_ANY_MOD, Button4, kscrollup, {.i = 1}, 0, -1 }, {XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1},
{ XK_ANY_MOD, Button5, kscrolldown, {.i = 1}, 0, -1 }, {ShiftMask, Button4, kscrollup, {.i = 1}},
{ShiftMask, Button5, kscrolldown, {.i = 1}},
}; };
/* Internal keyboard shortcuts. */ /* Internal keyboard shortcuts. */
@@ -198,11 +197,8 @@ static Shortcut shortcuts[] = {
{TERMMOD, XK_Y, selpaste, {.i = 0}}, {TERMMOD, XK_Y, selpaste, {.i = 0}},
{ShiftMask, XK_Insert, selpaste, {.i = 0}}, {ShiftMask, XK_Insert, selpaste, {.i = 0}},
{TERMMOD, XK_Num_Lock, numlock, {.i = 0}}, {TERMMOD, XK_Num_Lock, numlock, {.i = 0}},
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
}; };
/* /*
* Special keys (change & recompile st.info accordingly) * Special keys (change & recompile st.info accordingly)
* *
@@ -468,7 +464,6 @@ static uint selmasks[] = {
* Printable characters in ASCII, used to estimate the advance width * Printable characters in ASCII, used to estimate the advance width
* of single wide characters. * of single wide characters.
*/ */
static char ascii_printable[] = static char ascii_printable[] = " !\"#$%&'()*+,-./0123456789:;<=>?"
" !\"#$%&'()*+,-./0123456789:;<=>?"
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
"`abcdefghijklmnopqrstuvwxyz{|}~"; "`abcdefghijklmnopqrstuvwxyz{|}~";

View File

@@ -5,8 +5,12 @@
* *
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/ */
static char *font = "FiraCode Nerd Font Propo:pixelsize=13"; static char *font =
static int borderpx = 5; "JetBrainsMono NFP:pixelsize=15:antialias=true:autohint=true";
static char *font2[] = {
"Noto Color Emoji:pixelsize=15:antialias=true:autohint=true",
};
static int borderpx = 2;
/* /*
* What program is execed by st depends of these precedence rules: * What program is execed by st depends of these precedence rules:
@@ -16,7 +20,7 @@ static int borderpx = 5;
* 4: value of shell in /etc/passwd * 4: value of shell in /etc/passwd
* 5: value of shell in config.h * 5: value of shell in config.h
*/ */
static char *shell = "/bin/sh"; static char *shell = "/bin/bash";
char *utmp = NULL; char *utmp = NULL;
/* scroll program: to enable use a string like "scroll" */ /* scroll program: to enable use a string like "scroll" */
char *scroll = NULL; char *scroll = NULL;
@@ -96,37 +100,31 @@ unsigned int tabspaces = 8;
/* Terminal colors (16 first used in escape sequence) */ /* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = { static const char *colorname[] = {
/* 8 normal colors */ /* 8 normal colors */
"#323437", [0] = "#282828", /* hard contrast: #1d2021 / soft contrast: #32302f */
"#ff5454", [1] = "#cc241d", /* red */
"#8cc85f", [2] = "#98971a", /* green */
"#e3c78a", [3] = "#d79921", /* yellow */
"#80a0ff", [4] = "#458588", /* blue */
"#d183e8", [5] = "#b16286", /* magenta */
"#79dac8", [6] = "#689d6a", /* cyan */
"#a1aab8", [7] = "#a89984", /* white */
"#7c8f8f", [8] = "#928374", /* black */
"#ff5189", [9] = "#fb4934", /* red */
"#36c692", [10] = "#b8bb26", /* green */
"#bfbf97", [11] = "#fabd2f", /* yellow */
"#74b2ff", [12] = "#83a598", /* blue */
"#ae81ff", [13] = "#d3869b", /* magenta */
"#85dc85", [14] = "#8ec07c", /* cyan */
"#e2637f", [15] = "#ebdbb2", /* white */
[255] = 0, [255] = 0,
/* more colors can be added after 255 to use with DefaultXX */
"#272727",
"#f8f8f2",
"#080808",
"#eeeeee",
}; };
/* /*
* Default colors (colorname index) * Default colors (colorname index)
* foreground, background, cursor, reverse cursor * foreground, background, cursor, reverse cursor
*/ */
unsigned int defaultfg = 259; unsigned int defaultfg = 15;
unsigned int defaultbg = 256; unsigned int defaultbg = 0;
unsigned int defaultcs = 257; unsigned int defaultcs = 15;
static unsigned int defaultrcs = 257; static unsigned int defaultrcs = 257;
/* https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81 /* https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81
@@ -175,9 +173,10 @@ static uint forcemousemod = ShiftMask;
* Beware that overloading Button1 will disable the selection. * Beware that overloading Button1 will disable the selection.
*/ */
static MouseShortcut mshortcuts[] = { static MouseShortcut mshortcuts[] = {
/* mask button function argument release alt */ /* mask button function argument release */
{ XK_ANY_MOD, Button4, kscrollup, {.i = 1}, 0, -1 }, {XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1},
{ XK_ANY_MOD, Button5, kscrolldown, {.i = 1}, 0, -1 }, {ShiftMask, Button4, kscrollup, {.i = 1}},
{ShiftMask, Button5, kscrolldown, {.i = 1}},
}; };
/* Internal keyboard shortcuts. */ /* Internal keyboard shortcuts. */
@@ -198,11 +197,8 @@ static Shortcut shortcuts[] = {
{TERMMOD, XK_Y, selpaste, {.i = 0}}, {TERMMOD, XK_Y, selpaste, {.i = 0}},
{ShiftMask, XK_Insert, selpaste, {.i = 0}}, {ShiftMask, XK_Insert, selpaste, {.i = 0}},
{TERMMOD, XK_Num_Lock, numlock, {.i = 0}}, {TERMMOD, XK_Num_Lock, numlock, {.i = 0}},
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
}; };
/* /*
* Special keys (change & recompile st.info accordingly) * Special keys (change & recompile st.info accordingly)
* *
@@ -468,7 +464,6 @@ static uint selmasks[] = {
* Printable characters in ASCII, used to estimate the advance width * Printable characters in ASCII, used to estimate the advance width
* of single wide characters. * of single wide characters.
*/ */
static char ascii_printable[] = static char ascii_printable[] = " !\"#$%&'()*+,-./0123456789:;<=>?"
" !\"#$%&'()*+,-./0123456789:;<=>?"
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
"`abcdefghijklmnopqrstuvwxyz{|}~"; "`abcdefghijklmnopqrstuvwxyz{|}~";

BIN
hb.o

Binary file not shown.

BIN
st

Binary file not shown.

567
st.c

File diff suppressed because it is too large Load Diff

2749
st.c.orig Normal file

File diff suppressed because it is too large Load Diff

129
st.h.orig Normal file
View File

@@ -0,0 +1,129 @@
/* See LICENSE for license details. */
#include <stdint.h>
#include <sys/types.h>
/* macros */
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define LEN(a) (sizeof(a) / sizeof(a)[0])
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
#define ATTRCMP(a, b) (((a).mode & (~ATTR_WRAP)) != ((b).mode & (~ATTR_WRAP)) || \
(a).fg != (b).fg || \
(a).bg != (b).bg)
#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
(t1.tv_nsec-t2.tv_nsec)/1E6)
#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
#define IS_TRUECOL(x) (1 << 24 & (x))
enum glyph_attribute {
ATTR_NULL = 0,
ATTR_BOLD = 1 << 0,
ATTR_FAINT = 1 << 1,
ATTR_ITALIC = 1 << 2,
ATTR_UNDERLINE = 1 << 3,
ATTR_BLINK = 1 << 4,
ATTR_REVERSE = 1 << 5,
ATTR_INVISIBLE = 1 << 6,
ATTR_STRUCK = 1 << 7,
ATTR_WRAP = 1 << 8,
ATTR_WIDE = 1 << 9,
ATTR_WDUMMY = 1 << 10,
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
};
enum selection_mode {
SEL_IDLE = 0,
SEL_EMPTY = 1,
SEL_READY = 2
};
enum selection_type {
SEL_REGULAR = 1,
SEL_RECTANGULAR = 2
};
enum selection_snap {
SNAP_WORD = 1,
SNAP_LINE = 2
};
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned short ushort;
typedef uint_least32_t Rune;
#define Glyph Glyph_
typedef struct {
Rune u; /* character code */
ushort mode; /* attribute flags */
uint32_t fg; /* foreground */
uint32_t bg; /* background */
} Glyph;
typedef Glyph *Line;
typedef union {
int i;
uint ui;
float f;
const void *v;
const char *s;
} Arg;
void die(const char *, ...);
void redraw(void);
void draw(void);
void kscrolldown(const Arg *);
void kscrollup(const Arg *);
void printscreen(const Arg *);
void printsel(const Arg *);
void sendbreak(const Arg *);
void toggleprinter(const Arg *);
int tattrset(int);
void tnew(int, int);
void tresize(int, int);
void tsetdirtattr(int);
void ttyhangup(void);
int ttynew(const char *, char *, const char *, char **);
size_t ttyread(void);
void ttyresize(int, int);
void ttywrite(const char *, size_t, int);
void resettitle(void);
void selclear(void);
void selinit(void);
void selstart(int, int, int);
void selextend(int, int, int, int);
int selected(int, int);
char *getsel(void);
size_t utf8encode(Rune, char *);
void *xmalloc(size_t);
void *xrealloc(void *, size_t);
char *xstrdup(const char *);
/* config.h globals */
extern char *utmp;
extern char *scroll;
extern char *stty_args;
extern char *vtiden;
extern wchar_t *worddelimiters;
extern int allowaltscreen;
extern int allowwindowops;
extern char *termname;
extern unsigned int tabspaces;
extern unsigned int defaultfg;
extern unsigned int defaultbg;
extern unsigned int defaultcs;

BIN
st.o

Binary file not shown.

112
x.c
View File

@@ -4,6 +4,7 @@
#include <limits.h> #include <limits.h>
#include <locale.h> #include <locale.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h>
#include <sys/select.h> #include <sys/select.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
@@ -159,6 +160,8 @@ static void xhints(void);
static int xloadcolor(int, const char *, Color *); static int xloadcolor(int, const char *, Color *);
static int xloadfont(Font *, FcPattern *); static int xloadfont(Font *, FcPattern *);
static void xloadfonts(const char *, double); static void xloadfonts(const char *, double);
static int xloadsparefont(FcPattern *, int);
static void xloadsparefonts(void);
static void xunloadfont(Font *); static void xunloadfont(Font *);
static void xunloadfonts(void); static void xunloadfonts(void);
static void xsetenv(void); static void xsetenv(void);
@@ -309,6 +312,7 @@ zoomabs(const Arg *arg)
{ {
xunloadfonts(); xunloadfonts();
xloadfonts(usedfont, arg->f); xloadfonts(usedfont, arg->f);
xloadsparefonts();
cresize(0, 0); cresize(0, 0);
redraw(); redraw();
xhints(); xhints();
@@ -1053,6 +1057,101 @@ xloadfonts(const char *fontstr, double fontsize)
FcPatternDestroy(pattern); FcPatternDestroy(pattern);
} }
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 sizeshift, 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) {
sizeshift = usedfontsize - defaultfontsize;
if (sizeshift != 0 &&
FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
FcResultMatch) {
fontval += sizeshift;
FcPatternDel(pattern, FC_PIXEL_SIZE);
FcPatternDel(pattern, FC_SIZE);
FcPatternAddDouble(pattern, FC_PIXEL_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);
}
}
void void
xunloadfont(Font *f) xunloadfont(Font *f)
{ {
@@ -1151,7 +1250,11 @@ xinit(int cols, int rows)
die("could not init fontconfig.\n"); die("could not init fontconfig.\n");
usedfont = (opt_font == NULL)? font : opt_font; usedfont = (opt_font == NULL)? font : opt_font;
xloadfonts(usedfont, 0);
xloadfonts(usedfont, defaultfontsize);
/* spare fonts */
xloadsparefonts();
/* colors */ /* colors */
xw.cmap = XDefaultColormap(xw.dpy, xw.scr); xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
@@ -1649,7 +1752,7 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og, Line line, int le
break; break;
/* FALLTHROUGH */ /* FALLTHROUGH */
case 8: /* steady st cursor */ case 8: /* steady st cursor */
g.u = xsetcursor; g.u = (unsigned int) xsetcursor;
xdrawglyph(g, cx, cy); xdrawglyph(g, cx, cy);
break; break;
} }
@@ -2158,6 +2261,11 @@ main(int argc, char *argv[])
case 'v': case 'v':
die("%s " VERSION "\n", argv0); die("%s " VERSION "\n", argv0);
break; break;
case 'z':
defaultfontsize = strtod(EARGF(usage()), NULL);
if (!(defaultfontsize > 0))
usage();
break;
default: default:
usage(); usage();
} ARGEND; } ARGEND;

2284
x.c.orig Normal file

File diff suppressed because it is too large Load Diff

BIN
x.o

Binary file not shown.