kuro-qtile-theme/kuro/utils/bar.py

70 lines
2.6 KiB
Python

from libqtile import bar
from libqtile.widget.groupbox import GroupBox
from libqtile.log_utils import logger
class KuroBar(bar.Bar):
defaults = [
("background", "#000000", "Background colour."),
("background_normal", "#000000", "Background colour normally."),
("background_hover", "#000000", "Background colour on hover."),
("opacity", 1, "Bar window opacity."),
("margin", 0, "Space around bar as int or list of ints [N E S W]."),
("border_color", "#000000", "Border colour as str or list of str [N E S W]"),
("border_width", 0, "Width of border as int of list of ints [N E S W]"),
(
"reserve",
True,
"Reserve screen space (when set to 'False', bar will be drawn above windows).",
),
]
cur_type: str = "docked"
def _set_bg_transparent(self):
self.background = self.background_normal
# GroupBox Widget background color
for widget in self.widgets:
if isinstance(widget, GroupBox):
if len(widget.highlight_color) in [6, 7]:
widget.highlight_color = widget.highlight_color + "88"
else:
widget.highlight_color = widget.highlight_color[:-2] + "88"
logger.warning(f"Highlight: {widget.highlight_color}")
self.drawer.clear(self.background)
self.draw()
def _set_bg_opaque(self):
self.background = self.background_hover
# GroupBox Widget background color
for widget in self.widgets:
if isinstance(widget, GroupBox):
if len(widget.highlight_color) in [6, 7]:
widget.highlight_color = widget.highlight_color + "FF"
else:
widget.highlight_color = widget.highlight_color[:-2] + "FF"
logger.warning(f"Highlight: {widget.highlight_color}")
self.drawer.clear(self.background)
self.draw()
def process_pointer_enter(self, x: int, y: int) -> None:
super().process_pointer_enter(x=x, y=y)
if self.cur_type == "floating":
self._set_bg_opaque()
def process_pointer_leave(self, x: int, y: int) -> None:
super().process_pointer_leave(x=x, y=y)
if self.cur_type == "floating":
self._set_bg_transparent()
def update_bar_type(self, new_type: str):
if new_type not in ["docked", "floating"]:
return
self.cur_type = new_type
if new_type == "floating":
self.margin = [8, 8, 0, 8]
self._set_bg_transparent()
else:
self.margin = [0, 0, 0, 0]
self._set_bg_opaque()