Add fast blink support

    Fast blink is implemented using the new main loop changes. It may mark a
    few characters too many as dirty when the blink state hasn't changed,
    but it's not a major issue.


cheers
aes
From 9a1709928bd2e2bd8f8d7b5a63f9aec5d073d376 Mon Sep 17 00:00:00 2001
From: Anders Eurenius <a...@spotify.com>
Date: Sun, 22 Jun 2014 16:02:06 +0200
Subject: [PATCH 7/8] Add fast blink support

Fast blink is implemented using the new main loop changes. It may mark a
few characters too many as dirty when the blink state hasn't changed,
but it's not a major issue.
---
 st.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/st.c b/st.c
index fc3af74..f256528 100644
--- a/st.c
+++ b/st.c
@@ -3244,6 +3244,9 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
 	if(base.mode & ATTR_BLINK && term.mode & MODE_BLINK)
 		fg = bg;
 
+	if(base.mode & ATTR_FASTBLINK && term.mode & MODE_FBLINK)
+		fg = bg;
+
 	if(base.mode & ATTR_INVISIBLE)
 		fg = bg;
 
@@ -3794,6 +3797,26 @@ int do_select(struct timeval *tv)
 		(FD_ISSET(cmdfd, &rfd)? cmd_activity: 0);
 }
 
+int
+setblinks(struct timeval *now)
+{
+	unsigned long long int t = now->tv_sec * 1000 + now->tv_usec / 1000;
+	int blink, fblink, change = 0;
+
+	blink = (t / blinktimeout) & 1;
+	if(!!(term.mode & MODE_BLINK) != blink)
+		change = 1;
+
+	fblink = (t / (blinktimeout / 4)) & 1;
+	if(!!(term.mode & MODE_FBLINK) != fblink)
+		change = 1;
+
+	MODBIT(term.mode, blink, MODE_BLINK);
+	MODBIT(term.mode, fblink, MODE_FBLINK);
+
+	return change;
+}
+
 void
 run(void) {
 	XEvent ev;
@@ -3827,6 +3850,11 @@ run(void) {
 		tv = &drawtimeout;
 
 		dodraw = 0;
+		if(blinktimeout && blinkset && setblinks(&now)) {
+			tsetdirtattr(ATTR_BLINK);
+			tsetdirtattr(ATTR_FASTBLINK);
+			dodraw = 1;
+		}
 		deltatime = TIMEDIFF(now, last);
 		if(deltatime > (xev? (1000/xfps) : (1000/actionfps))
 				|| deltatime < 0) {
-- 
2.0.0

Reply via email to