Add hyprland/wayland config

This commit is contained in:
2023-08-18 19:38:09 +02:00
parent 0d1227ef19
commit 8276cf83b4
20 changed files with 1193 additions and 18 deletions

152
waybar/config Normal file
View File

@ -0,0 +1,152 @@
// vim: ft=jsonc
{
"layer": "top", // Waybar at top layer
// "position": "bottom", // Waybar position (top|bottom|left|right)
// "height": 30, // Waybar height (to be removed for auto height)
// "width": 1280, // Waybar width
"spacing": 4, // Gaps between modules (4px)
"output": "${PRIMARY_DISPLAY}",
// Choose the order of the modules
"modules-left": ["wlr/workspaces", "hyprland/submap", "custom/wifionice", "custom/spotify"],
"modules-center": ["hyprland/window", "custom/dunst"],
"modules-right": ["idle_inhibitor", "pulseaudio", "custom/network", "cpu", "memory", "temperature", "backlight", "battery", "clock", "tray"],
// Modules configuration
"wlr/workspaces": {
"disable-scroll": false,
"sort-by-number": true,
"all-outputs": true,
"warp-on-scroll": false,
"format": "{name}: {icon}",
"format-icons": {
"1": "",
"2": "",
"3": "",
"4": "",
"5": "",
"urgent": "",
"focused": "",
"default": ""
}
},
"keyboard-state": {
"numlock": true,
"capslock": true,
"format": "{name} {icon}",
"format-icons": {
"locked": "",
"unlocked": ""
}
},
"custom/spotify": {
"exec": "/usr/bin/python3 ~/.config/waybar/scripts/mediaplayer.py --player spotify",
"format": "{} ",
"return-type": "json",
"escape": true,
"on-click": "playerctl play-pause",
"on-scroll-up": "playerctl next",
"on-scroll-down": "playerctl previous"
},
"custom/dunst": {
"exec": "~/.config/waybar/scripts/dunst.sh",
"return-type": "json",
"on-click": "dunstctl set-paused toggle",
"on-click-middle": "dunstctl context",
"on-click-right": "dunstctl history-pop",
"restart-interval": 1
},
"custom/wifionice": {
"exec": "~/.config/waybar/scripts/wifionice.sh",
"escape": true
},
"idle_inhibitor": {
"format": "{icon}",
"format-icons": {
"activated": "",
"deactivated": ""
}
},
"tray": {
// "icon-size": 21,
"spacing": 10
},
"clock": {
// "timezone": "America/New_York",
"tooltip-format": "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>",
"format-alt": "{:%Y-%m-%d}"
},
"cpu": {
"format": "{usage}% ",
"tooltip": false
},
"memory": {
"format": "{}% "
},
"temperature": {
// "thermal-zone": 2,
// "hwmon-path": "/sys/class/hwmon/hwmon2/temp1_input",
"critical-threshold": 80,
// "format-critical": "{temperatureC}°C {icon}",
"format": "{temperatureC}°C {icon}",
"format-icons": ["", "", ""]
},
"backlight": {
// "device": "acpi_video1",
"format": "{percent}% {icon}",
"format-icons": ["", "", "", "", "", "", "", "", ""]
},
"battery": {
"states": {
// "good": 95,
"warning": 30,
"critical": 15
},
"format": "{capacity}% {icon}",
"format-charging": "{capacity}% ",
"format-plugged": "{capacity}% ",
"format-alt": "{time} {icon}",
// "format-good": "", // An empty format will hide the module
// "format-full": "",
"format-icons": ["", "", "", "", ""]
},
"battery#bat2": {
"bat": "BAT2"
},
"custom/network": {
"format": "{}",
"max-length": 40,
"escape": true,
"exec": "$HOME/.config/hypr/hooks/networkmanager.sh 2> /dev/null" // Script in resources folder
},
"pulseaudio": {
// "scroll-step": 1, // %, can be a float
"format": "{volume}% {icon} {format_source}",
"format-bluetooth": "{volume}% {icon} {format_source}",
"format-bluetooth-muted": " {icon} {format_source}",
"format-muted": " {format_source}",
"format-source": "{volume}% ",
"format-source-muted": "",
"format-icons": {
"headphone": "",
"hands-free": "",
"headset": "",
"phone": "",
"portable": "",
"car": "",
"default": ["", "", ""]
},
"on-click": "pavucontrol"
},
"custom/media": {
"format": "{icon} {}",
"return-type": "json",
"max-length": 40,
"format-icons": {
"spotify": "",
"default": "🎜"
},
"escape": true,
"exec": "$HOME/.config/waybar/mediaplayer.py 2> /dev/null" // Script in resources folder
// "exec": "$HOME/.config/waybar/mediaplayer.py --player spotify 2> /dev/null" // Filter player based on name
}
}

37
waybar/mocha.css Normal file
View File

@ -0,0 +1,37 @@
/*
*
* Catppuccin Mocha palette
* Maintainer: rubyowo
*
*/
@define-color base #1e1e2e;
@define-color mantle #181825;
@define-color crust #11111b;
@define-color text #cdd6f4;
@define-color subtext0 #a6adc8;
@define-color subtext1 #bac2de;
@define-color surface0 #313244;
@define-color surface1 #45475a;
@define-color surface2 #585b70;
@define-color overlay0 #6c7086;
@define-color overlay1 #7f849c;
@define-color overlay2 #9399b2;
@define-color blue #89b4fa;
@define-color lavender #b4befe;
@define-color sapphire #74c7ec;
@define-color sky #89dceb;
@define-color teal #94e2d5;
@define-color green #a6e3a1;
@define-color yellow #f9e2af;
@define-color peach #fab387;
@define-color maroon #eba0ac;
@define-color red #f38ba8;
@define-color mauve #cba6f7;
@define-color pink #f5c2e7;
@define-color flamingo #f2cdcd;
@define-color rosewater #f5e0dc;

21
waybar/scripts/dunst.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail
readonly ENABLED=' '
readonly DISABLED=' '
dbus-monitor path='/org/freedesktop/Notifications',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged' --profile |
while read -r _; do
PAUSED="$(dunstctl is-paused)"
if [ "$PAUSED" == 'false' ]; then
CLASS="enabled"
TEXT="$ENABLED"
else
CLASS="disabled"
TEXT="$DISABLED"
COUNT="$(dunstctl count waiting)"
if [ "$COUNT" != '0' ]; then
TEXT="$DISABLED ($COUNT)"
fi
fi
printf '{"text": "%s", "class": "%s"}\n' "$TEXT" "$CLASS"
done

View File

@ -0,0 +1,182 @@
#!/usr/bin/env python3
import gi
gi.require_version("Playerctl", "2.0")
from gi.repository import Playerctl, GLib
from gi.repository.Playerctl import Player
import argparse
import logging
import sys
import signal
import gi
import json
import os
from typing import List
logger = logging.getLogger(__name__)
def signal_handler(sig, frame):
logger.info("Received signal to stop, exiting")
sys.stdout.write("\n")
sys.stdout.flush()
# loop.quit()
sys.exit(0)
class PlayerManager:
def __init__(self, selected_player=None):
self.manager = Playerctl.PlayerManager()
self.loop = GLib.MainLoop()
self.manager.connect(
"name-appeared", lambda *args: self.on_player_appeared(*args))
self.manager.connect(
"player-vanished", lambda *args: self.on_player_vanished(*args))
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
self.selected_player = selected_player
self.init_players()
def init_players(self):
for player in self.manager.props.player_names:
if self.selected_player is not None and self.selected_player != player.name:
logger.debug(f"{player.name} is not the filtered player, skipping it")
continue
self.init_player(player)
def run(self):
logger.info("Starting main loop")
self.loop.run()
def init_player(self, player):
logger.info(f"Initialize new player: {player.name}")
player = Playerctl.Player.new_from_name(player)
player.connect("playback-status",
self.on_playback_status_changed, None)
player.connect("metadata", self.on_metadata_changed, None)
self.manager.manage_player(player)
self.on_metadata_changed(player, player.props.metadata)
def get_players(self) -> List[Player]:
return self.manager.props.players
def write_output(self, text, player):
logger.debug(f"Writing output: {text}")
output = {"text": text,
"class": "custom-" + player.props.player_name,
"alt": player.props.player_name}
sys.stdout.write(json.dumps(output) + "\n")
sys.stdout.flush()
def clear_output(self):
sys.stdout.write("\n")
sys.stdout.flush()
def on_playback_status_changed(self, player, status, _=None):
logger.debug(f"Playback status changed for player {player.props.player_name}: {status}")
self.on_metadata_changed(player, player.props.metadata)
def get_first_playing_player(self):
players = self.get_players()
logger.debug(f"Getting first playing player from {len(players)} players")
if len(players) > 0:
# if any are playing, show the first one that is playing
# reverse order, so that the most recently added ones are preferred
for player in players[::-1]:
if player.props.status == "Playing":
return player
# if none are playing, show the first one
return players[0]
else:
logger.debug("No players found")
return None
def show_most_important_player(self):
logger.debug("Showing most important player")
# show the currently playing player
# or else show the first paused player
# or else show nothing
current_player = self.get_first_playing_player()
if current_player is not None:
self.on_metadata_changed(current_player, current_player.props.metadata)
else:
self.clear_output()
def on_metadata_changed(self, player, metadata, _=None):
logger.debug(f"Metadata changed for player {player.props.player_name}")
player_name = player.props.player_name
artist = player.get_artist()
title = player.get_title()
track_info = ""
if player_name == "spotify" and "mpris:trackid" in metadata.keys() and ":ad:" in player.props.metadata["mpris:trackid"]:
track_info = "Advertisement"
elif artist is not None and title is not None:
track_info = f"{artist} - {title}"
else:
track_info = title
if track_info:
if player.props.status == "Playing":
track_info = "" + track_info
else:
track_info = "" + track_info
# only print output if no other player is playing
current_playing = self.get_first_playing_player()
if current_playing is None or current_playing.props.player_name == player.props.player_name:
self.write_output(track_info, player)
else:
logger.debug(f"Other player {current_playing.props.player_name} is playing, skipping")
def on_player_appeared(self, _, player):
logger.info(f"Player has appeared: {player.name}")
if player is not None and (self.selected_player is None or player.name == self.selected_player):
self.init_player(player)
else:
logger.debug(
"New player appeared, but it's not the selected player, skipping")
def on_player_vanished(self, _, player):
logger.info(f"Player {player.props.player_name} has vanished")
self.show_most_important_player()
def parse_arguments():
parser = argparse.ArgumentParser()
# Increase verbosity with every occurrence of -v
parser.add_argument("-v", "--verbose", action="count", default=0)
# Define for which player we"re listening
parser.add_argument("--player")
parser.add_argument("--enable-logging", action="store_true")
return parser.parse_args()
def main():
arguments = parse_arguments()
# Initialize logging
if arguments.enable_logging:
logfile = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "media-player.log")
logging.basicConfig(filename=logfile, level=logging.DEBUG,
format="%(asctime)s %(name)s %(levelname)s:%(lineno)d %(message)s")
# Logging is set by default to WARN and higher.
# With every occurrence of -v it's lowered by one
logger.setLevel(max((3 - arguments.verbose) * 10, 0))
logger.info("Creating player manager")
if arguments.player:
logger.info(f"Filtering for player: {arguments.player}")
player = PlayerManager(arguments.player)
player.run()
if __name__ == "__main__":
main()

72
waybar/scripts/wifionice.sh Executable file
View File

@ -0,0 +1,72 @@
#!/bin/sh
icon="🚄"
path_pid="/tmp/polybar-network-wifionice.pid"
print_train_info() {
while true; do
if [ "$(iwgetid -r)" = "WIFIonICE" ] || [ "$(iwgetid -r)" = "WIFI@DB" ]; then
wifionice=$(curl -sLf https://iceportal.de/api1/rs/status)
if [ "$(echo "$wifionice" | jq .connection)" = "true" ]; then
wifionice_speed=$(echo "$wifionice" | jq .speed)
wifionice_conn=$( echo "$wifionice" | jq -r .connectivity.currentState )
wifionice_nextConn=$( echo "$wifionice" | jq -r .connectivity.nextState )
wifionice_connTime=$( echo "$wifionice" | jq -r .connectivity.remainingTimeSeconds | awk '{printf "%d m", $1/60}' )
if [ "$wifionice_speed" -ne 0 ]; then
wifionice_speed=" - $wifionice_speed km/h"
else
wifionice_speed=""
fi
station=$(curl -sLf https://iceportal.de/api1/rs/tripInfo/trip | jq '[.[].stops[]? | select(.info.passed == false)][0]')
station_name=$(echo "$station" | jq -r '.station.name')
station_track=$(echo "$station" | jq -r '.track.actual')
station_arrival=$(echo "$station" | jq -r '.timetable.scheduledArrivalTime')
station_arrival=$(date --date="@$((station_arrival / 1000))" +%H:%M)
station_delay=$(echo "$station" | jq -r '.timetable.arrivalDelay')
if [ -n "$station_delay" ]; then
station_delay=" ($station_delay)"
else
station_delay=""
fi
if [ "${wifionice_conn}" = "NO_INFO" ]; then
net_text="Net: 🤷"
else
net_text="Net: $wifionice_conn$wifionice_nextConn ($wifionice_connTime)"
fi
echo "$icon $station_arrival$station_delay - $station_name, Gl. $station_track$wifionice_speed | $net_text"
fi
sleep 10
else
echo "" # hidden
sleep 600 &
wait
fi
done
}
network_update() {
pid=$(cat "$path_pid")
if [ "$pid" != "" ]; then
kill -USR1 "$pid"
fi
}
case "$1" in
--update)
network_update
;;
*)
echo $$ > $path_pid
trap exit INT
trap "echo" USR1
print_train_info # Does not return
;;
esac

244
waybar/style.css Normal file
View File

@ -0,0 +1,244 @@
@import "mocha.css";
* {
/* `otf-font-awesome` is required to be installed for icons */
font-family: FontAwesome, Roboto, Helvetica, Arial, sans-serif;
font-size: 13px;
}
window#waybar {
background-color: shade(@base, 0.9);
border: 2px solid alpha(@mantle, 0.3);
border-bottom: 3px solid alpha(@crust, 0.5);
color: @text;
transition-property: background-color;
transition-duration: .5s;
}
window#waybar.hidden {
opacity: 0.2;
}
/*
window#waybar.empty {
background-color: transparent;
}
window#waybar.solo {
background-color: #FFFFFF;
}
*/
window#waybar.termite {
background-color: #3F3F3F;
}
window#waybar.chromium {
background-color: #000000;
border: none;
}
button {
/* Use box-shadow instead of border so the text isn't offset */
box-shadow: inset 0 -3px transparent;
/* Avoid rounded borders under each button name */
border: none;
border-radius: 0;
}
/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */
button:hover {
background: inherit;
box-shadow: inset 0 -3px #ffffff;
}
#workspaces button {
padding: 0 5px;
background-color: transparent;
color: #ffffff;
}
#submap {
padding: 0 10px;
margin: 0 4px;
background-color: @peach;
color: black;
}
#dunst {
}
#workspaces button:hover {
background: alpha(@overlay0, 0.2);
}
#workspaces button.active {
background-color: @overlay1;
box-shadow: inset 0 -3px #ffffff;
}
#workspaces button.urgent {
background-color: @red;
}
#mode {
background-color: #64727D;
border-bottom: 3px solid #ffffff;
}
#clock,
#battery,
#cpu,
#memory,
#disk,
#temperature,
#backlight,
#custom-network,
#pulseaudio,
#wireplumber,
#custom-media,
#custom-wifionice,
#tray,
#mode,
#idle_inhibitor,
#custom-spotify,
#scratchpad,
#mpd {
padding: 0 10px;
color: #ffffff;
border-bottom: 3px solid alpha(@crust, 0.5);
}
#window,
#workspaces {
margin: 0 4px;
}
/* If workspaces is the leftmost module, omit left margin */
.modules-left > widget:first-child > #workspaces {
margin-left: 0;
}
/* If workspaces is the rightmost module, omit right margin */
.modules-right > widget:last-child > #workspaces {
margin-right: 0;
}
#clock {
background-color: #64727D;
}
#battery {
background-color: @yellow;
color: black;
}
#battery.charging, #battery.plugged {
color: black;
background-color: @green;
}
@keyframes blink {
to {
background-color: @yellow;
color: black;
}
}
#battery.critical:not(.charging) {
background-color: @red;
color: black;
animation-name: blink;
animation-duration: 0.5s;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-direction: alternate;
}
#custom-wifionice {
background-color: @red;
color: black;
}
label:focus {
background-color: black;
}
#cpu {
background-color: @green;
color: black;
}
#memory {
background-color: @lavender;
}
#disk {
background-color: @lavender;
}
#backlight {
background-color: @overlay1;
}
#custom-network {
background-color: @sky;
color: black;
}
#network.disconnected {
background-color: @overlay2;
}
#pulseaudio {
background-color: @yellow;
color: black;
}
#pulseaudio.muted {
background-color: @overlay2;
color: @text;
}
#custom-media {
background-color: @base;
color: @text;
min-width: 100px;
}
#custom-spotify {
padding: 0 10px;
margin: 0 4px;
background-color: @green;
color: black;
}
#temperature {
background-color: @peach;
color: black;
}
#temperature.critical {
background-color: @red;
}
#tray {
background-color: @base;
}
#tray > .passive {
-gtk-icon-effect: dim;
}
#tray > .needs-attention {
-gtk-icon-effect: highlight;
background-color: @red;
}
#idle_inhibitor {
background-color: @base;
}
#idle_inhibitor.activated {
background-color: @lavender;
color: #2d3436;
}