diff --git a/.config/i3/config b/.config/i3/config index a08f7fb..de8192b 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -13,6 +13,7 @@ set $mod2 Mod1 floating_modifier $mod # Application startup +exec_always --no-startup-id "pkill lemonbar.sh; $HOME/.scripts/panel/lemonbar.sh &" exec_always --no-startup-id $HOME/.scripts/wm/wallpaper.sh & exec --no-startup-id qutebrowser exec --no-startup-id urxvt @@ -54,7 +55,7 @@ client.focused_inactive $bgcolor_inactive $bgcolor_inactive $darkwhite $dar client.urgent $bgcolor_urgent $bgcolor_urgent $white $darkgreen # Font -font pango:DejaVu Sans, FontAwesome5Free Solid, FontAwesome5Brands 8 +font pango:DejaVu Sans 8 ##--- Bindings ---## @@ -161,8 +162,8 @@ for_window [class="QtBank"] floating enable #--- Function key bindings ---# # Screen brightness -bindsym $mod+F3 exec brightnessctl -q s +10% && pkill -RTMIN+2 i3blocks -bindsym $mod+F2 exec brightnessctl -q s 10%- && pkill -RTMIN+2 i3blocks +bindsym $mod+F3 exec --no-startup-id "brightnessctl -q s +10%; $HOME/.scripts/panel/brightness.sh" +bindsym $mod+F2 exec --no-startup-id "brightnessctl -q s 10%-; $HOME/.scripts/panel/brightness.sh" #--- Arrow key bindings ---# @@ -191,9 +192,9 @@ bindsym --release Shift+Print exec scrot -s -e "mv \$f "$capture # Selection bindsym --release $mod+Print exec scrot -u -e "mv \$f "$capture # Focused window # Volume -bindsym XF86AudioRaiseVolume exec --no-startup-id mediacontrol.sh up 5 -bindsym XF86AudioLowerVolume exec --no-startup-id mediacontrol.sh down 5 -bindsym XF86AudioMute exec --no-startup-id mediacontrol.sh toggle +bindsym XF86AudioRaiseVolume exec --no-startup-id "mediacontrol.sh up 5; $HOME/.scripts/panel/volume.sh" +bindsym XF86AudioLowerVolume exec --no-startup-id "mediacontrol.sh down 5; $HOME/.scripts/panel/volume.sh" +bindsym XF86AudioMute exec --no-startup-id "mediacontrol.sh toggle; $HOME/.scripts/panel/volume.sh" # Touchscreen toggle bindsym XF86HomePage exec --no-startup-id touchscreen.sh diff --git a/.scripts/panel/battery.sh b/.scripts/panel/battery.sh new file mode 100755 index 0000000..fac0236 --- /dev/null +++ b/.scripts/panel/battery.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +BAT_INFO=${BLOCK_INSTANCE:-"$(acpi -b | grep ': [^Unknown]')"} + +CAPACITY=$(echo $BAT_INFO | awk '{ print int($4) }') +TIME="$(echo $BAT_INFO | awk '{ print substr($5, 0, length($5) - 3) }')" +CHARACTER=":" + +if [ "$TIME" != "" ] && [ "${TIME#*$CHARACTER}" != "$TIME" ]; then + TIME=" ($TIME)" +else + TIME="" +fi + +COLOR="-" +if [ "$(echo $BAT_INFO | awk '{ print $6 }')" = "remaining" ]; then + if [ "$CAPACITY" -ge "80" ]; then + ICON="" + elif [ "$CAPACITY" -ge "60" ]; then + ICON="" + elif [ "$CAPACITY" -ge "40" ]; then + ICON="" + elif [ "$CAPACITY" -ge "20" ]; then + ICON="" + else + ICON="" + COLOR="$COLOR9" + + notify-send -u critical -r 1 -t 30000 "Battery critically low!" + fi +else + if [ "$CAPACITY" -ge "95" ]; then + notify-send -u low -r 1 "You should probably unplug." + fi + + ICON="" +fi + +printf "%s\n" "battery%{F$COLOR}$ICON $CAPACITY%$TIME%{F-}" diff --git a/.scripts/panel/brightness.sh b/.scripts/panel/brightness.sh new file mode 100755 index 0000000..f2d6b83 --- /dev/null +++ b/.scripts/panel/brightness.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# Right click, scroll up, scroll down +R="A3:brightnessctl -q s 30%; $0:" +U="A4:brightnessctl -q s +10%; $0:" +D="A5:brightnessctl -q s 10%-; $0:" + +PERCENTAGE=$(brightnessctl \ + | awk '/\([0-9]+%\)/ { print substr($4, 2, length($4) - 3) }') +if [ "$PERCENTAGE" -ge "75" ]; then + ICON="" # f111 +elif [ "$PERCENTAGE" -ge "25" ]; then + ICON="" # f042 +else + ICON="" # f1ce + # ICON="" # f111 +fi + +INPUT="%{$R}%{$U}%{$D}" +END="%{A}%{A}%{A}" +PIPE="$($(dirname $0)/lemonbar.sh getpipe)" + +printf "%s\n" "brightness$INPUT$ICON $PERCENTAGE%$END" > "$PIPE" & diff --git a/.scripts/panel/iface.sh b/.scripts/panel/iface.sh new file mode 100755 index 0000000..106724f --- /dev/null +++ b/.scripts/panel/iface.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +ICON="" +WIRED="${1:-eth0}" + +COLOR="-" +if [ ! -d /sys/class/net/${WIRED} ] || + [ "$(cat /sys/class/net/$WIRED/operstate)" = 'down' ] || + [ "$(ip a | grep $WIRED | awk '/inet / {print $2}')" = "" ]; then + COLOR="$COLOR7" +else + COLOR="$COLOR15" +fi + +printf "%s\n" "iface%{F$COLOR}$ICON%{F-}" diff --git a/.scripts/panel/lemonbar.sh b/.scripts/panel/lemonbar.sh new file mode 100755 index 0000000..403f2a0 --- /dev/null +++ b/.scripts/panel/lemonbar.sh @@ -0,0 +1,124 @@ +#!/bin/sh + +PIPE="/tmp/lemonbar_pipe" +PANEL="lemonbar_panel" + +title() { + # Grabs focused window's title + ID="$(printf "%s" "$1" | awk '{print $5}')" + if [ "$ID" == "0x0" ]; then + TITLE="" + else + TITLE="$(xprop -id "$ID" WM_NAME \ + | awk '{$1=$2=""; print substr($0, 4, length($0) - 4)}')" + fi + printf "%s\n" "title$TITLE" + + # Grabs focused window's title + # TITLE=$(xdotool getactivewindow getwindowname 2> /dev/null) + # printf "%s\n" "title$TITLE" +} + +clock() { + # Grabs date in 11:59 A/PM format + DATETIME=$(date "+%I:%M %p") + printf "%s\n" "clock $DATETIME" +} + +bar() { + lemonbar \ + -a 20 -g x38 -n "$PANEL" \ + -f "DejaVu Sans-8" \ + -f "FontAwesome5Free Solid-8" \ + -f "FontAwesome5Free Regular-8" \ + -f "FontAwesome5 Brands-8" \ + -B "$BGCOLOR_INACTIVE" -F "$COLOR15" +} + +start() { + # Exit if panel is already running + if [ "$(pgrep lemonbar | awk 'END {print FNR}')" -gt "2" ]; then + printf "%s\n" "The panel is already running." >&2 + exit 1 + fi + + # Trap all subshells + trap 'trap - TERM; kill 0' INT TERM QUIT EXIT + + # Create named pipe + [ -e "$PIPE" ] && rm "$PIPE" + mkfifo "$PIPE" + + # Directory of this script + DIR="$(dirname "$0")" + + # Setup workspaces with xprop events + xprop -root -spy _NET_CURRENT_DESKTOP | while read -r line; do + "$DIR"/workspaces.sh + done > "$PIPE" & + + # Setup window title with xprop events + xprop -root -spy _NET_ACTIVE_WINDOW | while read -r line; do + title "$line" + done > "$PIPE" & + + # Setup interrupt blocks + "$DIR"/volume.sh + "$DIR"/brightness.sh + + # Setup block timers + while :; do "$DIR"/wifi.sh; sleep 10; done > "$PIPE" & + while :; do "$DIR"/iface.sh; sleep 10; done > "$PIPE" & + while :; do "$DIR"/battery.sh; sleep 30; done > "$PIPE" & + while :; do clock; sleep 5; done > "$PIPE" & + + while read -r line ; do + case $line in + workspaces*) + workspaces=${line#workspaces} + ;; + title*) + title=${line#title} + ;; + volume*) + volume=${line#volume} + ;; + brightness*) + brightness=${line#brightness} + ;; + wifi*) + wifi=${line#wifi} + ;; + iface*) + iface=${line#iface} + ;; + battery*) + battery=${line#battery} + ;; + clock*) + clock=${line#clock} + ;; + esac + printf "%s\n" "%{l}$workspaces%{c}$title%{r}$volume $brightness $wifi $iface $battery $clock " + done < "$PIPE" | bar | sh + + wait +} + +getpipe() { + printf "%s" "$PIPE" +} + +if type "$1" 2> /dev/null | grep -q "function"; then + "$@" +else + start +fi + +#@Todo: +# v lemonbar.sh get_pipe() {} +# v implement in workspaces +# v rewrite workspaces getter +# +# v pipes in volume en brightness widget +# - i3 bindings diff --git a/.scripts/panel/volume.sh b/.scripts/panel/volume.sh new file mode 100755 index 0000000..209c2e5 --- /dev/null +++ b/.scripts/panel/volume.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +MEDIACONTROL="$HOME/.scripts/mediacontrol.sh" + +# Left click, scroll click, right click, scroll up and scroll down +L="A1:pavucontrol:" +S="A2:$MEDIACONTROL set 0; $0:" +R="A3:$MEDIACONTROL toggle; $0:" +U="A4:$MEDIACONTROL up 5; $0:" +D="A5:$MEDIACONTROL down 5; $0:" + +VOLUME="$($MEDIACONTROL getvolume)" + +COLOR="-" +if [ "$($MEDIACONTROL getmute)" = "1" ]; then + COLOR="$COLOR7" + + SYMBOL="" +else + COLOR="$COLOR15" + + if [ "$VOLUME" -ge "50" ]; then + SYMBOL="" + elif [ "$VOLUME" -ge "25" ]; then + SYMBOL="" + else + SYMBOL="" + fi +fi + +INPUT="%{$L}%{$S}%{$R}%{$U}%{$D}" +END="%{A}%{A}%{A}%{A}%{A}" +PIPE="$($(dirname $0)/lemonbar.sh getpipe)" + +printf "%s\n" "volume%{F$COLOR}$INPUT$SYMBOL $VOLUME%$END%{F-}" > "$PIPE" & diff --git a/.scripts/panel/wifi.sh b/.scripts/panel/wifi.sh new file mode 100755 index 0000000..a87b721 --- /dev/null +++ b/.scripts/panel/wifi.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +ICON="" +WIRELESS="${1:-wlan0}" + +if [ "$NOTIFY" = "1" ]; then + SSID="$(iw dev $WIRELESS link | awk '/SSID/ { print $2 }')" + IP="$(ip a show $WIRELESS \ + | awk '/inet / { print substr($2, 0, length($2) - 3) }')" + + notify-send -r 3 "Wifi" "\ +Interface: $WIRELESS +SSID: $SSID +IP: $IP" +else + COLOR="-" + if [ ! -d /sys/class/net/${WIRELESS}/wireless ] || + [ "$(cat /sys/class/net/$WIRELESS/operstate)" = 'down' ]; then + + COLOR="$COLOR7" + DISPLAY="$ICON" + else + QUALITY=$(grep $WIRELESS /proc/net/wireless | \ + awk '{ print int($3 * 100 / 70) }') + + COLOR="$COLOR15" + DISPLAY="$ICON $QUALITY%" + fi + + printf "%s\n" "wifi%{F$COLOR}%{A:NOTIFY=1 $0:}$DISPLAY%{A}%{F-}" +fi diff --git a/.scripts/panel/workspaces.sh b/.scripts/panel/workspaces.sh new file mode 100755 index 0000000..46b0a15 --- /dev/null +++ b/.scripts/panel/workspaces.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# Suppress output +NULL="> /dev/null 2>&1" + +# Scroll up, scroll down +U="A4:i3-msg workspace prev_on_output $NULL:" +D="A5:i3-msg workspace next_on_output $NULL:" + +# i3 +# WMNAME="$(xprop -root '\t$0' _NET_WM_NAME | cut -f 2 | tr -d '"')" + +CURRENT=$(xprop -root _NET_CURRENT_DESKTOP | awk '{print $3 + 1}') +WORKSPACES="$(xprop -root '\n$0\n$1\n$2\n$3\n$4\n$5\n$6\n$7\n$8\n$9' _NET_DESKTOP_NAMES \ + | awk -v c="$CURRENT" -v n="$NULL" \ + -v c7="$COLOR7" -v c15="$COLOR15" -v b="$BGCOLOR" -v bi="$BGCOLOR_INACTIVE" ' + /".*"/ { + name = substr($0, 2, length($0) - 2); + + if (c == FNR - 1) + printf "%{B%s} %s %{B%s}", + b, name, bi + else + printf "%{F%s}%{A:i3-msg workspace %s %s:} %s %{A}%{F%s}", + c7, name, n, name, c15 + } +')" + +printf "%s\n" "workspaces%{$U}%{$D}$WORKSPACES%{A}%{A}" diff --git a/packages b/packages index a51e0b1..3baa602 100644 --- a/packages +++ b/packages @@ -48,6 +48,7 @@ jdk10-openjdk jq kdenlive krita +lemonbar-xft-git libmtp libnotify-id libva-intel-driver