Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
75f92eb348 | |||
3be4cf11d7 | |||
16d98738e7 | |||
e23acb9188 | |||
7e19e11676 | |||
096b125db7 | |||
d7bf023b2f | |||
b4d68d4daa | |||
30ec9a3dc3 | |||
67d0cb65d0 | |||
4f4bccd162 | |||
8ed7a4b3b7 | |||
732be223ee | |||
5535c1f04c | |||
b51bcd5553 | |||
1911c9274d | |||
29f341da7c | |||
dc3b5babf1 | |||
235a783e03 | |||
30ce2cc002 | |||
041912a791 | |||
bd3f7fd842 | |||
74cff67bd7 |
2
Makefile
2
Makefile
@ -22,7 +22,7 @@ config.h:
|
||||
$(CC) $(STCFLAGS) -c $<
|
||||
|
||||
st.o: config.h st.h win.h
|
||||
x.o: arg.h st.h win.h
|
||||
x.o: arg.h config.h st.h win.h
|
||||
|
||||
$(OBJ): config.h config.mk
|
||||
|
||||
|
@ -176,8 +176,8 @@ static Shortcut shortcuts[] = {
|
||||
{ TERMMOD, XK_C, clipcopy, {.i = 0} },
|
||||
{ TERMMOD, XK_V, clippaste, {.i = 0} },
|
||||
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
||||
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
||||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
||||
{ TERMMOD, XK_I, iso14755, {.i = 0} },
|
||||
};
|
||||
|
||||
/*
|
||||
|
23
config.mk
23
config.mk
@ -1,5 +1,5 @@
|
||||
# st version
|
||||
VERSION = 0.8.1
|
||||
VERSION = 0.8.2
|
||||
|
||||
# Customize below to fit your system
|
||||
|
||||
@ -10,19 +10,26 @@ MANPREFIX = $(PREFIX)/share/man
|
||||
X11INC = /usr/X11R6/include
|
||||
X11LIB = /usr/X11R6/lib
|
||||
|
||||
PKG_CONFIG = pkg-config
|
||||
|
||||
# includes and libs
|
||||
INCS = -I$(X11INC) \
|
||||
`pkg-config --cflags fontconfig` \
|
||||
`pkg-config --cflags freetype2`
|
||||
`$(PKG_CONFIG) --cflags fontconfig` \
|
||||
`$(PKG_CONFIG) --cflags freetype2`
|
||||
LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
|
||||
`pkg-config --libs fontconfig` \
|
||||
`pkg-config --libs freetype2`
|
||||
`$(PKG_CONFIG) --libs fontconfig` \
|
||||
`$(PKG_CONFIG) --libs freetype2`
|
||||
|
||||
# flags
|
||||
CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
|
||||
STCFLAGS = $(INCS) $(CPPFLAGS) $(CFLAGS)
|
||||
STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
|
||||
STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS)
|
||||
STLDFLAGS = $(LIBS) $(LDFLAGS)
|
||||
|
||||
# OpenBSD:
|
||||
#CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
|
||||
#LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \
|
||||
# `pkg-config --libs fontconfig` \
|
||||
# `pkg-config --libs freetype2`
|
||||
|
||||
# compiler and linker
|
||||
# CC = c99
|
||||
|
||||
|
4
st.1
4
st.1
@ -159,10 +159,6 @@ Copy the selected text to the clipboard selection.
|
||||
.TP
|
||||
.B Ctrl-Shift-v
|
||||
Paste from the clipboard selection.
|
||||
.TP
|
||||
.B Ctrl-Shift-i
|
||||
Launch dmenu to enter a unicode codepoint and send the corresponding glyph
|
||||
to st.
|
||||
.SH CUSTOMIZATION
|
||||
.B st
|
||||
can be customized by creating a custom config.h and (re)compiling the source
|
||||
|
68
st.c
68
st.c
@ -38,15 +38,11 @@
|
||||
|
||||
/* macros */
|
||||
#define IS_SET(flag) ((term.mode & (flag)) != 0)
|
||||
#define NUMMAXLEN(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1)
|
||||
#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177')
|
||||
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
|
||||
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
|
||||
#define ISDELIM(u) (utf8strchr(worddelimiters, u) != NULL)
|
||||
|
||||
/* constants */
|
||||
#define ISO14755CMD "dmenu -w \"$WINDOWID\" -p codepoint: </dev/null"
|
||||
|
||||
enum term_mode {
|
||||
MODE_WRAP = 1 << 0,
|
||||
MODE_INSERT = 1 << 1,
|
||||
@ -256,10 +252,10 @@ xwrite(int fd, const char *s, size_t len)
|
||||
void *
|
||||
xmalloc(size_t len)
|
||||
{
|
||||
void *p = malloc(len);
|
||||
void *p;
|
||||
|
||||
if (!p)
|
||||
die("Out of memory\n");
|
||||
if (!(p = malloc(len)))
|
||||
die("malloc: %s\n", strerror(errno));
|
||||
|
||||
return p;
|
||||
}
|
||||
@ -268,7 +264,7 @@ void *
|
||||
xrealloc(void *p, size_t len)
|
||||
{
|
||||
if ((p = realloc(p, len)) == NULL)
|
||||
die("Out of memory\n");
|
||||
die("realloc: %s\n", strerror(errno));
|
||||
|
||||
return p;
|
||||
}
|
||||
@ -277,7 +273,7 @@ char *
|
||||
xstrdup(char *s)
|
||||
{
|
||||
if ((s = strdup(s)) == NULL)
|
||||
die("Out of memory\n");
|
||||
die("strdup: %s\n", strerror(errno));
|
||||
|
||||
return s;
|
||||
}
|
||||
@ -446,6 +442,7 @@ selstart(int col, int row, int snap)
|
||||
selclear();
|
||||
sel.mode = SEL_EMPTY;
|
||||
sel.type = SEL_REGULAR;
|
||||
sel.alt = IS_SET(MODE_ALTSCREEN);
|
||||
sel.snap = snap;
|
||||
sel.oe.x = sel.ob.x = col;
|
||||
sel.oe.y = sel.ob.y = row;
|
||||
@ -474,7 +471,6 @@ selextend(int col, int row, int type, int done)
|
||||
oldsey = sel.ne.y;
|
||||
oldtype = sel.type;
|
||||
|
||||
sel.alt = IS_SET(MODE_ALTSCREEN);
|
||||
sel.oe.x = col;
|
||||
sel.oe.y = row;
|
||||
selnormalize();
|
||||
@ -687,7 +683,7 @@ execsh(char *cmd, char **args)
|
||||
errno = 0;
|
||||
if ((pw = getpwuid(getuid())) == NULL) {
|
||||
if (errno)
|
||||
die("getpwuid:%s\n", strerror(errno));
|
||||
die("getpwuid: %s\n", strerror(errno));
|
||||
else
|
||||
die("who are you?\n");
|
||||
}
|
||||
@ -730,13 +726,15 @@ sigchld(int a)
|
||||
pid_t p;
|
||||
|
||||
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
|
||||
die("Waiting for pid %hd failed: %s\n", pid, strerror(errno));
|
||||
die("waiting for pid %hd failed: %s\n", pid, strerror(errno));
|
||||
|
||||
if (pid != p)
|
||||
return;
|
||||
|
||||
if (!WIFEXITED(stat) || WEXITSTATUS(stat))
|
||||
die("child finished with error '%d'\n", stat);
|
||||
if (WIFEXITED(stat) && WEXITSTATUS(stat))
|
||||
die("child exited with status %d\n", WEXITSTATUS(stat));
|
||||
else if (WIFSIGNALED(stat))
|
||||
die("child terminated due to signal %d\n", WTERMSIG(stat));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@ -781,7 +779,8 @@ ttynew(char *line, char *cmd, char *out, char **args)
|
||||
|
||||
if (line) {
|
||||
if ((cmdfd = open(line, O_RDWR)) < 0)
|
||||
die("open line failed: %s\n", strerror(errno));
|
||||
die("open line '%s' failed: %s\n",
|
||||
line, strerror(errno));
|
||||
dup2(cmdfd, 0);
|
||||
stty(args);
|
||||
return cmdfd;
|
||||
@ -793,7 +792,7 @@ ttynew(char *line, char *cmd, char *out, char **args)
|
||||
|
||||
switch (pid = fork()) {
|
||||
case -1:
|
||||
die("fork failed\n");
|
||||
die("fork failed: %s\n", strerror(errno));
|
||||
break;
|
||||
case 0:
|
||||
close(iofd);
|
||||
@ -805,9 +804,17 @@ ttynew(char *line, char *cmd, char *out, char **args)
|
||||
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
|
||||
close(s);
|
||||
close(m);
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio getpw proc exec", NULL) == -1)
|
||||
die("pledge\n");
|
||||
#endif
|
||||
execsh(cmd, args);
|
||||
break;
|
||||
default:
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio rpath tty proc", NULL) == -1)
|
||||
die("pledge\n");
|
||||
#endif
|
||||
close(s);
|
||||
cmdfd = m;
|
||||
signal(SIGCHLD, sigchld);
|
||||
@ -826,7 +833,7 @@ ttyread(void)
|
||||
|
||||
/* append read bytes to unprocessed bytes */
|
||||
if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
|
||||
die("Couldn't read from shell: %s\n", strerror(errno));
|
||||
die("couldn't read from shell: %s\n", strerror(errno));
|
||||
buflen += ret;
|
||||
|
||||
written = twrite(buf, buflen, 0);
|
||||
@ -1447,7 +1454,8 @@ tsetattr(int *attr, int l)
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"erresc(default): gfx attr %d unknown\n",
|
||||
attr[i]), csidump();
|
||||
attr[i]);
|
||||
csidump();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1972,28 +1980,6 @@ tprinter(char *s, size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
iso14755(const Arg *arg)
|
||||
{
|
||||
FILE *p;
|
||||
char *us, *e, codepoint[9], uc[UTF_SIZ];
|
||||
unsigned long utf32;
|
||||
|
||||
if (!(p = popen(ISO14755CMD, "r")))
|
||||
return;
|
||||
|
||||
us = fgets(codepoint, sizeof(codepoint), p);
|
||||
pclose(p);
|
||||
|
||||
if (!us || *us == '\0' || *us == '-' || strlen(us) > 7)
|
||||
return;
|
||||
if ((utf32 = strtoul(us, &e, 16)) == ULONG_MAX ||
|
||||
(*e != '\n' && *e != '\0'))
|
||||
return;
|
||||
|
||||
ttywrite(uc, utf8encode(utf32, uc), 1);
|
||||
}
|
||||
|
||||
void
|
||||
toggleprinter(const Arg *arg)
|
||||
{
|
||||
@ -2278,7 +2264,7 @@ eschandle(uchar ascii)
|
||||
case 'Z': /* DECID -- Identify Terminal */
|
||||
ttywrite(vtiden, strlen(vtiden), 0);
|
||||
break;
|
||||
case 'c': /* RIS -- Reset to inital state */
|
||||
case 'c': /* RIS -- Reset to initial state */
|
||||
treset();
|
||||
resettitle();
|
||||
xloadcols();
|
||||
|
1
st.h
1
st.h
@ -80,7 +80,6 @@ void die(const char *, ...);
|
||||
void redraw(void);
|
||||
void draw(void);
|
||||
|
||||
void iso14755(const Arg *);
|
||||
void printscreen(const Arg *);
|
||||
void printsel(const Arg *);
|
||||
void sendbreak(const Arg *);
|
||||
|
47
x.c
47
x.c
@ -672,6 +672,8 @@ cresize(int width, int height)
|
||||
|
||||
col = (win.w - 2 * borderpx) / win.cw;
|
||||
row = (win.h - 2 * borderpx) / win.ch;
|
||||
col = MAX(1, col);
|
||||
row = MAX(1, row);
|
||||
|
||||
tresize(col, row);
|
||||
xresize(col, row);
|
||||
@ -681,8 +683,8 @@ cresize(int width, int height)
|
||||
void
|
||||
xresize(int col, int row)
|
||||
{
|
||||
win.tw = MAX(1, col * win.cw);
|
||||
win.th = MAX(1, row * win.ch);
|
||||
win.tw = col * win.cw;
|
||||
win.th = row * win.ch;
|
||||
|
||||
XFreePixmap(xw.dpy, xw.buf);
|
||||
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
|
||||
@ -731,20 +733,20 @@ xloadcols(void)
|
||||
static int loaded;
|
||||
Color *cp;
|
||||
|
||||
dc.collen = MAX(LEN(colorname), 256);
|
||||
dc.col = xmalloc(dc.collen * sizeof(Color));
|
||||
|
||||
if (loaded) {
|
||||
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
|
||||
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
|
||||
} else {
|
||||
dc.collen = MAX(LEN(colorname), 256);
|
||||
dc.col = xmalloc(dc.collen * sizeof(Color));
|
||||
}
|
||||
|
||||
for (i = 0; i < dc.collen; i++)
|
||||
if (!xloadcolor(i, NULL, &dc.col[i])) {
|
||||
if (colorname[i])
|
||||
die("Could not allocate color '%s'\n", colorname[i]);
|
||||
die("could not allocate color '%s'\n", colorname[i]);
|
||||
else
|
||||
die("Could not allocate color %d\n", i);
|
||||
die("could not allocate color %d\n", i);
|
||||
}
|
||||
loaded = 1;
|
||||
}
|
||||
@ -788,15 +790,17 @@ xhints(void)
|
||||
|
||||
sizeh = XAllocSizeHints();
|
||||
|
||||
sizeh->flags = PSize | PResizeInc | PBaseSize;
|
||||
sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize;
|
||||
sizeh->height = win.h;
|
||||
sizeh->width = win.w;
|
||||
sizeh->height_inc = win.ch;
|
||||
sizeh->width_inc = win.cw;
|
||||
sizeh->base_height = 2 * borderpx;
|
||||
sizeh->base_width = 2 * borderpx;
|
||||
sizeh->min_height = win.ch + 2 * borderpx;
|
||||
sizeh->min_width = win.cw + 2 * borderpx;
|
||||
if (xw.isfixed) {
|
||||
sizeh->flags |= PMaxSize | PMinSize;
|
||||
sizeh->flags |= PMaxSize;
|
||||
sizeh->min_width = sizeh->max_width = win.w;
|
||||
sizeh->min_height = sizeh->max_height = win.h;
|
||||
}
|
||||
@ -869,7 +873,7 @@ xloadfont(Font *f, FcPattern *pattern)
|
||||
if ((XftPatternGetInteger(f->match->pattern, "slant", 0,
|
||||
&haveattr) != XftResultMatch) || haveattr < wantattr) {
|
||||
f->badslant = 1;
|
||||
fputs("st: font slant does not match\n", stderr);
|
||||
fputs("font slant does not match\n", stderr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -878,7 +882,7 @@ xloadfont(Font *f, FcPattern *pattern)
|
||||
if ((XftPatternGetInteger(f->match->pattern, "weight", 0,
|
||||
&haveattr) != XftResultMatch) || haveattr != wantattr) {
|
||||
f->badweight = 1;
|
||||
fputs("st: font weight does not match\n", stderr);
|
||||
fputs("font weight does not match\n", stderr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -906,14 +910,13 @@ xloadfonts(char *fontstr, double fontsize)
|
||||
FcPattern *pattern;
|
||||
double fontval;
|
||||
|
||||
if (fontstr[0] == '-') {
|
||||
if (fontstr[0] == '-')
|
||||
pattern = XftXlfdParse(fontstr, False, False);
|
||||
} else {
|
||||
else
|
||||
pattern = FcNameParse((FcChar8 *)fontstr);
|
||||
}
|
||||
|
||||
if (!pattern)
|
||||
die("st: can't open font %s\n", fontstr);
|
||||
die("can't open font %s\n", fontstr);
|
||||
|
||||
if (fontsize > 1) {
|
||||
FcPatternDel(pattern, FC_PIXEL_SIZE);
|
||||
@ -939,7 +942,7 @@ xloadfonts(char *fontstr, double fontsize)
|
||||
}
|
||||
|
||||
if (xloadfont(&dc.font, pattern))
|
||||
die("st: can't open font %s\n", fontstr);
|
||||
die("can't open font %s\n", fontstr);
|
||||
|
||||
if (usedfontsize < 0) {
|
||||
FcPatternGetDouble(dc.font.match->pattern,
|
||||
@ -956,17 +959,17 @@ xloadfonts(char *fontstr, double fontsize)
|
||||
FcPatternDel(pattern, FC_SLANT);
|
||||
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
|
||||
if (xloadfont(&dc.ifont, pattern))
|
||||
die("st: can't open font %s\n", fontstr);
|
||||
die("can't open font %s\n", fontstr);
|
||||
|
||||
FcPatternDel(pattern, FC_WEIGHT);
|
||||
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
|
||||
if (xloadfont(&dc.ibfont, pattern))
|
||||
die("st: can't open font %s\n", fontstr);
|
||||
die("can't open font %s\n", fontstr);
|
||||
|
||||
FcPatternDel(pattern, FC_SLANT);
|
||||
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
|
||||
if (xloadfont(&dc.bfont, pattern))
|
||||
die("st: can't open font %s\n", fontstr);
|
||||
die("can't open font %s\n", fontstr);
|
||||
|
||||
FcPatternDestroy(pattern);
|
||||
}
|
||||
@ -1003,13 +1006,13 @@ xinit(int cols, int rows)
|
||||
XColor xmousefg, xmousebg;
|
||||
|
||||
if (!(xw.dpy = XOpenDisplay(NULL)))
|
||||
die("Can't open display\n");
|
||||
die("can't open display\n");
|
||||
xw.scr = XDefaultScreen(xw.dpy);
|
||||
xw.vis = XDefaultVisual(xw.dpy, xw.scr);
|
||||
|
||||
/* font */
|
||||
if (!FcInit())
|
||||
die("Could not init fontconfig.\n");
|
||||
die("could not init fontconfig.\n");
|
||||
|
||||
usedfont = (opt_font == NULL)? font : opt_font;
|
||||
xloadfonts(usedfont, 0);
|
||||
@ -1925,7 +1928,7 @@ main(int argc, char *argv[])
|
||||
opt_embed = EARGF(usage());
|
||||
break;
|
||||
case 'v':
|
||||
die("%s " VERSION " (c) 2010-2016 st engineers\n", argv0);
|
||||
die("%s " VERSION "\n", argv0);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
|
Reference in New Issue
Block a user