From 125d6714218d6c633289cab24169a9cf234066ff Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Mon, 7 Apr 2025 14:13:09 +0200 Subject: [PATCH] Cooler waybar --- hypr/.gitignore | 1 + hypr/cpu.sh | 2 ++ hypr/hyprland.conf | 70 +++++++++++++++++++++++++++------------------- hypr/mem.sh | 2 ++ hypr/stat.py | 31 ++++++++++++++++++++ hypr/workspace.sh | 53 +++++++++++++++++++++++++++++++++++ waybar/config | 25 ++++++++++++----- waybar/style.css | 29 +++++++++++++------ 8 files changed, 170 insertions(+), 43 deletions(-) create mode 100644 hypr/.gitignore create mode 100755 hypr/cpu.sh create mode 100755 hypr/mem.sh create mode 100755 hypr/stat.py create mode 100755 hypr/workspace.sh diff --git a/hypr/.gitignore b/hypr/.gitignore new file mode 100644 index 0000000..6c3fb32 --- /dev/null +++ b/hypr/.gitignore @@ -0,0 +1 @@ +.stat.txt diff --git a/hypr/cpu.sh b/hypr/cpu.sh new file mode 100755 index 0000000..2d78910 --- /dev/null +++ b/hypr/cpu.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +head -n 1 ~/.config/dotfiles/hypr/.stat.txt diff --git a/hypr/hyprland.conf b/hypr/hyprland.conf index 954f8d1..338ed6f 100644 --- a/hypr/hyprland.conf +++ b/hypr/hyprland.conf @@ -29,6 +29,7 @@ workspace = 16, monitor:DP-3 workspace = 17, monitor:DP-3 workspace = 18, monitor:DP-3 workspace = 19, monitor:DP-3 +workspace = 20, monitor:DP-3 workspace = 21, monitor:DP-2, default:true workspace = 22, monitor:DP-2 @@ -39,6 +40,7 @@ workspace = 26, monitor:DP-2 workspace = 27, monitor:DP-2 workspace = 28, monitor:DP-2 workspace = 29, monitor:DP-2 +workspace = 30, monitor:DP-2 ################### @@ -48,9 +50,10 @@ workspace = 29, monitor:DP-2 # See https://wiki.hyprland.org/Configuring/Keywords/ # Set programs that you use -$terminal = alacritty +$terminal = new-terminal $fileManager = dolphin $menu = rofi -show drun -theme ~/.config/rofi/theme.rasi +$hyprscript = ~/.config/dotfiles/hypr/workspace.sh ################# @@ -61,12 +64,15 @@ $menu = rofi -show drun -theme ~/.config/rofi/theme.rasi # Or execute your favorite apps at launch like this: # exec-once = $terminal +exec-once = ~/.config/dotfiles/hypr/stat.py & exec-once = waybar & exec-once = hyprpaper & exec-once = nm-applet & exec-once = flameshot & exec-once = blueberry-tray & exec-once = nextcloud --background & +exec-once = systemctl start stream-deck --user & +exec-once = systemctl start mars --user & ############################# @@ -93,7 +99,7 @@ general { border_size = 1 # https://wiki.hyprland.org/Configuring/Variables/#variable-types for info about colors - col.active_border = rgba(ffffff55) + col.active_border = rgba(ffffffaa) col.inactive_border = rgba(ffffff22) # Set to true enable resizing windows by clicking and dragging on borders and gaps @@ -171,6 +177,9 @@ animations { # windowrule = bordersize 0, floating:0, onworkspace:f[1] # windowrule = rounding 0, floating:0, onworkspace:f[1] +# Borders only on alacritty +windowrule = noborder, class:negative:Alacritty + # See https://wiki.hyprland.org/Configuring/Dwindle-Layout/ for more dwindle { pseudotile = true # Master switch for pseudotiling. Enabling is bound to mainMod + P in the keybinds section below @@ -234,26 +243,26 @@ $mainMod = SUPER # Sets "Windows" key as main modifier # Example binds, see https://wiki.hyprland.org/Configuring/Binds/ for more bind = $mainMod, return, exec, $terminal -bind = $mainMod SHIFT, E, exec, $terminal bind = $mainMod, A, exec, firefox bind = $mainMod SHIFT, C, killactive, -bind = $mainMod, E, exec, $fileManager bind = $mainMod, V, togglefloating, bind = $mainMod, R, exec, $menu -bind = $mainMod, P, pseudo, # dwindle bind = $mainMod, J, togglesplit, # dwindle bind = $mainMod SHIFT, Right, movewindow,mon:r bind = $mainMod SHIFT, Left, movewindow,mon:l bind = $mainMod, Tab, cyclenext - -bind = $mainMod SHIFT, Q, exit +bind = $mainMod SHIFT, Q, exec, hyprctl dispatch exit bind = $mainMod CTRL, R, exec, hyprctl reload bind = $mainMod, Z, exec, firefox http://jdb.localhost/todo.html https://web.telegram.org https://web.whatsapp.com/ https://discord.com/app https://nuage.polymny.studio/index.php/apps/calendar/ https://mail.infomaniak.com/2 https://mail.infomaniak.com/0 -bind = $mainMod, E, exec, firefox ext+container:name=Yuzzit&url=https://yip.atlassian.net/ ext+container:name=Yuzzit&url=https://app.slack.com/client/T03UFFGJK/D07KS0S1LDT ext+container:name=Yuzzit&url=https://app.gather.town/app/bZRkf3gh7MIximOa/ytopenspace +bind = $mainMod, E, exec, firefox "ext+container:name=Yuzzit&url=https://yip.atlassian.net/" "ext+container:name=Yuzzit&url=https://app.slack.com/client/T03UFFGJK/D07KS0S1LDT" "ext+container:name=Yuzzit&url=https://app.gather.town/app/bZRkf3gh7MIximOa/ytopenspace" + +bind = $mainMod, C, exec, alacritty -e numbat +bind = $mainMod, P, exec, pavucontrol +bind = $mainMod, B, exec, blueberry # Move focus with mainMod + arrow keys # bind = $mainMod, left, movefocus, l @@ -261,30 +270,35 @@ bind = $mainMod, E, exec, firefox ext+container:name=Yuzzit&url=https://yip.atla # bind = $mainMod, up, movefocus, u # bind = $mainMod, down, movefocus, d -bind = $mainMod, left, workspace, e-1 -bind = $mainMod, right, workspace, e+1 +bind = $mainMod, left, exec, $hyprscript previous +bind = $mainMod, right, exec, $hyprscript next # Switch workspaces with mainMod + [0-9] -bind = $mainMod, code:10, exec, hyprsome workspace 1 -bind = $mainMod, code:11, exec, hyprsome workspace 2 -bind = $mainMod, code:12, exec, hyprsome workspace 3 -bind = $mainMod, code:13, exec, hyprsome workspace 4 -bind = $mainMod, code:14, exec, hyprsome workspace 5 -bind = $mainMod, code:15, exec, hyprsome workspace 6 -bind = $mainMod, code:16, exec, hyprsome workspace 7 -bind = $mainMod, code:17, exec, hyprsome workspace 8 -bind = $mainMod, code:18, exec, hyprsome workspace 9 +bind = $mainMod, code:10, exec, $hyprscript workspace 1 +bind = $mainMod, code:11, exec, $hyprscript workspace 2 +bind = $mainMod, code:12, exec, $hyprscript workspace 3 +bind = $mainMod, code:13, exec, $hyprscript workspace 4 +bind = $mainMod, code:14, exec, $hyprscript workspace 5 +bind = $mainMod, code:15, exec, $hyprscript workspace 6 +bind = $mainMod, code:16, exec, $hyprscript workspace 7 +bind = $mainMod, code:17, exec, $hyprscript workspace 8 +bind = $mainMod, code:18, exec, $hyprscript workspace 9 +bind = $mainMod, code:19, exec, $hyprscript workspace 10 # Move active window to a workspace with mainMod + SHIFT + [0-9] -bind = $mainMod SHIFT, code:10, exec, hyprsome movefocus 1 -bind = $mainMod SHIFT, code:11, exec, hyprsome movefocus 2 -bind = $mainMod SHIFT, code:12, exec, hyprsome movefocus 3 -bind = $mainMod SHIFT, code:13, exec, hyprsome movefocus 4 -bind = $mainMod SHIFT, code:14, exec, hyprsome movefocus 5 -bind = $mainMod SHIFT, code:15, exec, hyprsome movefocus 6 -bind = $mainMod SHIFT, code:16, exec, hyprsome movefocus 7 -bind = $mainMod SHIFT, code:17, exec, hyprsome movefocus 8 -bind = $mainMod SHIFT, code:18, exec, hyprsome movefocus 9 +bind = $mainMod SHIFT, code:10, exec, $hyprscript movetoworkspace 1 +bind = $mainMod SHIFT, code:11, exec, $hyprscript movetoworkspace 2 +bind = $mainMod SHIFT, code:12, exec, $hyprscript movetoworkspace 3 +bind = $mainMod SHIFT, code:13, exec, $hyprscript movetoworkspace 4 +bind = $mainMod SHIFT, code:14, exec, $hyprscript movetoworkspace 5 +bind = $mainMod SHIFT, code:15, exec, $hyprscript movetoworkspace 6 +bind = $mainMod SHIFT, code:16, exec, $hyprscript movetoworkspace 7 +bind = $mainMod SHIFT, code:17, exec, $hyprscript movetoworkspace 8 +bind = $mainMod SHIFT, code:18, exec, $hyprscript movetoworkspace 9 +bind = $mainMod SHIFT, code:19, exec, $hyprscript movetoworkspace 10 + +# Screenshot +bind = , Print, exec, grim -g "$(slurp -d)" - | wl-copy # Example special workspace (scratchpad) bind = $mainMod, S, togglespecialworkspace, magic diff --git a/hypr/mem.sh b/hypr/mem.sh new file mode 100755 index 0000000..37b6ffe --- /dev/null +++ b/hypr/mem.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +tail -n 1 ~/.config/dotfiles/hypr/.stat.txt diff --git a/hypr/stat.py b/hypr/stat.py new file mode 100755 index 0000000..933e076 --- /dev/null +++ b/hypr/stat.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import os +from os.path import expanduser +import psutil + +os.chdir(os.path.expanduser('~/.config/dotfiles/hypr')) + +bars = "_▂▃▄▅▆▇███" +cpu_values = [0] * 10 +mem_values = [0] * 10 + +def to_bar(x): + return bars[round((len(bars) - 1) * x / 100)] + +while True: + cpu_percent = psutil.cpu_percent(interval=2) + mem_percent = psutil.virtual_memory().percent + + for i in range(len(cpu_values) - 1): + cpu_values[i] = cpu_values[i+1] + mem_values[i] = mem_values[i+1] + + cpu_values[-1] = cpu_percent + mem_values[-1] = mem_percent + + with open('.stat.txt', 'w') as f: + f.write( + ' ' + ''.join([to_bar(x) for x in cpu_values]) + '\n' + + ' ' + ''.join([to_bar(x) for x in mem_values]) + ) diff --git a/hypr/workspace.sh b/hypr/workspace.sh new file mode 100755 index 0000000..80a1031 --- /dev/null +++ b/hypr/workspace.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +get_current_workspace() { + hyprctl activeworkspace | head -n 1 | cut -d ' ' -f 3 +} + +get_current_monitor() { + hyprctl activeworkspace | head -n 1 | rev | cut -d ' ' -f 1 | rev | tr -d ':' +} + +get_nth_workspace() { + cat /home/thomas/.config/hypr/hyprland.conf \ + | grep "^workspace =" \ + | grep $1 \ + | sed "${2}q;d" \ + | cut -d '=' -f 2 \ + | cut -d ',' -f 1 \ + | tr -d ' ' +} + +case "$1" in + "workspace") + current_monitor=$(get_current_monitor) + workspace=$(get_nth_workspace $current_monitor $2) + hyprctl dispatch workspace $workspace;; + + "movetoworkspace") + current_monitor=$(get_current_monitor) + workspace=$(get_nth_workspace $current_monitor $2) + hyprctl dispatch movetoworkspace $workspace;; + + "previous") + current_monitor=$(get_current_monitor) + current_workspace=$(get_current_workspace) + previous_workspace=$(($current_workspace - 1)) + + if [[ "$previous_workspace" == *0 ]]; then + previous_workspace=$(($previous_workspace + 10)) + fi + + hyprctl dispatch workspace $previous_workspace;; + + "next") + current_monitor=$(get_current_monitor) + current_workspace=$(get_current_workspace) + next_workspace=$(($current_workspace + 1)) + + if [[ "$next_workspace" == *1 ]]; then + next_workspace=$(($next_workspace - 10)) + fi + + hyprctl dispatch workspace $next_workspace;; +esac diff --git a/waybar/config b/waybar/config index 1102022..fdf87d2 100644 --- a/waybar/config +++ b/waybar/config @@ -2,7 +2,6 @@ "name": "float", "layer": "top", "position": "bottom", - "height": 75, "exclusive": false, "passthrough": false, "gtk-layer-shell": true, @@ -11,7 +10,7 @@ "margin-top" : 0, "margin-left": 0, "margin-right": 0, - "height" : 10, + "height" : 16, "modules-left": [ ], "modules-center": [ @@ -19,6 +18,8 @@ "modules-right": [ "hyprland/workspaces", "tray", + "custom/cpu", + "custom/mem", "battery", "clock", ], @@ -42,6 +43,7 @@ "17": "7", "18": "8", "19": "9", + "20": "0", "21": "1", "22": "2", "23": "3", @@ -51,16 +53,17 @@ "27": "7", "28": "8", "29": "9", + "30": "0", }, "on-click": "activate", "sort-by-number": true, "persistent-workspaces": { - "DP-3": [11, 12, 13, 14, 15, 16, 17, 18, 19], - "DP-2": [21, 22, 23, 24, 25, 26, 27, 28, 29] + "DP-3": [11, 12, 13, 14, 15, 16, 17, 18, 19, 20], + "DP-2": [21, 22, 23, 24, 25, 26, 27, 28, 29, 30] }, }, "clock": { - "format": "{:%d/%m/%Y %H:%M}", + "format": "{:L%A %d %B %H:%M}", "tooltip-format": "{:%Y %B}\n{calendar}", "format-alt": "{}", "interval": 1 @@ -128,7 +131,15 @@ } }, "tray": { - "icon-size": 15, - "spacing": 10 + "icon-size": 16, + "spacing": 5 + }, + "custom/cpu": { + "exec": "~/.config/dotfiles/hypr/cpu.sh", + "restart-interval": 2 + }, + "custom/mem": { + "exec": "~/.config/dotfiles/hypr/mem.sh", + "restart-interval": 2 } } diff --git a/waybar/style.css b/waybar/style.css index aa5982a..0842fe2 100644 --- a/waybar/style.css +++ b/waybar/style.css @@ -9,9 +9,10 @@ window#waybar.float { } * { - font-family: "JetBrainsMono Nerd Font", Roboto, Helvetica, Arial, sans-serif; - font-size: 16px; + font-family: "Ubuntu Mono Nerd Font", Roboto, Helvetica, Arial, sans-serif; + font-size: 14px; opacity: 0.9; + min-height: 0px; } window#waybar { @@ -35,8 +36,14 @@ button:hover { box-shadow: inset 0 -3px #ffffff; } +#workspaces { + padding-top: 2px; + padding-left: 5px; + padding-right: 5px; +} + #workspaces button { - padding: 2px 5px; + padding: 0px 0px; background-color: transparent; color: #ffffff; } @@ -81,12 +88,18 @@ button:hover { #temperature, #network, #pulseaudio, -#idle_inhibitor { - padding: 0 10px; +#idle_inhibitor, +#custom-cpu, +#custom-mem { + padding: 0 5px; } -#pulseaudio { - color: @maroon; +#custom-cpu { + color: @red; +} + +#custom-mem { + color: @blue; } #network { @@ -102,7 +115,7 @@ button:hover { } #clock { - color: @flamingo; + color: @white; } #window {