From c9308367ccd3cbfafc16c858faab62d552d3cf5e Mon Sep 17 00:00:00 2001 From: Frantisek Bohacek Date: Sun, 7 Apr 2024 10:52:49 +0200 Subject: [PATCH] refactor(qtile): output json for variables from config --- .../profiles/desktop/qtile/config/config.py | 33 +++++----- .../desktop/qtile/config/functions.py | 7 ++- .../profiles/desktop/qtile/config/screens.py | 6 +- .../profiles/desktop/qtile/default.nix | 62 ++++++++++++++----- home/modules/profiles/matrix.nix | 2 +- pkgs/rutherther/mpris-ctl.nix | 4 ++ pkgs/rutherther/sequence-detector.nix | 1 + 7 files changed, 79 insertions(+), 36 deletions(-) diff --git a/home/modules/profiles/desktop/qtile/config/config.py b/home/modules/profiles/desktop/qtile/config/config.py index 4503bfd..43b2f0b 100644 --- a/home/modules/profiles/desktop/qtile/config/config.py +++ b/home/modules/profiles/desktop/qtile/config/config.py @@ -12,7 +12,7 @@ from libqtile.backend.wayland import InputConfig import qtile_extras.widget as widget from qtile_extras.widget.decorations import BorderDecoration, PowerLineDecoration, RectDecoration import xmonadcustom -from nixenvironment import setupLocation, configLocation, sequenceDetectorExec +from nixenvironment import nixConfig import functions import utils from screens import init_screens, observe_monitors, init_navigation_keys @@ -22,7 +22,7 @@ import time # ##################################### # Environment mod = 'mod4' -terminal = 'alacritty' +terminal = nixConfig.defaults.terminal layout_theme = { 'border_focus': colors['active'], @@ -93,10 +93,10 @@ keys.extend([ EzKey('m', functions.focus_window_by_class('element')), # notifications - EzKey('l', lazy.spawn(f'{setupLocation}/scripts/notifications/clear-popups.sh')), - EzKey('p', lazy.spawn(f'{setupLocation}/scripts/notifications/pause.sh')), - EzKey('u', lazy.spawn(f'{setupLocation}/scripts/notifications/unpause.sh')), - EzKey('t', lazy.spawn(f'{setupLocation}/scripts/notifications/show-center.sh')), + EzKey('l', lazy.spawn(f'{nixConfig.scripts.notifications.clear_popups}')), + EzKey('p', lazy.spawn(f'{nixConfig.scripts.notifications.pause}')), + EzKey('u', lazy.spawn(f'{nixConfig.scripts.notifications.unpause}')), + EzKey('t', lazy.spawn(f'{nixConfig.scripts.notifications.show_center}')), EzKey('e', lazy.spawn('emacsclient -c')), ], 'M-a'), name = 'a') @@ -122,14 +122,14 @@ keys.extend([ # media keys keys.extend([ - EzKey('', lazy.spawn(f'{sequenceDetectorExec} -g mpris play')), - EzKey('', lazy.spawn(f'{sequenceDetectorExec} -g mpris pause')), - EzKey('', lazy.spawn(f'{sequenceDetectorExec} -g mpris stop')), - EzKey('', lazy.spawn(f'{sequenceDetectorExec} -g mpris next')), - EzKey('', lazy.spawn(f'{sequenceDetectorExec} -g mpris prev')), + EzKey('', lazy.spawn(f'{nixConfig.programs.sequence_detector} -g mpris play')), + EzKey('', lazy.spawn(f'{nixConfig.programs.sequence_detector} -g mpris pause')), + EzKey('', lazy.spawn(f'{nixConfig.programs.sequence_detector} -g mpris stop')), + EzKey('', lazy.spawn(f'{nixConfig.programs.sequence_detector} -g mpris next')), + EzKey('', lazy.spawn(f'{nixConfig.programs.sequence_detector} -g mpris prev')), EzKey('', lazy.spawn('amixer -D pulse set Master 1+ toggle')), - EzKey('', lazy.spawn(f'{configLocation}/brightness.sh up')), - EzKey('', lazy.spawn(f'{configLocation}/brightness.sh down')), + EzKey('', lazy.spawn(f'{nixConfig.scripts.brightness} up')), + EzKey('', lazy.spawn(f'{nixConfig.scripts.brightness} down')), ]) # Printscreen @@ -296,7 +296,12 @@ wmname = 'LG3D' @hook.subscribe.startup_once def autostart(): import subprocess - subprocess.call([f'{configLocation}/autostart.sh']) + # subprocess.call([f'{configLocation}/autostart.sh']) + + for hook in nixConfig.startup.hooks: + subprocess.Popen(hook.split()) + for app in nixConfig.startup.apps: + subprocess.Popen(app.split()) @hook.subscribe.startup diff --git a/home/modules/profiles/desktop/qtile/config/functions.py b/home/modules/profiles/desktop/qtile/config/functions.py index 6d96cbd..9451098 100644 --- a/home/modules/profiles/desktop/qtile/config/functions.py +++ b/home/modules/profiles/desktop/qtile/config/functions.py @@ -40,8 +40,11 @@ def go_to_screen(qtile: Qtile, index: int): qtile.core.warp_pointer(x, y) qtile.to_screen(index) - qtile.current_group.focus(qtile.current_group.current_window) - qtile.current_window.focus() + + if qtile.current_group != None: + qtile.current_group.focus(qtile.current_group.current_window) + if qtile.current_window != None: + qtile.current_window.focus() @lazy.function def go_to_group(qtile: Qtile, group_name: str, switch_monitor: bool = False): diff --git a/home/modules/profiles/desktop/qtile/config/screens.py b/home/modules/profiles/desktop/qtile/config/screens.py index 893ba57..a27ed28 100644 --- a/home/modules/profiles/desktop/qtile/config/screens.py +++ b/home/modules/profiles/desktop/qtile/config/screens.py @@ -6,11 +6,11 @@ import screeninfo import utils import bars from functions import focus_window_by_class, warp_cursor_to_focused_window, go_to_screen, go_to_group -from nixenvironment import setupLocation, configLocation, sequenceDetectorExec +from nixenvironment import nixConfig from libqtile.log_utils import logger def init_screens(): - wallpaper = f'{setupLocation}/wall.png' + wallpaper = nixConfig.wallpaper screens_info = screeninfo.get_monitors() screens_count = len(screens_info) @@ -26,7 +26,7 @@ def init_screens(): top_bar = bars.create_top_bar(systray = systray) - screens[i] = Screen(top=top_bar, bottom=bars.create_bottom_bar(), wallpaper=f'{setupLocation}/wall.png', width=screen_info.width, height=screen_info.height) + screens[i] = Screen(top=top_bar, bottom=bars.create_bottom_bar(), wallpaper=wallpaper, width=screen_info.width, height=screen_info.height) return screens diff --git a/home/modules/profiles/desktop/qtile/default.nix b/home/modules/profiles/desktop/qtile/default.nix index 368dbbd..17f2f24 100644 --- a/home/modules/profiles/desktop/qtile/default.nix +++ b/home/modules/profiles/desktop/qtile/default.nix @@ -1,6 +1,32 @@ -{ lib, config, pkgs, ... }: +{ lib, inputs, config, pkgs, ... }: -{ +let + configFormat = pkgs.formats.json {}; + configJson = configFormat.generate "qtile-config.json" { + scripts = { + brightness = ./config/brightness.sh; + notifications = { + clear_popups = "${inputs.self}/scripts/notifications/clear-popups.sh"; + pause = "${inputs.self}/scripts/notifications/pause.sh"; + unpause = "${inputs.self}/scripts/notifications/unpause.sh"; + show_center = "${inputs.self}/scripts/notifications/show-center.sh"; + }; + }; + wallpaper = "${inputs.self}/wall.png"; + defaults = { + terminal = config.home-config.defaultTerminal.meta.mainProgram; + }; + programs = { + sequence_detector = "${lib.getExe inputs.self.packages.${pkgs.system}.sequence-detector} -c ${./config/sequence-detector.config.json}"; + }; + startup = { + apps = config.home-config.startup.apps; + hooks = [ + "systemctl start --user wm-services.target" + ]; + }; + }; +in { imports = [ ./launcher.nix ./services.nix @@ -19,6 +45,24 @@ pkgs.ksnip ]; + # xdg.configFile."qtile/config.py".text = '' + # import sys + # sys.path.insert(0, "${./config}") + # import config + # ''; + + xdg.configFile."qtile/nixenvironment.py".text = '' + import json + + class obj(object): + def __init__(self, dict_): + self.__dict__.update(dict_) + + with open('${configJson}', 'r') as f: + nixConfig = json.load(f, object_hook = obj) + print('Loaded nix config') + ''; + xdg.configFile."qtile/config.py".source = ./config/config.py; xdg.configFile."qtile/utils.py".source = ./config/utils.py; xdg.configFile."qtile/functions.py".source = ./config/functions.py; @@ -28,19 +72,5 @@ xdg.configFile."qtile/tasklist.py".source = ./config/tasklist.py; xdg.configFile."qtile/xmonadcustom.py".source = ./config/xmonadcustom.py; - xdg.configFile."qtile/sequence-detector.config.json".source = ./config/sequence-detector.config.json; - - xdg.configFile."qtile/nixenvironment.py".text = '' - from string import Template - import os - - setupLocationRef = Template("${config.nixos-config.location}") - configLocationRef = Template("${config.nixos-config.location}/modules/desktop/qtile/config") - - setupLocation = setupLocationRef.substitute(os.environ) - configLocation = configLocationRef.substitute(os.environ) - - sequenceDetectorExec = "sequence_detector -c /home/${config.nixos-config.defaultUser}/.config/qtile/sequence-detector.config.json " - ''; }; } diff --git a/home/modules/profiles/matrix.nix b/home/modules/profiles/matrix.nix index fb1b591..672e4ca 100644 --- a/home/modules/profiles/matrix.nix +++ b/home/modules/profiles/matrix.nix @@ -39,6 +39,6 @@ }; }; - home-config.startup.apps = [ (lib.getExe pkgs.element) ]; + home-config.startup.apps = [ (lib.getExe pkgs.element-desktop) ]; }; } diff --git a/pkgs/rutherther/mpris-ctl.nix b/pkgs/rutherther/mpris-ctl.nix index cbeed51..5735f28 100644 --- a/pkgs/rutherther/mpris-ctl.nix +++ b/pkgs/rutherther/mpris-ctl.nix @@ -30,4 +30,8 @@ rustPlatform.buildRustPackage rec { checkInputs = [ cargo rustc dbus ]; doCheck = true; + + meta = { + mainProgram = "mpris-ctl"; + }; } diff --git a/pkgs/rutherther/sequence-detector.nix b/pkgs/rutherther/sequence-detector.nix index 73ea2f5..d2f3731 100644 --- a/pkgs/rutherther/sequence-detector.nix +++ b/pkgs/rutherther/sequence-detector.nix @@ -32,6 +32,7 @@ rustPlatform.buildRustPackage rec { meta = { license = [ lib.licenses.mit ]; + mainProgram = "sequence_detector"; maintainers = []; }; } -- 2.48.1