From 521dc19898bc979375638586f14c82612c49f0b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Av=C3=A9?= <email@thomasave.be>
Date: Fri, 22 Jul 2022 14:47:26 +0200
Subject: [PATCH] Use Powerline for Tasklist

---
 awesome/components/pastel/top-panel.lua |  23 +----
 awesome/powerline.lua                   |  32 +++++++
 awesome/theme.lua                       |   2 +-
 awesome/widgets/task-list.lua           | 108 ++++++++++++------------
 4 files changed, 86 insertions(+), 79 deletions(-)
 create mode 100644 awesome/powerline.lua

diff --git a/awesome/components/pastel/top-panel.lua b/awesome/components/pastel/top-panel.lua
index 7788819..776aacd 100644
--- a/awesome/components/pastel/top-panel.lua
+++ b/awesome/components/pastel/top-panel.lua
@@ -15,35 +15,14 @@ local beautiful = require("beautiful")
 local wibox = require("wibox")
 local theme = require("theme")
 local lain = require("lain")
-local dpi = beautiful.xresources.apply_dpi
 local battery_widget = require("widgets.battery-widget.battery")
 local volume_widget = require("widgets.volume-widget.volume")
+local pl = require("powerline")
 
 -- import widgets
 local task_list = require("widgets.task-list")
 
 
--- ===================================================================
--- Helper functions
--- ===================================================================
-
-local function pl(widget, bgcolor, adjacentcolor)
-    local container = wibox.widget{
-        {
-            {
-                layout = wibox.layout.fixed.horizontal,
-                wibox.layout.margin(widget, dpi(6), dpi(10)),
-                lain.util.separators.arrow_left(bgcolor, adjacentcolor),
-            },
-            bg = bgcolor,
-            widget = wibox.container.background
-        },
-        top = 2, bottom = 2, left = 0, right = 0,
-        widget = wibox.container.margin
-    }
-    return container
-end
-
 
 -- ===================================================================
 -- Custom Widgets
diff --git a/awesome/powerline.lua b/awesome/powerline.lua
new file mode 100644
index 0000000..5f446cc
--- /dev/null
+++ b/awesome/powerline.lua
@@ -0,0 +1,32 @@
+local lain = require("lain")
+local wibox = require("wibox")
+local beautiful = require("beautiful")
+local dpi = beautiful.xresources.apply_dpi
+
+-- ===================================================================
+-- Helper functions
+-- ===================================================================
+
+local function powerline(widget, bgcolor, adjacentcolor, right)
+    right = right or false
+    local container = {
+        layout = wibox.layout.fixed.horizontal,
+        wibox.layout.margin(widget, dpi(6), dpi(10)),
+    }
+    if (not right) then
+        table.insert(container, lain.util.separators.arrow_left(bgcolor, adjacentcolor))
+    else
+        table.insert(container, lain.util.separators.arrow_right(bgcolor, adjacentcolor))
+    end
+    return wibox.widget{
+        {
+            container,
+            bg = bgcolor,
+            widget = wibox.container.background
+        },
+        top = 0, bottom = 0, left = 0, right = 0,
+        widget = wibox.container.margin
+    }
+end
+
+return powerline
diff --git a/awesome/theme.lua b/awesome/theme.lua
index 88b419f..ccfe732 100644
--- a/awesome/theme.lua
+++ b/awesome/theme.lua
@@ -71,7 +71,7 @@ theme.tasklist_fg_urgent = theme.fg_urgent
 theme.tasklist_fg_normal = theme.fg_normal
 
 -- Panel Sizing
-theme.top_panel_height = dpi(32)
+theme.top_panel_height = dpi(30)
 theme.top_panel_powerline = "#002F5F"
 
 -- Notification Sizing
diff --git a/awesome/widgets/task-list.lua b/awesome/widgets/task-list.lua
index b12de4d..3cabe9d 100644
--- a/awesome/widgets/task-list.lua
+++ b/awesome/widgets/task-list.lua
@@ -15,6 +15,8 @@ local wibox = require('wibox')
 local gears = require('gears')
 local utf8 = require("utf8")
 local clickable_container = require('widgets.clickable-container')
+local pl = require("powerline")
+local theme = require("theme")
 
 local dpi = require('beautiful').xresources.apply_dpi
 local capi = {button = button}
@@ -58,64 +60,58 @@ end
 local function list_update(w, buttons, label, data, objects)
    -- update the widgets, creating them if needed
    w:reset()
+   local index = 0
+   local count = 0
+   for _ in pairs(objects) do
+       count = count + 1
+   end
    for i, o in ipairs(objects) do
-      local cache = data[o]
+      index = index + 1
       local ib, cb, tb, cbm, bgb, tbm, ibm, tt, l, ll, bg_clickable
-      if cache then
-         ib = cache.ib
-         tb = cache.tb
-         bgb = cache.bgb
-         tbm = cache.tbm
-         ibm = cache.ibm
-         tt  = cache.tt
+      ib = wibox.widget.imagebox()
+      tb = wibox.widget.textbox()
+      cb = clickable_container(wibox.container.margin(wibox.widget.imagebox(ICON_DIR .. "close.svg"), dpi(9), dpi(9), dpi(9), dpi(9)))
+      cb.shape = gears.shape.circle
+      cbm = wibox.container.margin(cb, dpi(0), dpi(0), dpi(0), dpi(0)) -- 4, 8 ,12 ,12 -- close button
+      cbm:buttons(gears.table.join(awful.button({}, 1, nil,
+         function()
+            o.kill(o)
+         end
+      )))
+      bg_clickable = clickable_container()
+      bgb = wibox.container.background()
+      tbm = wibox.container.margin(tb, dpi(4), dpi(4))
+      ibm = wibox.container.margin(ib, dpi(5), dpi(5), dpi(5), dpi(5)) -- 12 is default top and bottom margin --app icon
+      l = wibox.layout.fixed.horizontal()
+      ll = wibox.layout.fixed.horizontal()
+
+      -- All of this is added in a fixed widget
+      l:fill_space(true)
+      l:add(ibm)
+      l:add(tbm)
+      ll:add(l)
+      ll:add(cbm)
+
+
+      if (index % 2 == 0) then
+          local end_color = count == index and "#12151c" or theme.top_panel_powerline
+          bg_clickable:set_widget(pl(ll, theme.bg_normal, end_color, true))
       else
-         ib = wibox.widget.imagebox()
-         tb = wibox.widget.textbox()
-         cb = clickable_container(wibox.container.margin(wibox.widget.imagebox(ICON_DIR .. "close.svg"), dpi(9), dpi(9), dpi(9), dpi(9)))
-         cb.shape = gears.shape.circle
-         cbm = wibox.container.margin(cb, dpi(4), dpi(8), dpi(2), dpi(2)) -- 4, 8 ,12 ,12 -- close button
-         cbm:buttons(gears.table.join(awful.button({}, 1, nil,
-            function()
-               o.kill(o)
-            end
-         )))
-         bg_clickable = clickable_container()
-         bgb = wibox.container.background()
-         tbm = wibox.container.margin(tb, dpi(4), dpi(4))
-         ibm = wibox.container.margin(ib, dpi(9), dpi(9), dpi(9), dpi(9)) -- 12 is default top and bottom margin --app icon
-         l = wibox.layout.fixed.horizontal()
-         ll = wibox.layout.fixed.horizontal()
-
-         -- All of this is added in a fixed widget
-         l:fill_space(true)
-         l:add(ibm)
-         l:add(tbm)
-         ll:add(l)
-         ll:add(cbm)
-
-         bg_clickable:set_widget(ll)
-         -- And all of this gets a background
-         bgb:set_widget(bg_clickable)
-
-         l:buttons(create_buttons(buttons, o))
-
-         -- Tooltip to display whole title, if it was truncated
-         tt = awful.tooltip({
-            objects = {tb},
-            mode = 'outside',
-            align = 'bottom',
-            delay_show = 1,
-         })
-
-         data[o] = {
-            ib = ib,
-            tb = tb,
-            bgb = bgb,
-            tbm = tbm,
-            ibm = ibm,
-            tt  = tt
-         }
+          local end_color = count == index and "#12151c" or theme.bg_normal
+          bg_clickable:set_widget(pl(ll, theme.top_panel_powerline, end_color, true))
       end
+      -- And all of this gets a background
+      bgb:set_widget(bg_clickable)
+
+      l:buttons(create_buttons(buttons, o))
+
+      -- Tooltip to display whole title, if it was truncated
+      tt = awful.tooltip({
+         objects = {tb},
+         mode = 'outside',
+         align = 'bottom',
+         delay_show = 1,
+      })
 
       local text, bg, bg_image, icon, args = label(o, tb)
       args = args or {}
@@ -137,12 +133,12 @@ local function list_update(w, buttons, label, data, objects)
             tb:set_markup('<i>&lt;Invalid text&gt;</i>')
          end
       end
-      bgb:set_bg(bg)
+      -- bgb:set_bg(bg)
       if type(bg_image) == 'function' then
          -- TODO: Why does this pass nil as an argument?
          bg_image = bg_image(tb, o, nil, objects, i)
       end
-      bgb:set_bgimage(bg_image)
+      -- bgb:set_bgimage(bg_image)
          if icon then
             ib.image = icon
          else