From 8899dbdaeee737b92f6e2dd935633ed509c4688d Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Fri, 27 Jan 2023 21:38:53 +0530 Subject: [PATCH] home/natto/eww: init Signed-off-by: Amneesh Singh --- .gitattributes | 2 + home/natto/default.nix | 1 + home/natto/eww/bar/bar.scss | 271 +++++++++++++++++++++++++++++ home/natto/eww/bar/bar.yuck | 20 +++ home/natto/eww/bar/default.nix | 13 ++ home/natto/eww/bar/hyprworkspaces | 34 ++++ home/natto/eww/bar/music.yuck | 92 ++++++++++ home/natto/eww/bar/system.yuck | 187 ++++++++++++++++++++ home/natto/eww/bar/workspaces.yuck | 14 ++ home/natto/eww/default.nix | 36 ++++ home/natto/eww/eww.scss | 1 + home/natto/eww/eww.yuck | 1 + hosts/satori/networking.nix | 11 +- 13 files changed, 678 insertions(+), 5 deletions(-) create mode 100644 home/natto/eww/bar/bar.scss create mode 100644 home/natto/eww/bar/bar.yuck create mode 100644 home/natto/eww/bar/default.nix create mode 100755 home/natto/eww/bar/hyprworkspaces create mode 100644 home/natto/eww/bar/music.yuck create mode 100644 home/natto/eww/bar/system.yuck create mode 100644 home/natto/eww/bar/workspaces.yuck create mode 100644 home/natto/eww/default.nix create mode 100644 home/natto/eww/eww.scss create mode 100644 home/natto/eww/eww.yuck diff --git a/.gitattributes b/.gitattributes index d17f1fb..e7b2f7c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,3 @@ flake.lock linguist-generated +*.yuck linguist-language=lisp +**/emacs/config.org linguist-language=elisp diff --git a/home/natto/default.nix b/home/natto/default.nix index 5d0972d..78bb094 100644 --- a/home/natto/default.nix +++ b/home/natto/default.nix @@ -9,6 +9,7 @@ imports = [ ./email.nix ./programs.nix + ./eww # ./xsession.nix :( ./wayland.nix ./pkgs.nix diff --git a/home/natto/eww/bar/bar.scss b/home/natto/eww/bar/bar.scss new file mode 100644 index 0000000..047fb31 --- /dev/null +++ b/home/natto/eww/bar/bar.scss @@ -0,0 +1,271 @@ +$rosewater: #F5E0DC; +$flamingo: #F2CDCD; +$pink: #F5C2E7; +$mauve: #CBA6F7; +$red: #F38BA8; +$maroon: #EBA0AC; +$peach: #FAB387; +$yellow: #F9E2AF; +$green: #A6E3A1; +$teal: #94E2D5; +$sky: #89DCEB; +$sapphire: #74C7EC; +$blue: #89B4FA; +$lavender: #B4BEFE; +$text: #CDD6F4; +$subtext1: #BAC2DE; +$subtext0: #A6ADC8; +$overlay2: #9399B2; +$overlay1: #7F849C; +$overlay0: #6C7086; +$surface2: #585B70; +$surface1: #45475A; +$surface0: #313244; +$base: #1E1E2E; +$mantle: #181825; +$crust: #11111B; + +$background: $base; +$foreground: $text; + +* { + all: unset; +} + +tooltip { + background: $background; + border: 1px solid $pink; + border-radius: 2px; + + label { + padding: 5px; + } +} + +@mixin color-shadow($color, $opacity: 0.08, $on-hover: 1) { + color: $color; + + @if $on-hover == 0 { + box-shadow: 0 0 0 9999px rgba($color, $opacity) inset; + } @else { + &:hover { + box-shadow: 0 0 0 9999px rgba($color, $opacity) inset; + } + } +} + +.bar, .music-large { + font-family: "Fira Mono"; + background: $background; + + button:hover { + transition: 0.15s; + } + + scale trough, circular-progress { + background: $surface1; + } +} + +.workspaces { + font-size: 16px; + font-family: "Lohit Devanagari"; + + button { + background: none; + } + + .workspace-active { + @include color-shadow($mauve, $on-hover: 0); + font-size: 20px; + } + + .workspace-inactive { + @include color-shadow($flamingo); + } +} + +.music { + button { + background: none; + padding: 0 10px; + } + + .music-control { + @include color-shadow($mauve); + font-family: "Font Awesome 6 Free"; + font-size: 18px; + } + + .music-title { + @include color-shadow($sapphire); + font-size: 16px; + } +} + +.music-large { + border: solid 3px $sapphire; + color: $mauve; + border-radius: 5px; + + .music-large-cover { + background-size: cover; + background-position: center; + border-radius: 5px; + margin: 15px 0 15px 15px; + min-height: 200px; + min-width: 200px; + } + + .music-large-controls { + margin: 15px; + + scale trough { + min-height: 5px; + margin: 0 15px; + + highlight { + background-image: linear-gradient(to right, $sapphire, $teal); + } + + slider { + border-radius: 4px; + background: $background; + border: 2px $mauve solid; + margin: -10px -10px; + transition: 0.2s; + + &:hover { + box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.1); + } + + &:active { + box-shadow: 0 0 0 1px inset, 0 0 0 8px rgba(255, 255, 255, 0.1); + } + } + } + + .music-large-artist { + font-size: 18px; + color: $mauve; + } + + .music-large-album { + font-size: 16px; + color: $sapphire; + } + } +} + +.system { + button { + background: none; + font-size: 20px; + padding: 0 10px; + } + + .system-scale { + min-width: 100px; + } + + scale trough { + min-height: 20px; + min-width: 120px; + border-radius: 3px; + + highlight { + all: unset; + border-radius: 3px; + } + + slider { + all:unset; + border: none; + min-width: 0; + min-height: 0; + } + } + + .system-sound { + button { + @include color-shadow($green); + padding-right: 5px; + } + + scale trough highlight { + background-color: $green; + } + } + + .system-bright { + button { + @include color-shadow($yellow); + } + + scale trough highlight { + background-color: $yellow; + } + } + + .system-temp { + button { + @include color-shadow($red); + } + } + + .system-net { + button { + @include color-shadow($mauve); + } + } + + .system-separator { + min-width: 5px; + background-color: $sapphire; + } + + .system-metrics { + transition: 0.2s; + + label { + padding: 0 5px; + font-size: 20px; + } + + circular-progress { + margin: 0 5px; + } + + .system-metric-cpu { + color: $teal; + } + + .system-metric-battery { + color: $yellow; + } + + .system-metric-memory { + color: $pink; + } + + .system-metric-disk { + color: $blue; + } + } +} + +.system-time { + label { + color: $foreground; + padding: 0 5px; + font-weight: bold; + } + + .system-time-time { + font-size: 18px; + } + + .system-time-date { + font-size: 20px; + } +} diff --git a/home/natto/eww/bar/bar.yuck b/home/natto/eww/bar/bar.yuck new file mode 100644 index 0000000..f45234e --- /dev/null +++ b/home/natto/eww/bar/bar.yuck @@ -0,0 +1,20 @@ +(include "bar/music.yuck") +(include "bar/workspaces.yuck") +(include "bar/system.yuck") + +(defwidget bar [] + (box :class "bar" :orientation "h" :spacing 40 + (workspaces) + (music_compact) + (system))) + +(defwindow bar + :monitor 0 + :geometry (geometry :x "0%" + :y "0%" + :width "100%" + :height "40px" + :anchor "top center") + :stacking "fg" + :exclusive true + (bar)) diff --git a/home/natto/eww/bar/default.nix b/home/natto/eww/bar/default.nix new file mode 100644 index 0000000..aedea45 --- /dev/null +++ b/home/natto/eww/bar/default.nix @@ -0,0 +1,13 @@ +pkgs: with pkgs; [ + coreutils + bash + jq + less + gawk + socat + playerctl + networkmanager + light + iwgtk + wireplumber +] diff --git a/home/natto/eww/bar/hyprworkspaces b/home/natto/eww/bar/hyprworkspaces new file mode 100755 index 0000000..70306c0 --- /dev/null +++ b/home/natto/eww/bar/hyprworkspaces @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +########################################## +# workspace script to work with hyprland # +########################################## + +# i dont really have multiple monitors rn + +# active workspace +current=1 +list_workspaces() { + workspace_list=$(hyprctl -j workspaces | jq -rc '[.[]|.id]|sort') +} + +workspaces() { + echo '{"current": '"${current}"',"list": '"${workspace_list}"'}' +} + +list_workspaces +workspaces +hyprctl dispatch workspace $current + +socat -u UNIX-CONNECT:/tmp/hypr/"$HYPRLAND_INSTANCE_SIGNATURE"/.socket2.sock - | while read -r event; do + case ${event%>>*} in + "workspace") + current=${event##*>>} + workspaces + ;; + "createworkspace"|"destroyworkspace") + list_workspaces + workspaces + ;; + esac +done diff --git a/home/natto/eww/bar/music.yuck b/home/natto/eww/bar/music.yuck new file mode 100644 index 0000000..e3d3fa3 --- /dev/null +++ b/home/natto/eww/bar/music.yuck @@ -0,0 +1,92 @@ +(defvar playerctl "playerctl -p 'playerctld,%any'") + +; https://github.com/elkowar/eww/issues/518 +(deflisten music :initial "" + "playerctl -p 'playerctld,%any' --follow metadata --format '{\"artist\":\"{{artist}}\",\"album\":\"{{album}}\",\"title\":\"{{trunc(title,40)}}\",\"full_title\":\"{{title}}\",\"cover\":\"{{mpris:artUrl}}\", \"status\":\"{{lc(status)}}\",\"duration\":\"{{duration(mpris:length)}}\",\"raw_duration\":\"{{mpris:length}}\",\"position\":\"{{duration(position)}}\",\"raw_position\":\"{{position}}\"}'") + +(defwidget music_controls[] + (box + (button :class "music-control" :onclick "${playerctl} previous" "") + (button :class "music-control" :onclick "${playerctl} play-pause" {music.status == "playing" ? "" : "" }) + (button :class "music-control" :onclick "${playerctl} next" ""))) + +(defwidget music_large [] + (box + :halign "center" + :class "music-large" + :orientation "h" + (box + :class "music-large-cover" + :visible {music.cover != ""} + :style "background-image: url(\"${music.cover}\");") + (box + :orientation "v" + :class "music-large-controls" + :spacing {music.cover == "" ? 10 : 0} + (label + :visible {music.artist != ""} + :class "music-large-artist" + :text {music.artist}) + (label + :visible {music.album != ""} + :class "music-large-album" + :text {music.album}) + (eventbox + :cursor "pointer" + (music_controls)) + (box + (label + :visible {music.position != ""} + :xalign {music.duration == "" ? 0.5 : 0} + :style {music.duration == "" ? "font-size: 18px;": ""} + :text {music.position}) + (label + :visible {music.duration != ""} + :xalign {music.position == "" ? 0.5 : 1} + :style {music.position == "" ? "font-size: 18px;": ""} + :text {music.duration})) + (eventbox + :class "music-large-scale" + :cursor "pointer" + :visible {music.raw_duration != "" && music.raw_position != "" } + (scale + :min 0 + :max {music.raw_duration / 1000000} + :onchange "${playerctl} position {}" + :value {music.raw_position / 1000000}))))) + +(defvar music_control false) + +(defwidget music_compact [] + (eventbox + :cursor "pointer" + :onhover "${EWW_CMD} update music_control=true" + :onhoverlost "${EWW_CMD} update music_control=false" + :visible {music.title != "" && music.status != "stopped" && music != ""} + :halign "center" + (box + :class "music" + :space-evenly "false" + (button + :class "music-title" + :onclick "${EWW_CMD} open --toggle music" + :tooltip "${music.title} by ${music.artist}" + :onrightclick "wl-copy \"${music.artist} - ${music.full_title}\"" + {music.title}) + (revealer + :transition "slideright" + :reveal music_control + :duration "200ms" + (music_controls) + )))) + +(defwindow music + :stacking "overlay" + :monitor 0 + :geometry (geometry + :x "0%" + :y "20px" + :width "0%" + :height "0%" + :anchor "top center") + (music_large)) diff --git a/home/natto/eww/bar/system.yuck b/home/natto/eww/bar/system.yuck new file mode 100644 index 0000000..52e9439 --- /dev/null +++ b/home/natto/eww/bar/system.yuck @@ -0,0 +1,187 @@ +(defvar system_sound_control false) +(defvar system_sound_mute false) + +(defpoll volume :interval "3s" + "wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{print $2 * 100}'") + +(defwidget system_sound [] + (eventbox + :cursor "pointer" + :onhover "${EWW_CMD} update system_sound_control=true" + :onhoverlost "${EWW_CMD} update system_sound_control=false" + :tooltip "${ system_sound_mute ? 'Muted' : 'Volume: ${volume}%'}" + (box + :space-evenly false + :orientation "h" + :class "system-sound" + (revealer + :transition "slideleft" + :reveal system_sound_control + :duration "250ms" + (scale + :class "system-scale" + :min 0 + :max 151 + :onchange "wpctl set-volume @DEFAULT_AUDIO_SINK@ {}%" + :value {volume} + )) + (button + ; since we do not know the initial state, we will just update the variable + :onclick "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle && ${EWW_CMD} update system_sound_mute=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{print $3 ~ /MUTED/ ? \"true\" : \"false\"}')" + {system_sound_mute ? "" : volume > 75 ? "" : "" }) + ))) + +(defvar system_bright_control false) + +(defpoll bright :interval "3s" "light") + +(defwidget system_bright [] + (eventbox + :cursor "pointer" + :onhover "${EWW_CMD} update system_bright_control=true" + :onhoverlost "${EWW_CMD} update system_bright_control=false" + :tooltip "Brightness: ${round(bright,0)}%" + (box + :space-evenly false + :orientation "h" + :class "system-bright" + (revealer + :transition "slideleft" + :reveal system_bright_control + :duration "250ms" + (scale + :class "system-scale" + :min 5 + :max 101 + :onchange "light -S {}" + :value {bright} + )) + (button + :onclick "light -S ${bright < 51 ? 100 : 50}" + "")))) + +(defwidget system_temp [] + (eventbox + :cursor "pointer" + :tooltip {EWW_TEMPS["CORETEMP_PACKAGE_ID_0"] != "" ? "CPU: ${EWW_TEMPS['CORETEMP_PACKAGE_ID_0']} C" : EWW_TEMPS} + :class "system-temp" + (button + ""))) + +(defpoll system_net_ethernet :interval "4s" :initial "" + "nmcli -f NAME,TYPE con show --active | awk '$NF == \"ethernet\" {NF--; print}'") + +(defpoll system_net_wifi :interval "4s" :initial "" + "nmcli -f NAME,TYPE con show --active | awk '$NF == \"wifi\" { NF--; print}'") + +(defwidget system_net [] + (eventbox + :cursor "pointer" + :class "system-net" + :visible {system_net_ethernet != "" || system_net_wifi != ""} + :tooltip {EWW_NET} + (box + :orientation "h" + (button + :visible {system_net_ethernet != ""} + :tooltip {system_net_ethernet} + "") + (button + :visible {system_net_wifi != ""} + :tooltip {system_net_wifi} + :onclick "iwgtk &" + "")))) + +(defwidget system_info [] + (box + :orientation "h" + :space-evenly false + :spacing 5 + (system_sound) + (system_bright) + (system_temp))) + +(defpoll system_cpu_freq :interval "2s" :initial "0" + "cat /proc/cpuinfo | awk '/cpu MHz/ { sum += $4; n++} END { if (n != 0) print sum / n; }'") + +(defwidget system_metric [value class tooltip] + (box + :orientation "h" + :space-evenly false + :class "system-metric-${class}" + :tooltip "${tooltip}" + (circular-progress + :value value + :start-at 0 + :thickness 4 + (label :text "")))) + +(defwidget system_metrics [] + (eventbox + :cursor "pointer" + :class "system-metrics" + :tooltip "test" + :onclick "${EWW_CMD} open --toggle system" + (box + :space-evenly false + (system_metric + :value {EWW_CPU.avg} + :tooltip "CPU Usage: ${round(EWW_CPU.avg, 2)}%${system_cpu_freq == '0' ? '' : ' +CPU Freq: ${system_cpu_freq} MHz'}" + :class "cpu") + (system_metric + :value {EWW_RAM.used_mem_perc} + :tooltip "Free Memory: ${round(EWW_RAM.free_mem / 1024 / 1024, 2)} MB +Available Memory: ${round(EWW_RAM.available_mem / 1024 / 1024, 2)} MB +Free %: ${round(100 - EWW_RAM.used_mem_perc, 2)}%" + :class "memory") + (system_metric + :value {EWW_BATTERY.total_avg} + :tooltip "Battery ${round(EWW_BATTERY.total_avg, 0)}%" + :class "battery") + (system_metric + :value {round((1 - (EWW_DISK["/"].free / EWW_DISK["/"].total)) * 100, 0)} + :tooltip "Free Disk: ${round(EWW_DISK['/'].free / EWW_DISK['/'].total * 100, 2)} GB +Free Disk %: ${round(EWW_DISK['/'].free / EWW_DISK['/'].total * 100, 2)}%" + :class "disk")))) + +(defvar system_date_reveal false) + +(defpoll time :interval "1s" + "date '+%H:%M:%S'") + +(defpoll date :interval "10m" + "date '+%b %d'") + +(defwidget system_time [] + (eventbox + :onhover "${EWW_CMD} update system_date_reveal=true" + :onhoverlost "${EWW_CMD} update system_date_reveal=false" + (box + :space-evenly false + :orientation "h" + :class "system-time" + (label :class "system-time-time" :text {time}) + (revealer + :transition "slideright" + :reveal system_date_reveal + :duration "250ms" + (label :class "system-time-date" :text {date}))))) + +(defwidget system_separator [?visible] (box :class "system-separator" :visible {visible == "false" ? false : true})) + +(defwidget system [] + (box + :halign "end" + :class "system" + :space-evenly false + :spacing 5 + (system_separator) + (system_info) + (system_separator + :visible "${system_net_ethernet != "" || system_net_wifi != ""}") + (system_net) + (system_separator) + (system_metrics) + (system_separator) + (system_time))) diff --git a/home/natto/eww/bar/workspaces.yuck b/home/natto/eww/bar/workspaces.yuck new file mode 100644 index 0000000..e4b18ad --- /dev/null +++ b/home/natto/eww/bar/workspaces.yuck @@ -0,0 +1,14 @@ +(deflisten workspace "bar/hyprworkspaces") +(defvar numerals "[\"१\", \"२\", \"३\", \"४\", \"५\", \"६\", \"७\", \"८\", \"९\", \"०\"]") + +(defwidget workspaces [] + (eventbox + :cursor "pointer" + (box + :class "workspaces" + (for ws in {workspace.list} + (button + :class "${ws == workspace.current ? 'workspace-active' : 'workspace-inactive'}" + :onclick "hyprctl dispatch workspace ${ws}" + {ws <= 10 ? numerals[ws - 1] : ws })) + ))) diff --git a/home/natto/eww/default.nix b/home/natto/eww/default.nix new file mode 100644 index 0000000..621a4c1 --- /dev/null +++ b/home/natto/eww/default.nix @@ -0,0 +1,36 @@ +{ config, pkgs, lib, ... }: +{ + programs.eww = { + enable = true; + package = pkgs.eww-wayland; + configDir = lib.cleanSourceWith { + src = ./.; + filter = name: _: + let + baseName = baseNameOf (toString name); + in + !(lib.hasSuffix ".nix" baseName); + }; + }; + + systemd.user.services.eww = { + Unit = { + Description = "EWW Daemon"; + }; + Service = + let + deps = [ + config.programs.eww.package + config.wayland.windowManager.hyprland.package + ] ++ (import ./bar pkgs); + in + { + Environment = "PATH=${lib.makeBinPath deps}"; + Type = "simple"; + Restart = "on-failure"; + ExecStart = "${config.programs.eww.package}/bin/eww daemon --no-daemonize"; + }; + Install.WantedBy = [ "graphical-session.target" ]; + }; +} + diff --git a/home/natto/eww/eww.scss b/home/natto/eww/eww.scss new file mode 100644 index 0000000..f4450db --- /dev/null +++ b/home/natto/eww/eww.scss @@ -0,0 +1 @@ +@import "bar/bar.scss" diff --git a/home/natto/eww/eww.yuck b/home/natto/eww/eww.yuck new file mode 100644 index 0000000..8af233b --- /dev/null +++ b/home/natto/eww/eww.yuck @@ -0,0 +1 @@ +(include "bar/bar.yuck") diff --git a/hosts/satori/networking.nix b/hosts/satori/networking.nix index 8460ddd..a95da1b 100644 --- a/hosts/satori/networking.nix +++ b/hosts/satori/networking.nix @@ -5,12 +5,13 @@ hostName = "satori"; hostId = "beca3df0"; defaultGateway = "192.168.1.1"; - wireless = { - enable = false; - iwd.enable = true; - interfaces = [ "wlp0s20f3" ]; + networkmanager = { + enable = true; + wifi = { + powersave = true; + backend = "iwd"; + }; }; - networkmanager.enable = true; firewall = { allowedTCPPorts = [ 22 18172 6600 8001 25565 ]; allowedUDPPorts = [ 22 17840 18172 ];