From 0db16d56d1a167be71b1b464af8f4fef3d052054 Mon Sep 17 00:00:00 2001
From: Tim Keller <tjkeller.xyz>
Date: Wed, 16 Apr 2025 22:36:00 -0500
Subject: fix max not updating and refactor classiclayouts + add tooltip

---
 widgets/classiclayouts.lua | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

(limited to 'widgets')

diff --git a/widgets/classiclayouts.lua b/widgets/classiclayouts.lua
index 1f71698..994f520 100644
--- a/widgets/classiclayouts.lua
+++ b/widgets/classiclayouts.lua
@@ -1,3 +1,4 @@
+local awful = require("awful")
 local wibox = require("wibox")
 local layout = require("awful.layout")
 local beautiful = require("beautiful")
@@ -33,22 +34,22 @@ 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
+		screen_widgets[s] = {
+			widget = wibox.widget {
+				font = beautiful.layoutbox_font or beautiful.font_mono or "monospace 10",
+				widget = wibox.widget.textbox,
+			},
+			layout = l,
+			tooltip = awful.tooltip { delay_show = 1 },
+		}
 		w = screen_widgets[s]
-		--w._layoutbox_tooltip = tooltip {objects = {w}, delay_show = 1}
-
-	-- skip if no change
-	elseif w.layout == l then
-		return
+		w.tooltip:add_to_object(w.widget)
 	end
 	w.layout = l
 
 	-- set widget
 	local name = layout.getname(l)
-	--w._layoutbox_tooltip:set_text(name)
+	w.tooltip:set_text(name)
 	local wtxt = layout_icons[name]
 	if type(wtxt) == 'function' then
 		wtxt = wtxt(s)
@@ -67,14 +68,18 @@ function update_screens()
 	end
 end
 
-function update_current_tag(t)
+function update_tag(t)
 	update(t.screen)
 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
+function update_client(c)
+	update(c.screen)
+end
+
+tag.connect_signal("property::selected", update_tag)
+tag.connect_signal("property::layout",   update_tag)
+tag.connect_signal("tagged",             update_client) -- max
+tag.connect_signal("untagged",           update_client) -- max
 tag.connect_signal("property::screen",   update_screens)
 
 return update
-- 
cgit v1.2.3