From 53e0dc39b185f81b8e4920f201931e268fb75872 Mon Sep 17 00:00:00 2001
From: Tim Keller <tjkeller.xyz>
Date: Sat, 9 Nov 2024 17:19:36 -0600
Subject: max layout function implement

---
 widgets/classiclayouts.lua | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

(limited to 'widgets')

diff --git a/widgets/classiclayouts.lua b/widgets/classiclayouts.lua
index 3b4fd64..515e66c 100644
--- a/widgets/classiclayouts.lua
+++ b/widgets/classiclayouts.lua
@@ -1,5 +1,6 @@
 local wibox = require("wibox")
 local layout = require("awful.layout")
+local beautiful = require("beautiful")
 
 local screen_widgets = {} -- need one widget per screen
 
@@ -10,7 +11,6 @@ local layout_icons = {
 	cornerse   = "=LL",
 	fairh      = "#_#",
 	fairv      = "##H",
-	max        = "[M]",
 	floating   = "><>",
 	magnifier  = "=O=",
 	fullscreen = "[*]",
@@ -20,6 +20,9 @@ local layout_icons = {
 	tiletop    = "LLL",
 	tilebottom = "TTT",
 	tileleft   = "=[]",
+	max = function(s)
+		return string.format("[%s]", #s.clients > 0 and #s.clients or 'M')
+	end,
 }
 
 function update(screen_index)
@@ -30,6 +33,9 @@ function update(screen_index)
 	-- create widget if not existing
 	if w == nil then
 		screen_widgets[s] = { widget = wibox.widget.textbox(), layout = l }
+		if beautiful.font_mono then
+			screen_widgets[s].widget.font = beautiful.font_mono
+		end
 		w = screen_widgets[s]
 		--w._layoutbox_tooltip = tooltip {objects = {w}, delay_show = 1}
 
@@ -41,7 +47,13 @@ function update(screen_index)
 	-- set widget
 	local name = layout.getname(l)
 	--w._layoutbox_tooltip:set_text(name)
-	w.widget:set_text(layout_icons[name]) -- TODO handle nil
+	local wtxt = layout_icons[name]
+	if type(wtxt) == 'function' then
+		wtxt = wtxt(s)
+	elseif wtxt == nil then
+		wtxt = "???"
+	end
+	w.widget:set_text(wtxt)
 	return w.widget
 end
 
@@ -59,6 +71,8 @@ end
 
 tag.connect_signal("property::selected", update_current_tag)
 tag.connect_signal("property::layout",   update_current_tag)
+tag.connect_signal("tagged",             update_current_tag) -- max
+tag.connect_signal("untagged",           update_current_tag) -- max
 tag.connect_signal("property::screen",   update_screens)
 
 return update
-- 
cgit v1.2.3