[hackers] [st] reverse video mode. (thx Bert Münnich) || Aurélien Aptel

From: <hg_AT_suckless.org>
Date: Wed, 8 Jun 2011 19:37:32 +0200 (CEST)

changeset: 200:44f257fdaca0
user: Aurélien Aptel <aurelien.aptel_AT_gmail.com>
date: Wed Jun 08 12:40:35 2011 +0200
files: st.c st.info
description:
reverse video mode. (thx Bert Münnich)

diff -r f52faaeeb124 -r 44f257fdaca0 st.c
--- a/st.c Wed Jun 01 19:57:48 2011 +0200
+++ b/st.c Wed Jun 08 12:40:35 2011 +0200
@@ -64,7 +64,7 @@
 enum { CURSOR_DEFAULT = 0, CURSOR_HIDE = 1, CURSOR_WRAPNEXT = 2 };
 enum { GLYPH_SET=1, GLYPH_DIRTY=2 };
 enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8,
- MODE_CRLF=16, MODE_MOUSE=32 };
+ MODE_CRLF=16, MODE_MOUSE=32, MODE_REVERSE=64 };
 enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 };
 enum { WIN_VISIBLE=1, WIN_REDRAW=2, WIN_FOCUSED=4 };
 
@@ -1103,7 +1103,11 @@
                         case 1:
                                 term.mode &= ~MODE_APPKEYPAD;
                                 break;
- case 5: /* TODO: DECSCNM -- Remove reverse video */
+ case 5: /* DECSCNM -- Remove reverse video */
+ if(IS_SET(MODE_REVERSE)) {
+ term.mode &= ~MODE_REVERSE;
+ draw();
+ }
                                 break;
                         case 7:
                                 term.mode &= ~MODE_WRAP;
@@ -1167,7 +1171,10 @@
                                 term.mode |= MODE_APPKEYPAD;
                                 break;
                         case 5: /* DECSCNM -- Reverve video */
- /* TODO: set REVERSE on the whole screen (f) */
+ if(!IS_SET(MODE_REVERSE)) {
+ term.mode |= MODE_REVERSE;
+ draw();
+ }
                                 break;
                         case 7:
                                 term.mode |= MODE_WRAP;
@@ -1508,7 +1515,7 @@
 
 void
 xclear(int x1, int y1, int x2, int y2) {
- XSetForeground(xw.dpy, dc.gc, dc.col[DefaultBG]);
+ XSetForeground(xw.dpy, dc.gc, dc.col[IS_SET(MODE_REVERSE) ? DefaultFG : DefaultBG]);
         XFillRectangle(xw.dpy, xw.buf, dc.gc,
                        x1 * xw.cw, y1 * xw.ch,
                        (x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch);
@@ -1640,14 +1647,20 @@
 
 void
 xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
- unsigned long xfg, xbg;
+ unsigned long xfg = dc.col[base.fg], xbg = dc.col[base.bg], temp;
         int winx = x*xw.cw, winy = y*xw.ch + dc.font.ascent, width = charlen*xw.cw;
         int i;
+
+ /* only switch default fg/bg if term is in RV mode */
+ if(IS_SET(MODE_REVERSE)) {
+ if(base.fg == DefaultFG)
+ xfg = dc.col[DefaultBG];
+ if(base.bg == DefaultBG)
+ xbg = dc.col[DefaultFG];
+ }
 
         if(base.mode & ATTR_REVERSE)
- xfg = dc.col[base.bg], xbg = dc.col[base.fg];
- else
- xfg = dc.col[base.fg], xbg = dc.col[base.bg];
+ temp = xfg, xfg = xbg, xbg = temp;
 
         XSetBackground(xw.dpy, dc.gc, xbg);
         XSetForeground(xw.dpy, dc.gc, xfg);
@@ -1692,6 +1705,8 @@
         /* draw the new one */
         if(!(term.c.state & CURSOR_HIDE) && (xw.state & WIN_FOCUSED)) {
                 sl = utf8size(g.c);
+ if(IS_SET(MODE_REVERSE))
+ g.mode |= ATTR_REVERSE, g.fg = DefaultCS, g.bg = DefaultFG;
                 xdraws(g.c, g, term.c.x, term.c.y, 1, sl);
                 oldx = term.c.x, oldy = term.c.y;
         }
diff -r f52faaeeb124 -r 44f257fdaca0 st.info
--- a/st.info Wed Jun 01 19:57:48 2011 +0200
+++ b/st.info Wed Jun 08 12:40:35 2011 +0200
@@ -33,6 +33,7 @@
         ed=\E[J,
         el=\E[K,
         el1=\E[1K,
+ flash=\E[?5h\E[?5l,
         fsl=^G,
         home=\E[H,
         hpa=\E[%i%p1%dG,
Received on Wed Jun 08 2011 - 19:37:32 CEST

This archive was generated by hypermail 2.2.0 : Wed Jun 08 2011 - 19:48:06 CEST