wayland: Consolidate with mako into desktop module

Since the existing wayland module basically describes everything about
my 'desktop environment' setup already anyway, might as well rename it
accordingly. Additionally, mako is important for notifications in this
environment so it moves here as well.
This commit is contained in:
Marty Oehme 2023-01-07 16:06:00 +01:00
parent 4c33a6da56
commit 2e0c992a54
Signed by: Marty
GPG key ID: 73BA40D5AFAF49C9
12 changed files with 10 additions and 2 deletions

View file

@ -0,0 +1,47 @@
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<alias>
<family>serif</family>
<prefer><family>Heuristica</family></prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer><family>Noto Sans</family></prefer>
</alias>
<alias>
<family>monospace</family>
<prefer><family>Iosevka</family></prefer>
</alias>
<alias>
<family>fantasy</family>
<prefer><family>Signika</family></prefer>
</alias>
<alias>
<family>cursive</family>
<prefer><family>Comic Neue</family></prefer>
</alias>
<match target="font">
<edit name="antialias" mode="assign">
<bool>true</bool>
</edit>
<edit name="rgba" mode="assign">
<const>rgb</const>
</edit>
<edit name="lcdfilter" mode="assign">
<const>lcddefault</const>
</edit>
<edit name="hinting" mode="assign">
<bool>true</bool>
</edit>
<edit name="hintstyle" mode="assign">
<const>hintfull</const>
</edit>
<edit name="autohint" mode="assign">
<bool>false</bool>
</edit>
<edit name="dpi" mode="assign">
<double>93</double>
</edit>
</match>
</fontconfig>

View file

@ -0,0 +1,18 @@
profile docked {
output eDP-1 disable
output "LG Electronics W2442 0x000075FD" position 1920,0
output "LG Electronics W2442 0x000075E1" position 0,0
exec notify-send "💻 Display changed" "Applying docked profile"
}
profile docked {
output eDP-1 disable
output "Goldstar Company Ltd W2442 0x000075FD" position 1920,0
output "Goldstar Company Ltd W2442 0x000075E1" position 0,0
exec notify-send "💻 Display changed" "Applying docked profile"
}
profile portable {
output eDP-1 enable position 0,0
exec notify-send "💻 Display changed" "Applying portable profile"
}

View file

@ -0,0 +1,30 @@
sort=-time
layer=overlay
background-color=#2e3440
width=300
height=110
border-size=2
border-color=#88c0d0
border-radius=15
max-icon-size=64
default-timeout=5000
ignore-timeout=1
font=monospace 14
[urgency=low]
border-color=#cccccc
[urgency=normal]
border-color=#d08770
[urgency=critical]
#on-notify=exec mpv /usr/share/sounds/freedesktop/stereo/message.oga
border-color=#bf616a
default-timeout=0
[mode=do-not-disturb]
invisible=1
[category=mpd]
default-timeout=2000
group-by=category

287
desktop/.config/river/init Executable file
View file

@ -0,0 +1,287 @@
#!/usr/bin/env sh
mod="Mod4"
modemod="Mod1"
term=${TERMINAL:-foot}
time_to_lockscreen=300
time_to_screendim=600
time_to_suspend=1200
## OPTIONS
riverctl spawn "dbus-update-activation-environment SEATD_SOCK DISPLAY WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=river"
riverctl focus-follows-cursor normal
riverctl set-cursor-warp on-output-change
riverctl hide-cursor when-typing enabled
riverctl attach-mode bottom
# Set background and border color
riverctl background-color 0x000000
riverctl border-width 1
riverctl border-color-focused 0xffffff
riverctl border-color-unfocused 0x586e75
# Set repeat rate
riverctl set-repeat 75 300
# Make certain views start floating
riverctl float-filter-add app-id float
# riverctl float-filter-add title "popup title with spaces"
# # Set app-ids and titles of views which should use client side decorations
# riverctl csd-filter-add app-id "gedit"
riverctl csd-filter-remove app-id "org.pwmt.zathura"
## DEBUG
# Reload river configuration
riverctl map normal $mod+Shift F12 spawn "$HOME/.config/river/init"
## HOTKEYS
# close focused view
riverctl map normal $mod+Shift C close
# Open terminal
riverctl map normal $mod Return spawn "$term"
# Open run menu
riverctl map normal $mod Space spawn "bemenu-run"
# Toggle status bar
riverctl map normal $mod F7 spawn "killall -SIGUSR1 waybar"
# Switch to lockscreen
riverctl map normal $mod X spawn "lockscreen"
# Open logout script
riverctl map normal $mod backspace spawn "powermenu"
# Open Bookmark search
riverctl map normal None XF86Search spawn "qutedmenu"
riverctl map normal $mod+Shift O spawn "qutedmenu"
# Open clipboard history
riverctl map normal $mod+Shift Space spawn "clipman pick --tool=bemenu"
# Open floating calculator
riverctl map normal $mod+Shift R spawn "$term start --class float -e qalc"
# Open emoji picker
riverctl map normal $mod+Shift E spawn "bemoji -nt"
# Open translation helper
riverctl map normal $mod+Shift T spawn "bemenu-translate"
# Desktop theming
# shellcheck disable=SC2016
riverctl map normal $mod+Shift S spawn 'styler set $(styler list themes | bemenu)'
# Password dropdown frontend
riverctl map normal $mod+Shift P spawn "pass-pick"
# File upload
riverctl map normal $mod+Shift U spawn "$term start --class float -e sharefile | xargs notify-send"
# # Screenshot
riverctl map normal None Print spawn "screenshot"
riverctl map normal Shift Print spawn "screenshot | sharefile -"
riverctl map normal $mod Print spawn "screenshot region"
riverctl map normal $mod+Shift Print spawn "screenshot region | sharefile -"
# control notification daemon
riverctl map normal $mod N spawn "makoctl dismiss"
riverctl map normal $mod+Shift N spawn "makoctl dismiss --all"
riverctl map normal $mod+Control N spawn "makoctl restore"
# MOVEMENT
# focus the next/previous view in the layout stack
riverctl map normal $mod J focus-view next
riverctl map normal $mod K focus-view previous
# swap the focused view with the next/previous view in the layout stack
riverctl map normal $mod+Shift J swap next
riverctl map normal $mod+Shift K swap previous
# bump the focused view to the top of the layout stack
riverctl map normal $mod+Shift Return zoom
# change layout orientation
riverctl map normal $mod Up send-layout-cmd rivercarro "main-location top"
riverctl map normal $mod Right send-layout-cmd rivercarro "main-location right"
riverctl map normal $mod Down send-layout-cmd rivercarro "main-location bottom"
riverctl map normal $mod Left send-layout-cmd rivercarro "main-location left"
# snap views to screen edges
riverctl map normal $mod+Control H snap left
riverctl map normal $mod+Control J snap down
riverctl map normal $mod+Control K snap up
riverctl map normal $mod+Control L snap right
# Mod+F to toggle fullscreen
riverctl map normal $mod F toggle-fullscreen
# shellcheck disable=SC2016
# Make all connected outputs show the desktop and no windows at all
riverctl map normal $mod+Shift M spawn 'for i in $(wlopm | wc -l); do riverctl set-focused-tags $((1 << 10)); riverctl focus-output next; done; riverctl set-focused-tags $((1 << 10)); riverctl focus-output next'
# toggle float
riverctl map normal $mod+Shift v toggle-float
# Mod + Left Mouse Button to move views
riverctl map-pointer normal $mod BTN_LEFT move-view
# Mod + Right Mouse Button to resize views
riverctl map-pointer normal $mod BTN_RIGHT resize-view
### Begin resize and moving mode, for floating windows
riverctl declare-mode interact_float
riverctl map normal $modemod R enter-mode interact_float
riverctl map interact_float $modemod R enter-mode normal
# resize views on screen
riverctl map interact_float $mod H resize horizontal -100
riverctl map interact_float $mod J resize vertical 100
riverctl map interact_float $mod K resize vertical -100
riverctl map interact_float $mod L resize horizontal 100
# move views around screen
riverctl map interact_float $mod+Shift H move left 100
riverctl map interact_float $mod+Shift J move down 100
riverctl map interact_float $mod+Shift K move up 100
riverctl map interact_float $mod+Shift L move right 100
# decrease/increase the main ratio of layout
riverctl map interact_float None H send-layout-cmd rivercarro "main-ratio -0.05"
riverctl map interact_float None L send-layout-cmd rivercarro "main-ratio +0.05"
# increment/decrement the main layout
riverctl map interact_float None J send-layout-cmd rivercarro "main-count +1"
riverctl map interact_float None K send-layout-cmd rivercarro "main-count -1"
### End resize and moving mode
# focus the next/previous output
riverctl map normal $mod Period focus-output next
riverctl map normal $mod Comma focus-output previous
# send the focused view to the next/previous output
riverctl map normal $mod+Shift Period send-to-output next
riverctl map normal $mod+Shift Comma send-to-output previous
# set up 10 tags (with '0' opening the 10th one)
for i in $(seq 0 9); do
tags=$((1 << (i - 1)))
if [ "$i" -eq 0 ]; then tags=$((1 << 9)); fi
# Mod+[1-9] to focus tag [0-8]
riverctl map normal $mod "$i" set-focused-tags $tags
# Mod+Shift+[1-9] to tag focused view with tag [0-8]
riverctl map normal $mod+Shift "$i" set-view-tags $tags
# Mod+Ctrl+[1-9] to toggle focus of tag [0-8]
riverctl map normal $mod+Control "$i" toggle-focused-tags $tags
# Mod+Shift+Ctrl+[1-9] to toggle tag [0-8] of focused view
riverctl map normal $mod+Shift+Control "$i" toggle-view-tags $tags
done
# focus all tags
all_tags=$(((1 << 32) - 1))
riverctl map normal $mod equal set-focused-tags $all_tags
# tag focused view with all tags
riverctl map normal $mod+Shift equal set-view-tags $all_tags
# Various media key mapping examples for both normal and locked mode which do
# not have a modifier
for mode in normal locked; do
# Eject the optical drive
riverctl map $mode None XF86Eject spawn 'eject -T'
riverctl map $mode None XF86AudioRaiseVolume spawn 'pactl set-sink-volume @DEFAULT_SINK@ +5%'
riverctl map $mode None XF86AudioLowerVolume spawn 'pactl set-sink-volume @DEFAULT_SINK@ -5%'
riverctl map $mode None XF86AudioMute spawn 'pactl set-sink-mute @DEFAULT_SINK@ toggle'
# Control MPRIS aware media players with playerctl (https://github.com/altdesktop/playerctl)
riverctl map $mode None XF86AudioMedia spawn 'playerctl play-pause'
riverctl map $mode None XF86AudioPlay spawn 'playerctl play-pause'
riverctl map $mode None XF86AudioPrev spawn 'playerctl previous'
riverctl map $mode None XF86AudioNext spawn 'playerctl next'
# You can control screen backlight brighness with light (https://github.com/haikarainen/light); but we prefer brightnessctl
riverctl map $mode None XF86MonBrightnessUp spawn 'brightnessctl set 10%+'
riverctl map $mode None XF86MonBrightnessDown spawn 'brightnessctl set 10%-'
done
# The scratchpad will live on an unused tag. Which tags are used depends on your
# config, but rivers default uses the first 9 tags.
scratch_tag=$((1 << 20))
# Toggle the scratchpad with Super+P
riverctl map normal $mod grave toggle-focused-tags ${scratch_tag}
# Send windows to the scratchpad with Super+Shift+P
riverctl map normal $mod+Shift grave set-view-tags ${scratch_tag}
# Set spawn tagmask to ensure new windows don't have the scratchpad tag unless
# explicitly set.
all_but_scratch_tag=$((((1 << 32) - 1) ^ scratch_tag))
riverctl spawn-tagmask ${all_but_scratch_tag}
# set up scratch pad for todo and 'drop-down' terminal
# call scratchpads to current workspace -- scratchpads started on i3 starting (see end of file)
# bindsym $mod+t [class="scratchpad" title="dropdown-todo"] scratchpad show
# bindsym $mod+Shift+Return [class="scratchpad" title="dropdown-terminal"] scratchpad show
## INPUT
# device (touchscreen)
# enable touch clicking for touchpads
for pad in $(riverctl list-inputs | grep -i touchpad); do
riverctl input "$pad" events enabled
riverctl input "$pad" tap enabled
done
for pad in $(riverctl list-inputs | grep -i touchscreen); do
riverctl input "$pad" events enabled
riverctl input "$pad" tap enabled
riverctl input "$pad" drag enabled
riverctl input "$pad" pointer-accel 0.5
done
setxkbmap -option "compose:menu"
# set a nice wallpaper
if exist wlopm && exist swww; then
riverctl spawn "swww init"
if [ -e "$HOME/pictures/wall.jpg" ]; then
swww img "$HOME/pictures/wall.jpg"
fi
if wlopm | grep -q DP-5 && wlopm | grep -q DP-3 && [ -e "$HOME/pictures/wall_l.jpg" ] && [ -e "$HOME/pictures/wall_r.jpg" ]; then
swww img -o DP-5 "$HOME/pictures/wall_l.jpg"
swww img -o DP-3 "$HOME/pictures/wall_r.jpg"
fi
fi
# start status bar
killall waybar
riverctl spawn waybar
# start dynamic display configuration
killall kanshi
riverctl spawn kanshi
# start redshift-like sundown warming using current location or standard values
killall wlsunset
loc=$(curl ipinfo.io | grep -e '"loc": ' | sed -e 's/^.*"loc": "\(.*\)",$/\1/')
if [ -n "$loc" ]; then
riverctl spawn "wlsunset -l \"$(echo "$loc" | cut -d, -f1)\" -L \"$(echo "$loc" | cut -d, -f2)\""
else
riverctl spawn "wlsunset -S \"09:00\" -s \"21:00\" -d \"3600\""
fi
unset loc
# start screen idle locking/dimming/sleep tool
killall swayidle
riverctl spawn "swayidle \
timeout ${time_to_lockscreen} 'pidof waylock || lockscreen' \
timeout ${time_to_screendim} 'wlopm --off \"*\"' \
timeout ${time_to_suspend} 'systemctl suspend-then-hibernate' \
resume 'wlopm --on \"*\"' \
after-resume 'wlopm --on \"*\"' \
before-sleep 'pidof waylock || lockscreen' &"
killall clipman
riverctl spawn "wl-paste -t text --watch clipman store"
# bash ~/.config/bin/gtktheme # setting our gtk variables
# killall polkit-gnome-authentication-agent-1
# /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 &
# start layouting engine
killall rivercarro
riverctl spawn "rivercarro -main-ratio 0.65"
# River will send the process group of the init executable SIGTERM on exit.
riverctl default-layout rivercarro
# exec rivercarro -main-ratio 0.65 -view-padding 6 -outer-padding 6 & # -> does not work with current rivercarro version (0.1.4)
brightnessctl set 70%

View file

@ -0,0 +1,3 @@
#!/usr/bin/env sh
export XKB_DEFAULT_OPTIONS='compose:menu'

View file

@ -0,0 +1,181 @@
{
"layer": "top",
"modules-left": ["river/tags", "custom/events", "custom/vidl"],
"modules-center": ["clock", "custom/media"],
"modules-right": ["custom/wireguard", "custom/archupdates", "pulseaudio", "backlight", "network", "cpu", "memory", "temperature", "battery", "tray"],
"custom/archupdates": {
"format": "{} {icon}",
"format-alt-click": "right",
"format-icons": {
"default": ""
},
"return-type": "json",
"exec": "~/.config/waybar/modules/archupdates 5 json",
"interval": 3600,
"on-click": "$TERMINAL start --class float topgrade"
},
"backlight": {
"device": "intel_backlight",
"format": "{percent}% {icon}",
"format-icons": ["滋", "", "", ""],
"on-scroll-up": "brightnessctl set 1%+",
"on-scroll-down": "brightnessctl set 1%-"
},
"battery": {
"format": "{capacity}% {icon}",
"format-alt":"{capacity}% ({time}) {icon}",
"format-alt-click": "click-right",
"format-icons": ["", "", "", "", ""],
"interval": 60,
"states": {
"warning": 30,
"critical": 15
},
},
"clock": {
"format-alt": "{:%a, %d. %b %H:%M}",
"format-alt-click": "click-right",
"on-click": "gsimplecal"
},
"cpu": {
"interval": 10,
"format": "{usage}% ",
"max-length": 10,
"states": {
"warning": 50,
"critical": 80
},
"on-click": "$TERMINAL start --class float top",
"on-click-right": "$TERMINAL start --class float glances"
},
"custom/events": {
"format": "{}",
"interval": 300,
"format-icons": {
"default": ""
},
"exec": "~/.config/waybar/modules/khal.py 2>/dev/null",
"exec-if": "command -v khal >/dev/null 2>&1",
"return-type": "json"
},
"memory": {
"interval": 30,
"format": "{avail:0.1f}G ",
"format-alt": "{used:0.1f}G/{total:0.1f}G ",
"format-alt-click": "click-right",
"max-length": 10
},
"mpd": {
"format": "{stateIcon} {consumeIcon}{randomIcon}{repeatIcon}{singleIcon}",
"format-disconnected": "ﱙ",
"format-stopped": "",
"interval": 10,
"consume-icons": {
"on": " " // Icon shows only when "consume" is on
},
"random-icons": {
"on": " "
},
"repeat-icons": {
"on": " "
},
"single-icons": {
"on": "1 "
},
"state-icons": {
"paused": "",
"playing": "",
},
"tooltip-format": "{artist} - {album} - {title} ({elapsedTime:%M:%S}/{totalTime:%M:%S}) ",
"tooltip-format-disconnected": "MPD (disconnected)"
},
"custom/media": {
"format": "{icon}{}",
"format-alt-click": "right",
"return-type": "json",
"format-icons": {
"Playing": " ",
"Paused": " ",
},
"escape": true,
"max-length":70,
"exec": "playerctl -a metadata --format '{\"text\": \"\", \"tooltip\": \"{{playerName}} : {{markup_escape(title)}}\", \"alt\": \"{{status}}\", \"class\": \"{{status}}\"}' -F",
"exec-if": "command -v playerctl >/dev/null 2>&1",
"on-click": "playerctl play-pause",
"on-click-right": "playerctl stop",
},
"network": {
"interface": "wlp58s0",
"format": "{ifname}",
"format-wifi": "{signalStrength}% ",
"format-ethernet": "{ipaddr}/{cidr} ",
"format-disconnected": "睊",
"tooltip-format": "{ifname} via {gwaddr} ",
"tooltip-format-wifi": "{essid}: {bandwidthDownBits}-{bandwidthUpBits} ({signalStrength}%)  {ifname}",
"tooltip-format-ethernet": "{ifname} ",
"tooltip-format-disconnected": "Disconnected",
"max-length": 50,
"on-click": "$TERMINAL start --class float nmtui",
// "on-click-right": "sudo rfkill toggle wlan"
},
"pulseaudio": {
"format": "{volume}% {icon}",
"format-bluetooth": "{volume}% {icon}",
"format-muted": "",
"format-icons": {
"headphone": "",
"hands-free": "",
"headset": "",
"phone": "",
"portable": "",
"car": "",
"default": ["", ""]
},
"scroll-step": 1,
"on-click": "$TERMINAL start --class float pulsemixer",
"on-scroll-up": "pactl set-sink-volume @DEFAULT_SINK@ +1%",
"on-scroll-down": "pactl set-sink-volume @DEFAULT_SINK@ -1%"
},
"river/tags": {
"num-tags": 10,
"tag-labels": [ "", "", "", "", "", "", "", "", "", "" ]
},
"temperature": {
// "thermal-zone": 2,
"hwmon-path": "/sys/class/hwmon/hwmon5/temp1_input",
"critical-threshold": 80,
// "format-critical": "{temperatureC}° ",
"format": "{temperatureC}° ",
"on-click": "$TERMINAL start --class float watch sensors"
},
"tray": {
"icon-size": 21,
"spacing": 10
},
"custom/weather": {
"exec": "curl 'https://wttr.in/?format=%t'",
"exec-if": "command -v curl >/dev/null 2>&1",
"interval": 3600
},
"custom/wireguard": {
"format-icons": {
"default": "嬨"
},
"exec": "~/.config/waybar/modules/wireguard json",
"exec-if": "command -v nmcli >/dev/null 2>&1",
"return-type": "json",
"signal": 6,
"interval": 60,
},
"custom/vidl": {
"format": "{} {icon}",
"format-alt-click": "right",
"format-icons": {
"default": ""
},
"exec": "wc -l ~/.local/share/vidl/vidl_queue | cut -d' ' -f1",
"exec-if": "[ -f ~/.local/share/vidl/vidl_queue ]",
"interval": 5,
"on-click": "$TERMINAL start --class float nvim ~/.local/share/vidl/vidl_queue"
},
}

View file

@ -0,0 +1,58 @@
#!/bin/sh
#
# Check for available archupdates and return their number.
# Checks both repositories and aur,
# returns empty string when 0 packages are available, so
# that polybar simply displays nothing.
# Can be used to generate json-like output for waybar.
#
# dependencies: yay, (pacman-contrib optional)
# optional: jq
#
# Takes 2 arguments:
# Takes an optional integer argument, which is the minimum
# numer of package updates for an answer to be returned.
min_upd=${1:-0}
# Takes as second optional argument the output format
# Valid value is "json", everything else returns plain-text.
# json output requires jq.
format=${2:-plain}
# prefer checkupdates since it allows checking w/o partial upgrade
if command -v "checkupdates" >/dev/null; then
updates_repo="$(checkupdates 2>&1)"
fi
# fall back to yay, but be aware it will not find everything
# if checkupdates finds nothing or returns an error
if [ "$updates_repo" = "" ] || [ -z "${updates_repo##*==> ERROR: Cannot fetch updates*}" ]; then
updates_repo="$(yay -Qun 2>/dev/null)"
fi
updates_repo=$(echo "$updates_repo" | wc -l)
updates_aur="$(yay -Qum 2>/dev/null | wc -l)"
# updates_aur=$(cower -u 2> /dev/null | wc -l)
# updates_aur=$(trizen -Su --aur --quiet | wc -l)
# updates_aur=$(pikaur -Qua 2> /dev/null | wc -l)
# updates_aur=$(rua upgrade --printonly 2> /dev/null | wc -l)
updates=$((updates_repo + updates_aur))
text="${updates}"
alt="${updates_repo}|${updates_aur}"
tooltip="Repositories: ${updates_repo} | AUR: ${updates_aur}"
[ "$updates" -gt "$min_upd" ] && class="available" || class="empty"
if [ "$format" = "json" ]; then
printf "{\"text\": \"%s\", \"alt\": \"%s\", \"tooltip\": \"%s\", \"class\": \"%s\"}" \
"$text" \
"$alt" \
"$tooltip" \
"$class"
exit
fi
if [ "$updates" -gt "$min_upd" ]; then
echo "$updates"
else
echo ""
fi

View file

@ -0,0 +1,35 @@
#!/usr/bin/env python
# from https://gist.github.com/bjesus/178a9bd3453470d74803945dbbf9ed40
# List upcoming khal events in simple json container fit for waybar
import subprocess
import datetime
import json
from html import escape
data = {}
today = datetime.date.today().strftime("%Y-%m-%d")
next_week = (datetime.date.today() + datetime.timedelta(days=10)).strftime("%Y-%m-%d")
output = subprocess.check_output("khal list now " + next_week, shell=True)
output = output.decode("utf-8")
lines = output.split("\n")
new_lines = []
for line in lines:
clean_line = escape(line).split(" ::")[0]
if len(clean_line) and not clean_line[0] in ["0", "1", "2"]:
clean_line = "\n<b>" + clean_line + "</b>"
new_lines.append(clean_line)
output = "\n".join(new_lines).strip()
if today in output:
data["text"] = "" + output.split("\n")[1]
else:
data["text"] = ""
data["tooltip"] = output
print(json.dumps(data))

View file

@ -0,0 +1,151 @@
#!/usr/bin/env bash
# nmcli WireGuard abstraction layer for use with my waybar module and rofi custom menu script
#
# requires nmcli on your path
# install to the same directory as wireguard-rofi.sh
#
# usage: ./wireguard.sh [menu|toggle NAME]
# no argument: print current connections
# json: print waybar-ready json output
# menu: print all connections
# toggle NAME: toggle connection NAME
if ! command -v nmcli >/dev/null 2>&1; then
echo "err: nmcli not found"
exit 1
fi
nargs=$#
showmenu="no"
dotoggle="no"
printjson="no"
if [[ $nargs == 1 ]]; then
if [[ $1 == "menu" ]]; then
showmenu="yes"
elif [[ $1 == "json" ]]; then
printjson="yes"
fi
elif [[ $nargs == 2 ]]; then
if [[ $1 == "toggle" ]]; then
dotoggle="yes"
conn="$2"
fi
fi
nmclicmd="nmcli connection"
wgconns="$nmclicmd show"
wgactive="$wgconns --active"
connected=()
available=()
function print_as_json() {
text="嬨" # only prints a single icon when connected
# text="${1}" # use this line to show all output in text
alt="${1}"
tooltip="${1}"
[ -n "$1" ] && class="connected" || class="disconnected"
printf "{\"text\": \"%s\", \"alt\": \"%s\", \"tooltip\": \"%s\", \"class\": \"%s\"}" \
"$text" \
"$alt" \
"$tooltip" \
"$class"
}
function get_conns {
while read -r name _ type device; do
if [[ $type != "wireguard" && ($type != "tun" || $device != "proton0") ]]; then
continue
fi
if [[ $device != "--" ]]; then
while read -r key value; do
if [[ $key != "ipv4.addresses:" ]]; then
continue
fi
connected+=("$name: $value")
done < <($wgconns "$name")
else
available+=("$name")
fi
done < <($1)
}
function get_pia {
if ! command -v piactl >/dev/null 2>&1; then
return 1
fi
status=$(piactl get connectionstate)
if [[ $status = "Connected" ]]; then
connected+=("$(piactl get region): $(piactl get vpnip)")
fi
}
function print_conns {
local first="yes"
local array_print="$1[@]"
local array_print=("${!array_print}")
if [[ $2 == "list" ]]; then
for c in "${array_print[@]}"; do
output="$1: $c"
done
else
output=""
for c in "${array_print[@]}"; do
if [[ "$first" != "yes" ]]; then
output+=" | "
fi
output+="$c"
first="no"
done
fi
if [[ "$printjson" == "yes" ]]; then
print_as_json "$output"
else
echo "$output"
fi
}
function array_contains {
local array_has="$1[@]"
local array_has=("${!array_has}")
local element="$2"
for e in "${array_has[@]}"; do
if [[ "$e" == *"$element"* ]]; then
echo "yes"
return
fi
done
echo "no"
}
if [[ $nargs == 0 ]] || [[ $printjson = "yes" ]]; then
get_conns "$wgactive"
get_pia
print_conns connected
elif [[ $showmenu == "yes" ]]; then
get_conns "$wgconns"
get_pia
print_conns connected "list"
print_conns available "list"
elif [[ $dotoggle == "yes" ]]; then
get_conns "$wgconns"
get_pia
if [[ "$(array_contains connected "$conn")" == "yes" ]]; then
$nmclicmd down "$conn"
elif [[ "$(array_contains available "$conn")" == "yes" ]]; then
$nmclicmd up "$conn"
else
echo "err: connection not found"
exit 1
fi
else
echo "err: wrong args"
exit 1
fi

View file

@ -0,0 +1,152 @@
* {
border: none;
border-radius: 0;
min-height: 0;
}
window#waybar {
font-size: 15px;
color: @base0F;
background-color: @base00;
border-bottom: 1px solid @base01;
transition-property: background-color;
transition-duration: .5s;
}
window#waybar.hidden {
opacity: 0.2;
}
#tags button {
font-size:17px;
font-weight:900;
background-color: transparent;
color: @base03;
margin: 0px;
padding: 0px 5px;
/* Use box-shadow instead of border so the text isn't offset */
}
/* /1* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect *1/ */
#tags button:hover {
background: rgba(0, 0, 0, 0.2);
/* box-shadow: inset 0 -1px #d5c4a1; */
box-shadow: inset 0 0;
}
#tags button.occupied {
font-weight: 400;
color: @base05;
}
#tags button.focused {
font-weight: 400;
color: @base0D;
}
#tags button.urgent {
color: @base0C;
}
#clock,
#battery,
#cpu,
#memory,
#disk,
#temperature,
#backlight,
#network,
#pulseaudio,
#tray,
#mode,
#idle_inhibitor,
#mpd,
#custom-archupdates,
#custom-wireguard,
#custom-events,
#custom-vidl,
#custom-media {
padding: 0 10px;
margin: 0 5px;
color: @base05;
background-color: @base01;
}
/* If workspaces is the leftmost module, omit left margin */
.modules-left > widget:first-child > #tags {
margin-left: 0;
}
/* If workspaces is the rightmost module, omit right margin */
.modules-right > widget:last-child > #tags {
margin-right: 0;
}
#battery.charging, #battery.plugged {
background-color: @base02;
}
#battery.warning {
background-color: @base09;
color: @base00;
}
@keyframes blink {
to {
background-color: @base08;
color: @base00;
}
}
#battery.critical:not(.charging) {
color: @base05;
background-color: @base00;
animation-name: blink;
animation-duration: 0.5s;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-direction: alternate;
}
#cpu.warning {
color: @base00;
background-color: @base0A;
}
#cpu.critical {
color: @base05;
background-color: @base08;
}
#custom-archupdates.empty {
background-color: transparent;
color: transparent;
font-size: 0;
margin: 0;
padding: 0;
}
#custom-wireguard.disconnected {
background-color: transparent;
color: transparent;
font-size: 0;
margin: 0;
padding: 0;
}
#temperature.critical {
background-color: @base08;
}
#tray > .passive {
-gtk-icon-effect: dim;
}
#tray > .needs-attention {
-gtk-icon-effect: highlight;
}
#mpd.disconnected {
background-color: transparent;
color: transparent;
font-size: 0;
margin: 0;
padding: 0;
}
@import "/home/marty/.local/share/waybar/colorscheme.css";