1
0
mirror of git://git.suckless.org/st synced 2025-08-04 06:02:15 -07:00

31 Commits
0.8 ... 0.8.2

Author SHA1 Message Date
Hiltjo Posthuma
75f92eb348 bump version to 0.8.2 2019-02-09 12:48:39 +01:00
Hiltjo Posthuma
3be4cf11d7 config: add Shift+Insert as selpaste() again
This was changed before in:
commit 20f713548d on Wed Jan 25 19:17:38 2017
2019-01-10 18:16:17 +01:00
Paride Legovini
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
Paride Legovini
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
Hiltjo Posthuma
7e19e11676 Makefile: fix dependencies on config.h
patch by Younes Khoudli (changed slightly). Thanks
2019-01-04 12:33:01 +01:00
Lauri Tirkkonen
096b125db7 output child WEXITSTATUS/WTERMSIG on abnormal termination 2018-12-11 18:36:02 +01:00
Hiltjo Posthuma
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
Hiltjo Posthuma
b4d68d4daa st: small typofix in comment 2018-11-04 14:30:56 +01:00
Hiltjo Posthuma
30ec9a3dc3 small code-style fix 2018-09-11 19:06:35 +02:00
Quentin Rameau
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
Hiltjo Posthuma
4f4bccd162 Revert "Simplify cursor color handling"
This reverts commit 1911c9274d.
2018-07-17 20:01:58 +02:00
Hiltjo Posthuma
8ed7a4b3b7 Revert "Make cursor follow text color"
This reverts commit b51bcd5553.
2018-07-17 20:01:57 +02:00
Hiltjo Posthuma
732be223ee Revert "Fix crash when cursor color is truecolor"
This reverts commit 5535c1f04c.
2018-07-17 20:01:54 +02:00
Jules Maselbas
5535c1f04c Fix crash when cursor color is truecolor
Reported-by: Ivan Tham <pickfire@riseup.net>
2018-07-15 18:16:52 +02:00
Jules Maselbas
b51bcd5553 Make cursor follow text color 2018-07-14 12:49:37 +02:00
Jules Maselbas
1911c9274d Simplify cursor color handling 2018-07-14 12:49:35 +02:00
Jules Maselbas
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
Hiltjo Posthuma
dc3b5babf1 config.mk: remove extra newline before EOF 2018-06-02 17:11:14 +02:00
Hiltjo Posthuma
235a783e03 code-style for pledge(2)
feedback from Klemens, thanks
2018-05-25 13:04:09 +02:00
Hiltjo Posthuma
30ce2cc002 Pledge on OpenBSD 2018-05-25 11:59:28 +02:00
Hiltjo Posthuma
041912a791 error message style and use strerror in a few places 2018-03-29 18:30:05 +02:00
Hiltjo Posthuma
bd3f7fd842 st -v: remove years and copyright text 2018-03-29 18:18:30 +02:00
Daniel Tameling
74cff67bd7 set sel.alt in selstart instead of selextend 2018-03-29 18:15:29 +02:00
Hiltjo Posthuma
6f0f2b7ec3 bump version to 0.8.1 2018-03-20 21:29:10 +01:00
Hiltjo Posthuma
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
Hiltjo Posthuma
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
Hiltjo Posthuma
6ac8c8aa50 selextend: clarify: !sel.mode == SEL_IDLE 2018-03-17 13:48:29 +01:00
Hiltjo Posthuma
5345db3c9b clipcopy: no need to check for free(NULL), set to NULL after free 2018-03-17 13:48:10 +01:00
Hiltjo Posthuma
7648697f71 minor code-style: whitespace fixes 2018-03-16 16:45:58 +01:00
Quentin Rameau
0b507bb731 Fix title initialization 2018-03-16 16:44:30 +01:00
Quentin Rameau
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 $< $(CC) $(STCFLAGS) -c $<
st.o: config.h st.h win.h 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 $(OBJ): config.h config.mk

22
arg.h
View File

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

View File

@@ -176,8 +176,8 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_C, clipcopy, {.i = 0} }, { TERMMOD, XK_C, clipcopy, {.i = 0} },
{ TERMMOD, XK_V, clippaste, {.i = 0} }, { TERMMOD, XK_V, clippaste, {.i = 0} },
{ TERMMOD, XK_Y, selpaste, {.i = 0} }, { TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
{ TERMMOD, XK_I, iso14755, {.i = 0} },
}; };
/* /*

View File

@@ -1,5 +1,5 @@
# st version # st version
VERSION = 0.8 VERSION = 0.8.2
# Customize below to fit your system # Customize below to fit your system
@@ -10,19 +10,26 @@ MANPREFIX = $(PREFIX)/share/man
X11INC = /usr/X11R6/include X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib X11LIB = /usr/X11R6/lib
PKG_CONFIG = pkg-config
# includes and libs # includes and libs
INCS = -I$(X11INC) \ INCS = -I$(X11INC) \
`pkg-config --cflags fontconfig` \ `$(PKG_CONFIG) --cflags fontconfig` \
`pkg-config --cflags freetype2` `$(PKG_CONFIG) --cflags freetype2`
LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \ LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
`pkg-config --libs fontconfig` \ `$(PKG_CONFIG) --libs fontconfig` \
`pkg-config --libs freetype2` `$(PKG_CONFIG) --libs freetype2`
# flags # flags
CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
STCFLAGS = $(INCS) $(CPPFLAGS) $(CFLAGS) STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS)
STLDFLAGS = $(LIBS) $(LDFLAGS) 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 # compiler and linker
# CC = c99 # CC = c99

4
st.1
View File

@@ -159,10 +159,6 @@ Copy the selected text to the clipboard selection.
.TP .TP
.B Ctrl-Shift-v .B Ctrl-Shift-v
Paste from the clipboard selection. 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 .SH CUSTOMIZATION
.B st .B st
can be customized by creating a custom config.h and (re)compiling the source can be customized by creating a custom config.h and (re)compiling the source

71
st.c
View File

@@ -38,15 +38,11 @@
/* macros */ /* macros */
#define IS_SET(flag) ((term.mode & (flag)) != 0) #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 ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177')
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) #define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
#define ISDELIM(u) (utf8strchr(worddelimiters, u) != NULL) #define ISDELIM(u) (utf8strchr(worddelimiters, u) != NULL)
/* constants */
#define ISO14755CMD "dmenu -w \"$WINDOWID\" -p codepoint: </dev/null"
enum term_mode { enum term_mode {
MODE_WRAP = 1 << 0, MODE_WRAP = 1 << 0,
MODE_INSERT = 1 << 1, MODE_INSERT = 1 << 1,
@@ -256,10 +252,10 @@ xwrite(int fd, const char *s, size_t len)
void * void *
xmalloc(size_t len) xmalloc(size_t len)
{ {
void *p = malloc(len); void *p;
if (!p) if (!(p = malloc(len)))
die("Out of memory\n"); die("malloc: %s\n", strerror(errno));
return p; return p;
} }
@@ -268,7 +264,7 @@ void *
xrealloc(void *p, size_t len) xrealloc(void *p, size_t len)
{ {
if ((p = realloc(p, len)) == NULL) if ((p = realloc(p, len)) == NULL)
die("Out of memory\n"); die("realloc: %s\n", strerror(errno));
return p; return p;
} }
@@ -277,7 +273,7 @@ char *
xstrdup(char *s) xstrdup(char *s)
{ {
if ((s = strdup(s)) == NULL) if ((s = strdup(s)) == NULL)
die("Out of memory\n"); die("strdup: %s\n", strerror(errno));
return s; return s;
} }
@@ -446,6 +442,7 @@ selstart(int col, int row, int snap)
selclear(); selclear();
sel.mode = SEL_EMPTY; sel.mode = SEL_EMPTY;
sel.type = SEL_REGULAR; sel.type = SEL_REGULAR;
sel.alt = IS_SET(MODE_ALTSCREEN);
sel.snap = snap; sel.snap = snap;
sel.oe.x = sel.ob.x = col; sel.oe.x = sel.ob.x = col;
sel.oe.y = sel.ob.y = row; 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; int oldey, oldex, oldsby, oldsey, oldtype;
if (!sel.mode) if (sel.mode == SEL_IDLE)
return; return;
if (done && sel.mode == SEL_EMPTY) { if (done && sel.mode == SEL_EMPTY) {
selclear(); selclear();
@@ -474,7 +471,6 @@ selextend(int col, int row, int type, int done)
oldsey = sel.ne.y; oldsey = sel.ne.y;
oldtype = sel.type; oldtype = sel.type;
sel.alt = IS_SET(MODE_ALTSCREEN);
sel.oe.x = col; sel.oe.x = col;
sel.oe.y = row; sel.oe.y = row;
selnormalize(); selnormalize();
@@ -687,7 +683,7 @@ execsh(char *cmd, char **args)
errno = 0; errno = 0;
if ((pw = getpwuid(getuid())) == NULL) { if ((pw = getpwuid(getuid())) == NULL) {
if (errno) if (errno)
die("getpwuid:%s\n", strerror(errno)); die("getpwuid: %s\n", strerror(errno));
else else
die("who are you?\n"); die("who are you?\n");
} }
@@ -730,17 +726,18 @@ sigchld(int a)
pid_t p; pid_t p;
if ((p = waitpid(pid, &stat, WNOHANG)) < 0) 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) if (pid != p)
return; return;
if (!WIFEXITED(stat) || WEXITSTATUS(stat)) if (WIFEXITED(stat) && WEXITSTATUS(stat))
die("child finished with error '%d'\n", 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); exit(0);
} }
void void
stty(char **args) stty(char **args)
{ {
@@ -782,7 +779,8 @@ ttynew(char *line, char *cmd, char *out, char **args)
if (line) { if (line) {
if ((cmdfd = open(line, O_RDWR)) < 0) 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); dup2(cmdfd, 0);
stty(args); stty(args);
return cmdfd; return cmdfd;
@@ -794,7 +792,7 @@ ttynew(char *line, char *cmd, char *out, char **args)
switch (pid = fork()) { switch (pid = fork()) {
case -1: case -1:
die("fork failed\n"); die("fork failed: %s\n", strerror(errno));
break; break;
case 0: case 0:
close(iofd); close(iofd);
@@ -806,9 +804,17 @@ ttynew(char *line, char *cmd, char *out, char **args)
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno)); die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
close(s); close(s);
close(m); close(m);
#ifdef __OpenBSD__
if (pledge("stdio getpw proc exec", NULL) == -1)
die("pledge\n");
#endif
execsh(cmd, args); execsh(cmd, args);
break; break;
default: default:
#ifdef __OpenBSD__
if (pledge("stdio rpath tty proc", NULL) == -1)
die("pledge\n");
#endif
close(s); close(s);
cmdfd = m; cmdfd = m;
signal(SIGCHLD, sigchld); signal(SIGCHLD, sigchld);
@@ -827,7 +833,7 @@ ttyread(void)
/* append read bytes to unprocessed bytes */ /* append read bytes to unprocessed bytes */
if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0) 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; buflen += ret;
written = twrite(buf, buflen, 0); written = twrite(buf, buflen, 0);
@@ -1448,7 +1454,8 @@ tsetattr(int *attr, int l)
} else { } else {
fprintf(stderr, fprintf(stderr,
"erresc(default): gfx attr %d unknown\n", "erresc(default): gfx attr %d unknown\n",
attr[i]), csidump(); attr[i]);
csidump();
} }
break; 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 void
toggleprinter(const Arg *arg) toggleprinter(const Arg *arg)
{ {
@@ -2279,7 +2264,7 @@ eschandle(uchar ascii)
case 'Z': /* DECID -- Identify Terminal */ case 'Z': /* DECID -- Identify Terminal */
ttywrite(vtiden, strlen(vtiden), 0); ttywrite(vtiden, strlen(vtiden), 0);
break; break;
case 'c': /* RIS -- Reset to inital state */ case 'c': /* RIS -- Reset to initial state */
treset(); treset();
resettitle(); resettitle();
xloadcols(); xloadcols();

1
st.h
View File

@@ -80,7 +80,6 @@ void die(const char *, ...);
void redraw(void); void redraw(void);
void draw(void); void draw(void);
void iso14755(const Arg *);
void printscreen(const Arg *); void printscreen(const Arg *);
void printsel(const Arg *); void printsel(const Arg *);
void sendbreak(const Arg *); void sendbreak(const Arg *);

64
x.c
View File

@@ -245,8 +245,8 @@ clipcopy(const Arg *dummy)
{ {
Atom clipboard; Atom clipboard;
if (xsel.clipboard != NULL)
free(xsel.clipboard); free(xsel.clipboard);
xsel.clipboard = NULL;
if (xsel.primary != NULL) { if (xsel.primary != NULL) {
xsel.clipboard = xstrdup(xsel.primary); xsel.clipboard = xstrdup(xsel.primary);
@@ -618,6 +618,9 @@ selrequest(XEvent *e)
void void
setsel(char *str, Time t) setsel(char *str, Time t)
{ {
if (!str)
return;
free(xsel.primary); free(xsel.primary);
xsel.primary = str; xsel.primary = str;
@@ -669,6 +672,8 @@ cresize(int width, int height)
col = (win.w - 2 * borderpx) / win.cw; col = (win.w - 2 * borderpx) / win.cw;
row = (win.h - 2 * borderpx) / win.ch; row = (win.h - 2 * borderpx) / win.ch;
col = MAX(1, col);
row = MAX(1, row);
tresize(col, row); tresize(col, row);
xresize(col, row); xresize(col, row);
@@ -678,8 +683,8 @@ cresize(int width, int height)
void void
xresize(int col, int row) xresize(int col, int row)
{ {
win.tw = MAX(1, col * win.cw); win.tw = col * win.cw;
win.th = MAX(1, row * win.ch); win.th = row * win.ch;
XFreePixmap(xw.dpy, xw.buf); XFreePixmap(xw.dpy, xw.buf);
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
@@ -728,20 +733,20 @@ xloadcols(void)
static int loaded; static int loaded;
Color *cp; Color *cp;
dc.collen = MAX(LEN(colorname), 256);
dc.col = xmalloc(dc.collen * sizeof(Color));
if (loaded) { if (loaded) {
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp) for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
XftColorFree(xw.dpy, xw.vis, xw.cmap, 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++) for (i = 0; i < dc.collen; i++)
if (!xloadcolor(i, NULL, &dc.col[i])) { if (!xloadcolor(i, NULL, &dc.col[i])) {
if (colorname[i]) if (colorname[i])
die("Could not allocate color '%s'\n", colorname[i]); die("could not allocate color '%s'\n", colorname[i]);
else else
die("Could not allocate color %d\n", i); die("could not allocate color %d\n", i);
} }
loaded = 1; loaded = 1;
} }
@@ -785,15 +790,17 @@ xhints(void)
sizeh = XAllocSizeHints(); sizeh = XAllocSizeHints();
sizeh->flags = PSize | PResizeInc | PBaseSize; sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize;
sizeh->height = win.h; sizeh->height = win.h;
sizeh->width = win.w; sizeh->width = win.w;
sizeh->height_inc = win.ch; sizeh->height_inc = win.ch;
sizeh->width_inc = win.cw; sizeh->width_inc = win.cw;
sizeh->base_height = 2 * borderpx; sizeh->base_height = 2 * borderpx;
sizeh->base_width = 2 * borderpx; sizeh->base_width = 2 * borderpx;
sizeh->min_height = win.ch + 2 * borderpx;
sizeh->min_width = win.cw + 2 * borderpx;
if (xw.isfixed) { if (xw.isfixed) {
sizeh->flags |= PMaxSize | PMinSize; sizeh->flags |= PMaxSize;
sizeh->min_width = sizeh->max_width = win.w; sizeh->min_width = sizeh->max_width = win.w;
sizeh->min_height = sizeh->max_height = win.h; sizeh->min_height = sizeh->max_height = win.h;
} }
@@ -866,7 +873,7 @@ xloadfont(Font *f, FcPattern *pattern)
if ((XftPatternGetInteger(f->match->pattern, "slant", 0, if ((XftPatternGetInteger(f->match->pattern, "slant", 0,
&haveattr) != XftResultMatch) || haveattr < wantattr) { &haveattr) != XftResultMatch) || haveattr < wantattr) {
f->badslant = 1; 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, if ((XftPatternGetInteger(f->match->pattern, "weight", 0,
&haveattr) != XftResultMatch) || haveattr != wantattr) { &haveattr) != XftResultMatch) || haveattr != wantattr) {
f->badweight = 1; 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; FcPattern *pattern;
double fontval; double fontval;
if (fontstr[0] == '-') { if (fontstr[0] == '-')
pattern = XftXlfdParse(fontstr, False, False); pattern = XftXlfdParse(fontstr, False, False);
} else { else
pattern = FcNameParse((FcChar8 *)fontstr); pattern = FcNameParse((FcChar8 *)fontstr);
}
if (!pattern) if (!pattern)
die("st: can't open font %s\n", fontstr); die("can't open font %s\n", fontstr);
if (fontsize > 1) { if (fontsize > 1) {
FcPatternDel(pattern, FC_PIXEL_SIZE); FcPatternDel(pattern, FC_PIXEL_SIZE);
@@ -936,7 +942,7 @@ xloadfonts(char *fontstr, double fontsize)
} }
if (xloadfont(&dc.font, pattern)) 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) { if (usedfontsize < 0) {
FcPatternGetDouble(dc.font.match->pattern, FcPatternGetDouble(dc.font.match->pattern,
@@ -953,17 +959,17 @@ xloadfonts(char *fontstr, double fontsize)
FcPatternDel(pattern, FC_SLANT); FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC); FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
if (xloadfont(&dc.ifont, pattern)) 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); FcPatternDel(pattern, FC_WEIGHT);
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
if (xloadfont(&dc.ibfont, pattern)) 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); FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN); FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
if (xloadfont(&dc.bfont, pattern)) if (xloadfont(&dc.bfont, pattern))
die("st: can't open font %s\n", fontstr); die("can't open font %s\n", fontstr);
FcPatternDestroy(pattern); FcPatternDestroy(pattern);
} }
@@ -1000,13 +1006,13 @@ xinit(int cols, int rows)
XColor xmousefg, xmousebg; XColor xmousefg, xmousebg;
if (!(xw.dpy = XOpenDisplay(NULL))) if (!(xw.dpy = XOpenDisplay(NULL)))
die("Can't open display\n"); die("can't open display\n");
xw.scr = XDefaultScreen(xw.dpy); xw.scr = XDefaultScreen(xw.dpy);
xw.vis = XDefaultVisual(xw.dpy, xw.scr); xw.vis = XDefaultVisual(xw.dpy, xw.scr);
/* font */ /* font */
if (!FcInit()) if (!FcInit())
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, 0);
@@ -1492,7 +1498,7 @@ void
xsettitle(char *p) xsettitle(char *p)
{ {
XTextProperty prop; XTextProperty prop;
DEFAULT(p, "st"); DEFAULT(p, opt_title);
Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
&prop); &prop);
@@ -1922,19 +1928,19 @@ main(int argc, char *argv[])
opt_embed = EARGF(usage()); opt_embed = EARGF(usage());
break; break;
case 'v': case 'v':
die("%s " VERSION " (c) 2010-2016 st engineers\n", argv0); die("%s " VERSION "\n", argv0);
break; break;
default: default:
usage(); usage();
} ARGEND; } ARGEND;
run: run:
if (argc > 0) { if (argc > 0) /* eat all remaining arguments */
/* eat all remaining arguments */
opt_cmd = argv; 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, ""); setlocale(LC_CTYPE, "");
XSetLocaleModifiers(""); XSetLocaleModifiers("");
cols = MAX(cols, 1); cols = MAX(cols, 1);