From 93879b3ef7097fdc8708877830fd906693f311b2 Mon Sep 17 00:00:00 2001 From: Mark Riedesel Date: Wed, 12 Jun 2024 13:05:12 -0500 Subject: [PATCH] more sway and some waybar --- .config/sway/autostart | 2 +- .config/sway/config | 15 +- .../config.d/99-autostart-applications.conf | 18 + .config/sway/definitions | 9 +- .config/sway/modes/recording | 4 +- .config/sway/modes/resize | 5 +- .config/sway/modes/shutdown | 2 +- .config/sway/scripts/dnd.sh | 13 + .config/sway/scripts/recorder.sh | 2 +- .config/sway/scripts/scratchpad.sh | 15 + .config/sway/scripts/screenshot-notify.sh | 8 + .config/sway/scripts/sunset.sh | 67 ++++ .config/sway/scripts/valent.py | 97 +++++ .config/sway/scripts/waybar.sh | 7 + .config/sway/scripts/wluma.sh | 28 ++ .config/sway/themes/dracula/packages | 5 + .config/sway/themes/dracula/theme.conf | 46 +++ .config/user-dirs.dirs | 19 +- .config/waybar/config.jsonc | 349 ++++++++++++++++++ .config/waybar/scripts/weather.py | 73 ++++ .config/waybar/style.css | 2 + 21 files changed, 760 insertions(+), 26 deletions(-) create mode 100644 .config/sway/config.d/99-autostart-applications.conf create mode 100755 .config/sway/scripts/dnd.sh create mode 100755 .config/sway/scripts/scratchpad.sh create mode 100755 .config/sway/scripts/screenshot-notify.sh create mode 100755 .config/sway/scripts/sunset.sh create mode 100755 .config/sway/scripts/valent.py create mode 100755 .config/sway/scripts/waybar.sh create mode 100755 .config/sway/scripts/wluma.sh create mode 100644 .config/sway/themes/dracula/packages create mode 100644 .config/sway/themes/dracula/theme.conf create mode 100644 .config/waybar/config.jsonc create mode 100755 .config/waybar/scripts/weather.py create mode 100644 .config/waybar/style.css diff --git a/.config/sway/autostart b/.config/sway/autostart index 3e40557..75bdc21 100644 --- a/.config/sway/autostart +++ b/.config/sway/autostart @@ -2,7 +2,7 @@ set $initialize_foot_server '[ -x "$(command -v foot)" ] && systemctl --now --user enable foot-server.socket && systemctl --now --user enable foot-server' set $initialize_swayr_daemon '[ -x "$(command -v swayrd)" ] && systemctl --now --user enable swayrd' -set $initialize_waybar '[ -x "$(command -v waybar)" ] && (pkill waybar || exit 0) && systemctl --now --user enable waybar && (systemctl --user start waybar || /usr/share/sway/scripts/waybar.sh)' +set $initialize_waybar '[ -x "$(command -v waybar)" ] && (pkill waybar || exit 0) && systemctl --now --user enable waybar && (systemctl --user start waybar || $sway-config-dir/scripts/waybar.sh)' set $initialize_workspace_icons '[ -x "$(command -v sworkstyle)" ] && systemctl --now --user enable sworkstyle' set $initialize_poweralert_daemon '[ -x "$(command -v poweralertd)" ] && systemctl --now --user enable poweralertd' set $initialize_idlehack_daemon '[ -x "$(command -v idlehack)" ] && systemctl --now --user enable idlehack' diff --git a/.config/sway/config b/.config/sway/config index 6bb4781..2c1a78a 100644 --- a/.config/sway/config +++ b/.config/sway/config @@ -1,8 +1,9 @@ -set $sway-scripts-dir $HOME/.config/sway/scripts +set $sway-config-dir $HOME/.config/sway +set $sway-scripts-dir $sway-config-dir/scripts -include "$HOME/.config/sway/definitions" -include "$HOME/.config/sway/definitions.d/*.conf" -include "$HOME/.config/sway/autostart" -include "$HOME/.config/sway/modes/*" -include "$HOME/.config/sway/config.d/*.conf" -include "$HOME/.config/sway/hosts/`hostname`" +include "$sway-config-dir/definitions" +include "$sway-config-dir/definitions.d/*.conf" +include "$sway-config-dir/autostart" +include "$sway-config-dir/modes/*" +include "$sway-config-dir/config.d/*.conf" +include "$sway-config-dir/hosts/`hostname`" diff --git a/.config/sway/config.d/99-autostart-applications.conf b/.config/sway/config.d/99-autostart-applications.conf new file mode 100644 index 0000000..d68a8c0 --- /dev/null +++ b/.config/sway/config.d/99-autostart-applications.conf @@ -0,0 +1,18 @@ +# autostarts +exec { + $initialize_way_displays + + $xdg-dirs + $swayidle + $swappy_notify + $flashfocus + $wlsunset + $autotiling + $cliphist_store + $cliphist_watch +} + +# commands that "reload" something +exec_always { + $initialize_waybar +} diff --git a/.config/sway/definitions b/.config/sway/definitions index a04fb7e..87d46d9 100644 --- a/.config/sway/definitions +++ b/.config/sway/definitions @@ -1,6 +1,9 @@ # shellcheck disable=SC2148,SC2086,SC2154,SC2046,SC2016 ### Variables # +set $theme "$sway-config-dir/themes/dracula" +include $theme/theme.conf + # Logo key. Use Mod1 for Alt and Mod4 for Super. set $mod Mod4 set $alt_mod Mod1 @@ -26,10 +29,10 @@ set $term kitty set $term_cwd $term -D "$(swaycwd 2>/dev/null || echo $HOME)" # onscreen bar -set $onscreen_bar /usr/share/sway/scripts/wob.sh "$accent-color" "$background-color" +set $onscreen_bar $sway-scripts-dir/wob.sh "$accent-color" "$background-color" # brightness control -set $brightness /usr/share/sway/scripts/brightness.sh +set $brightness $sway-scripts-dir/brightness.sh set $brightness_up $brightness up | $onscreen_bar set $brightness_down $brightness down | $onscreen_bar @@ -83,7 +86,7 @@ include /etc/sway/autostart seat seat0 hide_cursor 5000 # pulseaudio command -set $pulseaudio $once $term_float pulsemixer +set $pulseaudio pavucontrol # help command set $help /usr/share/sway/scripts/help.sh --toggle diff --git a/.config/sway/modes/recording b/.config/sway/modes/recording index 666ac38..7b6c815 100644 --- a/.config/sway/modes/recording +++ b/.config/sway/modes/recording @@ -13,7 +13,7 @@ mode --pango_markup $mode_recording { } ## Launch // Recording Mode ## -$bindsym $mod+Shift+r mode $mode_recording +$bindsym $mod+Shift+Print mode $mode_recording ## Launch // Stop Recording Mode ## -$bindsym $mod+Escape exec killall -s SIGINT wf-recorder \ No newline at end of file +$bindsym $mod+Escape exec killall -s SIGINT wf-recorder diff --git a/.config/sway/modes/resize b/.config/sway/modes/resize index 538aa74..3933c03 100644 --- a/.config/sway/modes/resize +++ b/.config/sway/modes/resize @@ -1,4 +1,5 @@ -mode "resize" { +set $mode_resize "Resizeeo" +mode --pango_markup $mode_resize { $bindsym h resize shrink width 10 px or 10 ppt $bindsym j resize grow height 10 px or 10 ppt $bindsym k resize shrink height 10 px or 10 ppt @@ -14,4 +15,4 @@ mode "resize" { $bindsym Return mode "default" $bindsym Escape mode "default" } -$bindsym $mod+r mode "resize" +$bindsym $mod+r mode $mode_resize diff --git a/.config/sway/modes/shutdown b/.config/sway/modes/shutdown index 48f446a..7a826bf 100644 --- a/.config/sway/modes/shutdown +++ b/.config/sway/modes/shutdown @@ -31,4 +31,4 @@ mode --pango_markup $mode_shutdown { } ## Launch // Exit Menu ## -$bindsym $mod+Shift+e mode $mode_shutdown +bindsym $mod+Shift+e mode $mode_shutdown diff --git a/.config/sway/scripts/dnd.sh b/.config/sway/scripts/dnd.sh new file mode 100755 index 0000000..a9a41af --- /dev/null +++ b/.config/sway/scripts/dnd.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +case $1'' in +'status') + printf '{\"alt\":\"%s\",\"tooltip\":\"mode: %s\"}' $(makoctl mode | grep -q 'do-not-disturb' && echo dnd || echo default) $(makoctl mode | tail -1) + ;; +'restore') + makoctl restore + ;; +'toggle') + makoctl mode | grep 'do-not-disturb' && makoctl mode -r do-not-disturb || makoctl mode -a do-not-disturb + ;; +esac diff --git a/.config/sway/scripts/recorder.sh b/.config/sway/scripts/recorder.sh index ac92463..aeac90f 100755 --- a/.config/sway/scripts/recorder.sh +++ b/.config/sway/scripts/recorder.sh @@ -20,7 +20,7 @@ notify() { } if [ $status != 0 ]; then - target_path=$(xdg-user-dir SCREENSHOT) + target_path=$(xdg-user-dir SCREENSHOTS) timestamp=$(date +'recording_%Y%m%d-%H%M%S') notify "Select a region to record" -t 1000 diff --git a/.config/sway/scripts/scratchpad.sh b/.config/sway/scripts/scratchpad.sh new file mode 100755 index 0000000..50d8546 --- /dev/null +++ b/.config/sway/scripts/scratchpad.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env sh +tooltip=$(swaymsg -r -t get_tree | jq -r 'recurse(.nodes[]) | first(select(.name=="__i3_scratch")) | .floating_nodes | .[] | "\(.app_id) | \(.name)"') +count=$(printf "%s" "$tooltip" | grep -c '^') + +if [ "$count" -eq 0 ]; then + exit 1 +elif [ "$count" -eq 1 ]; then + class="one" +elif [ "$count" -gt 1 ]; then + class="many" +else + class="unknown" +fi + +printf '{"text":"%s", "class":"%s", "alt":"%s", "tooltip":"%s"}\n' "$count" "$class" "$class" "$(echo "${tooltip}" | sed -z 's/\n/\\n/g')" diff --git a/.config/sway/scripts/screenshot-notify.sh b/.config/sway/scripts/screenshot-notify.sh new file mode 100755 index 0000000..d5a8562 --- /dev/null +++ b/.config/sway/scripts/screenshot-notify.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +set -e +DIR=${XDG_SCREENSHOTS_DIR:-$HOME/Screenshots} + +while true; do + mkdir -p "$DIR" && inotifywait -q -e create "$DIR" --format '%w%f' | xargs notify-send "Screenshot saved" +done diff --git a/.config/sway/scripts/sunset.sh b/.config/sway/scripts/sunset.sh new file mode 100755 index 0000000..58d68bc --- /dev/null +++ b/.config/sway/scripts/sunset.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env sh + +config="$HOME/.config/wlsunset/config" + +#Startup function +start() { + [ -f "$config" ] && . "$config" + temp_low=${temp_low:-"4000"} + temp_high=${temp_high:-"6500"} + duration=${duration:-"900"} + sunrise=${sunrise:-"07:00"} + sunset=${sunset:-"19:00"} + location=${location:-"on"} + fallback_longitude=${fallback_longitude:-"8.7"} + fallback_latitude=${fallback_latitude:-"50.1"} + + if [ "${location}" = "on" ]; then + if [ -z ${longitude+x} ] || [ -z ${latitude+x} ]; then + GEO_CONTENT=$(curl -sL https://manjaro-sway.download/geoip) + fi + longitude=${longitude:-$(echo "$GEO_CONTENT" | jq -r '.longitude // empty')} + longitude=${longitude:-$fallback_longitude} + latitude=${latitude:-$(echo "$GEO_CONTENT" | jq -r '.latitude // empty')} + latitude=${latitude:-$fallback_latitude} + + echo longitude: "$longitude" latitude: "$latitude" + + wlsunset -l "$latitude" -L "$longitude" -t "$temp_low" -T "$temp_high" -d "$duration" & + else + wlsunset -t "$temp_low" -T "$temp_high" -d "$duration" -S "$sunrise" -s "$sunset" & + fi +} + +#Accepts managing parameter +case $1'' in +'off') + pkill -x wlsunset + waybar-signal sunset + ;; +'on') + start + waybar-signal sunset + ;; +'toggle') + if pkill -x -0 wlsunset; then + pkill -x wlsunset + else + start + fi + waybar-signal sunset + ;; +'check') + command -v wlsunset + exit $? + ;; +esac + +#Returns a string for Waybar +if pkill -x -0 wlsunset; then + class="on" + text="location-based gamma correction" +else + class="off" + text="no gamma correction" +fi + +printf '{"alt":"%s","tooltip":"%s"}\n' "$class" "$text" diff --git a/.config/sway/scripts/valent.py b/.config/sway/scripts/valent.py new file mode 100755 index 0000000..3058a2d --- /dev/null +++ b/.config/sway/scripts/valent.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +import dbus +import json +import logging, sys +import os +import math + +level = logging.DEBUG if os.environ.get("DEBUG") == "true" else logging.INFO + +logging.basicConfig(stream=sys.stderr, level=level) + +CONNECTIVITY_STRENGTH_SYMBOL = ["󰞃", "󰢼", "󰢽", "󰢾", "󰢾"] + +BATTERY_PERCENTAGE_SYMBOL = ["󱃍", "󰁺", "󰁼", "󰁽", "󰁾", "󰁿", "󰂀", "󰂁", "󰂂", "󰁹"] + +bus = dbus.SessionBus() +valent_object = bus.get_object("ca.andyholmes.Valent", "/ca/andyholmes/Valent") +valent_interface = dbus.Interface(valent_object, "org.freedesktop.DBus.ObjectManager") +managed_objects = valent_interface.GetManagedObjects() + +dangerously_empty = False +connected = False +no_connectivity = False + +devices = [] + +for path in managed_objects: + device = {} + device["state"] = ( + "connected" + if managed_objects[path].get("ca.andyholmes.Valent.Device", {}).get("State", 0) + == 3 + else "disconnected" + ) + device["id"] = ( + managed_objects[path].get("ca.andyholmes.Valent.Device", {}).get("Id", 0) + ) + device["name"] = ( + managed_objects[path].get("ca.andyholmes.Valent.Device", {}).get("Name", 0) + ) + + device_obj = bus.get_object("ca.andyholmes.Valent", path) + device_action_interface = dbus.Interface(device_obj, "org.gtk.Actions") + + battery_state = device_action_interface.Describe("battery.state")[2][0] + device["battery_percentage"] = battery_state["percentage"] + device["battery_status"] = ( + "discharging" if battery_state["charging"] == 0 else "charging" + ) + + connectivity_state = device_action_interface.Describe("connectivity_report.state")[ + 2 + ][0]["signal-strengths"]["1"] + device["connectivity_strength"] = connectivity_state["signal-strength"] + + if device["state"] == "connected": + connected = True + + if device["connectivity_strength"] <= 1: + no_connectivity = True + + if device["battery_percentage"] <= 15 and device["battery_status"] == "discharging": + dangerously_empty = True + + devices.append(device) + +data = {} +data["alt"] = ( + "no-devices" + if len(devices) == 0 + else "dangerously-empty" + if dangerously_empty + else "no-signal" + if no_connectivity + else "connected" + if connected + else "disconnected" +) +data["class"] = data["alt"] +data["tooltip"] = "" + +logging.debug(devices) + +tooltip = [] + +for device in devices: + battery_symbol = math.ceil(round(device["battery_percentage"] / 10, 0)) + details = ( + f"\t{CONNECTIVITY_STRENGTH_SYMBOL[device['connectivity_strength']]} {BATTERY_PERCENTAGE_SYMBOL[battery_symbol]} {device['battery_percentage']}% ({device['battery_status']})" + if device["state"] == "connected" + else "" + ) + tooltip.append(f"{device['name']} ({device['state']}){details}") + +data["tooltip"] = "\n".join(tooltip) + +print(json.dumps(data)) diff --git a/.config/sway/scripts/waybar.sh b/.config/sway/scripts/waybar.sh new file mode 100755 index 0000000..51076ce --- /dev/null +++ b/.config/sway/scripts/waybar.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# wrapper script for waybar with args, see https://github.com/swaywm/sway/issues/5724 +CONFIG_PATH=$HOME/.config/waybar/config.jsonc +STYLE_PATH=$HOME/.config/waybar/style.css + +pkill -x waybar +waybar -c "${CONFIG_PATH}" -s "${STYLE_PATH}" > $(mktemp -t XXXX.waybar.log) diff --git a/.config/sway/scripts/wluma.sh b/.config/sway/scripts/wluma.sh new file mode 100755 index 0000000..e8163d9 --- /dev/null +++ b/.config/sway/scripts/wluma.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env sh + +status() { + systemctl --user is-active wluma >/dev/null 2>&1 +} + +#Accepts managing parameter +case $1'' in +'toggle') + status && systemctl --user stop wluma || systemctl --user --now enable wluma + waybar-signal adaptive-brightness + ;; +'check') + [ -x "$(command -v wluma)" ] && [ $(ls -A /sys/class/backlight/ | wc -l) -gt 0 ] + exit $? + ;; +esac + +#Returns data for Waybar +if status; then + class="on" + text="adaptive brightness" +else + class="off" + text="static brightness" +fi + +printf '{"alt":"%s","tooltip":"%s"}\n' "$class" "$text" diff --git a/.config/sway/themes/dracula/packages b/.config/sway/themes/dracula/packages new file mode 100644 index 0000000..190c268 --- /dev/null +++ b/.config/sway/themes/dracula/packages @@ -0,0 +1,5 @@ +dracula-gtk-theme +dracula-kde-theme-git +dracula-icons-git +ttf-jetbrains-mono-nerd +ttf-roboto \ No newline at end of file diff --git a/.config/sway/themes/dracula/theme.conf b/.config/sway/themes/dracula/theme.conf new file mode 100644 index 0000000..5fdc1ac --- /dev/null +++ b/.config/sway/themes/dracula/theme.conf @@ -0,0 +1,46 @@ +# dracula + +# some global theme specific variables +set $gtk-theme Dracula +set $icon-theme Dracula-icons +set $cursor-theme Dracula-cursors +set $gui-font Roboto 11 +set $term-font JetBrainsMono NF +set $gtk-color-scheme prefer-dark +set $kvantum-theme Dracula-purple-solid +set $background $HOME/.config/sway/generated_background.svg + +set $color0 #141a1b +set $color1 #282a2b +set $color2 #3B758C +set $color3 #41535B +set $color4 #43a5d5 +set $color5 #d6d6d6 +set $color6 #f8f8f2 +set $color7 #ffffff +set $color8 #Cd3f45 +set $color9 #db7b55 +set $color10 #e6cd69 +set $color11 #9fca56 +set $color12 #bd93f9 +set $color13 #55b5db +set $color14 #a074c4 +set $color15 #8a553f + +#$color0 +set $background-color $color0 +#$color6 +set $text-color $color6 +#color1 +set $selection-color $color1 +#color12 +set $accent-color $color12 + +# Basic color configuration using the Base16 variables for windows and borders. +# Property Name Border BG Text Indicator Child Border +client.focused $color12 $color12 $color0 $color6 $color12 +client.focused_inactive $color1 $color1 $color5 $color3 $color1 +client.unfocused $color1 $color0 $color5 $color6 $color1 +client.urgent $color8 $color8 $color0 $color9 $color8 +client.placeholder $color0 $color0 $color5 $color0 $color0 +client.background $color7 diff --git a/.config/user-dirs.dirs b/.config/user-dirs.dirs index 13699fe..a49eeb0 100644 --- a/.config/user-dirs.dirs +++ b/.config/user-dirs.dirs @@ -5,13 +5,14 @@ # homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an # absolute path. No other format is supported. # -XDG_DESKTOP_DIR="$HOME/desktop" -XDG_DOWNLOAD_DIR="$HOME/downloads" -XDG_TEMPLATES_DIR="$HOME/templates" -XDG_PUBLICSHARE_DIR="$HOME/pub" -XDG_DOCUMENTS_DIR="$HOME/docs" -XDG_MUSIC_DIR="$HOME/media/music" -XDG_PICTURES_DIR="$HOME/media/pictures" -XDG_VIDEOS_DIR="$HOME/media/videos" +XDG_DESKTOP_DIR="$HOME/" +XDG_DOWNLOAD_DIR="$HOME/" +XDG_TEMPLATES_DIR="$HOME/" +XDG_PUBLICSHARE_DIR="$HOME/" +XDG_DOCUMENTS_DIR="$HOME/" +XDG_MUSIC_DIR="$HOME/" +XDG_PICTURES_DIR="$HOME/" +XDG_VIDEOS_DIR="$HOME/" XDG_CACHE_DIR="$HOME/.cache" -XDG_SCREENSHOT_DIR="$HOME/screenshots" +XDG_SCREENSHOTS_DIR="$HOME/screenshots" +XDG_WALLPAPERS_DIR="$HOME/wallpaper" diff --git a/.config/waybar/config.jsonc b/.config/waybar/config.jsonc new file mode 100644 index 0000000..7bd720b --- /dev/null +++ b/.config/waybar/config.jsonc @@ -0,0 +1,349 @@ +// ============================================================================= +// +// Waybar configuration +// +// Configuration reference: https://github.com/Alexays/Waybar/wiki/Configuration +// +// ============================================================================= + +{ + // ------------------------------------------------------------------------- + // Global configuration + // ------------------------------------------------------------------------- + + "layer": "top", + + // If height property would be not present, it'd be calculated dynamically + "height": 30, + "position": "top", + + "modules-left": ["custom/menu", "sway/workspaces", "custom/scratchpad"], + "modules-center": ["custom/wf-recorder", "sway/mode", "custom/weather"], + "modules-right": [ + // informational + "sway/language", + "custom/github", + "custom/clipboard", + "custom/zeit", + "cpu", + "temperature", + "memory", + "battery", + + // connecting + "network", + "bluetooth", + "custom/valent", + + // media + "custom/playerctl", + "custom/idle_inhibitor", + "custom/dnd", + "pulseaudio", + "backlight", + + // system + "custom/adaptive-light", + "custom/sunset", + "custom/pacman", + + "tray", + "clock" + ], + + // ------------------------------------------------------------------------- + // Modules + // ------------------------------------------------------------------------- + + "battery": { + "interval": 30, + "states": { + "warning": 30, + "critical": 15 + }, + "format-charging": "󰂄 {capacity}%", + "format": "{icon} {capacity}%", + "format-icons": ["󱃍", "󰁺", "󰁼", "󰁽", "󰁾", "󰁿", "󰂀", "󰂁", "󰂂", "󰁹"], + "tooltip": true + }, + + "clock": { + "interval": 60, + "format": "{:%e %b %Y %H:%M}", + "tooltip": true, + "tooltip-format": "{:%B %Y}\n{calendar}", + "on-click": "swaymsg exec \\$calendar" + }, + + "cpu": { + "interval": 10, + "format": "󰘚", + "states": { + "warning": 70, + "critical": 90 + }, + "on-click": "swaymsg exec \\$once \\$term_float htop", + "tooltip": true + }, + + "memory": { + "interval": 10, + "format": "󰍛", + "states": { + "warning": 70, + "critical": 90 + }, + "on-click": "swaymsg exec \\$once \\$term_float htop", + "tooltip": true + }, + + "network": { + "interval": 5, + "format-wifi": " ", + "format-ethernet": "󰈀", + "format-disconnected": "󰖪", + "tooltip-format": "{icon} {ifname}: {ipaddr}", + "tooltip-format-ethernet": "{icon} {ifname}: {ipaddr}", + "tooltip-format-wifi": "{icon} {ifname} ({essid}): {ipaddr}", + "tooltip-format-disconnected": "{icon} disconnected", + "tooltip-format-disabled": "{icon} disabled", + "on-click": "swaymsg exec \\$once \\$term_float nmtui connect" + }, + + "sway/mode": { + "format": "{}", + "tooltip": false + }, + + "backlight": { + "format": "{icon} {percent}%", + "format-icons": ["󰃞", "󰃟", "󰃠"], + "on-scroll-up": "swaymsg exec \\$brightness_up", + "on-scroll-down": "swaymsg exec \\$brightness_down" + }, + + "pulseaudio": { + "scroll-step": 5, + "format": "{icon} {volume}%{format_source}", + "format-muted": "󰖁 {format_source}", + "format-source": "", + "format-source-muted": " 󰍭", + "format-icons": { + "headphone": "󰋋", + "headset": "󰋎", + "default": ["󰕿", "󰖀", "󰕾"] + }, + "tooltip-format": "{icon}  {volume}% {format_source}", + "on-click": "swaymsg exec \\$pulseaudio", + "on-click-middle": "swaymsg exec \\$volume_mute", + "on-scroll-up": "swaymsg exec \\$volume_up", + "on-scroll-down": "swaymsg exec \\$volume_down" + }, + + "temperature": { + "critical-threshold": 90, + "interval": 5, + "format": "{icon}", + "tooltip-format": "{temperatureC}°C", + "format-icons": ["", "", ""], + "tooltip": true, + "on-click": "swaymsg exec \"\\$once \\$term_float watch sensors\"" + }, + + "tray": { + "icon-size": 21, + "spacing": 5 + }, + + "custom/pacman": { + "format": "󰀼 {}", + "interval": 3600, + "return-type": "json", + "exec-if": "$HOME/.config/scripts/checkupdates.sh check", + "exec": "$HOME/.config/scripts/checkupdates.sh status", + "on-click": "$HOME/.config/scripts/checkupdates.sh check && swaymsg exec \\$update-manager", + "on-click-middle": "waybar-signal pacman", + "signal": 14 + }, + + "bluetooth": { + "format": "󰂯", + "format-disabled": "󰂲", + "on-click": "swaymsg exec \\$bluetooth", + "on-click-right": "rfkill toggle bluetooth", + "tooltip-format": "{}" + }, + + "sway/language": { + "format": " {}", + "min-length": 5, + "tooltip": false, + "on-click": "swaymsg input type:keyboard xkb_switch_layout next" + }, + + "custom/scratchpad": { + "interval": "once", + "return-type": "json", + "format": "{icon}", + "format-icons": { + "one": "󰖯", + "many": "󰖲" + }, + "exec": "/bin/sh $HOME/.config/scripts/scratchpad.sh", + "on-click": "swaymsg 'scratchpad show'", + "signal": 7 + }, + + "custom/sunset": { + "interval": "once", + "tooltip": true, + "return-type": "json", + "format": "{icon}", + "format-icons": { + "on": "󰌵", + "off": "󰌶" + }, + "exec": "fallback_latitude=50.1 fallback_longitude=8.7 latitude= longitude= $HOME/.config/scripts/sunset.sh", + "on-click": "$HOME/.config/scripts/sunset.sh toggle", + "exec-if": "$HOME/.config/scripts/sunset.sh check", + "signal": 6 + }, + + "custom/wf-recorder": { + "interval": "once", + "return-type": "json", + "format": "{}", + "exec": "echo '{\"class\": \"recording\",\"text\":\"󰑊\",\"tooltip\":\"press $mod+Esc to stop recording\"}'", + "exec-if": "pgrep wf-recorder", + "on-click": "waybar-signal recorder", + "signal": 8 + }, + + "custom/github": { + "interval": 300, + "tooltip": false, + "return-type": "json", + "format": " {}", + "exec": "gh api '/notifications' -q '{ text: length }' | cat -", + "exec-if": "[ -x \"$(command -v gh)\" ] && gh auth status 2>&1 | grep -q -m 1 'Logged in' && test $(gh api '/notifications' -q 'length') -ne 0", + "on-click": "test $(gh api '/notifications' -q 'length') -ne 0 && xdg-open https://github.com/notifications && sleep 30 && waybar-signal github", + "signal": 4 + }, + + "custom/playerctl": { + "interval": "once", + "tooltip": true, + "return-type": "json", + "format": "{icon}", + "format-icons": { + "Playing": "󰏦", + "Paused": "󰐍" + }, + "exec": "playerctl metadata --format '{\"alt\": \"{{status}}\", \"tooltip\": \"{{playerName}}: {{markup_escape(title)}} - {{markup_escape(artist)}}\" }'", + "on-click": "playerctl play-pause", + "on-click-right": "playerctl next", + "on-scroll-up": "playerctl position 10+", + "on-scroll-down": "playerctl position 10-", + "signal": 5 + }, + + "custom/clipboard": { + "format": "󰨸", + "interval": "once", + "return-type": "json", + "on-click": "swaymsg -q exec '$clipboard'; waybar-signal clipboard", + "on-click-right": "swaymsg -q exec '$clipboard-del'; waybar-signal clipboard", + "on-click-middle": "rm -f ~/.cache/cliphist/db; waybar-signal clipboard", + "exec": "printf '{\"tooltip\":\"%s\"}' $(cliphist list | wc -l)' item(s) in the clipboard\r(Mid click to clear)'", + "exec-if": "[ -x \"$(command -v cliphist)\" ] && [ $(cliphist list | wc -l) -gt 0 ]", + "signal": 9 + }, + + "custom/weather": { + "format": "{}", + "tooltip": true, + "interval": 3600, + // accepts -c/--city -t/--temperature -d/--distance + "exec": "$HOME/.config/waybar/scripts/weather.py -t F", + "return-type": "json", + "on-click": "xdg-open \"https://wttr.in/$(curl -s https://manjaro-sway.download/geoip | jq -r '.city')\"", + "on-click-right": "waybar-signal weathr", + "signal": 16 + }, + + "custom/zeit": { + "return-type": "json", + "interval": "once", + "format": "{icon}", + "format-icons": { + "tracking": "󰖷", + "stopped": "󰋣" + }, + "exec": "$HOME/.config/waybar/scripts/zeit.sh status", + "on-click": "$HOME/.config/scripts/zeit.sh click; waybar-signal zeit", + "exec-if": "[ -x \"$(command -v zeit)\" ]", + "signal": 10 + }, + + "custom/dnd": { + "interval": "once", + "return-type": "json", + "format": "{}{icon}", + "format-icons": { + "default": "󰚢", + "dnd": "󰚣" + }, + "on-click": "$HOME/.config/scripts/dnd.sh toggle; waybar-signal dnd", + "on-click-right": "$HOME/.config/scripts/dnd.sh restore", + "exec": "$HOME/.config/scripts/dnd.sh status", + "signal": 11 + }, + + "custom/adaptive-light": { + "interval": "once", + "tooltip": true, + "return-type": "json", + "format": "{icon}", + "format-icons": { + "on": "󰃡", + "off": "󰃠" + }, + "exec": "$HOME/.config/scripts/wluma.sh", + "on-click": "$HOME/.config/scripts/wluma.sh toggle", + "exec-if": "$HOME/.config/scripts/wluma.sh check", + "signal": 12 + }, + + "custom/valent": { + "format": "{icon}", + "tooltip": true, + "interval": 60, + "exec": "$HOME/.config/scripts/valent.py", + "exec-if": "[ -x \"$(command -v valent)\" ]", + "return-type": "json", + "format-icons": { + "no-devices": "", + "dangerously-empty": "󰂃", + "no-signal": "󰞃", + "connected": "", + "disconnected": "" + }, + "on-click": "valent", + "on-click-middle": "waybar-signal valent", + "signal": 13 + }, + + "custom/idle_inhibitor": { + "interval": 60, + "return-type": "json", + "format": "{icon}", + "format-icons": { + "on": "󰒳", + "off": "󰒲" + }, + "exec": "inhibit-idle", + "on-click": "inhibit-idle off; inhibit-idle interactive", + "on-click-middle": "inhibit-idle off", + "signal": 15 + } +} diff --git a/.config/waybar/scripts/weather.py b/.config/waybar/scripts/weather.py new file mode 100755 index 0000000..2df9cd7 --- /dev/null +++ b/.config/waybar/scripts/weather.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +"""Script for the Waybar weather module.""" + +import getopt +import json +import locale +import sys +import urllib.parse +from datetime import datetime +import requests + +# see https://docs.python.org/3/library/locale.html#background-details-hints-tips-and-caveats +locale.setlocale(locale.LC_ALL, "") +current_locale, _ = locale.getlocale(locale.LC_NUMERIC) +data = {} +city = "auto" +temperature = "C" +temperature_unit = "celsius" +distance = "km" +wind_speed_unit = "kmh" + +if current_locale == "en_US": + temperature = "F" + distance = "miles" + +argument_list = sys.argv[1:] +options = "t:c:d:" +long_options = ["temperature=", "city=", "distance="] + +try: + args, values = getopt.getopt(argument_list, options, long_options) + + for current_argument, current_value in args: + if current_argument in ("-t", "--temperature"): + temperature = current_value[0].upper() + if temperature not in ("C", "F"): + msg = "temperature unit is neither (C)elsius, nor (F)ahrenheit" + raise RuntimeError( + msg, + temperature, + ) + + elif current_argument in ("-d", "--distance"): + distance = current_value.lower() + if distance not in ("km", "miles"): + msg = "distance unit is neither km, nor miles", distance + raise RuntimeError(msg) + + else: + city = urllib.parse.quote(current_value) + +except getopt.error as err: + print(str(err)) + sys.exit(1) + +if temperature == "F": + temperature_unit = "fahrenheit" + +if distance == "miles": + wind_speed_unit = "mph" + +try: + headers = {"Accept-Language": f"{locale.getlocale()[0].replace("_", "-")},{locale.getlocale()[0].split("_")[0]};q=0.5"} + weather = requests.get(f"https://manjaro-sway.download/weather/{city}?temperature_unit={temperature_unit}&wind_speed_unit={wind_speed_unit}", timeout=10, headers=headers).json() +except ( + requests.exceptions.HTTPError, + requests.exceptions.ConnectionError, + requests.exceptions.Timeout, +) as err: + print(str(err)) + sys.exit(1) + +print(json.dumps(weather)) diff --git a/.config/waybar/style.css b/.config/waybar/style.css new file mode 100644 index 0000000..d09cbf5 --- /dev/null +++ b/.config/waybar/style.css @@ -0,0 +1,2 @@ +@import "/usr/share/sway/templates/waybar/style.css"; +