multi user qtile fiddling

multi user qtile fiddling

This post is going to detail how I solved a very particular problem I had created for myself. First, a quick description of the problem. I use home-manager on nixos to declaratively configure what happens on my computer. In the cases where home-manager does not expose sufficient configuration options for my liking (qtile for example), I instead link a configuration file from my nixos config to where it belongs in my home using xdg.configFile. This is what I do with my qtile config.py. I use qtile on my desktop and laptop but I dont want an identical setup on the two machines. I have jumped through many different slightly silly hoops in my nixos config sort of solving this problem until the other day it occured to me this could all be achieved with my python in my qtile config.

THE NUB OF THE PROBLEM

I basically just want the config to work out which computer it’’s on and then change some things accordingly. This can be achieved by getting the hostname with the socket module:

if socket.gethostname() == 'baron':
    # some stuff i want to happen on my desktop
elif socket.gethostname() == 'countess':
    # some stuff i want to happen on my laptop 

There are three main things that I like to differ between my two computers:

WIDGETS

My current solution for this is to define to separate lists of widgets and then point to each one when I make my bar for each computer. This isn’t perfect; it would be nice to have a list of all common widgets and then add to that with the unique ones. I haven’t worked out a way to add the additional widgets without just plopping them all at the end of the bar which isn’t necessarily where I want them (thinking about this now I think I might be able to use the insert method with a little for loop).

countess_widgets = [
    # all the great widgets i want on my laptop
]

screens = [
    Screen(
	    top = bar.Bar(
		    widgets = countess_widgets
		),
	),
]

KEYBINDINGS

For keybindings I use extend to add some additional bindings to my global ones. This is mainly useful for the ones I use to change brightness on my laptop.

countess_keys = [
    Key([m], 'Up',
        lazy.spawn('light -A 5'),
        desc='backlight up'
        ),
    Key([m], 'Down',
        lazy.spawn('light -U 5'),
        desc='backlight down'
        ),
    ]

keys.extend(countess_keys)

You could even change a specific global binding on one computer if you knew its index in the list:

keys[420] = Key([m], 'd',
                lazy.spawn('dmenu_run'),
                desc = 'dmenu'
            )

AUTOSTART

Finally, I use this to autostart different programs which I want to change on each computer. For example I use an xrandr command to make sure my desktop monitor is at 144hz. It looks like this:

@hook.subscribe.startup_once
def autostart():
    processes = [
        [
        'feh', 
        '--bg-scale',
        '/home/james/pics/wallpapers/beaut.jpg'
        ],
        [
        'xrandr',
        '--output',
        'DisplayPort2',
        '--primary',
        '--mode',
        '1920x1080',
        '--rate',
        '143.85'
        ]
    ]
    for p in processes:
        subprocess.Popen(p)

Of course, there are many ways that this could all be achievd but I think it’s quite neat having it all in my one qtile config. That’s about it for today. lots of love x