Switch to qtile.
This commit is contained in:
parent
072f0ed604
commit
29788d6fec
75 changed files with 214 additions and 1 deletions
65
_desktop/_scripts/dmenu-audio
Executable file
65
_desktop/_scripts/dmenu-audio
Executable file
|
@ -0,0 +1,65 @@
|
|||
#!/bin/sh
|
||||
|
||||
div="----------"
|
||||
|
||||
set_output() {
|
||||
sel_sink=$(printf "$sinks\\n$div\\nback\\nexit" | dmenu -c -l 10 -i)
|
||||
case "$sel_sink" in
|
||||
back) show_current ;;
|
||||
exit) exit ;;
|
||||
*) pactl set-default-sink $(pactl list sinks | grep -B 1 "$sel_sink" | awk -F': ' '/Name:/ {print $2}') ;;
|
||||
esac
|
||||
kill -46 $(pidof dwmblocks)
|
||||
show_current
|
||||
}
|
||||
|
||||
set_input() {
|
||||
sel_source=$(printf "$sources\\n$div\\nBluetooth profile\\n$div\\nback\\nexit" | dmenu -c -l 10 -i)
|
||||
case "$sel_source" in
|
||||
back) show_current ;;
|
||||
exit) exit ;;
|
||||
Bluetooth*) set_bt_profile ;;
|
||||
*) pactl set-default-source "$(pactl list sources | grep -B 1 "$sel_source" | awk -F': ' '/Name:/ {print $2}')" ;;
|
||||
esac
|
||||
kill -46 $(pidof dwmblocks)
|
||||
show_current
|
||||
}
|
||||
|
||||
set_bt_profile() {
|
||||
bt_sink=$(pactl list cards | awk -F'"' '/device.name.*bluez/ {print $2}')
|
||||
[ -z "${bt_sink}" ] &&
|
||||
{ dunstify -u critical "🎧 no headphones connected"; exit; }
|
||||
profile_chosen=$(printf "profile mSBC\\nprofile LDAC\\n$div\\nback\\nexit" | dmenu -c -l 5 -i)
|
||||
case "$profile_chosen" in
|
||||
back) show_current ;;
|
||||
exit) exit ;;
|
||||
profile*mSBC) pactl set-card-profile $bt_sink headset-head-unit-msbc
|
||||
pactl set-default-source $(pactl list sources short | awk '/bluez_input/ {print $2}') ;;
|
||||
profile*LDAC) pactl set-card-profile $bt_sink a2dp-sink-ldac ;;
|
||||
*) show_current ;;
|
||||
esac
|
||||
pactl set-default
|
||||
}
|
||||
|
||||
show_current() {
|
||||
def_snk=$(pactl list | grep -A 1 "Name: $(pactl get-default-sink)\$" | awk -F': ' '/Description: / {print $2}')
|
||||
def_src=$(pactl list | grep -A 1 "Name: $(pactl get-default-source)\$" | awk -F': ' '/Description: / {print $2}')
|
||||
chosen=$(printf "Output: $def_snk\\nInput: $def_src" | dmenu -c -l 2)
|
||||
if [ "$1" = "no_switch" ]; then
|
||||
case "$chosen" in
|
||||
*) dunstify -u critical "🔊 no device to switch" ;;
|
||||
esac
|
||||
else
|
||||
case "$chosen" in
|
||||
Output*) set_output ;;
|
||||
Input*) set_input ;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
sinks=$(pactl list sinks | awk -F': ' '/Description:/ {print $2}')
|
||||
sources=$(pactl list sources | grep -v 'Monitor of ' | awk -F': ' '/Description:/ {print $2}')
|
||||
[ "$(echo "$sinks" | wc -l)" -lt 2 ] &&
|
||||
{ show_current no_switch; exit; }
|
||||
|
||||
show_current
|
299
_desktop/_scripts/dmenu-bluetooth
Executable file
299
_desktop/_scripts/dmenu-bluetooth
Executable file
|
@ -0,0 +1,299 @@
|
|||
#!/usr/bin/env bash
|
||||
# __ _ _ _ _ _ _
|
||||
# _ __ ___ / _(_) | |__ | |_ _ ___| |_ ___ ___ | |_| |__
|
||||
# | '__/ _ \| |_| |_____| '_ \| | | | |/ _ \ __/ _ \ / _ \| __| '_ \
|
||||
# | | | (_) | _| |_____| |_) | | |_| | __/ || (_) | (_) | |_| | | |
|
||||
# |_| \___/|_| |_| |_.__/|_|\__,_|\___|\__\___/ \___/ \__|_| |_|
|
||||
#
|
||||
# Author: Nick Clyde (clydedroid)
|
||||
#
|
||||
|
||||
# Constants
|
||||
divider="----------"
|
||||
goback="back"
|
||||
|
||||
# Checks if bluetooth controller is powered on
|
||||
power_on() {
|
||||
if bluetoothctl show | grep -q "Powered: yes"; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Toggles power state
|
||||
toggle_power() {
|
||||
if power_on; then
|
||||
bluetoothctl power off
|
||||
show_menu
|
||||
else
|
||||
if rfkill list bluetooth | grep -q 'blocked: yes'; then
|
||||
rfkill unblock bluetooth && sleep 3
|
||||
fi
|
||||
bluetoothctl power on
|
||||
show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
# Checks if controller is scanning for new devices
|
||||
scan_on() {
|
||||
if bluetoothctl show | grep -q "Discovering: yes"; then
|
||||
echo "scan: on"
|
||||
return 0
|
||||
else
|
||||
echo "scan: off"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Toggles scanning state
|
||||
toggle_scan() {
|
||||
if scan_on; then
|
||||
kill $(pgrep -f "bluetoothctl scan on")
|
||||
bluetoothctl scan off
|
||||
show_menu
|
||||
else
|
||||
bluetoothctl scan on &
|
||||
echo "scanning..."
|
||||
sleep 5
|
||||
show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
# Checks if controller is able to pair to devices
|
||||
pairable_on() {
|
||||
if bluetoothctl show | grep -q "Pairable: yes"; then
|
||||
echo "pairable: on"
|
||||
return 0
|
||||
else
|
||||
echo "pairable: off"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Toggles pairable state
|
||||
toggle_pairable() {
|
||||
if pairable_on; then
|
||||
bluetoothctl pairable off
|
||||
show_menu
|
||||
else
|
||||
bluetoothctl pairable on
|
||||
show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
# Checks if controller is discoverable by other devices
|
||||
discoverable_on() {
|
||||
if bluetoothctl show | grep -q "Discoverable: yes"; then
|
||||
echo "discoverable: on"
|
||||
return 0
|
||||
else
|
||||
echo "discoverable: off"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Toggles discoverable state
|
||||
toggle_discoverable() {
|
||||
if discoverable_on; then
|
||||
bluetoothctl discoverable off
|
||||
show_menu
|
||||
else
|
||||
bluetoothctl discoverable on
|
||||
show_menu
|
||||
fi
|
||||
}
|
||||
|
||||
# Checks if a device is connected
|
||||
device_connected() {
|
||||
device_info=$(bluetoothctl info "$1")
|
||||
if echo "$device_info" | grep -q "Connected: yes"; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Toggles device connection
|
||||
toggle_connection() {
|
||||
if device_connected $1; then
|
||||
bluetoothctl disconnect $1
|
||||
device_menu "$device"
|
||||
else
|
||||
bluetoothctl connect $1
|
||||
device_menu "$device"
|
||||
fi
|
||||
}
|
||||
|
||||
# Checks if a device is paired
|
||||
device_paired() {
|
||||
device_info=$(bluetoothctl info "$1")
|
||||
if echo "$device_info" | grep -q "Paired: yes"; then
|
||||
echo "paired: yes"
|
||||
return 0
|
||||
else
|
||||
echo "paired: no"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Toggles device paired state
|
||||
toggle_paired() {
|
||||
if device_paired $1; then
|
||||
bluetoothctl remove $1
|
||||
device_menu "$device"
|
||||
else
|
||||
bluetoothctl pair $1
|
||||
device_menu "$device"
|
||||
fi
|
||||
}
|
||||
|
||||
# Checks if a device is trusted
|
||||
device_trusted() {
|
||||
device_info=$(bluetoothctl info "$1")
|
||||
if echo "$device_info" | grep -q "Trusted: yes"; then
|
||||
echo "trusted: yes"
|
||||
return 0
|
||||
else
|
||||
echo "trusted: no"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Toggles device connection
|
||||
toggle_trust() {
|
||||
if device_trusted $1; then
|
||||
bluetoothctl untrust $1
|
||||
device_menu "$device"
|
||||
else
|
||||
bluetoothctl trust $1
|
||||
device_menu "$device"
|
||||
fi
|
||||
}
|
||||
|
||||
# Prints a short string with the current bluetooth status
|
||||
# Useful for status bars like polybar, etc.
|
||||
print_status() {
|
||||
if power_on; then
|
||||
printf ''
|
||||
|
||||
mapfile -t paired_devices < <(bluetoothctl paired-devices | grep Device | cut -d ' ' -f 2)
|
||||
counter=0
|
||||
|
||||
for device in "${paired_devices[@]}"; do
|
||||
if device_connected $device; then
|
||||
device_alias=$(bluetoothctl info $device | grep "Alias" | cut -d ' ' -f 2-)
|
||||
|
||||
if [ $counter -gt 0 ]; then
|
||||
printf ", %s" "$device_alias"
|
||||
else
|
||||
printf " %s" "$device_alias"
|
||||
fi
|
||||
|
||||
((counter++))
|
||||
fi
|
||||
done
|
||||
printf "\n"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# A submenu for a specific device that allows connecting, pairing, and trusting
|
||||
device_menu() {
|
||||
device=$1
|
||||
|
||||
# Get device name and mac address
|
||||
device_name=$(echo $device | cut -d ' ' -f 3-)
|
||||
mac=$(echo $device | cut -d ' ' -f 2)
|
||||
|
||||
# Build options
|
||||
if device_connected $mac; then
|
||||
connected="connected: yes"
|
||||
else
|
||||
connected="connected: no"
|
||||
fi
|
||||
paired=$(device_paired $mac)
|
||||
trusted=$(device_trusted $mac)
|
||||
options="$connected\n$paired\n$trusted\n$divider\n$goback\nexit"
|
||||
|
||||
chosen="$(echo -e "$options" | $rofi_command "$device_name")"
|
||||
|
||||
# Match chosen option to command
|
||||
case $chosen in
|
||||
"" | $divider)
|
||||
echo "no option chosen."
|
||||
;;
|
||||
$connected)
|
||||
toggle_connection $mac
|
||||
;;
|
||||
$paired)
|
||||
toggle_paired $mac
|
||||
;;
|
||||
$trusted)
|
||||
toggle_trust $mac
|
||||
;;
|
||||
$goback)
|
||||
show_menu
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
show_menu() {
|
||||
# Get menu options
|
||||
if power_on; then
|
||||
power="power: on"
|
||||
|
||||
# Human-readable names of devices, one per line
|
||||
# If scan is off, will only list paired devices
|
||||
devices=$(bluetoothctl devices | grep Device | cut -d ' ' -f 3-)
|
||||
|
||||
# Get controller flags
|
||||
scan=$(scan_on)
|
||||
pairable=$(pairable_on)
|
||||
discoverable=$(discoverable_on)
|
||||
|
||||
options="$devices\n$divider\n$power\n$scan\n$pairable\n$discoverable\nexit"
|
||||
else
|
||||
power="power: off"
|
||||
options="$power\nexit"
|
||||
fi
|
||||
|
||||
chosen="$(echo -e "$options" | $rofi_command "bluetooth")"
|
||||
|
||||
# Match chosen option to command
|
||||
case $chosen in
|
||||
"" | $divider)
|
||||
echo "No option chosen."
|
||||
;;
|
||||
$power)
|
||||
toggle_power
|
||||
;;
|
||||
$scan)
|
||||
toggle_scan
|
||||
;;
|
||||
$discoverable)
|
||||
toggle_discoverable
|
||||
;;
|
||||
$pairable)
|
||||
toggle_pairable
|
||||
;;
|
||||
*)
|
||||
device=$(bluetoothctl devices | grep "$chosen")
|
||||
# Open a submenu if a device is selected
|
||||
if [[ $device ]]; then device_menu "$device"; fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# command to pipe into, can add any options here
|
||||
rofi_command="dmenu -c -l 20 -i -p"
|
||||
|
||||
case "$1" in
|
||||
--status)
|
||||
print_status
|
||||
;;
|
||||
*)
|
||||
show_menu
|
||||
;;
|
||||
esac
|
64
_desktop/_scripts/dmenu-display
Executable file
64
_desktop/_scripts/dmenu-display
Executable file
|
@ -0,0 +1,64 @@
|
|||
#!/bin/sh
|
||||
|
||||
twoscreen() {
|
||||
mirror=$(printf "no\\nyes" | dmenu -c -l 2 -i -p "mirror?")
|
||||
if [ "$mirror" = "yes" ]; then
|
||||
external=$(echo "$screens" | dmenu -c -l 2 -i)
|
||||
internal=$(echo "$screens" | grep -v "$external")
|
||||
res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \
|
||||
tail -n 1 | awk '{print $1}')
|
||||
res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | \
|
||||
tail -n 1 | awk '{print $1}')
|
||||
res_ext_x=$(echo "$res_external" | sed 's/x.*//')
|
||||
res_ext_y=$(echo "$res_external" | sed 's/.*x//')
|
||||
res_int_x=$(echo "$res_internal" | sed 's/x.*//')
|
||||
res_int_y=$(echo "$res_internal" | sed 's/.*x//')
|
||||
scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l)
|
||||
scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l)
|
||||
xrandr --output "$external" --auto --scale 1.0x1.0 \
|
||||
--output "$internal" --auto --same-as "$external" \
|
||||
--scale "$scale_x"x"$scale_y"
|
||||
else
|
||||
primary=$(echo "$screens" | dmenu -c -l 50 -i -p "select primary output")
|
||||
secondary=$(echo "$screens" | grep -v "$primary")
|
||||
direction=$(printf "left\\nright" | dmenu -c -l 2 -i -p "secondary display location")
|
||||
xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0
|
||||
fi
|
||||
}
|
||||
|
||||
onescreen() {
|
||||
if [ "$2" = "native" ]; then
|
||||
xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
|
||||
else
|
||||
scale=$(printf "native\\n0.75\\n0.5" | dmenu -c -l 3 -i -p "scale") &&
|
||||
case "$scale" in
|
||||
"native") xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -);;
|
||||
*) xrandr --output "$1" --auto --scale ${scale}x${scale} $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -);;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
postrun() {
|
||||
feh --no-fehbg --bg-scale ~/.local/share/wallpaper.jpg
|
||||
{ killall dunst ; setsid -f dunst ;} >/dev/null 2>&1 # Restart dunst to ensure proper location on screen
|
||||
kill -46 $(pidof dwmblocks)
|
||||
}
|
||||
|
||||
# Get all possible displays
|
||||
allposs=$(xrandr -q | grep "connected")
|
||||
|
||||
# Get all connected screens.
|
||||
screens=$(echo "$allposs" | awk '/ connected/ {print $1}')
|
||||
|
||||
# If there's only one screen
|
||||
[ "$(echo "$screens" | wc -l)" -lt 2 ] &&
|
||||
{ onescreen "$screens" "native"; postrun; dunstify -u critical "💻 no device to switch"; exit ;}
|
||||
|
||||
# Get user choice including both and manual selection:
|
||||
chosen=$(printf -- "%s\\nmulti" "$screens" | dmenu -c -l 5 -i -p "select output") &&
|
||||
case "$chosen" in
|
||||
"multi") twoscreen ;;
|
||||
*) onescreen "$chosen" ;;
|
||||
esac
|
||||
|
||||
postrun
|
11
_desktop/_scripts/dmenu-emoji
Executable file
11
_desktop/_scripts/dmenu-emoji
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
|
||||
chosen=$(cut -d ';' -f1 ~/.local/share/emoji | dmenu -l 30 -i | sed "s/ .*//")
|
||||
[ -z "$chosen" ] && exit
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
xdotool type "$chosen"
|
||||
else
|
||||
printf "$chosen" | xclip -rmlastnl
|
||||
dunstify "'$chosen' copied to clipboard" &
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue