From 39416d9e65fd9a58651c04c9b39f04723f262a84 Mon Sep 17 00:00:00 2001 From: ffuentes Date: Mon, 21 Dec 2020 21:44:15 -0300 Subject: Agregado cursor parpadeante (blinkingcursor) --- LEEME | 9 +- config.def.h | 19 ++- config.def.h.orig | 1 + config.h | 19 ++- patches/st-blinking_cursor-20200531-a2a7044.diff | 150 +++++++++++++++++++++++ st | Bin 106272 -> 106304 bytes x.c | 42 +++++-- x.c.orig | 28 ++++- x.o | Bin 74248 -> 74816 bytes 9 files changed, 237 insertions(+), 31 deletions(-) create mode 100644 patches/st-blinking_cursor-20200531-a2a7044.diff diff --git a/LEEME b/LEEME index a1a0ae6..60d4d70 100644 --- a/LEEME +++ b/LEEME @@ -3,8 +3,11 @@ PARCHES Apliqué hasta el momento: -- Solarized (dark y light) -- Copyurl +- Solarized (dark y light modificables con F6) +- Copyurl (para seleccionar cualquier URL en pantalla con Alt+L) - w3m (para que muestre imágenes si es que tienes alguna aplicación que muestre fotos dentro de la terminal) +- blinking cursor -El código fuente ya está modificado. Los parches están en /patches pero sólo como referencia futura. +El código fuente ya está modificado. Sólo hay que hacer "sudo make clean install" + + Los parches están en /patches pero sólo como referencia futura. diff --git a/config.def.h b/config.def.h index a432657..19a9d64 100644 --- a/config.def.h +++ b/config.def.h @@ -145,13 +145,20 @@ static unsigned int defaultcs = 14; static unsigned int defaultrcs = 15; /* - * Default shape of cursor - * 2: Block ("█") - * 4: Underline ("_") - * 6: Bar ("|") - * 7: Snowman ("☃") + * https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81 + * Default style of cursor + * 0: Blinking block + * 1: Blinking block (default) + * 2: Steady block ("█") + * 3: Blinking underline + * 4: Steady underline ("_") + * 5: Blinking bar + * 6: Steady bar ("|") + * 7: Blinking st cursor + * 8: Steady st cursor */ -static unsigned int cursorshape = 2; +static unsigned int cursorstyle = 1; +static Rune stcursor = 0x2603; /* snowman (U+2603) */ /* * Default columns and rows numbers diff --git a/config.def.h.orig b/config.def.h.orig index f68cd06..a432657 100644 --- a/config.def.h.orig +++ b/config.def.h.orig @@ -211,6 +211,7 @@ static Shortcut shortcuts[] = { { TERMMOD, XK_Y, selpaste, {.i = 0} }, { ShiftMask, XK_Insert, selpaste, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, + { MODKEY, XK_l, copyurl, {.i = 0} }, { XK_ANY_MOD, XK_F6, swapcolors, {.i = 0} }, }; diff --git a/config.h b/config.h index a432657..19a9d64 100644 --- a/config.h +++ b/config.h @@ -145,13 +145,20 @@ static unsigned int defaultcs = 14; static unsigned int defaultrcs = 15; /* - * Default shape of cursor - * 2: Block ("█") - * 4: Underline ("_") - * 6: Bar ("|") - * 7: Snowman ("☃") + * https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81 + * Default style of cursor + * 0: Blinking block + * 1: Blinking block (default) + * 2: Steady block ("█") + * 3: Blinking underline + * 4: Steady underline ("_") + * 5: Blinking bar + * 6: Steady bar ("|") + * 7: Blinking st cursor + * 8: Steady st cursor */ -static unsigned int cursorshape = 2; +static unsigned int cursorstyle = 1; +static Rune stcursor = 0x2603; /* snowman (U+2603) */ /* * Default columns and rows numbers diff --git a/patches/st-blinking_cursor-20200531-a2a7044.diff b/patches/st-blinking_cursor-20200531-a2a7044.diff new file mode 100644 index 0000000..d544f74 --- /dev/null +++ b/patches/st-blinking_cursor-20200531-a2a7044.diff @@ -0,0 +1,150 @@ +From bff176133618854676bbdc74c0099f184d3da365 Mon Sep 17 00:00:00 2001 +From: Steve Ward +Date: Sun, 31 May 2020 22:48:25 -0400 +Subject: [PATCH] Allow blinking cursor + +--- + config.def.h | 19 +++++++++++++------ + x.c | 42 ++++++++++++++++++++++++++++++++---------- + 2 files changed, 45 insertions(+), 16 deletions(-) + +diff --git a/config.def.h b/config.def.h +index 6f05dce..3dbe915 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -133,13 +133,20 @@ static unsigned int defaultcs = 256; + static unsigned int defaultrcs = 257; + + /* +- * Default shape of cursor +- * 2: Block ("█") +- * 4: Underline ("_") +- * 6: Bar ("|") +- * 7: Snowman ("☃") ++ * https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81 ++ * Default style of cursor ++ * 0: Blinking block ++ * 1: Blinking block (default) ++ * 2: Steady block ("█") ++ * 3: Blinking underline ++ * 4: Steady underline ("_") ++ * 5: Blinking bar ++ * 6: Steady bar ("|") ++ * 7: Blinking st cursor ++ * 8: Steady st cursor + */ +-static unsigned int cursorshape = 2; ++static unsigned int cursorstyle = 1; ++static Rune stcursor = 0x2603; /* snowman (U+2603) */ + + /* + * Default columns and rows numbers +diff --git a/x.c b/x.c +index 210f184..bd80a5e 100644 +--- a/x.c ++++ b/x.c +@@ -253,6 +253,7 @@ static char *opt_name = NULL; + static char *opt_title = NULL; + + static int oldbutton = 3; /* button event on startup: 3 = release */ ++static int cursorblinks = 0; + + void + clipcopy(const Arg *dummy) +@@ -1526,16 +1527,19 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) + /* draw the new one */ + if (IS_SET(MODE_FOCUSED)) { + switch (win.cursor) { +- case 7: /* st extension */ +- g.u = 0x2603; /* snowman (U+2603) */ ++ case 0: /* Blinking block */ ++ case 1: /* Blinking block (default) */ ++ if (IS_SET(MODE_BLINK)) ++ break; + /* FALLTHROUGH */ +- case 0: /* Blinking Block */ +- case 1: /* Blinking Block (Default) */ +- case 2: /* Steady Block */ ++ case 2: /* Steady block */ + xdrawglyph(g, cx, cy); + break; +- case 3: /* Blinking Underline */ +- case 4: /* Steady Underline */ ++ case 3: /* Blinking underline */ ++ if (IS_SET(MODE_BLINK)) ++ break; ++ /* FALLTHROUGH */ ++ case 4: /* Steady underline */ + XftDrawRect(xw.draw, &drawcol, + borderpx + cx * win.cw, + borderpx + (cy + 1) * win.ch - \ +@@ -1543,12 +1547,23 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) + win.cw, cursorthickness); + break; + case 5: /* Blinking bar */ ++ if (IS_SET(MODE_BLINK)) ++ break; ++ /* FALLTHROUGH */ + case 6: /* Steady bar */ + XftDrawRect(xw.draw, &drawcol, + borderpx + cx * win.cw, + borderpx + cy * win.ch, + cursorthickness, win.ch); + break; ++ case 7: /* Blinking st cursor */ ++ if (IS_SET(MODE_BLINK)) ++ break; ++ /* FALLTHROUGH */ ++ case 8: /* Steady st cursor */ ++ g.u = stcursor; ++ xdrawglyph(g, cx, cy); ++ break; + } + } else { + XftDrawRect(xw.draw, &drawcol, +@@ -1690,9 +1705,12 @@ xsetmode(int set, unsigned int flags) + int + xsetcursor(int cursor) + { +- if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */ ++ if (!BETWEEN(cursor, 0, 8)) /* 7-8: st extensions */ + return 1; + win.cursor = cursor; ++ cursorblinks = win.cursor == 0 || win.cursor == 1 || ++ win.cursor == 3 || win.cursor == 5 || ++ win.cursor == 7; + return 0; + } + +@@ -1936,6 +1954,10 @@ run(void) + if (FD_ISSET(ttyfd, &rfd) || xev) { + if (!drawing) { + trigger = now; ++ if (IS_SET(MODE_BLINK)) { ++ win.mode ^= MODE_BLINK; ++ } ++ lastblink = now; + drawing = 1; + } + timeout = (maxlatency - TIMEDIFF(now, trigger)) \ +@@ -1946,7 +1968,7 @@ run(void) + + /* idle detected or maxlatency exhausted -> draw */ + timeout = -1; +- if (blinktimeout && tattrset(ATTR_BLINK)) { ++ if (blinktimeout && (cursorblinks || tattrset(ATTR_BLINK))) { + timeout = blinktimeout - TIMEDIFF(now, lastblink); + if (timeout <= 0) { + if (-timeout > blinktimeout) /* start visible */ +@@ -1982,7 +2004,7 @@ main(int argc, char *argv[]) + { + xw.l = xw.t = 0; + xw.isfixed = False; +- xsetcursor(cursorshape); ++ xsetcursor(cursorstyle); + + ARGBEGIN { + case 'a': +-- +2.20.1 + diff --git a/st b/st index 5a7ee61..4cf70f5 100755 Binary files a/st and b/st differ diff --git a/x.c b/x.c index 2f16fc3..5a6980d 100644 --- a/x.c +++ b/x.c @@ -254,6 +254,7 @@ static char *opt_name = NULL; static char *opt_title = NULL; static int oldbutton = 3; /* button event on startup: 3 = release */ +static int cursorblinks = 0; int usealtcolors = 0; /* 1 to use alternate palette */ @@ -1543,16 +1544,19 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) /* draw the new one */ if (IS_SET(MODE_FOCUSED)) { switch (win.cursor) { - case 7: /* st extension */ - g.u = 0x2603; /* snowman (U+2603) */ + case 0: /* Blinking block */ + case 1: /* Blinking block (default) */ + if (IS_SET(MODE_BLINK)) + break; /* FALLTHROUGH */ - case 0: /* Blinking Block */ - case 1: /* Blinking Block (Default) */ - case 2: /* Steady Block */ + case 2: /* Steady block */ xdrawglyph(g, cx, cy); break; - case 3: /* Blinking Underline */ - case 4: /* Steady Underline */ + case 3: /* Blinking underline */ + if (IS_SET(MODE_BLINK)) + break; + /* FALLTHROUGH */ + case 4: /* Steady underline */ XftDrawRect(xw.draw, &drawcol, borderpx + cx * win.cw, borderpx + (cy + 1) * win.ch - \ @@ -1560,12 +1564,23 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) win.cw, cursorthickness); break; case 5: /* Blinking bar */ + if (IS_SET(MODE_BLINK)) + break; + /* FALLTHROUGH */ case 6: /* Steady bar */ XftDrawRect(xw.draw, &drawcol, borderpx + cx * win.cw, borderpx + cy * win.ch, cursorthickness, win.ch); break; + case 7: /* Blinking st cursor */ + if (IS_SET(MODE_BLINK)) + break; + /* FALLTHROUGH */ + case 8: /* Steady st cursor */ + g.u = stcursor; + xdrawglyph(g, cx, cy); + break; } } else { XftDrawRect(xw.draw, &drawcol, @@ -1722,9 +1737,12 @@ xsetmode(int set, unsigned int flags) int xsetcursor(int cursor) { - if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */ + if (!BETWEEN(cursor, 0, 8)) /* 7-8: st extensions */ return 1; win.cursor = cursor; + cursorblinks = win.cursor == 0 || win.cursor == 1 || + win.cursor == 3 || win.cursor == 5 || + win.cursor == 7; return 0; } @@ -1968,6 +1986,10 @@ run(void) if (FD_ISSET(ttyfd, &rfd) || xev) { if (!drawing) { trigger = now; + if (IS_SET(MODE_BLINK)) { + win.mode ^= MODE_BLINK; + } + lastblink = now; drawing = 1; } timeout = (maxlatency - TIMEDIFF(now, trigger)) \ @@ -1978,7 +2000,7 @@ run(void) /* idle detected or maxlatency exhausted -> draw */ timeout = -1; - if (blinktimeout && tattrset(ATTR_BLINK)) { + if (blinktimeout && (cursorblinks || tattrset(ATTR_BLINK))) { timeout = blinktimeout - TIMEDIFF(now, lastblink); if (timeout <= 0) { if (-timeout > blinktimeout) /* start visible */ @@ -2014,7 +2036,7 @@ main(int argc, char *argv[]) { xw.l = xw.t = 0; xw.isfixed = False; - xsetcursor(cursorshape); + xsetcursor(cursorstyle); ARGBEGIN { case 'a': diff --git a/x.c.orig b/x.c.orig index 3c7fc47..2f16fc3 100644 --- a/x.c.orig +++ b/x.c.orig @@ -55,6 +55,7 @@ static void clipcopy(const Arg *); static void clippaste(const Arg *); static void numlock(const Arg *); static void selpaste(const Arg *); +static void swapcolors(const Arg *); static void zoom(const Arg *); static void zoomabs(const Arg *); static void zoomreset(const Arg *); @@ -254,6 +255,8 @@ static char *opt_title = NULL; static int oldbutton = 3; /* button event on startup: 3 = release */ +int usealtcolors = 0; /* 1 to use alternate palette */ + void clipcopy(const Arg *dummy) { @@ -292,6 +295,14 @@ numlock(const Arg *dummy) win.mode ^= MODE_NUMLOCK; } +void +swapcolors(const Arg *dummy) +{ + usealtcolors = !usealtcolors; + xloadcols(); + redraw(); +} + void zoom(const Arg *arg) { @@ -748,6 +759,11 @@ sixd_to_16bit(int x) return x == 0 ? 0 : 0x3737 + 0x2828 * x; } +const char* getcolorname(int i) +{ + return (usealtcolors) ? altcolorname[i] : colorname[i]; +} + int xloadcolor(int i, const char *name, Color *ncolor) { @@ -766,7 +782,7 @@ xloadcolor(int i, const char *name, Color *ncolor) return XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, ncolor); } else - name = colorname[i]; + name = getcolorname(i); } return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor); @@ -789,8 +805,8 @@ xloadcols(void) 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]); + if (getcolorname(i)) + die("could not allocate color '%s'\n", getcolorname(i)); else die("could not allocate color %d\n", i); } @@ -1169,13 +1185,13 @@ xinit(int cols, int rows) cursor = XCreateFontCursor(xw.dpy, mouseshape); XDefineCursor(xw.dpy, xw.win, cursor); - if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) { + if (XParseColor(xw.dpy, xw.cmap, getcolorname(mousefg), &xmousefg) == 0) { xmousefg.red = 0xffff; xmousefg.green = 0xffff; xmousefg.blue = 0xffff; } - if (XParseColor(xw.dpy, xw.cmap, colorname[mousebg], &xmousebg) == 0) { + if (XParseColor(xw.dpy, xw.cmap, getcolorname(mousebg), &xmousebg) == 0) { xmousebg.red = 0x0000; xmousebg.green = 0x0000; xmousebg.blue = 0x0000; @@ -1383,7 +1399,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i /* Change basic system colors [0-7] to bright system colors [8-15] */ if ((base.mode & ATTR_BOLD_FAINT) == ATTR_BOLD && BETWEEN(base.fg, 0, 7)) - fg = &dc.col[base.fg + 8]; + fg = &dc.col[base.fg]; if (IS_SET(MODE_REVERSE)) { if (fg == &dc.col[defaultfg]) { diff --git a/x.o b/x.o index 1e2bdff..29b5afd 100644 Binary files a/x.o and b/x.o differ -- cgit v1.2.3