Repository: qtile/qtile

Issue:
Bar transparency broken with latest days commits
<!--
Please do not ask general questions here! There are [community
contact](https://github.com/qtile/qtile#community) options for that.

If you are suggesting a new feature/enhancement please instead post it on the
discussions board as an idea: https://github.com/qtile/qtile/discussions/categories/ideas
-->

# Issue description

Just updated qtile today and the latest commit seems to have broken my bars transparency. Everything else is working as expected with picom, it's just my bar that has become solid black  since updating today. It was fine before the update.

It was fine with the 8th commit but the 10th has no bar transparency. Nothing new in my log file either ???


# Qtile version


4d9210224e4eca23c0e461f5ec64392e4bf60e83


# Stack traces

<!--
Please attach any stack traces found in:

* `~/.xsession-errors`
* `~/.local/share/qtile/qtile.log`
-->

# Configuration

<!--
Please include a link or attach your configuration to the issue.
-->



Discussion:
I suspect 4d9210224e4eca23c0e461f5ec64392e4bf60e83 caused this. Are you able to confirm?
Not sure as I'm running Qtile on arch and I'm using the qtile-git aur pkgbuild ?
OK, no worries! What are you passing to the `Bar`'s `background`?

Resolving patch:
diff --git a/libqtile/backend/base.py b/libqtile/backend/base.py
--- a/libqtile/backend/base.py
+++ b/libqtile/backend/base.py
@@ -671,23 +671,19 @@ def set_source_rgb(self, colour: ColorsType, ctx: cairocffi.Context = None):
         if isinstance(colour, list):
             if len(colour) == 0:
                 # defaults to black
-                r, g, b, _ = utils.rgb("#000000")
-                ctx.set_source_rgba(r, g, b)
+                ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
             elif len(colour) == 1:
-                r, g, b, _ = utils.rgb(colour[0])
-                ctx.set_source_rgba(r, g, b)
+                ctx.set_source_rgba(*utils.rgb(colour[0]))
             else:
                 linear = cairocffi.LinearGradient(0.0, 0.0, 0.0, self.height)
                 step_size = 1.0 / (len(colour) - 1)
                 step = 0.0
                 for c in colour:
-                    r, g, b, _ = utils.rgb(c)
-                    linear.add_color_stop_rgba(step, r, g, b)
+                    linear.add_color_stop_rgba(step, *utils.rgb(c))
                     step += step_size
                 ctx.set_source(linear)
         else:
-            r, g, b, _ = utils.rgb(colour)
-            ctx.set_source_rgba(r, g, b)
+            ctx.set_source_rgba(*utils.rgb(colour))
 
     def clear(self, colour):
         self.set_source_rgb(colour)
diff --git a/libqtile/utils.py b/libqtile/utils.py
--- a/libqtile/utils.py
+++ b/libqtile/utils.py
@@ -70,7 +70,7 @@ def shuffle_down(lst):
 ColorsType = Union[ColorType, List[ColorType]]
 
 
-def rgb(x) -> Tuple[int, int, int, float]:
+def rgb(x: ColorType) -> Tuple[float, float, float, float]:
     """
         Returns a valid RGBA tuple.
 
@@ -81,28 +81,30 @@ def rgb(x) -> Tuple[int, int, int, float]:
             with alpha: ff0000.5
             (255, 0, 0)
             with alpha: (255, 0, 0, 0.5)
+
+        Which is returned as (1.0, 0.0, 0.0, 0.5).
     """
     if isinstance(x, (tuple, list)):
         if len(x) == 4:
-            alpha = x[3]
+            alpha = x[-1]
         else:
-            alpha = 1
+            alpha = 1.0
         return (x[0] / 255.0, x[1] / 255.0, x[2] / 255.0, alpha)
     elif isinstance(x, str):
         if x.startswith("#"):
             x = x[1:]
         if "." in x:
-            x, alpha = x.split(".")
-            alpha = float("0." + alpha)
+            x, alpha_str = x.split(".")
+            alpha = float("0." + alpha_str)
         else:
-            alpha = 1
+            alpha = 1.0
         if len(x) not in (6, 8):
             raise ValueError("RGB specifier must be 6 or 8 characters long.")
-        vals = [int(i, 16) for i in (x[0:2], x[2:4], x[4:6])]
+        vals = tuple(int(i, 16) for i in (x[0:2], x[2:4], x[4:6]))
         if len(x) == 8:
             alpha = int(x[6:8], 16) / 255.0
-        vals.append(alpha)
-        return rgb(vals)
+        vals += (alpha,)
+        return rgb(vals)  # type: ignore
     raise ValueError("Invalid RGB specifier.")
 
 


Test patch: