From 67d76bdc68102df976177de351f65329d8683064 Mon Sep 17 00:00:00 2001
From: Chris Down <chris@chrisdown.name>
Date: Thu, 2 Jul 2020 20:18:30 +0100
Subject: [PATCH 1/5] Do not allow focus to drift from fullscreen client via
 focusstack()

It generally doesn't make much sense to allow focusstack() to navigate
away from the selected fullscreen client, as you can't even see which
client you're selecting behind it.

I have had this up for a while on the wiki as a separate patch[0], but
it seems reasonable to avoid this behaviour in dwm mainline, since I'm
struggling to think of any reason to navigate away from a fullscreen
client other than a mistake.

0: https://dwm.suckless.org/patches/alwaysfullscreen/
---
 dwm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dwm.c b/dwm.c
index 664c527..b0b3466 100644
--- a/dwm.c
+++ b/dwm.c
@@ -835,7 +835,7 @@ focusstack(const Arg *arg)
 {
 	Client *c = NULL, *i;
 
-	if (!selmon->sel)
+	if (!selmon->sel || selmon->sel->isfullscreen)
 		return;
 	if (arg->i > 0) {
 		for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);

From 138b405f0c8aa24d8a040cc1a1cf6e3eb5a0ebc7 Mon Sep 17 00:00:00 2001
From: Quentin Rameau <quinq@fifth.space>
Date: Mon, 12 Jul 2021 23:44:16 +0200
Subject: [PATCH 2/5] Add a configuration option for fullscreen locking

Some people are annoyed to have this new behaviour forced for some
application which use fake fullscreen.
---
 config.def.h | 1 +
 dwm.c        | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/config.def.h b/config.def.h
index 1c0b587..a2ac963 100644
--- a/config.def.h
+++ b/config.def.h
@@ -35,6 +35,7 @@ static const Rule rules[] = {
 static const float mfact     = 0.55; /* factor of master area size [0.05..0.95] */
 static const int nmaster     = 1;    /* number of clients in master area */
 static const int resizehints = 1;    /* 1 means respect size hints in tiled resizals */
+static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
 
 static const Layout layouts[] = {
 	/* symbol     arrange function */
diff --git a/dwm.c b/dwm.c
index b0b3466..5e4d494 100644
--- a/dwm.c
+++ b/dwm.c
@@ -835,7 +835,7 @@ focusstack(const Arg *arg)
 {
 	Client *c = NULL, *i;
 
-	if (!selmon->sel || selmon->sel->isfullscreen)
+	if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
 		return;
 	if (arg->i > 0) {
 		for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);

From 716233534b35f74dba5a46ade8f1a6f8cc72fea4 Mon Sep 17 00:00:00 2001
From: Miles Alan <m@milesalan.com>
Date: Mon, 9 Aug 2021 18:24:14 +0200
Subject: [PATCH 3/5] Improve speed of drw_text when provided with large
 strings

Calculates len & ew in drw_font_getexts loop by incrementing instead of
decrementing; as such avoids proportional increase in time spent in loop
based on provided strings size.
---
 drw.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drw.c b/drw.c
index 4cdbcbe..9c39086 100644
--- a/drw.c
+++ b/drw.c
@@ -310,8 +310,11 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
 		if (utf8strlen) {
 			drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
 			/* shorten text if necessary */
-			for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--)
-				drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
+			if (ew > w)
+				for (ew = 0, len = 0; ew < w - lpad * 2 && len < MIN(utf8strlen, sizeof(buf) - 1); len++)
+					drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
+			else
+				len = MIN(utf8strlen, sizeof(buf) - 1);
 
 			if (len) {
 				memcpy(buf, utf8str, len);

From a786211d6cb794fba0ea406d86002c7618998afc Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 20 Aug 2021 23:09:48 +0200
Subject: [PATCH 4/5] Revert "Improve speed of drw_text when provided with
 large strings"

This reverts commit 716233534b35f74dba5a46ade8f1a6f8cc72fea4.

It causes issues with truncation of characters when the text does not fit and
so on.  The patch should be reworked and properly tested.
---
 drw.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drw.c b/drw.c
index 9c39086..4cdbcbe 100644
--- a/drw.c
+++ b/drw.c
@@ -310,11 +310,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
 		if (utf8strlen) {
 			drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
 			/* shorten text if necessary */
-			if (ew > w)
-				for (ew = 0, len = 0; ew < w - lpad * 2 && len < MIN(utf8strlen, sizeof(buf) - 1); len++)
-					drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
-			else
-				len = MIN(utf8strlen, sizeof(buf) - 1);
+			for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--)
+				drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
 
 			if (len) {
 				memcpy(buf, utf8str, len);

From 8657affa2a61e85ca8df76b62e43cb02897d1d80 Mon Sep 17 00:00:00 2001
From: Chris Down <chris@chrisdown.name>
Date: Sat, 18 Dec 2021 16:58:23 +0000
Subject: [PATCH 5/5] drawbar: Don't expend effort drawing bar if it is
 occluded

I noticed that a non-trivial amount of dwm's work on my machine was from
drw_text, which seemed weird, because I have the bar disabled and we
only use drw_text as part of bar drawing.

Looking more closely, I realised that while we use m->showbar when
updating the monitor bar margins, but don't skip actually drawing the
bar if it is hidden. This patch skips drawing it entirely if that is the
case.

On my machine, this takes 10% of dwm's on-CPU time, primarily from
restack() and focus().

When the bar is toggled on again, the X server will generate an Expose
event, and we'll redraw the bar as normal as part of expose().
---
 dwm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/dwm.c b/dwm.c
index 5e4d494..a96f33c 100644
--- a/dwm.c
+++ b/dwm.c
@@ -702,6 +702,9 @@ drawbar(Monitor *m)
 	unsigned int i, occ = 0, urg = 0;
 	Client *c;
 
+	if (!m->showbar)
+		return;
+
 	/* draw status first so it can be overdrawn by tags later */
 	if (m == selmon) { /* status is only drawn on selected monitor */
 		drw_setscheme(drw, scheme[SchemeNorm]);