home/qtile: add volume keys and ease testing

This commit is contained in:
steveej 2018-11-03 18:43:22 +01:00
parent dd4cd9aaf4
commit b53ad263e6
3 changed files with 89 additions and 63 deletions

View file

@ -44,6 +44,17 @@ update-this-device:
fi fi
fi fi
hm-iterate-qtile:
#!/usr/bin/env bash
set -xe
home-manager switch
Xephyr -ac -br -resizeable :1 &
XEPHYR_PID=$!
echo ${XEPHYR_PID}
DISPLAY=:1 $(grep qtile ~/.xsession) &
wait $!
kill ${XEPHYR_PID}
# Sorry, this is a manual step for now. Please see nix/os/modules/encryptedDisk.nix for the layout # Sorry, this is a manual step for now. Please see nix/os/modules/encryptedDisk.nix for the layout
disk-prepare: disk-prepare:
echo NOT IMPLEMENTED echo NOT IMPLEMENTED

View file

@ -7,7 +7,27 @@ let
mkSimpleTrayService mkSimpleTrayService
; ;
qtileConfig = pkgs.writeScript "config.py" '' audio = pkgs.writeScript "audio" ''
#!${pkgs.bash}/bin/bash
case $1 in
mute)
${pkgs.pulseaudio}/bin/pactl set-sink-mute $(${pkgs.pulseaudio}/bin/pactl list short sinks | grep RUNNING | awk '{ print $1 }') toggle
;;
lower)
${pkgs.pulseaudio}/bin/pactl set-sink-volume $(${pkgs.pulseaudio}/bin/pactl list short sinks | grep RUNNING | awk '{ print $1 }') -10%
;;
raise)
${pkgs.pulseaudio}/bin/pactl set-sink-volume $(${pkgs.pulseaudio}/bin/pactl list short sinks | grep RUNNING | awk '{ print $1 }') +10%
;;
*)
echo Unknown command: $1
exit 1
;;
esac
'';
qtileConfig = pkgs.writeScript "qtile_config.py" ''
from libqtile.config import Key, Screen, Group, Drag, Click from libqtile.config import Key, Screen, Group, Drag, Click
from libqtile.command import lazy from libqtile.command import lazy
from libqtile import layout, bar, widget from libqtile import layout, bar, widget
@ -24,45 +44,45 @@ handler = logging.handlers.RotatingFileHandler(
handler.setLevel(logging.WARN) handler.setLevel(logging.WARN)
logger.addHandler(handler) logger.addHandler(handler)
@hook.subscribe.screen_change # @hook.subscribe.screen_change
def restart_on_randr(qtile, ev): # def restart_on_randr(qtile, ev):
import time # import time
#
with open(os.path.join(os.environ['HOME'], ".qtilelastrestart"), "w"): # with open(os.path.join(os.environ['HOME'], ".qtilelastrestart"), "w"):
pass # pass
#
lastRestart = 0 # lastRestart = 0
with open(os.path.join(os.environ['HOME'], ".qtilelastrestart"), "r+") as lastRestartFile: # with open(os.path.join(os.environ['HOME'], ".qtilelastrestart"), "r+") as lastRestartFile:
lastRestartStr = lastRestartFile.read() # lastRestartStr = lastRestartFile.read()
if len(lastRestartStr) > 0: # if len(lastRestartStr) > 0:
lastRestart = float(lastRestartStr) # lastRestart = float(lastRestartStr)
#
print("screen changed. (last change: %s)" % lastRestart) # print("screen changed. (last change: %s)" % lastRestart)
#
delta=time.time()-lastRestart # delta=time.time()-lastRestart
if delta > 3: # if delta > 3:
import subprocess # import subprocess
lastRestartFile.seek(0) # lastRestartFile.seek(0)
lastRestartFile.write("%s" % time.time()) # lastRestartFile.write("%s" % time.time())
lastRestartFile.truncate() # lastRestartFile.truncate()
#
subprocess.call(["autorandr","-c"]) # subprocess.call(["autorandr","-c"])
qtile.cmd_restart() # qtile.cmd_restart()
else: # else:
print("screen is changing too fast: %s" % delta) # print("screen is changing too fast: %s" % delta)
#
active_screen = 0 # active_screen = 0
@hook.subscribe.client_focus # @hook.subscribe.client_focus
def focus_changed(window): # def focus_changed(window):
global active_screen # global active_screen
pass # pass
active_screen = window.group.screen.index # active_screen = window.group.screen.index
#
@hook.subscribe.current_screen_change # @hook.subscribe.current_screen_change
def move_widget(): # def move_widget():
global active_screen # global active_screen
systray = widget.Systray() # systray = widget.Systray()
logging.warn("Screen changed to %i" % active_screen) # logging.warn("Screen changed to %i" % active_screen)
key_super = "mod4" key_super = "mod4"
key_alt = "mod1" key_alt = "mod1"
@ -76,14 +96,11 @@ keys = [
Key([key_super], "r", lazy.spawncmd()), Key([key_super], "r", lazy.spawncmd()),
Key([key_super], "w", lazy.window.kill()), Key([key_super], "w", lazy.window.kill()),
# Key([key_alt, key_super], "l", lazy.spawn("xscreensaver-command -lock")),
# Key([key_alt, key_super], "l", lazy.spawn("sh -c '(sleep 1; xset dpms force off) & xautolock -locknow'")),
# Key([key_alt, key_super], "l", lazy.spawn("light-locker-command -l")),
# Key([key_alt, key_super], "l", lazy.spawn("dm-tool lock")),
Key([key_alt, key_super], "l", lazy.spawn('${pkgs.bash}/bin/sh -c "loginctl lock-session $XDG_SESSION_ID"')), Key([key_alt, key_super], "l", lazy.spawn('${pkgs.bash}/bin/sh -c "loginctl lock-session $XDG_SESSION_ID"')),
Key([key_alt, key_super], "s", lazy.spawn("${pkgs.systemd}/bin/systemctl suspend")), Key([key_alt, key_super], "s", lazy.spawn("${pkgs.systemd}/bin/systemctl suspend")),
Key([key_super, key_control], "r", lazy.restart()), # Key([key_super, key_control], "r", lazy.restart()),
Key([key_super, key_control], "r", lazy.spawn("${pkgs.autorandr}/bin/autorandr -c"), lazy.restart()),
Key([key_super, key_control], "q", lazy.shutdown()), Key([key_super, key_control], "q", lazy.shutdown()),
# Toggle between different layouts as defined below # Toggle between different layouts as defined below
@ -137,11 +154,9 @@ keys = [
## Microsoft Comfort Curve specific ## Microsoft Comfort Curve specific
Key([key_super, "shift"], "XF86TouchpadToggle", lazy.spawn("${pkgs.dbus}/bin/dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous")), Key([key_super, "shift"], "XF86TouchpadToggle", lazy.spawn("${pkgs.dbus}/bin/dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous")),
Key([key_alt, key_super], "XF86TouchpadToggle", lazy.spawn("${pkgs.dbus}/bin/dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next")), Key([key_alt, key_super], "XF86TouchpadToggle", lazy.spawn("${pkgs.dbus}/bin/dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next")),
Key([], "XF86AudioMute", lazy.spawn("${audio} mute")),
# FIXME: Backlight currently broken Key([], "XF86AudioLowerVolume", lazy.spawn("${audio} lower")),
# Key([], "XF86MonBrightnessDown", lazy.spawn("xbacklight -inc -5")), Key([], "XF86AudioRaiseVolume", lazy.spawn("${audio} raise")),
# Key([], "XF86MonBrightnessUp", lazy.spawn("xbacklight -inc 5")),
Key([], "Print", lazy.spawn("${pkgs.flameshot}/bin/flameshot gui")), Key([], "Print", lazy.spawn("${pkgs.flameshot}/bin/flameshot gui")),
] ]
groups = [Group(i) for i in "1234567890"] groups = [Group(i) for i in "1234567890"]