from qtile_extras.widget import Volume as QVolume
from libqtile import images

class Volume(QVolume):
    def __init__(self, size=None, **kwargs):
        super().__init__(**kwargs)
        self.size = size

    def setup_images(self):
        names = (
            "audio-volume-high",
            "audio-volume-low",
            "audio-volume-medium",
            "audio-volume-muted",
        )
        d_images = images.Loader(self.theme_path)(*names)
        for name, img in d_images.items():
            new_height = self.size if self.size else self.bar.height - 1
            img.resize(height=new_height)
            if img.width > self.length:
                self.length = img.width + self.actual_padding * 2

            if self.size:
                matrix = img.pattern.get_matrix()
                matrix.translate(tx=0, ty=-1 * (self.bar.height -1 - self.size) / 2 - 1)
                img.pattern.set_matrix(matrix)

            self.surfaces[name] = img.pattern
