diff --git a/home/qtile/src/autostart.sh b/home/qtile/src/autostart.sh deleted file mode 100755 index e9cd4e7..0000000 --- a/home/qtile/src/autostart.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env sh - -[[ "$(hostname)" =~ 'Sigmachine' ]] \ - && xrandr --output HDMI-0 --right-of DP-1 --primary - -notify-send "Welcome, $USER!" & diff --git a/home/qtile/src/bar.py b/home/qtile/src/bar.py new file mode 100644 index 0000000..490af9f --- /dev/null +++ b/home/qtile/src/bar.py @@ -0,0 +1,157 @@ +import colors + +from functools import partialmethod + +from libqtile import widget +from libqtile.lazy import lazy + +import re +import subprocess + +from libqtile import bar, widget + + +widget_defaults = dict( + font="JetBrainsMono Nerd Font", + fontsize=12, + padding=12, + background=colors.BG_DARK.with_alpha(0.9), + foreground=colors.TEXT_LIGHT, +) + + +def mk_overrides(cls, **conf): + init_method = partialmethod(cls.__init__, **conf) + return type(cls.__name__, (cls,), {"__init__": init_method}) + + +Battery = mk_overrides( + widget.Battery, + format="⚡{percent:2.0%}", + background=colors.BG_DARK.with_alpha(0.7), + foreground=colors.TEXT_LIGHT, + low_background=colors.RED_DARK.with_alpha(0.7), + low_percentage=0.1, +) + +CPUGraph = mk_overrides( + widget.CPUGraph, type="line", line_width=1, border_width=0 +) + +GroupBox = mk_overrides( + widget.GroupBox, + highlight_method="line", + disable_drag=True, + other_screen_border=colors.BLUE_VERY_DARK, + other_current_screen_border=colors.BLUE_VERY_DARK, + this_screen_border=colors.BLUE_DARK, + this_current_screen_border=colors.BLUE_DARK, + block_highlight_text_color=colors.TEXT_LIGHT, + highlight_color=[colors.BG_LIGHT, colors.BG_LIGHT], + inactive=colors.TEXT_INACTIVE, + active=colors.TEXT_LIGHT, +) + +Mpris2 = mk_overrides( + widget.Mpris2, + objname="org.mpris.MediaPlayer2.spotify", + format='{xesam:title} - {xesam:artist}', +) + +Memory = mk_overrides( + widget.Memory, + format="{MemUsed: .3f}Mb", + mouse_callbacks={ + "Button1": lazy.spawn( + "kitty" + " -o initial_window_width=1720" + " -o initial_window_height=860" + " -e btop" + ) + }, +) + +TaskList = mk_overrides( + widget.TaskList, + icon_size=0, + fontsize=12, + borderwidth=0, + margin=0, + padding=4, + txt_floating="", + highlight_method="block", + title_width_method="uniform", + spacing=8, + foreground=colors.TEXT_LIGHT, + background=colors.BG_DARK.with_alpha(0.8), + border=colors.BG_DARK.with_alpha(0.9), +) + +Separator = mk_overrides(widget.Spacer, length=4) +Clock = mk_overrides(widget.Clock, format="%A, %b %-d %H:%M") + + +QuickExit = mk_overrides( + widget.QuickExit, default_text="⏻", countdown_format="{}" +) + +Prompt = mk_overrides( + widget.Prompt, + prompt=">", + bell_style="visual", + background=colors.BG_DARK, + foreground=colors.TEXT_LIGHT, + padding=8, +) + +Systray = mk_overrides( + widget.Systray, + icon_size=14, + padding=8 +) + + +class Bar(bar.Bar): + _widgets = [ + GroupBox, + Separator, + TaskList, + Separator, + Prompt, + Mpris2, + Battery, + Memory, + CPUGraph, + Separator, + widget.Volume, + Clock, + Separator, + QuickExit, + ] + + def __init__(self, id_): + self.id = id_ + super().__init__( + widgets=self._build_widgets(), + size=24, + background=colors.BG_DARK, + margin=[0, 0, 8, 0] + ) + + def is_desktop(self): + machine_info = subprocess.check_output( + ["hostnamectl", "status"], universal_newlines=True) + m = re.search(r"Chassis: (\w+)\s.*\n", machine_info) + chassis_type = "desktop" if m is None else m.group(1) + + return chassis_type == "desktop" + + def _build_widgets(self): + if self.is_desktop(): + self._widgets = [w for w in self._widgets if w != Battery] + + widgets = [widget_cls() for widget_cls in self._widgets] + if self.id == 0: + widgets.insert(13, Systray()) + + return widgets diff --git a/home/qtile/src/colors.py b/home/qtile/src/colors.py new file mode 100644 index 0000000..ae575de --- /dev/null +++ b/home/qtile/src/colors.py @@ -0,0 +1,31 @@ +class Color(str): + def with_alpha(self, alpha: float) -> str: + return f"{self}{int(alpha * 255):02x}" + + +BG_DARK = Color("#0F0F1C") +BG_LIGHT = Color("#1A1C31") +BG_LIGHTER = Color("#22263F") + +RED_DARK = Color("#D22942") +RED_LIGHT = Color("#DE4259") + +GREEN_DARK = Color("#17B67C") +GREEN_LIGHT = Color("#3FD7A0") + +YELLOW_DARK = Color("#F2A174") +YELLOW_LIGHT = Color("#EED49F") + +BLUE_VERY_DARK = Color("#3F3D9E") +BLUE_DARK = Color("#8B8AF1") +BLUE_LIGHT = Color("#A7A5FB") + +PURPLE_DARK = Color("#D78AF1") +PURPLE_LIGHT = Color("#E5A5FB") + +CYAN_DARK = Color("#8ADEF1") +CYAN_LIGHT = Color("#A5EBFB") + +TEXT_INACTIVE = Color("#292C39") +TEXT_DARK = Color("#A2B1E8") +TEXT_LIGHT = Color("#CAD3F5") diff --git a/home/qtile/src/config.py b/home/qtile/src/config.py index cf0b410..962f799 100644 --- a/home/qtile/src/config.py +++ b/home/qtile/src/config.py @@ -1,44 +1,109 @@ -from core import ( - autostart, - floating_layout, - groups, - keys, - layouts, - mouse, - screens -) +from functools import partial -from widgets import widget_defaults +import os +from libqtile.bar import Gap +from libqtile.config import DropDown, Group, Key, Match, Screen, ScratchPad +from libqtile.layout.columns import Columns +from libqtile.layout.floating import Floating +from libqtile.lazy import lazy +from bar import Bar, widget_defaults +from controls import mod, keys -@lambda f: globals().update(f()) -def setup_qtile_globals(): - return dict( - extension_defaults = widget_defaults.copy(), +import colors - dgroups_key_binder = None, - dgroups_app_rules = [], - follow_mouse_focus = True, - bring_front_click = False, - cursor_warp = False, +_gap = Gap(4) +Screen = partial( + Screen, + bottom=_gap, left=_gap, right=_gap, + wallpaper=os.path.expanduser("~/assets/wallpaper.png"), + wallpaper_mode="fill" +) - auto_fullscreen = True, - focus_on_window_activation = "smart", - reconfigure_screens = True, +screens = [Screen(top=Bar(i)) for i in range(2)] - auto_minimize = False, - wmname = "Qtile" +layouts = [ + Columns( + border_width=2, + margin=4, + border_focus=colors.BLUE_DARK, + border_normal=colors.BG_DARK ) +] + +floating_layout = Floating( + border_width=2, + border_focus=colors.BLUE_DARK, + border_normal=colors.BG_DARK, + float_rules=[ + *Floating.default_float_rules, + Match(wm_class="pavucontrol"), + Match(wm_class="confirmreset"), + Match(wm_class="ssh-askpass"), + Match(title="pinentry"), + Match(title="kitty"), + ], +) + +class _Group(Group): + + def __init__(self, name: str, key: str): + self.name = name + self.key = key + + super().__init__(name) + self.setup_keys() + + @classmethod + def setup_single_keys(cls): + toggle_term = Key( + [mod, "shift"], "space", + lazy.group["scratchpad"].dropdown_toggle("term"), + ) + + keys.append(toggle_term) + def setup_keys(self): + move = Key([mod], self.key, lazy.group[self.name].toscreen()) + switch = Key( + [mod, "shift"], self.key, + lazy.window.togroup(self.name, switch_group=True), + ) -__all__ = ( - "autostart", - "keys", - "mouse", - "groups", - "layouts", - "floating_layout", - "screens", - "widget_defaults", + keys.extend((move, switch)) + +_scratchpad_defaults = dict( + x=0.05, + y=0.05, + opacity=0.95, + height=0.9, + width=0.9, + on_focus_lost_hide=False ) + +_scratchpads = [ + ScratchPad( + "scratchpad", + [DropDown("term", "kitty", **_scratchpad_defaults)] + ) +] + +_Group.setup_single_keys() +groups = _scratchpads + [_Group(lb, k) for lb, k in zip("ζπδωλσς", "1234567")] + +extension_defaults = widget_defaults.copy() + +dgroups_key_binder = None +dgroups_app_rules = [] + +follow_mouse_focus = True +bring_front_click = False +cursor_warp = False + +auto_fullscreen = True +focus_on_window_activation = "smart" +reconfigure_screens = True + +auto_minimize = False +wmname = "Qtile" diff --git a/home/qtile/src/core/keys.py b/home/qtile/src/controls.py similarity index 74% rename from home/qtile/src/core/keys.py rename to home/qtile/src/controls.py index 3b945e6..7ad0741 100644 --- a/home/qtile/src/core/keys.py +++ b/home/qtile/src/controls.py @@ -1,38 +1,21 @@ -import re -import os - -import subprocess - -from libqtile.config import Key +from libqtile.config import Click, Drag, Key from libqtile.lazy import lazy mod = "mod4" -def _toggle(*args, **kwargs): - def wrapper(func): - state: bool = False - - def wrapped(_): - nonlocal state - - state = not state - func(*args, **kwargs, state=state) - - return wrapped - return wrapper - - -@_toggle(control=150) -def toggle_keypad(control: int, state: bool): - proc = subprocess.run("xinput list | grep Touchpad", - text=True, capture_output=True) - - id_ = re.search(r"id=(\d+)", proc.stdout) - if id_ is None: - return - - os.system(f"xinput set-prop {id_} {control} {int(state)}") - +mouse = [ + Drag( + [mod], + "Button1", + lazy.window.set_position_floating(), + start=lazy.window.get_position()), + Drag( + [mod], + "Button3", + lazy.window.set_size_floating(), + start=lazy.window.get_size()), + Click([mod], "Button2", lazy.window.bring_to_front()), +] keys = [ Key([mod], "e", lazy.spawn("thunar")), @@ -52,7 +35,6 @@ def toggle_keypad(control: int, state: bool): Key([mod, "control"], "r", lazy.reload_config()), Key([mod, "control"], "q", lazy.shutdown()), Key([mod], "r", lazy.spawncmd()), - Key([], "XF86TouchpadToggle", lazy.function(toggle_keypad)), # Backlight Key([], "XF86MonBrightnessUp", lazy.spawn("brightnessctl set +5%")), Key([], "XF86MonBrightnessDown", lazy.spawn("brightnessctl set 5%-")), diff --git a/home/qtile/src/core/__init__.py b/home/qtile/src/core/__init__.py deleted file mode 100644 index d4403a1..0000000 --- a/home/qtile/src/core/__init__.py +++ /dev/null @@ -1,23 +0,0 @@ -from .groups import groups -from .hooks import autostart -from .keys import keys, mod -from .layouts import floating_layout, layouts -from .mouse import mouse -from .screens import screens - -__all__ = ( - # Keybindings - "keys", - "mod", - # Hooks - "autostart", - # Mouse - "mouse", - # Workspaces groups - "groups", - # Layouts - "layouts", - "floating_layout", - # Screens - "screens", -) diff --git a/home/qtile/src/core/bar.py b/home/qtile/src/core/bar.py deleted file mode 100644 index b34b1e3..0000000 --- a/home/qtile/src/core/bar.py +++ /dev/null @@ -1,66 +0,0 @@ -import re -import subprocess - -from libqtile import bar, widget - -from utils import Color -from widgets import ( - Battery, - Clock, - CPUGraph, - GroupBox, - Memory, - Mpris2, - Prompt, - QuickExit, - Separator, - Systray, - TaskList, -) - - -class Bar(bar.Bar): - _widgets = [ - GroupBox, - Separator, - TaskList, - Separator, - Prompt, - Mpris2, - Battery, - Memory, - CPUGraph, - Separator, - widget.Volume, - Clock, - Separator, - QuickExit, - ] - - def __init__(self, id_): - self.id = id_ - super().__init__( - widgets=self._build_widgets(), - size=24, - background=Color.BG_DARK, - margin=[0, 0, 8, 0] - ) - - def is_desktop(self): - machine_info = subprocess.check_output( - ["hostnamectl", "status"], universal_newlines=True) - m = re.search(r"Chassis: (\w+)\s.*\n", machine_info) - chassis_type = "desktop" if m is None else m.group(1) - - return chassis_type == "desktop" - - def _build_widgets(self): - if self.is_desktop(): - self._widgets = [w for w in self._widgets if w != Battery] - - widgets = [widget_cls() for widget_cls in self._widgets] - if self.id == 0: - widgets.insert(13, Systray()) - - return widgets - diff --git a/home/qtile/src/core/groups.py b/home/qtile/src/core/groups.py deleted file mode 100644 index 945dcfd..0000000 --- a/home/qtile/src/core/groups.py +++ /dev/null @@ -1,51 +0,0 @@ -from libqtile.config import DropDown, Group, Key, ScratchPad -from libqtile.lazy import lazy - -from .keys import keys, mod - - -class _Group(Group): - - def __init__(self, name: str, key: str): - self.name = name - self.key = key - - super().__init__(name) - self.setup_keys() - - @classmethod - def setup_single_keys(cls): - toggle_term = Key( - [mod, "shift"], "space", - lazy.group["scratchpad"].dropdown_toggle("term"), - ) - - keys.append(toggle_term) - - def setup_keys(self): - move = Key([mod], self.key, lazy.group[self.name].toscreen()) - switch = Key( - [mod, "shift"], self.key, - lazy.window.togroup(self.name, switch_group=True), - ) - - keys.extend((move, switch)) - -_scratchpad_defaults = dict( - x=0.05, - y=0.05, - opacity=0.95, - height=0.9, - width=0.9, - on_focus_lost_hide=False -) - -_scratchpads = [ - ScratchPad( - "scratchpad", - [DropDown("term", "kitty", **_scratchpad_defaults)] - ) -] - -_Group.setup_single_keys() -groups = _scratchpads + [_Group(lb, k) for lb, k in zip("ζπδωλσς", "1234567")] diff --git a/home/qtile/src/core/hooks.py b/home/qtile/src/core/hooks.py deleted file mode 100644 index 316d324..0000000 --- a/home/qtile/src/core/hooks.py +++ /dev/null @@ -1,13 +0,0 @@ -import pathlib -import os -import subprocess - -from libqtile import hook - - -@hook.subscribe.startup_once -def autostart(): - cwd = pathlib.Path(os.path.dirname(os.path.realpath(__file__))) - autostart_path = str((cwd / ".." / "autostart.sh").absolute()) - - subprocess.call([autostart_path]) diff --git a/home/qtile/src/core/layouts.py b/home/qtile/src/core/layouts.py deleted file mode 100644 index a850458..0000000 --- a/home/qtile/src/core/layouts.py +++ /dev/null @@ -1,27 +0,0 @@ -from libqtile.layout.columns import Columns -from libqtile.layout.floating import Floating -from libqtile.config import Match - -from utils import Color - -layouts = [ - Columns( - border_width=2, - margin=4, - border_focus=Color.BLUE_DARK, - border_normal=Color.BG_DARK) -] - -floating_layout = Floating( - border_width=2, - border_focus=Color.BLUE_DARK, - border_normal=Color.BG_DARK, - float_rules=[ - *Floating.default_float_rules, - Match(wm_class="pavucontrol"), - Match(wm_class="confirmreset"), - Match(wm_class="ssh-askpass"), - Match(title="pinentry"), - Match(title="kitty"), - ], -) diff --git a/home/qtile/src/core/mouse.py b/home/qtile/src/core/mouse.py deleted file mode 100644 index 2227470..0000000 --- a/home/qtile/src/core/mouse.py +++ /dev/null @@ -1,18 +0,0 @@ -from libqtile.config import Click, Drag -from libqtile.lazy import lazy - -from core import mod - -mouse = [ - Drag( - [mod], - "Button1", - lazy.window.set_position_floating(), - start=lazy.window.get_position()), - Drag( - [mod], - "Button3", - lazy.window.set_size_floating(), - start=lazy.window.get_size()), - Click([mod], "Button2", lazy.window.bring_to_front()), -] diff --git a/home/qtile/src/core/screens.py b/home/qtile/src/core/screens.py deleted file mode 100644 index 11da501..0000000 --- a/home/qtile/src/core/screens.py +++ /dev/null @@ -1,14 +0,0 @@ -import os - -from libqtile.bar import Gap -from libqtile.config import Screen - -from core.bar import Bar - -_gap = Gap(4) -_screen_attr = dict( - bottom=_gap, left=_gap, right=_gap, - wallpaper=os.path.expanduser("~/assets/wallpaper.png"), - wallpaper_mode="fill") - -screens = [Screen(top=Bar(i), **_screen_attr) for i in range(2)] diff --git a/home/qtile/src/utils/__init__.py b/home/qtile/src/utils/__init__.py deleted file mode 100644 index 54f1c74..0000000 --- a/home/qtile/src/utils/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .colors import Color - -__all__ = ("Color",) diff --git a/home/qtile/src/utils/colors.py b/home/qtile/src/utils/colors.py deleted file mode 100644 index 90a00cd..0000000 --- a/home/qtile/src/utils/colors.py +++ /dev/null @@ -1,37 +0,0 @@ -from __future__ import annotations - -AlphaColor = str - - -class _Color(AlphaColor): - def with_alpha(self, alpha: float) -> AlphaColor: - return AlphaColor(f"{self}{int(alpha * 255):02x}") - - -class Color(AlphaColor): - BG_DARK = _Color("#0F0F1C") - BG_LIGHT = _Color("#1A1C31") - BG_LIGHTER = _Color("#22263F") - - RED_DARK = _Color("#D22942") - RED_LIGHT = _Color("#DE4259") - - GREEN_DARK = _Color("#17B67C") - GREEN_LIGHT = _Color("#3FD7A0") - - YELLOW_DARK = _Color("#F2A174") - YELLOW_LIGHT = _Color("#EED49F") - - BLUE_VERY_DARK = _Color("#3F3D9E") - BLUE_DARK = _Color("#8B8AF1") - BLUE_LIGHT = _Color("#A7A5FB") - - PURPLE_DARK = _Color("#D78AF1") - PURPLE_LIGHT = _Color("#E5A5FB") - - CYAN_DARK = _Color("#8ADEF1") - CYAN_LIGHT = _Color("#A5EBFB") - - TEXT_INACTIVE = _Color("#292C39") - TEXT_DARK = _Color("#A2B1E8") - TEXT_LIGHT = _Color("#CAD3F5") diff --git a/home/qtile/src/widgets/__init__.py b/home/qtile/src/widgets/__init__.py deleted file mode 100644 index e0acb9a..0000000 --- a/home/qtile/src/widgets/__init__.py +++ /dev/null @@ -1,29 +0,0 @@ -from .defaults import widget_defaults -from .overides import ( - Battery, - Clock, - CPUGraph, - GroupBox, - Mpris2, - Memory, - Prompt, - QuickExit, - Separator, - TaskList, - Systray -) - -__all__ = ( - "widget_defaults", - "Battery", - "Clock", - "CPUGraph", - "GroupBox", - "Mpris2", - "Memory", - "Prompt", - "QuickExit", - "Separator", - "TaskList", - "Systray", -) diff --git a/home/qtile/src/widgets/defaults.py b/home/qtile/src/widgets/defaults.py deleted file mode 100644 index 99d218e..0000000 --- a/home/qtile/src/widgets/defaults.py +++ /dev/null @@ -1,9 +0,0 @@ -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, -) diff --git a/home/qtile/src/widgets/overides.py b/home/qtile/src/widgets/overides.py deleted file mode 100644 index e65bee6..0000000 --- a/home/qtile/src/widgets/overides.py +++ /dev/null @@ -1,97 +0,0 @@ -from functools import partialmethod - -from libqtile import widget -from libqtile.lazy import lazy - -from utils import Color - - -def mk_overrides(cls, **conf): - init_method = partialmethod(cls.__init__, **conf) - return type(cls.__name__, (cls,), {"__init__": init_method}) - - -Battery = mk_overrides( - widget.Battery, - format="⚡{percent:2.0%}", - background=Color.BG_DARK.with_alpha(0.7), - foreground=Color.TEXT_LIGHT, - low_background=Color.RED_DARK.with_alpha(0.7), - low_percentage=0.1, -) - -CPUGraph = mk_overrides( - widget.CPUGraph, type="line", line_width=1, border_width=0 -) - -GroupBox = mk_overrides( - widget.GroupBox, - highlight_method="line", - disable_drag=True, - other_screen_border=Color.BLUE_VERY_DARK, - other_current_screen_border=Color.BLUE_VERY_DARK, - this_screen_border=Color.BLUE_DARK, - this_current_screen_border=Color.BLUE_DARK, - block_highlight_text_color=Color.TEXT_LIGHT, - highlight_color=[Color.BG_LIGHT, Color.BG_LIGHT], - inactive=Color.TEXT_INACTIVE, - active=Color.TEXT_LIGHT, -) - -Mpris2 = mk_overrides( - widget.Mpris2, - objname="org.mpris.MediaPlayer2.spotify", - format='{xesam:title} - {xesam:artist}', -) - -Memory = mk_overrides( - widget.Memory, - format="{MemUsed: .3f}Mb", - mouse_callbacks={ - "Button1": lazy.spawn( - "kitty" - " -o initial_window_width=1720" - " -o initial_window_height=860" - " -e btop" - ) - }, -) - -TaskList = mk_overrides( - widget.TaskList, - icon_size=0, - fontsize=12, - borderwidth=0, - margin=0, - padding=4, - txt_floating="", - highlight_method="block", - title_width_method="uniform", - spacing=8, - foreground=Color.TEXT_LIGHT, - background=Color.BG_DARK.with_alpha(0.8), - border=Color.BG_DARK.with_alpha(0.9), -) - -Separator = mk_overrides(widget.Spacer, length=4) -Clock = mk_overrides(widget.Clock, format="%A, %b %-d %H:%M") - - -QuickExit = mk_overrides( - widget.QuickExit, default_text="⏻", countdown_format="{}" -) - -Prompt = mk_overrides( - widget.Prompt, - prompt=">", - bell_style="visual", - background=Color.BG_DARK, - foreground=Color.TEXT_LIGHT, - padding=8, -) - -Systray = mk_overrides( - widget.Systray, - icon_size=14, - padding=8 -)