Adding spoiler, external pipe and themed cursor patches

This commit is contained in:
bakkeby 2019-09-17 01:18:44 +02:00
parent d52c5e4ce8
commit db32474a7f
9 changed files with 130 additions and 3 deletions

View File

@ -11,7 +11,7 @@ Refer to [https://dwm.suckless.org/](https://st.suckless.org/) for details on th
### Changelog:
2019-09-16 - Added alpha, anysize, bold-is-not-bright, clipboard, copyurl, disable-fonts, fixime, hidecursor, newterm, open-copied-url, vertcenter, scrollback and xresources patches
2019-09-16 - Added alpha, anysize, bold-is-not-bright, clipboard, copyurl, disable-fonts, externalpipe, fixime, hidecursor, newterm, open-copied-url, vertcenter, scrollback, spoiler, themed cursor and xresources patches
### Patches included:
@ -36,6 +36,9 @@ Refer to [https://dwm.suckless.org/](https://st.suckless.org/) for details on th
- [disable-fonts](https://st.suckless.org/patches/disable_bold_italic_fonts/)
- this patch adds the option of disabling bold/italic/roman fonts globally
- [externalpipe](https://st.suckless.org/patches/externalpipe/)
- this patch allows for eading and writing st's screen through a pipe, e.g. to pass info to dmenu
- [fixime](https://st.suckless.org/patches/fix_ime/)
- adds better Input Method Editor (IME) support
@ -52,6 +55,12 @@ Refer to [https://dwm.suckless.org/](https://st.suckless.org/) for details on th
- [scrollback](https://st.suckless.org/patches/scrollback/)
- allows you scroll back through terminal output using keyboard shortcuts or mousewheel
- [spoiler](https://st.suckless.org/patches/spoiler/)
- use inverted defaultbg/fg for selection when bg/fg are the same
- [themed-cursor](https://st.suckless.org/patches/themed_cursor/)
- instead of a default X cursor, use the xterm cursor from your cursor theme
- [vertcenter](https://st.suckless.org/patches/vertcenter/)
- vertically center lines in the space available if you have set a larger chscale in config.h

View File

@ -149,12 +149,19 @@ static unsigned int cursorshape = 2;
static unsigned int cols = 80;
static unsigned int rows = 24;
#if THEMED_CURSOR_PATCH
/*
* Default shape of the mouse cursor
*/
static char* mouseshape = "xterm";
#else
/*
* Default colour and shape of the mouse cursor
*/
static unsigned int mouseshape = XC_xterm;
static unsigned int mousefg = 7;
static unsigned int mousebg = 0;
#endif // THEMED_CURSOR_PATCH
/*
* Color used to display font attributes when fontconfig selected a font which
@ -232,6 +239,12 @@ MouseKey mkeys[] = {
#define MODKEY Mod1Mask
#define TERMMOD (ControlMask|ShiftMask)
#if EXTERNALPIPE_PATCH // example command
static char *openurlcmd[] = { "/bin/sh", "-c",
"xurls | dmenu -l 10 -w $WINDOWID | xargs -r open",
"externalpipe", NULL };
#endif // EXTERNALPIPE_PATCH
static Shortcut shortcuts[] = {
/* mask keysym function argument */
{ XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} },
@ -264,6 +277,9 @@ static Shortcut shortcuts[] = {
#if NEWTERM_PATCH
{ TERMMOD, XK_Return, newterm, {.i = 0} },
#endif // NEWTERM_PATCH
#if EXTERNALPIPE_PATCH
{ TERMMOD, XK_U, externalpipe, { .v = openurlcmd } },
#endif // EXTERNALPIPE_PATCH
};
/*

View File

@ -16,7 +16,7 @@ PKG_CONFIG = pkg-config
INCS = -I$(X11INC) \
`$(PKG_CONFIG) --cflags fontconfig` \
`$(PKG_CONFIG) --cflags freetype2`
LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender -lXcursor\
`$(PKG_CONFIG) --libs fontconfig` \
`$(PKG_CONFIG) --libs freetype2`

52
patch/externalpipe.c Normal file
View File

@ -0,0 +1,52 @@
void
externalpipe(const Arg *arg)
{
int to[2];
char buf[UTF_SIZ];
void (*oldsigpipe)(int);
Glyph *bp, *end;
int lastpos, n, newline;
if (pipe(to) == -1)
return;
switch (fork()) {
case -1:
close(to[0]);
close(to[1]);
return;
case 0:
dup2(to[0], STDIN_FILENO);
close(to[0]);
close(to[1]);
execvp(((char **)arg->v)[0], (char **)arg->v);
fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
perror("failed");
exit(0);
}
close(to[0]);
/* ignore sigpipe for now, in case child exists early */
oldsigpipe = signal(SIGPIPE, SIG_IGN);
newline = 0;
for (n = 0; n < term.row; n++) {
bp = term.line[n];
lastpos = MIN(tlinelen(n) + 1, term.col) - 1;
if (lastpos < 0)
break;
end = &bp[lastpos + 1];
for (; bp < end; ++bp)
if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0)
break;
if ((newline = term.line[n][lastpos].mode & ATTR_WRAP))
continue;
if (xwrite(to[1], "\n", 1) < 0)
break;
newline = 0;
}
if (newline)
(void)xwrite(to[1], "\n", 1);
close(to[1]);
/* restore */
signal(SIGPIPE, oldsigpipe);
}

1
patch/externalpipe.h Normal file
View File

@ -0,0 +1 @@
void externalpipe(const Arg *);

View File

@ -4,6 +4,10 @@
#include "copyurl.c"
#endif
#if EXTERNALPIPE_PATCH
#include "externalpipe.c"
#endif
#if NEWTERM_PATCH
#include "newterm.c"
#endif

View File

@ -4,6 +4,10 @@
#include "copyurl.h"
#endif
#if EXTERNALPIPE_PATCH
#include "externalpipe.h"
#endif
#if FIXIME_PATCH
void xximspot(int, int);
#endif

View File

@ -58,6 +58,11 @@
*/
#define DISABLE_ROMAN_FONTS_PATCH 1
/* Reading and writing st's screen through a pipe, e.g. pass info to dmenu.
* https://st.suckless.org/patches/externalpipe/
*/
#define EXTERNALPIPE_PATCH 1
/* This patch adds better Input Method Editor (IME) support.
* https://st.suckless.org/patches/fix_ime/
*/
@ -97,6 +102,16 @@
*/
#define SCROLLBACK_MOUSE_ALTSCREEN_PATCH 1
/* Use inverted defaultbg/fg for selection when bg/fg are the same.
* https://st.suckless.org/patches/spoiler/
*/
#define SPOILER_PATCH 1
/* Instead of a default X cursor, use the xterm cursor from your cursor theme.
* https://st.suckless.org/patches/themed_cursor/
*/
#define THEMED_CURSOR_PATCH 1
/*
* Vertically center lines in the space available if you have set a larger chscale in config.h
* https://st.suckless.org/patches/vertcenter/

28
x.c
View File

@ -20,6 +20,10 @@ static char *argv0;
#include "st.h"
#include "win.h"
#if THEMED_CURSOR_PATCH
#include <X11/Xcursor/Xcursor.h>
#endif // THEMED_CURSOR_PATCH
/* types used in config.h */
typedef struct {
uint mod;
@ -1233,13 +1237,21 @@ xinit(int cols, int rows)
/* white cursor, black outline */
#if HIDECURSOR_PATCH
xw.pointerisvisible = 1;
#if THEMED_CURSOR_PATCH
xw.vpointer = XcursorLibraryLoadCursor(xw.dpy, mouseshape);
#else
xw.vpointer = XCreateFontCursor(xw.dpy, mouseshape);
#endif // THEMED_CURSOR_PATCH
XDefineCursor(xw.dpy, xw.win, xw.vpointer);
#elif THEMED_CURSOR_PATCH
cursor = XcursorLibraryLoadCursor(xw.dpy, mouseshape);
XDefineCursor(xw.dpy, xw.win, cursor);
#else
cursor = XCreateFontCursor(xw.dpy, mouseshape);
XDefineCursor(xw.dpy, xw.win, cursor);
#endif // HIDECURSOR_PATCH
#if !THEMED_CURSOR_PATCH
if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
xmousefg.red = 0xffff;
xmousefg.green = 0xffff;
@ -1251,13 +1263,16 @@ xinit(int cols, int rows)
xmousebg.green = 0x0000;
xmousebg.blue = 0x0000;
}
#endif // THEMED_CURSOR_PATCH
#if HIDECURSOR_PATCH
#if !THEMED_CURSOR_PATCH
XRecolorCursor(xw.dpy, xw.vpointer, &xmousefg, &xmousebg);
#endif // THEMED_CURSOR_PATCH
blankpm = XCreateBitmapFromData(xw.dpy, xw.win, &(char){0}, 1, 1);
xw.bpointer = XCreatePixmapCursor(xw.dpy, blankpm, blankpm,
&xmousefg, &xmousebg, 0, 0);
#else
#elif !THEMED_CURSOR_PATCH
XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);
#endif // HIDECURSOR_PATCH
@ -1520,9 +1535,20 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
}
if (base.mode & ATTR_REVERSE) {
#if SPOILER_PATCH
if (bg == fg) {
bg = &dc.col[defaultfg];
fg = &dc.col[defaultbg];
} else {
temp = fg;
fg = bg;
bg = temp;
}
#else
temp = fg;
fg = bg;
bg = temp;
#endif // SPOILER_PATCH
}
if (base.mode & ATTR_BLINK && win.mode & MODE_BLINK)