~ruther/nixos-config

c9308367ccd3cbfafc16c858faab62d552d3cf5e — Frantisek Bohacek 1 year, 5 days ago 6904cf1
refactor(qtile): output json for variables from config
M home/modules/profiles/desktop/qtile/config/config.py => home/modules/profiles/desktop/qtile/config/config.py +19 -14
@@ 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('<XF86AudioPlay>', lazy.spawn(f'{sequenceDetectorExec} -g mpris play')),
    EzKey('<XF86AudioPause>', lazy.spawn(f'{sequenceDetectorExec} -g mpris pause')),
    EzKey('<XF86AudioStop>', lazy.spawn(f'{sequenceDetectorExec} -g mpris stop')),
    EzKey('<XF86AudioNext>', lazy.spawn(f'{sequenceDetectorExec} -g mpris next')),
    EzKey('<XF86AudioPrev>', lazy.spawn(f'{sequenceDetectorExec} -g mpris prev')),
    EzKey('<XF86AudioPlay>', lazy.spawn(f'{nixConfig.programs.sequence_detector} -g mpris play')),
    EzKey('<XF86AudioPause>', lazy.spawn(f'{nixConfig.programs.sequence_detector} -g mpris pause')),
    EzKey('<XF86AudioStop>', lazy.spawn(f'{nixConfig.programs.sequence_detector} -g mpris stop')),
    EzKey('<XF86AudioNext>', lazy.spawn(f'{nixConfig.programs.sequence_detector} -g mpris next')),
    EzKey('<XF86AudioPrev>', lazy.spawn(f'{nixConfig.programs.sequence_detector} -g mpris prev')),
    EzKey('<XF86AudioMute>', lazy.spawn('amixer -D pulse set Master 1+ toggle')),
    EzKey('<XF86MonBrightnessUp>', lazy.spawn(f'{configLocation}/brightness.sh up')),
    EzKey('<XF86MonBrightnessDown>', lazy.spawn(f'{configLocation}/brightness.sh down')),
    EzKey('<XF86MonBrightnessUp>', lazy.spawn(f'{nixConfig.scripts.brightness} up')),
    EzKey('<XF86MonBrightnessDown>', 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

M home/modules/profiles/desktop/qtile/config/functions.py => home/modules/profiles/desktop/qtile/config/functions.py +5 -2
@@ 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):

M home/modules/profiles/desktop/qtile/config/screens.py => home/modules/profiles/desktop/qtile/config/screens.py +3 -3
@@ 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


M home/modules/profiles/desktop/qtile/default.nix => home/modules/profiles/desktop/qtile/default.nix +46 -16
@@ 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 "
    '';
  };
}

M home/modules/profiles/matrix.nix => home/modules/profiles/matrix.nix +1 -1
@@ 39,6 39,6 @@
      };
    };

    home-config.startup.apps = [ (lib.getExe pkgs.element) ];
    home-config.startup.apps = [ (lib.getExe pkgs.element-desktop) ];
  };
}

M pkgs/rutherther/mpris-ctl.nix => pkgs/rutherther/mpris-ctl.nix +4 -0
@@ 30,4 30,8 @@ rustPlatform.buildRustPackage rec {

  checkInputs = [ cargo rustc dbus ];
  doCheck = true;

  meta = {
    mainProgram = "mpris-ctl";
  };
}

M pkgs/rutherther/sequence-detector.nix => pkgs/rutherther/sequence-detector.nix +1 -0
@@ 32,6 32,7 @@ rustPlatform.buildRustPackage rec {

  meta = {
    license = [ lib.licenses.mit ];
    mainProgram = "sequence_detector";
    maintainers = [];
  };
}

Do not follow this link