This commit is contained in:
WanderingPenwing 2024-07-29 12:54:38 +02:00
parent 73f6a950ad
commit dd0b463434
6 changed files with 64 additions and 86 deletions

View file

@ -1,14 +1,12 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
void clearhistory(const Arg *arg);
/* /*
* appearance * appearance
* *
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/ */
static char *font = "DejaVu Sans Mono:pixelsize=16:antialias=true:autohint=true"; static char *font = "Mononoki Nerd Font:pixelsize=20:antialias=true:autohint=true";
static int borderpx = 2; static int borderpx = 16;
/* /*
* What program is execed by st depends of these precedence rules: * What program is execed by st depends of these precedence rules:
@ -100,30 +98,30 @@ static const int alpha = 0xff;
/* 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 */
"#3B4252", /* nord1 */ "#222222",
"#BF616A", /* nord11 */ "#FF5555",
"#A3BE8C", /* nord14 */ "#5FD38D",
"#EBCB8B", /* nord13 */ "#FF9955",
"#81A1C1", /* nord9 */ "#3771C8",
"#B48EAD", /* nord15 */ "#BC5FD3",
"#88C0D0", /* nord8 */ "#5FD3BC",
"#E5E9F0", /* nord5 */ "#999999",
/* 8 bright colors */ /* 8 bright colors */
"#4C566A", /* nord3 */ "#666666",
"#D08770", /* nord12 */ "#FF8080",
"#8FBCBB", /* nord7 */ "#87DEAA",
"#EBCB8B", /* nord13 */ "#FFB380",
"#5E81AC", /* nord10 */ "#5F8DD3",
"#B48EAD", /* nord15 (same as normal magenta) */ "#CD87DE",
"#88C0D0", /* nord8 (same as normal cyan) */ "#87DECD",
"#ECEFF4", /* nord6 */ "#CCCCCC",
[255] = 0, [255] = 0,
/* more colors can be added after 255 to use with DefaultXX */ /* more colors can be added after 255 to use with DefaultXX */
"#D8DEE9", /* nord4 (default foreground colour) */ "#CCCCCC", /* nord4 (default foreground colour) */
"#2E3440", /* nord0 (default background colour) */ "#222222", /* nord0 (default background colour) */
}; };
@ -201,9 +199,7 @@ 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} },
{ ControlMask, XK_L, clearhistory, {.i = 0} },
}; };
/* /*

BIN
st

Binary file not shown.

19
st.c
View file

@ -225,8 +225,6 @@ static char base64dec_getc(const char **);
static ssize_t xwrite(int, const char *, size_t); static ssize_t xwrite(int, const char *, size_t);
void clearhistory(const Arg *arg);
/* Globals */ /* Globals */
static Term term; static Term term;
static Selection sel; static Selection sel;
@ -241,23 +239,6 @@ static const uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
static const Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; static const Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000};
static const Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; static const Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
void
clearhistory(const Arg *arg) {
// Clear the visible screen
tclearregion(0, 0, term.col-1, term.row-1);
tsetdirt(0, term.row);
// Clear the scrollback buffer
term.scr = 0;
term.histi = 0;
for (int i = 0; i < HISTSIZE; i++) {
memset(term.hist[i], 0, term.col * sizeof(Line));
}
// Redraw to apply changes
tfulldirt();
}
ssize_t ssize_t
xwrite(int fd, const char *s, size_t len) xwrite(int fd, const char *s, size_t len)
{ {

BIN
st.o

Binary file not shown.

87
x.c
View file

@ -41,13 +41,13 @@ typedef struct {
uint mask; uint mask;
char *s; char *s;
/* three-valued logic variables: 0 indifferent, 1 on, -1 off */ /* three-valued logic variables: 0 indifferent, 1 on, -1 off */
signed char appkey; /* application keypad */ signed char appkey; /* application keypad */
signed char appcursor; /* application cursor */ signed char appcursor; /* application cursor */
} Key; } Key;
/* X modifiers */ /* X modifiers */
#define XK_ANY_MOD UINT_MAX #define XK_ANY_MOD UINT_MAX
#define XK_NO_MOD 0 #define XK_NO_MOD 0
#define XK_SWITCH_MOD (1<<13|1<<14) #define XK_SWITCH_MOD (1<<13|1<<14)
/* function definitions used in config.h */ /* function definitions used in config.h */
@ -247,7 +247,7 @@ static char *opt_class = NULL;
static char **opt_cmd = NULL; static char **opt_cmd = NULL;
static char *opt_embed = NULL; static char *opt_embed = NULL;
static char *opt_font = NULL; static char *opt_font = NULL;
static char *opt_io = NULL; static char *opt_io = NULL;
static char *opt_line = NULL; static char *opt_line = NULL;
static char *opt_name = NULL; static char *opt_name = NULL;
static char *opt_title = NULL; static char *opt_title = NULL;
@ -273,6 +273,7 @@ void
clippaste(const Arg *dummy) clippaste(const Arg *dummy)
{ {
Atom clipboard; Atom clipboard;
printf("test");
clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0); clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
XConvertSelection(xw.dpy, clipboard, xsel.xtarget, clipboard, XConvertSelection(xw.dpy, clipboard, xsel.xtarget, clipboard,
@ -415,8 +416,8 @@ mousereport(XEvent *e)
if (!IS_SET(MODE_MOUSEX10)) { if (!IS_SET(MODE_MOUSEX10)) {
code += ((state & ShiftMask ) ? 4 : 0) code += ((state & ShiftMask ) ? 4 : 0)
+ ((state & Mod1Mask ) ? 8 : 0) /* meta key: alt */ + ((state & Mod1Mask ) ? 8 : 0) /* meta key: alt */
+ ((state & ControlMask) ? 16 : 0); + ((state & ControlMask) ? 16 : 0);
} }
if (IS_SET(MODE_MOUSESGR)) { if (IS_SET(MODE_MOUSESGR)) {
@ -437,11 +438,11 @@ uint
buttonmask(uint button) buttonmask(uint button)
{ {
return button == Button1 ? Button1Mask return button == Button1 ? Button1Mask
: button == Button2 ? Button2Mask : button == Button2 ? Button2Mask
: button == Button3 ? Button3Mask : button == Button3 ? Button3Mask
: button == Button4 ? Button4Mask : button == Button4 ? Button4Mask
: button == Button5 ? Button5Mask : button == Button5 ? Button5Mask
: 0; : 0;
} }
int int
@ -454,9 +455,9 @@ mouseaction(XEvent *e, uint release)
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) { for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
if (ms->release == release && if (ms->release == release &&
ms->button == e->xbutton.button && ms->button == e->xbutton.button &&
(match(ms->mod, state) || /* exact or forced */ (match(ms->mod, state) || /* exact or forced */
match(ms->mod, state & ~forcemousemod))) { match(ms->mod, state & ~forcemousemod))) {
ms->func(&(ms->arg)); ms->func(&(ms->arg));
return 1; return 1;
} }
@ -782,7 +783,7 @@ xloadcolor(int i, const char *name, Color *ncolor)
color.green = color.blue = color.red; color.green = color.blue = color.red;
} }
return XftColorAllocValue(xw.dpy, xw.vis, return XftColorAllocValue(xw.dpy, xw.vis,
xw.cmap, &color, ncolor); xw.cmap, &color, ncolor);
} else } else
name = colorname[i]; name = colorname[i];
} }
@ -860,7 +861,7 @@ void
xhints(void) xhints(void)
{ {
XClassHint class = {opt_name ? opt_name : termname, XClassHint class = {opt_name ? opt_name : termname,
opt_class ? opt_class : termname}; opt_class ? opt_class : termname};
XWMHints wm = {.flags = InputHint, .input = 1}; XWMHints wm = {.flags = InputHint, .input = 1};
XSizeHints *sizeh; XSizeHints *sizeh;
@ -941,22 +942,22 @@ xloadfont(Font *f, FcPattern *pattern)
} }
if ((XftPatternGetInteger(pattern, "slant", 0, &wantattr) == if ((XftPatternGetInteger(pattern, "slant", 0, &wantattr) ==
XftResultMatch)) { XftResultMatch)) {
/* /*
* Check if xft was unable to find a font with the appropriate * Check if xft was unable to find a font with the appropriate
* slant but gave us one anyway. Try to mitigate. * slant but gave us one anyway. Try to mitigate.
*/ */
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("font slant does not match\n", stderr); fputs("font slant does not match\n", stderr);
} }
} }
if ((XftPatternGetInteger(pattern, "weight", 0, &wantattr) == if ((XftPatternGetInteger(pattern, "weight", 0, &wantattr) ==
XftResultMatch)) { XftResultMatch)) {
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("font weight does not match\n", stderr); fputs("font weight does not match\n", stderr);
} }
@ -1022,7 +1023,7 @@ xloadfonts(const char *fontstr, double fontsize)
if (usedfontsize < 0) { if (usedfontsize < 0) {
FcPatternGetDouble(dc.font.match->pattern, FcPatternGetDouble(dc.font.match->pattern,
FC_PIXEL_SIZE, 0, &fontval); FC_PIXEL_SIZE, 0, &fontval);
usedfontsize = fontval; usedfontsize = fontval;
if (fontsize == 0) if (fontsize == 0)
defaultfontsize = fontval; defaultfontsize = fontval;
@ -1084,17 +1085,17 @@ ximopen(Display *dpy)
if (XSetIMValues(xw.ime.xim, XNDestroyCallback, &imdestroy, NULL)) if (XSetIMValues(xw.ime.xim, XNDestroyCallback, &imdestroy, NULL))
fprintf(stderr, "XSetIMValues: " fprintf(stderr, "XSetIMValues: "
"Could not set XNDestroyCallback.\n"); "Could not set XNDestroyCallback.\n");
xw.ime.spotlist = XVaCreateNestedList(0, XNSpotLocation, &xw.ime.spot, xw.ime.spotlist = XVaCreateNestedList(0, XNSpotLocation, &xw.ime.spot,
NULL); NULL);
if (xw.ime.xic == NULL) { if (xw.ime.xic == NULL) {
xw.ime.xic = XCreateIC(xw.ime.xim, XNInputStyle, xw.ime.xic = XCreateIC(xw.ime.xim, XNInputStyle,
XIMPreeditNothing | XIMStatusNothing, XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, xw.win, XNClientWindow, xw.win,
XNDestroyCallback, &icdestroy, XNDestroyCallback, &icdestroy,
NULL); NULL);
} }
if (xw.ime.xic == NULL) if (xw.ime.xic == NULL)
fprintf(stderr, "XCreateIC: Could not create input context.\n"); fprintf(stderr, "XCreateIC: Could not create input context.\n");
@ -1107,7 +1108,7 @@ ximinstantiate(Display *dpy, XPointer client, XPointer call)
{ {
if (ximopen(dpy)) if (ximopen(dpy))
XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL, XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
ximinstantiate, NULL); ximinstantiate, NULL);
} }
void void
@ -1115,7 +1116,7 @@ ximdestroy(XIM xim, XPointer client, XPointer call)
{ {
xw.ime.xim = NULL; xw.ime.xim = NULL;
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL, XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
ximinstantiate, NULL); ximinstantiate, NULL);
XFree(xw.ime.spotlist); XFree(xw.ime.spotlist);
} }
@ -1193,7 +1194,7 @@ xinit(int cols, int rows)
/* input methods */ /* input methods */
if (!ximopen(xw.dpy)) { if (!ximopen(xw.dpy)) {
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL, XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
ximinstantiate, NULL); ximinstantiate, NULL);
} }
/* white cursor, black outline */ /* white cursor, black outline */
@ -1312,7 +1313,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
if (f >= frclen) { if (f >= frclen) {
if (!font->set) if (!font->set)
font->set = FcFontSort(0, font->pattern, font->set = FcFontSort(0, font->pattern,
1, 0, &fcres); 1, 0, &fcres);
fcsets[0] = font->set; fcsets[0] = font->set;
/* /*
@ -1376,7 +1377,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
{ {
int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1); int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1);
int winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, int winx = borderpx + x * win.cw, winy = borderpx + y * win.ch,
width = charlen * win.cw; width = charlen * win.cw;
Color *fg, *bg, *temp, revfg, revbg, truefg, truebg; Color *fg, *bg, *temp, revfg, revbg, truefg, truebg;
XRenderColor colfg, colbg; XRenderColor colfg, colbg;
XRectangle r; XRectangle r;
@ -1386,7 +1387,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
if (dc.ibfont.badslant || dc.ibfont.badweight) if (dc.ibfont.badslant || dc.ibfont.badweight)
base.fg = defaultattr; base.fg = defaultattr;
} else if ((base.mode & ATTR_ITALIC && dc.ifont.badslant) || } else if ((base.mode & ATTR_ITALIC && dc.ifont.badslant) ||
(base.mode & ATTR_BOLD && dc.bfont.badweight)) { (base.mode & ATTR_BOLD && dc.bfont.badweight)) {
base.fg = defaultattr; base.fg = defaultattr;
} }
@ -1621,7 +1622,7 @@ xseticontitle(char *p)
p = opt_title; p = opt_title;
if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
&prop) != Success) &prop) != Success)
return; return;
XSetWMIconName(xw.dpy, xw.win, &prop); XSetWMIconName(xw.dpy, xw.win, &prop);
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmiconname); XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmiconname);
@ -1638,7 +1639,7 @@ xsettitle(char *p)
p = opt_title; p = opt_title;
if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
&prop) != Success) &prop) != Success)
return; return;
XSetWMName(xw.dpy, xw.win, &prop); XSetWMName(xw.dpy, xw.win, &prop);
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname); XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname);
@ -1995,7 +1996,7 @@ run(void)
drawing = 1; drawing = 1;
} }
timeout = (maxlatency - TIMEDIFF(now, trigger)) \ timeout = (maxlatency - TIMEDIFF(now, trigger)) \
/ maxlatency * minlatency; / maxlatency * minlatency;
if (timeout > 0) if (timeout > 0)
continue; /* we have time, try to find idle */ continue; /* we have time, try to find idle */
} }
@ -2024,13 +2025,13 @@ void
usage(void) usage(void)
{ {
die("usage: %s [-aiv] [-c class] [-f font] [-g geometry]" die("usage: %s [-aiv] [-c class] [-f font] [-g geometry]"
" [-n name] [-o file]\n" " [-n name] [-o file]\n"
" [-T title] [-t title] [-w windowid]" " [-T title] [-t title] [-w windowid]"
" [[-e] command [args ...]]\n" " [[-e] command [args ...]]\n"
" %s [-aiv] [-c class] [-f font] [-g geometry]" " %s [-aiv] [-c class] [-f font] [-g geometry]"
" [-n name] [-o file]\n" " [-n name] [-o file]\n"
" [-T title] [-t title] [-w windowid] -l line" " [-T title] [-t title] [-w windowid] -l line"
" [stty_args ...]\n", argv0, argv0); " [stty_args ...]\n", argv0, argv0);
} }
int int

BIN
x.o

Binary file not shown.