summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitsuo Tokumori <[email protected]>2023-11-25 15:50:08 -0500
committerMitsuo Tokumori <[email protected]>2023-11-25 15:50:56 -0500
commitc285ddd9d16f0038da0c036882eef7be75e2aae0 (patch)
tree7c4b75f275c2bf63dea6d5691051ea6e973def4c
parent6778640f84cce092f425ad4ab9a1ec310a08f6d2 (diff)
downloaddotfiles-c285ddd9d16f0038da0c036882eef7be75e2aae0.tar.gz
dotfiles-c285ddd9d16f0038da0c036882eef7be75e2aae0.tar.bz2
dotfiles-c285ddd9d16f0038da0c036882eef7be75e2aae0.zip
Add helper scripts for dwmblocks
-rw-r--r--code/dwm/config.h6
-rw-r--r--code/st/config.h6
-rw-r--r--config/xorg/xbindkeysrc39
-rw-r--r--config/xorg/xinitrc1
-rw-r--r--local/bin/README.txt10
-rwxr-xr-xlocal/bin/audio_control.sh28
-rwxr-xr-xlocal/bin/brightness_control.sh17
-rwxr-xr-xlocal/bin/input_control.sh62
-rwxr-xr-xlocal/bin/network_control.sh23
-rwxr-xr-xlocal/bin/sb-audio30
-rwxr-xr-xlocal/bin/sb-battery37
-rwxr-xr-xlocal/bin/sb-input9
-rwxr-xr-xlocal/bin/setup_default_apps.sh (renamed from local/bin/setup-default-apps.sh)0
13 files changed, 254 insertions, 14 deletions
diff --git a/code/dwm/config.h b/code/dwm/config.h
index 1ce52fb..d12931a 100644
--- a/code/dwm/config.h
+++ b/code/dwm/config.h
@@ -5,7 +5,11 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */
static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
-static const char *fonts[] = { "monospace:size=10" };
+static const char *fonts[] = {
+ "monospace:size=10",
+ "Noto Sans CJK JP:size=10", //:antialias=true:autohint=true",
+ "Noto Color Emoji:size=8", //:antialias=true:autohint=true",
+};
static const char dmenufont[] = "monospace:size=10";
static const char col_gray1[] = "#222222";
static const char col_gray2[] = "#444444";
diff --git a/code/st/config.h b/code/st/config.h
index bffaed5..267246f 100644
--- a/code/st/config.h
+++ b/code/st/config.h
@@ -8,6 +8,12 @@
* 2560x1440 (15.6"): pixelsize=16
*
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
+ *
+ * NOTE: Use either pixelsize=10 (absolute) or size=10 (relative to xrandr DPI
+ * setting). In my config I'm currently using `size` for dwm, but
+ * `pixelsize` for st. Idk, maybe one day I'll make it tidy. Also the
+ * font for st is Hack because I'm used to it, but in dwm is monospace,
+ * which currently defaults to "Noto Sans Mono".
*/
//static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
static char *font = "Hack:pixelsize=16:antialias=true:autohint=true";
diff --git a/config/xorg/xbindkeysrc b/config/xorg/xbindkeysrc
index 61a978e..20c458c 100644
--- a/config/xorg/xbindkeysrc
+++ b/config/xorg/xbindkeysrc
@@ -99,28 +99,28 @@
# Ref.:
# https://wiki.archlinux.org/title/Backlight
-"pactl set-sink-volume '@DEFAULT_SINK@' '+10%'"
- Mod4 + k
+"audio_control.sh inc"
+ Mod4 + 0
# XF86AudioRaiseVolume
-"pactl set-sink-volume '@DEFAULT_SINK@' '-10%'"
- Mod4 + j
+"audio_control.sh dec"
+ Mod4 + 9
# XF86AudioLowerVolume
-"pactl set-sink-mute '@DEFAULT_SINK@' 'toggle'"
- Shift+Mod4 + m
+"audio_control.sh mutetoggle"
+ Mod4 + m
# XF86AudioMute
-"pactl set-source-mute @DEFAULT_SOURCE@ toggle"
- Mod4 + m
+"audio_control.sh deafentoggle"
+ Mod4 + n
# Maybe it'd be a good idea to remove the sudo from here, idk
-"sudo xbacklight -inc 10"
- Shift+Mod4 + k
+"brightness_control.sh inc"
+ Shift+Mod4 + 0
# XF86MonBrightnessUp
-"sudo xbacklight -dec 10"
- Shift+Mod4 + j
+"brightness_control.sh dec"
+ Shift+Mod4 + 9
# XF86MonBrightnessDown
# Suckless desktop
@@ -138,6 +138,21 @@
"screenshot.sh screen"
Shift + Print
+# This key combination (Mod4 + Space) seems to break xbindkeys
+# See Also:
+# https://bbs.archlinux.org/viewtopic.php?id=226182
+#"audio_control.sh dec"
+# Mod4 + Space
+
+"input_control.sh en"
+ Mod4 + k
+
+"input_control.sh es"
+ Mod4 + l
+
+"input_control.sh ja"
+ Mod4 + j
+
# Launch applications (super + key)
# ---------------------------------
diff --git a/config/xorg/xinitrc b/config/xorg/xinitrc
index 6268abc..c70e4fa 100644
--- a/config/xorg/xinitrc
+++ b/config/xorg/xinitrc
@@ -68,4 +68,5 @@ setxkbmap -option caps:escape # map CAPSLOCK to ESC
# Start dwm
xautolock -time 10 -locker slock &
+dwmblocks &
exec dwm
diff --git a/local/bin/README.txt b/local/bin/README.txt
index b9207a4..094a5b3 100644
--- a/local/bin/README.txt
+++ b/local/bin/README.txt
@@ -1,7 +1,15 @@
My Linux executable scripts.
-Notes:
+NOTES
* Beware of not leaking personal information
I also use other people's awesome scrips. I store them in `~/code` and then
slink the ones I use in `~/.local/bin`.
+
+NOTATION
+* All scripts here should end in ".sh"
+* `laptop-*` scripts might only work on my current machine
+* `sb-*` scripts are meant to be called by dwmblocks
+ See also:
+ https://github.com/LukeSmithxyz/voidrice/tree/master/.local/bin/statusbar
+ https://github.com/LukeSmithxyz/dwmblocks/blob/master/config.h
diff --git a/local/bin/audio_control.sh b/local/bin/audio_control.sh
new file mode 100755
index 0000000..516721a
--- /dev/null
+++ b/local/bin/audio_control.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+delta=${2:-10}
+signal=10
+
+# signal dwmblocks to update volume block
+send_signal() {
+ pkill -RTMIN+$signal dwmblocks
+}
+
+case $1 in
+ inc) pactl set-sink-volume @DEFAULT_SINK@ +$delta% ;;
+ dec) pactl set-sink-volume @DEFAULT_SINK@ -$delta% ;;
+ mutetoggle) pactl set-sink-mute @DEFAULT_SINK@ toggle ;;
+ deafentoggle) pactl set-source-mute @DEFAULT_SOURCE@ toggle ;;
+ *)
+ echo Speaker:
+ pactl get-sink-volume @DEFAULT_SINK@
+ pactl get-sink-mute @DEFAULT_SINK@
+ echo -e "\nMic:"
+ pactl get-source-volume @DEFAULT_SOURCE@
+ pactl get-source-mute @DEFAULT_SOURCE@
+ echo -e "\nApplications:"
+ pactl list sink-inputs | grep -e 'Sink Input' -e 'application.name' -e 'Volume:'
+ ;;
+esac
+
+send_signal
diff --git a/local/bin/brightness_control.sh b/local/bin/brightness_control.sh
new file mode 100755
index 0000000..13345d7
--- /dev/null
+++ b/local/bin/brightness_control.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+delta=${2:-10}
+signal=11
+
+# signal dwmblocks to update block
+send_signal() {
+ pkill -RTMIN+$signal dwmblocks
+}
+
+case $1 in
+ inc) xbacklight -inc $delta ;;
+ dec) xbacklight -dec $delta ;;
+ *) xbacklight -get ;;
+esac
+
+send_signal
diff --git a/local/bin/input_control.sh b/local/bin/input_control.sh
new file mode 100755
index 0000000..05bc1cb
--- /dev/null
+++ b/local/bin/input_control.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+# Use either X keyboard extension layouts (setxkbmap), or fcitx (or both).
+#
+# At first I configured this to use setxkbmap, it works fine.
+#
+# fcitx already provides keybindings, but I wanted to display
+# the current input method in dwmblocks immediatly. So I'm
+# adding such support through fcitx5-remote.
+
+signal=20
+
+# signal dwmblocks to update block
+send_signal() {
+ pkill -RTMIN+$signal dwmblocks
+}
+
+# Cycle X keyboard extension layouts
+cycle_layouts() {
+ layouts=(us latam) # X keyboard extension
+ STATE_FILE="$XDG_STATE_HOME/keyboard_layout_state"
+
+ if [ -f "$STATE_FILE" ]; then
+ index=$(cat "$STATE_FILE")
+ else
+ index=0
+ fi
+ next_index=$(( (index + 1) % ${#layouts[@]} ))
+ echo $next_index > "$STATE_FILE"
+
+ setxkbmap ${layouts[$index]}
+}
+
+fcitx_control() {
+ # For this to correctly reflect the state of the system "Share Input State"
+ # should be set to "All" in fcitx5-configtool.
+
+ case $1 in
+ en)
+ fcitx5-remote -g Default
+ fcitx5-remote -c # Closed
+ ;;
+ es)
+ fcitx5-remote -g Spanish
+ fcitx5-remote -c # Closed
+ ;;
+ ja)
+ fcitx5-remote -g Default
+ fcitx5-remote -o # Open
+ ;;
+ *)
+ fcitx5-remote -q #
+ fcitx5-remote -n
+ fcitx5-remote
+ ;;
+ esac
+}
+
+#cycle_layouts
+fcitx_control $1
+
+send_signal
diff --git a/local/bin/network_control.sh b/local/bin/network_control.sh
new file mode 100755
index 0000000..381cbec
--- /dev/null
+++ b/local/bin/network_control.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+signal=30
+
+# signal dwmblocks to update volume block
+send_signal() {
+ pkill -RTMIN+$signal dwmblocks
+}
+
+case $1 in
+ inc) pactl set-sink-volume @DEFAULT_SINK@ +$delta% ;;
+ dec) pactl set-sink-volume @DEFAULT_SINK@ -$delta% ;;
+ mutetoggle) pactl set-sink-mute @DEFAULT_SINK@ toggle ;;
+ deafentoggle) pactl set-source-mute @DEFAULT_SOURCE@ toggle ;;
+ *)
+ echo Wifi:
+ echo -e "\nBluetooth:"
+ bluetoothctl show
+ echo -e "\nEthernet:"
+ ;;
+esac
+
+send_signal
diff --git a/local/bin/sb-audio b/local/bin/sb-audio
new file mode 100755
index 0000000..6258869
--- /dev/null
+++ b/local/bin/sb-audio
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+# Prints the current volume and 🔇 if muted.
+
+case $BLOCK_BUTTON in
+ 1) setsid -w -f "$TERMINAL" -e pulsemixer; pkill -RTMIN+10 "${STATUSBAR:-dwmblocks}" ;;
+ 2) wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle ;;
+ 4) wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%+ ;;
+ 5) wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%- ;;
+ 3) notify-send "📢 Volume module" "\- Shows volume 🔊, 🔇 if muted.
+- Middle click to mute.
+- Scroll to change." ;;
+ 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
+esac
+
+#vol="$(wpctl get-volume @DEFAULT_AUDIO_SINK@)"
+
+vol="$(pactl get-sink-volume @DEFAULT_SINK@ | awk '/Volume/ { gsub(/%/,"",$5); print $5 }')"
+
+case 1 in
+ $((vol >= 70)) ) icon="🔊" ;;
+ $((vol >= 30)) ) icon="🔉" ;;
+ * ) icon="🔈" ;;
+esac
+
+if pactl get-sink-mute @DEFAULT_SINK@ | grep -q yes; then
+ icon="🔇"
+fi
+
+echo "$icon$vol%"
diff --git a/local/bin/sb-battery b/local/bin/sb-battery
new file mode 100755
index 0000000..93cbe08
--- /dev/null
+++ b/local/bin/sb-battery
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# Prints all batteries, their percentage remaining and an emoji corresponding
+# to charge status (🔌 for plugged up, 🔋 for discharging on battery, etc.).
+
+case $BLOCK_BUTTON in
+ 3) notify-send "🔋 Battery module" "🔋: discharging
+🛑: not charging
+♻: stagnant charge
+🔌: charging
+⚡: charged
+❗: battery very low!
+- Scroll to change adjust xbacklight." ;;
+ 4) xbacklight -inc 10 ;;
+ 5) xbacklight -dec 10 ;;
+ 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
+esac
+
+# Loop through all attached batteries and format the info
+for battery in /sys/class/power_supply/BAT?*; do
+ # If non-first battery, print a space separator.
+ [ -n "${capacity+x}" ] && printf " "
+ # Sets up the status and capacity
+ case "$(cat "$battery/status" 2>&1)" in
+ "Full") status="⚡" ;;
+ "Discharging") status="🔋" ;;
+ "Charging") status="🔌" ;;
+ "Not charging") status="🛑" ;;
+ "Unknown") status="♻️" ;;
+ *) exit 1 ;;
+ esac
+ capacity="$(cat "$battery/capacity" 2>&1)"
+ # Will make a warn variable if discharging and low
+ [ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗"
+ # Prints the info
+ printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn
+done && printf "\\n"
diff --git a/local/bin/sb-input b/local/bin/sb-input
new file mode 100755
index 0000000..4fb1575
--- /dev/null
+++ b/local/bin/sb-input
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+icon="🌐"
+layout="$(setxkbmap -query | grep layout | awk '{print $2}')"
+
+# fcitx state, 0 for close, 1 for inactive, 2 for active
+test $(fcitx5-remote) = 2 && layout="日本語"
+
+echo $icon$layout
diff --git a/local/bin/setup-default-apps.sh b/local/bin/setup_default_apps.sh
index 809824f..809824f 100755
--- a/local/bin/setup-default-apps.sh
+++ b/local/bin/setup_default_apps.sh