Skip to content

Commit

Permalink
Rewrite widgets default configuration system
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigmanificient committed Aug 19, 2023
1 parent 5373e8e commit 5a7c1b0
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 247 deletions.
Empty file removed home/qtile/src/__init__.py
Empty file.
15 changes: 4 additions & 11 deletions home/qtile/src/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
from core import (
autostart,
extension_defaults,
floating_layout,
groups,
keys,
layouts,
mouse,
screens,
widget_defaults,
)
from core import autostart, floating_layout, groups, keys, layouts, mouse, screens
from widgets import widget_defaults

extension_defaults = widget_defaults.copy()

dgroups_key_binder = None
dgroups_app_rules = []
Expand Down
4 changes: 0 additions & 4 deletions home/qtile/src/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .layouts import floating_layout, layouts
from .mouse import mouse
from .screens import screens
from .widgets import extension_defaults, widget_defaults

__all__ = (
# Keybindings
Expand All @@ -21,7 +20,4 @@
"floating_layout",
# Screens
"screens",
# Widgets
"widget_defaults",
"extension_defaults",
)
73 changes: 35 additions & 38 deletions home/qtile/src/core/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,60 @@
from libqtile import bar, widget

from utils import Color

from .widgets import (
battery,
chords,
clock,
cpu_graph,
group_box,
memory,
prompt,
quick_exit,
seperator,
systray,
wakatime,
win_name,
from widgets import (
Battery,
Clock,
CPUGraph,
GroupBox,
Memory,
Prompt,
QuickExit,
Separator,
Systray,
TaskList,
Wakatime,
)


class Bar(bar.Bar):
instance_count: int = 0

widgets_checks = {
battery: lambda: os.uname().nodename == 'Bacon',
systray: lambda: Bar.instance_count == 1
Battery: lambda _: os.uname().nodename == "Bacon",
Systray: lambda self: self.id == 1,
}

widgets = [
group_box,
seperator,
win_name,
seperator,
prompt,
wakatime,
chords,
battery,
memory,
cpu_graph,
seperator,
_widgets = [
GroupBox,
Separator,
TaskList,
Separator,
Prompt,
Wakatime,
Battery,
Memory,
CPUGraph,
Separator,
widget.Volume,
systray,
clock,
seperator,
quick_exit,
Systray,
Clock,
Separator,
QuickExit,
]

def __init__(self):
def __init__(self, id_):
self.id = id_

super().__init__(
widgets=self._build_widgets(),
size=24,
background=Color.BG_DARK.with_alpha(0.7),
margin=[0, 0, 8, 0],
)

self.instance_count += 1

def _build_widgets(self):
return [
self.widgets_checks.get(widget_builder, lambda: True)
for widget_builder in self.widgets
widget_builder()
for widget_builder in self._widgets
if self.widgets_checks.get(widget_builder, bool)(self)
]

24 changes: 10 additions & 14 deletions home/qtile/src/core/screens.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import os

from libqtile.bar import Gap
from libqtile.config import Screen

from core.bar import create_bar, gap
from core.bar import Bar

gap = Gap(4)
wallpaper_path = os.path.expanduser("~/assets/wallpaper.png")

screens = [
Screen(
top=create_bar(),
bottom=gap(),
left=gap(),
right=gap(),
wallpaper=wallpaper_path,
wallpaper_mode="fill",
),
Screen(
top=create_bar(secondary=True),
bottom=gap(),
left=gap(),
right=gap(),
top=Bar(i),
bottom=gap,
left=gap,
right=gap,
wallpaper=wallpaper_path,
wallpaper_mode="fill",
),
)
for i in range(2)
]
180 changes: 0 additions & 180 deletions home/qtile/src/core/widgets.py

This file was deleted.

29 changes: 29 additions & 0 deletions home/qtile/src/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from .defaults import widget_defaults
from .overides import (
Battery,
Clock,
CPUGraph,
GroupBox,
Memory,
Prompt,
QuickExit,
Separator,
Systray,
TaskList,
)
from .wakatime import Wakatime

__all__ = (
"widget_defaults",
"Battery",
"Clock",
"CPUGraph",
"GroupBox",
"Memory",
"Prompt",
"QuickExit",
"Separator",
"Systray",
"TaskList",
"Wakatime",
)
9 changes: 9 additions & 0 deletions home/qtile/src/widgets/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from utils import Color

widget_defaults = dict(
font="JetBrainsMono Nerd Font",
fontsize=12,
padding=12,
background=Color.BG_DARK.with_alpha(0.9),
foreground=Color.TEXT_LIGHT,
)
Loading

0 comments on commit 5a7c1b0

Please sign in to comment.