'Calculate box width for each window in current group.
If the available space is less than overall size of boxes,
the boxes are shrunk by percentage if greater than average.'

def calc_box_widths(self):

    windows = self.bar.screen.group.windows
    window_count = len(windows)
    if (not window_count):
        return []
    width_total = ((self.width - (2 * self.margin_x)) - ((window_count - 1) * self.spacing))
    width_avg = (width_total / window_count)
    names = [self.get_taskname(w) for w in windows]
    icons = [self.get_window_icon(w) for w in windows]
    width_boxes = [(self.box_width(names[idx]) + ((self.icon_size + self.padding_x) if icons[idx] else 0)) for idx in range(window_count)]
    if self.max_title_width:
        width_boxes = [min(w, self.max_title_width) for w in width_boxes]
    width_sum = sum(width_boxes)
    if (width_sum > width_total):
        width_shorter_sum = sum([w for w in width_boxes if (w < width_avg)])
        ratio = ((width_total - width_shorter_sum) / (width_sum - width_shorter_sum))
        width_boxes = [(w if (w < width_avg) else (w * ratio)) for w in width_boxes]
    return zip(windows, icons, names, width_boxes)
