Here is an updated version of the slide numbers patch

the patch adds:
- opptionals slide numbers 
- optional total number of slides
- configurable font size
- configurable position bottom-(left|center|right)
- configruable appearance: default is "4|32" for "slide number four of
  total 32 slides starting from 0". but one can provide arbitrary format
  string, like "#%d of %d" or in particular "%d" to get rid of the total
  number.


>From 9e8771523c05e9d55f3c2ea5501f40147bc5c399 Mon Sep 17 00:00:00 2001
From: ssd <[email protected]>
Date: Sat, 2 Sep 2017 02:55:55 +0200
Subject: [sent] add slide numbers (+configurable appearance)
To: [email protected]

---
 config.def.h |  5 +++++
 sent.c       | 14 ++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/config.def.h b/config.def.h
index f66d121..80392a4 100644
--- a/config.def.h
+++ b/config.def.h
@@ -15,6 +15,11 @@ static const char *colors[] = {
 
 static const float linespacing = 1.4;
 
+/* slide numbers */ 
+static const int numfontidx = 5; /* use fonts[numfontidx] to display them */
+static const int numpos = 1; /* -1: left, 0: middle, 1: right, any: none*/
+static char *numfmt = "%d|%d"; /* "%d" to omit total num; or try "#%d of %d"*/
+
 /* how much screen estate is to be used at max for the content */
 static const float usablewidth = 0.75;
 static const float usableheight = 0.75;
diff --git a/sent.c b/sent.c
index 6cf53ff..568f782 100644
--- a/sent.c
+++ b/sent.c
@@ -482,10 +482,14 @@ void
 xdraw()
 {
 	unsigned int height, width, i;
+	unsigned int idxstrw;
 	Image *im = slides[idx].img;
+	char idxstr[64];
 
 	getfontsize(&slides[idx], &width, &height);
 	XClearWindow(xw.dpy, xw.win);
+ 
+	snprintf(idxstr, sizeof(idxstr), numfmt, idx, slidecount - 1);
 
 	if (!im) {
 		drw_rect(d, 0, 0, xw.w, xw.h, 1, 1);
@@ -498,6 +502,16 @@ xdraw()
 			         0,
 			         slides[idx].lines[i],
 			         0);
+		drw_setfontset(d, fonts[numfontidx]);
+		idxstrw = 1 + drw_fontset_getwidth(d, idxstr);
+		drw_text(d,
+			(numpos + 1) * (xw.w - idxstrw - d->fonts->h / 4) / 2,
+			xw.h - fonts[numfontidx]->h * 9 / 8,
+			idxstrw,
+			d->fonts->h,
+			1,
+			idxstr,
+			0);
 		drw_map(d, xw.win, 0, 0, xw.w, xw.h);
 	} else {
 		if (!(im->state & SCALED))
-- 
2.13.2

Reply via email to