31 Commits
0.8 ... 0.8.2

Author SHA1 Message Date
75f92eb348 bump version to 0.8.2 2019-02-09 12:48:39 +01:00
3be4cf11d7 config: add Shift+Insert as selpaste() again
This was changed before in:
commit 20f713548de451b67db3306cf8cf7b2f38fee05c on Wed Jan 25 19:17:38 2017
2019-01-10 18:16:17 +01:00
16d98738e7 Let the user specify CPPFLAGS
This complements the work done in d4928ed, allowing the user to specify
the preprocessor flags with the CPPFLAGS environment variable. This is
useful for example to specify preprocessor macros with -D.

CFLAGS could be used instead, but CPPFLAGS is more correct and is expected
to be honored in some cases. For example, the helper scripts to build
Debian packages make use of CPPFLAGS, but the variable is currently
being ignored unless manually appended to CFLAGS.
2019-01-10 18:13:13 +01:00
e23acb9188 Set the path of pkg-config in a variable instead of hardcoding it
In this way the path of pkg-config can be overridden from the command
line. This is useful for example when cross-compiling.
2019-01-04 16:00:54 +01:00
7e19e11676 Makefile: fix dependencies on config.h
patch by Younes Khoudli (changed slightly). Thanks
2019-01-04 12:33:01 +01:00
096b125db7 output child WEXITSTATUS/WTERMSIG on abnormal termination 2018-12-11 18:36:02 +01:00
d7bf023b2f fix memory leak in xloadcols()
reported by Avi Halachmi (:avih)" <avihpit@yahoo.com>

patch slightly changed by me.
2018-11-04 14:35:07 +01:00
b4d68d4daa st: small typofix in comment 2018-11-04 14:30:56 +01:00
30ec9a3dc3 small code-style fix 2018-09-11 19:06:35 +02:00
67d0cb65d0 Remove the ISO 14755 feature
And move it to the patches section.
Keeping it would force to add an exec pledge on OpenBSD, and some
people think it's bloated, so bye!
2018-09-11 19:05:55 +02:00
4f4bccd162 Revert "Simplify cursor color handling"
This reverts commit 1911c9274d9b03f3d7999c6ce26e2d5169642d26.
2018-07-17 20:01:58 +02:00
8ed7a4b3b7 Revert "Make cursor follow text color"
This reverts commit b51bcd5553af3db394014efbd78acf7828fa48ff.
2018-07-17 20:01:57 +02:00
732be223ee Revert "Fix crash when cursor color is truecolor"
This reverts commit 5535c1f04c665c05faff2a65d5558246b7748d49.
2018-07-17 20:01:54 +02:00
5535c1f04c Fix crash when cursor color is truecolor
Reported-by: Ivan Tham <pickfire@riseup.net>
2018-07-15 18:16:52 +02:00
b51bcd5553 Make cursor follow text color 2018-07-14 12:49:37 +02:00
1911c9274d Simplify cursor color handling 2018-07-14 12:49:35 +02:00
29f341da7c Fix crash on resize
Prevent to realloc xw.specbuc with a negative number of col.
Add proper hints for the minimal size, for one character.
2018-06-30 20:51:46 +02:00
dc3b5babf1 config.mk: remove extra newline before EOF 2018-06-02 17:11:14 +02:00
235a783e03 code-style for pledge(2)
feedback from Klemens, thanks
2018-05-25 13:04:09 +02:00
30ce2cc002 Pledge on OpenBSD 2018-05-25 11:59:28 +02:00
041912a791 error message style and use strerror in a few places 2018-03-29 18:30:05 +02:00
bd3f7fd842 st -v: remove years and copyright text 2018-03-29 18:18:30 +02:00
74cff67bd7 set sel.alt in selstart instead of selextend 2018-03-29 18:15:29 +02:00
6f0f2b7ec3 bump version to 0.8.1 2018-03-20 21:29:10 +01:00
f4020b2cc4 fix regression by selecting clipboard text
"restore the old behaviour that the primary doesn't get deleted by a simple
left click"

Patch by Daniel Tameling <tamelingdaniel@gmail.com>, thanks!
2018-03-20 21:25:30 +01:00
a5a928bfc1 don't modify argv, use a counter
on some platforms (OpenBSD) this changes the exposed argv in tools using
the kvm_* interface, such as ps and pgrep.
2018-03-20 21:22:27 +01:00
6ac8c8aa50 selextend: clarify: !sel.mode == SEL_IDLE 2018-03-17 13:48:29 +01:00
5345db3c9b clipcopy: no need to check for free(NULL), set to NULL after free 2018-03-17 13:48:10 +01:00
7648697f71 minor code-style: whitespace fixes 2018-03-16 16:45:58 +01:00
0b507bb731 Fix title initialization 2018-03-16 16:44:30 +01:00
e7ef3c4ce9 Fix regression from 69e32a6 when setting title. 2018-03-16 16:44:30 +01:00
8 changed files with 94 additions and 99 deletions

View File

@ -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

22
arg.h
View File

@ -21,28 +21,30 @@ extern char *argv0;
argc--;\
break;\
}\
for (brk_ = 0, argv[0]++, argv_ = argv;\
argv[0][0] && !brk_;\
argv[0]++) {\
int i_;\
for (i_ = 1, brk_ = 0, argv_ = argv;\
argv[0][i_] && !brk_;\
i_++) {\
if (argv_ != argv)\
break;\
argc_ = argv[0][0];\
argc_ = argv[0][i_];\
switch (argc_)
#define ARGEND }\
}
#define ARGC() argc_
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
#define EARGF(x) ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
((x), abort(), (char *)0) :\
(brk_ = 1, (argv[0][1] != '\0')?\
(&argv[0][1]) :\
(brk_ = 1, (argv[0][i_+1] != '\0')?\
(&argv[0][i_+1]) :\
(argc--, argv++, argv[0])))
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
#define ARGF() ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
(char *)0 :\
(brk_ = 1, (argv[0][1] != '\0')?\
(&argv[0][1]) :\
(brk_ = 1, (argv[0][i_+1] != '\0')?\
(&argv[0][i_+1]) :\
(argc--, argv++, argv[0])))
#endif

View File

@ -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} },
};
/*

View File

@ -1,5 +1,5 @@
# st version
VERSION = 0.8
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
View File

@ -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

73
st.c
View File

@ -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;
@ -461,7 +458,7 @@ selextend(int col, int row, int type, int done)
{
int oldey, oldex, oldsby, oldsey, oldtype;
if (!sel.mode)
if (sel.mode == SEL_IDLE)
return;
if (done && sel.mode == SEL_EMPTY) {
selclear();
@ -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,17 +726,18 @@ 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);
}
void
stty(char **args)
{
@ -762,7 +759,7 @@ stty(char **args)
}
*q = '\0';
if (system(cmd) != 0)
perror("Couldn't call stty");
perror("Couldn't call stty");
}
int
@ -782,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;
@ -794,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);
@ -806,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);
@ -827,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);
@ -1448,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;
}
@ -1973,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)
{
@ -2279,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
View File

@ -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 *);

66
x.c
View File

@ -245,8 +245,8 @@ clipcopy(const Arg *dummy)
{
Atom clipboard;
if (xsel.clipboard != NULL)
free(xsel.clipboard);
free(xsel.clipboard);
xsel.clipboard = NULL;
if (xsel.primary != NULL) {
xsel.clipboard = xstrdup(xsel.primary);
@ -618,6 +618,9 @@ selrequest(XEvent *e)
void
setsel(char *str, Time t)
{
if (!str)
return;
free(xsel.primary);
xsel.primary = str;
@ -669,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);
@ -678,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,
@ -728,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;
}
@ -785,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;
}
@ -866,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);
}
}
@ -875,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);
}
}
@ -903,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);
@ -936,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,
@ -953,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);
}
@ -1000,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);
@ -1492,7 +1498,7 @@ void
xsettitle(char *p)
{
XTextProperty prop;
DEFAULT(p, "st");
DEFAULT(p, opt_title);
Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
&prop);
@ -1922,19 +1928,19 @@ 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();
} ARGEND;
run:
if (argc > 0) {
/* eat all remaining arguments */
if (argc > 0) /* eat all remaining arguments */
opt_cmd = argv;
if (!opt_title && !opt_line)
opt_title = basename(xstrdup(argv[0]));
}
if (!opt_title)
opt_title = (opt_line || !opt_cmd) ? "st" : opt_cmd[0];
setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");
cols = MAX(cols, 1);