aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-02-18 13:22:42 +0100
committerMattias Andrée <maandree@kth.se>2024-02-18 13:22:42 +0100
commitc274475635d410c0e9f812e71d20183cb923cd6b (patch)
tree70f59c3b28a36921ea46a93effc565d59e20f43b
parentAdd makeenv (diff)
downloaddotfiles-c274475635d410c0e9f812e71d20183cb923cd6b.tar.gz
dotfiles-c274475635d410c0e9f812e71d20183cb923cd6b.tar.bz2
dotfiles-c274475635d410c0e9f812e71d20183cb923cd6b.tar.xz
misc updates
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--alsa-utils/Makefile28
-rwxr-xr-xalsa-utils/headphones5
-rwxr-xr-xalsa-utils/speakers5
-rw-r--r--alsa-utils/xinit6
-rwxr-xr-xcat-nonbackups3
-rwxr-xr-xcat-nonbackups-with-head18
-rwxr-xr-xcat-with-head19
-rwxr-xr-xcheck-any-installed4
-rwxr-xr-xman/man2
-rwxr-xr-xxorg-server/setkeys7
-rwxr-xr-xxorg-xrandr/setres/__main__.py320
-rwxr-xr-xxorg-xrandr/setres/__main__.py.gpp4
-rw-r--r--xpybar/config/myalsa.py18
-rw-r--r--xpybar/config/xmonad-monitor.gpp5
14 files changed, 113 insertions, 331 deletions
diff --git a/alsa-utils/Makefile b/alsa-utils/Makefile
new file mode 100644
index 0000000..13cc906
--- /dev/null
+++ b/alsa-utils/Makefile
@@ -0,0 +1,28 @@
+.POSIX:
+
+XINITRC_ORDER = 90
+
+install:
+ ../check-installed-shebang speakers
+ ../check-installed-shebang headphones
+ mkdir -p -- ~/.local/bin
+ test ! -e ~/.local/bin/speakers || test -L ~/.local/bin/speakers
+ ln -sf -- ~/.dotfiles/alsa-utils/speakers ~/.local/bin/speakers
+ test ! -e ~/.local/bin/headphones || test -L ~/.local/bin/headphones
+ ln -sf -- ~/.dotfiles/alsa-utils/headphones ~/.local/bin/headphones
+ mkdir -p -- ~/.config/X11/xinit/xinitrc.d
+ test ! -e ~/.config/X11/xinit/xinitrc.d/$(XINITRC_ORDER)-alsa-util || \
+ test -L ~/.config/X11/xinit/xinitrc.d/$(XINITRC_ORDER)-alsa-util
+ ln -sf -- ~/.dotfiles/alsa-util/xinit ~/.config/X11/xinit/xinitrc.d/$(XINITRC_ORDER)-alsa-util
+
+uninstall:
+ +! ../check-installed alsa-utils
+ -unlink -- ~/.local/bin/speakers
+ -unlink -- ~/.local/bin/headphones
+ -unlink -- ~/.config/X11/xinit/xinitrc.d/$(XINITRC_ORDER)-alsa-util
+ -rmdir -- ~/.config/X11/xinit/xinitrc.d
+ -rmdir -- ~/.config/X11/xinit
+ -rmdir -- ~/.config/X11
+
+clean:
+ @:
diff --git a/alsa-utils/headphones b/alsa-utils/headphones
new file mode 100755
index 0000000..59eb283
--- /dev/null
+++ b/alsa-utils/headphones
@@ -0,0 +1,5 @@
+#!/bin/dash
+amixer -c "${MAIN_ALSA_CARD}" -- set Speaker '0%' mute
+amixer -c "${MAIN_ALSA_CARD}" -- set PCM '15%' unmute
+amixer -c "${MAIN_ALSA_CARD}" -- set Master '100%' unmute
+amixer -c "${MAIN_ALSA_CARD}" -- set Headphone '100%' unmute
diff --git a/alsa-utils/speakers b/alsa-utils/speakers
new file mode 100755
index 0000000..0d238d3
--- /dev/null
+++ b/alsa-utils/speakers
@@ -0,0 +1,5 @@
+#!/bin/dash
+amixer -c "${MAIN_ALSA_CARD}" -- set Headphone '0%' mute
+amixer -c "${MAIN_ALSA_CARD}" -- set PCM '100%' unmute
+amixer -c "${MAIN_ALSA_CARD}" -- set Master '100%' unmute
+amixer -c "${MAIN_ALSA_CARD}" -- set Speaker '100%' unmute
diff --git a/alsa-utils/xinit b/alsa-utils/xinit
new file mode 100644
index 0000000..bd9b579
--- /dev/null
+++ b/alsa-utils/xinit
@@ -0,0 +1,6 @@
+# -*- shell-script -*-
+
+# Mute speakers and use headphones if using a work computer (TODO if on a laptop)
+if iswork; then
+ headphones || :
+fi
diff --git a/cat-nonbackups b/cat-nonbackups
index 387cf7a..2031eab 100755
--- a/cat-nonbackups
+++ b/cat-nonbackups
@@ -8,6 +8,9 @@ good_filename () {
test -n "$(printf '%s\n' "$1" | grep -v '^\.#' || :)" || return 1
test -n "$(printf '%s\n' "$1" | grep -v '^#' || :)" || return 1
}
+if test "$1" = "--"; then
+ shift 1
+fi
for file; do
if good_filename "$file" >/dev/null 2>/dev/null; then
cat -- "$file"
diff --git a/cat-nonbackups-with-head b/cat-nonbackups-with-head
new file mode 100755
index 0000000..426a50f
--- /dev/null
+++ b/cat-nonbackups-with-head
@@ -0,0 +1,18 @@
+#!/bin/sh
+set -e
+good_filename () {
+ test -n "$(printf '%s\n' "$1" | grep -v '~$' || :)" || return 1
+ test -n "$(printf '%s\n' "$1" | grep -v '\.swo$' || :)" || return 1
+ test -n "$(printf '%s\n' "$1" | grep -v '\.swp$' || :)" || return 1
+ test -n "$(printf '%s\n' "$1" | grep -v '\.bak$' || :)" || return 1
+ test -n "$(printf '%s\n' "$1" | grep -v '^\.#' || :)" || return 1
+ test -n "$(printf '%s\n' "$1" | grep -v '^#' || :)" || return 1
+}
+if test "$1" = "--"; then
+ shift 1
+fi
+for file; do
+ if good_filename "$file" >/dev/null 2>/dev/null; then
+ samedrun "$0" cat-with-head -- "$file"
+ fi
+done
diff --git a/cat-with-head b/cat-with-head
new file mode 100755
index 0000000..81e73bd
--- /dev/null
+++ b/cat-with-head
@@ -0,0 +1,19 @@
+#!/bin/sh
+set -e
+home="$(printf '%s\n' "$HOME" | sed 's:/\+:/:g' | sed '$s:/$::g')"
+if test -z "$(printf '%s\n' "$home" | tr -d '[A-Za-z0-9_/-]')"; then
+ pretty_filename () {
+ printf '%s' "$1" | sed '1s:^'"${home}"'/:~/:' | sed 's:/\+:/:g'
+ }
+else
+ pretty_filename () {
+ printf '%s' "$1" | sed 's:/\+:/:g'
+ }
+fi
+if test "$1" = "--"; then
+ shift 1
+fi
+for file; do
+ printf '\n\n\n### %s\n\n' "$(pretty_filename "$(realpath -- "$file")")"
+ cat -- "$file"
+done
diff --git a/check-any-installed b/check-any-installed
index 8329769..b8ae197 100755
--- a/check-any-installed
+++ b/check-any-installed
@@ -5,8 +5,8 @@ set -ue
if test -r /etc/lsb-release; then
. /etc/lsb-release
fi
-if test -r ~.dotfiles/.work/distrib-tweak; then
- . ~.dotfiles/.work/distrib-tweak
+if test -r ~/.dotfiles/.work/distrib-tweak; then
+ . ~/.dotfiles/.work/distrib-tweak
fi
for pkg; do
diff --git a/man/man b/man/man
index bcd9481..edc36af 100755
--- a/man/man
+++ b/man/man
@@ -33,7 +33,7 @@ fi
# Display, open new terminal if in the background
-if isfg; then
+if (! which isfg >/dev/null 2>/dev/null) || isfg; then
exec /usr/bin/man "$@"
elif test -x /usr/bin/terminator; then
exec terminator -e "/usr/bin/man $*"
diff --git a/xorg-server/setkeys b/xorg-server/setkeys
index 5837607..5837464 100755
--- a/xorg-server/setkeys
+++ b/xorg-server/setkeys
@@ -57,7 +57,7 @@ setxkbmap \
if test -z "${NO_UNICOMP}"; then
# Unicomp's newer versions of New Model M swapped AltGr and RSuper
# making it a torture device for even someone with as big hands as mine
- if cat /sys/class/input/*/name | grep Unicomp > /dev/null; then
+ if (cat /sys/class/input/*/name; cat "${XDG_RUNTIME_DIR}/vmhostkeyboards" ) 2>/dev/null | grep Unicomp > /dev/null; then
# Assign Compose to AltGr
printf '%s\n' 'keycode 108 = Multi_key Multi_key Multi_key Multi_key'
@@ -87,10 +87,11 @@ EOF
if cat /sys/class/input/*/name | grep Unicomp > /dev/null; then
# Turn off numlock LED
- input="$(grep Unicomp /sys/class/input/*/name | sed 's|^/sys/class/input/\(.*\)/name:.*$|\1|g' | sed 1q)"
+ input="$( (grep Unicomp /sys/class/input/*/name; cat "${XDG_RUNTIME_DIR}/vmhostkeyboards" | grep Unicomp || :) 2>/dev/null | \
+ sed 's|^/sys/class/input/\(.*\)/name:.*$|\1|g' | sed 1q)"
if ! echo 0 | sponge "/sys/class/leds/${input}::numlock/brightness" 2>/dev/null; then
if isfg; then
- # TODO do at boot
+ # TODO do at boot
asroot chown ${USER}:${USER} "/sys/class/leds/${input}::numlock/brightness"
echo 0 | sponge "/sys/class/leds/${input}::numlock/brightness"
fi
diff --git a/xorg-xrandr/setres/__main__.py b/xorg-xrandr/setres/__main__.py
deleted file mode 100755
index 94a2db1..0000000
--- a/xorg-xrandr/setres/__main__.py
+++ /dev/null
@@ -1,320 +0,0 @@
-#!/usr/bin/env python3
-
-import sys, os, pwd
-from subprocess import Popen, PIPE
-
-from get import *
-from set import *
-
-args = sys.argv[1:]
-home = os.environ['HOME'] if 'HOME' in os.environ else pwd.getpwuid(os.getuid()).pw_dir
-session_ = os.environ['SESSION_'] if 'SESSION_' in os.environ else ''
-hostname = os.uname().nodename.lower()
-
-t = lambda lopt, sopt : any(arg in args for arg in (lopt, '-' + lopt, '--' + lopt, sopt, '-' + sopt))
-
-mirror = t('mirror', 'm')
-swap = t('swap', 's')
-tv = t('tv', 't')
-wide = t('wide', 'w')
-crt = t('crt', 'c')
-large = t('large', 'l')
-single = t('single', '1')
-pretend = t('pretend', 'P')
-
-[screen] = get_setup()
-ok = False
-
-if pretend:
- def apply_setup(display):
- print(repr(display.to_xrandr()))
- return True
-
-phonies = []
-
-
-
-### Configurations
-
-if hostname == 'zenith':
- prime = screen['DisplayPort-1' if not swap else 'DisplayPort-1']
- sec = screen['DisplayPort-0' if not swap else 'DisplayPort-0']
- embed = None
-
- prime_alt = None
- sec_alt = None
-
- prime.want_mode = '1920x1200'
- sec.want_mode = '1920x1200'
-
- sec_position = 'left'
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-else:
- print('%s: no configurations found for this machine (%s)' % (sys.argv[0], hostname),
- file = sys.stderr)
- sys.exit(1)
-
-if prime is not None and not prime.connected and prime_alt is not None:
- prime, prime_alt = prime_alt, prime
-if sec is not None and not sec.connected and sec_alt is not None:
- sec, sec_alt = sec_alt, sec
-
-
-if large:
- prime.want_mode = '1792x1344'
- sec.want_mode = '1792x1344'
-
-if crt:
- prime.want_mode = '800x600'
- sec.want_mode = '800x600'
-
-if wide:
- prime.want_mode = '1920x1080'
- sec.want_mode = '1920x1080'
-
-if tv:
- sec.want_mode = '1920x1080'
-
-
-if prime is not None:
- prime.want_rate = prime.best_rate(prime.want_mode)
-if sec is not None:
- sec.want_rate = sec.best_rate(sec.want_mode)
-if embed is not None:
- embed.want_rate = embed.best_rate(embed.want_mode)
-
-
-
-
-if '+prime' in args:
- prime.connected = True
-if '+sec' in args:
- sec.connected = True
-if '+embed' in args:
- embed.connected = True
-
-if '-prime' in args:
- prime.connected = False
-if '-sec' in args:
- sec.connected = False
-if '-embed' in args:
- embed.connected = False
-
-
-
-
-### Apply
-
-if prime is not None and prime.connected and sec is not None and sec.connected and not single:
- display = Display()
- ok = True
-
- output = Output(prime.name)
- display.outputs.append(output)
- output.mode = prime.want_mode
- output.rate = prime.want_rate
- output.primary = True
- output.relpos = None
- output.relto = None
-
- output = Output(sec.name)
- display.outputs.append(output)
- output.mode = sec.want_mode
- output.rate = sec.want_rate
- output.primary = False
- output.relpos = (sec_position + '-of') if not mirror else 'same-as'
- output.relto = prime.name
-
- if embed is not None:
- output = Output(embed.name)
- display.outputs.append(output)
- if embed.want_mode == prime.want_mode:
- output.mode = embed.want_mode
- output.rate = embed.want_rate
- output.primary = False
- output.off = False
- output.relpos = 'same-as'
- output.relto = prime.name
- else:
- output.off = True
-
-
-elif prime is not None and prime.connected:
- display = Display()
- ok = True
-
- output = Output(prime.name)
- display.outputs.append(output)
- output.mode = prime.want_mode
- output.rate = prime.want_rate
- output.primary = True
-
- if sec is not None:
- output = Output(sec.name)
- display.outputs.append(output)
- output.off = True
-
- if embed is not None:
- output = Output(embed.name)
- display.outputs.append(output)
- if embed.want_mode == prime.want_mode:
- output.mode = embed.want_mode
- output.rate = embed.want_rate
- output.primary = False
- output.off = False
- output.relpos = 'same-as'
- output.relto = prime.name
- else:
- output.off = True
-
-
-elif sec is not None and sec.connected:
- display = Display()
- ok = True
-
- output = Output(sec.name)
- display.outputs.append(output)
- output.mode = sec.want_mode
- output.rate = sec.want_rate
- output.primary = True
-
- if prime is not None:
- output = Output(prime.name)
- display.outputs.append(output)
- output.off = True
-
- if embed is not None:
- output = Output(embed.name)
- display.outputs.append(output)
- if embed.want_mode == sec.want_mode:
- output.mode = embed.want_mode
- output.rate = embed.want_rate
- output.primary = False
- output.off = False
- output.relpos = 'same-as'
- output.relto = sec.name
- else:
- output.off = True
-
-
-elif embed is None or not embed.connected:
- print('%s: don\'t know how to configure' % sys.argv[0], file = sys.stderr)
-
-
-else:
- display = Display()
- ok = True
-
- output = Output(embed.name)
- display.outputs.append(output)
- output.mode = embed.want_mode
- output.rate = embed.want_rate
- output.primary = True
-
- if prime is not None:
- output = Output(prime.name)
- display.outputs.append(output)
- output.off = True
-
- if sec is not None:
- output = Output(sec.name)
- display.outputs.append(output)
- output.off = True
-
-
-if ok:
- if prime_alt is not None:
- output = Output(prime_alt.name)
- display.outputs.append(output)
- output.off = True
-
- if sec_alt is not None:
- output = Output(sec_alt.name)
- display.outputs.append(output)
- output.off = True
-
- for phony in phonies:
- output = Output(phony.name)
- display.outputs.append(output)
- output.off = True
-
- ok = apply_setup(display)
-
-
-
-### Epilogue
-
-if not ok:
- sys.exit(1)
-if pretend:
- sys.exit(0)
-
-reschargs = []
-for output in (prime, sec):
- if output is not None:
- output = screen[output.name]
- reschargs.extend(output.size)
- reschargs.extend(output.position)
-[screen] = get_setup()
-prime = screen[True]
-if prime.position[0] > 0:
- print(prime.position[0], flush = True)
-
-file = '%s/.config/resolution-changed' % home
-if os.path.exists(file):
- try:
- os.execlp(file, file, *reschargs)
- except:
- pass
-
-for file in ('%s/.config/background.%s' % (home, session_), '%s/.config/background' % home):
- if os.path.exists(file):
- try:
- os.execlp('xwallpaper', 'xwallpaper', '--zoom', file)
- except:
- pass
diff --git a/xorg-xrandr/setres/__main__.py.gpp b/xorg-xrandr/setres/__main__.py.gpp
index d34b85c..f5200c8 100755
--- a/xorg-xrandr/setres/__main__.py.gpp
+++ b/xorg-xrandr/setres/__main__.py.gpp
@@ -50,12 +50,12 @@ if hostname == 'zenith':
sec_position = 'left'
%%>hostname="$(hostname | tr '[A-Z]' '[a-z]')"
-%%>file="${HOME}/.dotfiles/xorg-xrandr/setres/${hostname}"
+%%>file="${HOME}/.dotfiles/private/setres/${hostname}"
%%>if test -r "${file}"; then
elif hostname == '%%{hostname}':
connectors = {con.edid: con.name for con in screen.connectors if con.connected and con.edid and con.name}
-%%>cat -- "${file}"
+%%>sed 's/^[[:space:]]*\([^[:space:]]\)/ \1/' < "${file}"
primes = [(home_prime, '1920x1200'),
(work_prime, '1920x1080')]
diff --git a/xpybar/config/myalsa.py b/xpybar/config/myalsa.py
index 552c459..ef246c0 100644
--- a/xpybar/config/myalsa.py
+++ b/xpybar/config/myalsa.py
@@ -4,6 +4,11 @@ import alsaaudio
from common import *
+class MixerAction:
+ def __init__(self, name, action):
+ self.name = name
+ self.action = action
+
class MyALSA(Entry):
def __init__(self, *args, timeout = None, sleep = None, cards = -1, mixers = None, colours = {}, prefix = '', **kwargs): ## TODO support multiple cards and all mixers
self.colours = colours if colours is not None else {}
@@ -28,6 +33,7 @@ class MyALSA(Entry):
else:
cards = cards
self.alsa = []
+ self.actions = []
names = {}
for index in alsaaudio.card_indexes():
for name in alsaaudio.card_name(index):
@@ -36,6 +42,11 @@ class MyALSA(Entry):
card = names.get(card, card)
for mixer in mixers: ## TODO support by name (and 'default')
try:
+ if isinstance(mixer, MixerAction):
+ self.actions.append(mixer.action)
+ mixer = mixer.name
+ else:
+ self.actions.append(None)
if isinstance(mixer, tuple) or isinstance(mixer, list):
self.alsa.append([ALSA(card, m) for m in mixer])
else:
@@ -112,7 +123,8 @@ class MyALSA(Entry):
channel = -1
break
col -= 1
-
+
+ action = self.actions[mixer]
mixer = self.alsa[mixer]
if isinstance(mixer, list):
if button == LEFT_BUTTON:
@@ -125,6 +137,10 @@ class MyALSA(Entry):
volume = mixer.get_volume()
volume = limited(sum(volume) / len(volume))
mixer.set_volume(volume, -1)
+ elif button == MIDDLE_BUTTON:
+ if action is not None:
+ print('middle click: ' + str(action is not None))
+ action()
elif button in (SCROLL_UP, SCROLL_DOWN):
volume = mixer.get_volume()
adj = -5 if button == SCROLL_DOWN else 5
diff --git a/xpybar/config/xmonad-monitor.gpp b/xpybar/config/xmonad-monitor.gpp
index 4e9d0c4..df42701 100644
--- a/xpybar/config/xmonad-monitor.gpp
+++ b/xpybar/config/xmonad-monitor.gpp
@@ -32,7 +32,7 @@ G.TERMINAL = 'xterm'
G.OUTPUT, G.HEIGHT_PER_LINE, G.YPOS, G.TOP = 0, 12, 0, True
G.FONT = '-misc-fixed-medium-r-normal-*-10-*-*-*-c-*-iso10646-1'
-from myalsa import MyALSA
+from myalsa import MyALSA, MixerAction
from mybacklight import MyBacklight
from mybattery import MyBattery
from mybrilliance import MyBrilliance
@@ -96,7 +96,8 @@ mixers1 = ['Master', 'PCM'] ## TODO
%%>if iswork; then
#mixers1.append(('Headphone', 'Speaker'))
if not isvm:
- mixers1.extend(('Headphone', 'Speaker'))
+ mixers1.append(MixerAction('Headphone', lambda : spawn_read('headphones')))
+ mixers1.append(MixerAction('Speaker', lambda : spawn_read('speakers')))
%%>fi
card2 = 'Yeti Stereo Microphone'
mixers2 = ['Speaker', 'Mic']