aboutsummaryrefslogtreecommitdiffstats
path: root/home/eww/default.nix
blob: b6a745cd36b99c2ceb75d07f73fe576359d2919a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
{
  pkgs,
  lib,
  config,
  ...
}:

let
  timerScript = pkgs.writeShellScriptBin "timer.sh" ''
    #!${pkgs.bash}/bin/bash
    CUR_TIME=$(${pkgs.coreutils}/bin/date +%s)
    STATUS=$(${pkgs.coreutils}/bin/cat /var/tmp/timer_status || echo "READY")

    if [ "$STATUS" = "READY" ]; then
        echo ""
    elif [ "$STATUS" = "FINISHED" ]; then
        ${pkgs.pulseaudio}/bin/paplay "${config.home.homeDirectory}/.config/eww/timer.wav" &
        echo "READY" > /var/tmp/timer_status
        echo ""
    elif [ "$STATUS" -gt "$CUR_TIME" ]; then
        DIFF=$(( STATUS - CUR_TIME ))
        echo $(${pkgs.coreutils}/bin/date -d "@$DIFF" +%M:%S)
    else
        echo "FINISHED" > /var/tmp/timer_status
        echo ""
    fi
  '';

  calendarScript = pkgs.writeShellScriptBin "calendar.sh" ''
    #!${pkgs.bash}/bin/bash
    ${pkgs.coreutils}/bin/date +'<big>%Y %B</big>\n<tt><small>%d %A</small></tt>'
  '';

in

{
  programs.eww = {
    enable = true;
    package = pkgs.eww;
  };

  # Dependencies
  home.packages = with pkgs; [
    hyprland
    brightnessctl
    lxqt.pavucontrol-qt
    wttrbar
    bluetui
    wlogout
    walker
    lm_sensors
    pulseaudio
    socat
    jq
    procps
    gawk
    gnugrep
    gnused
    systemd
    iproute2
    dbus
  ];

  home.file.".config/eww/eww.yuck".text = ''
    ;; Variables and Polls
    (defpoll time :interval "1s" "${pkgs.coreutils}/bin/date +'%A, %Y-%m-%d %H:%M:%S'")
    (defpoll weather :interval "3600s" "${pkgs.wttrbar}/bin/wttrbar --main-indicator=FeelsLikeC --date-format=%d.%m.%Y --location=Helsinki | ${pkgs.jq}/bin/jq .FeelsLikeC")
    (defpoll cpu-usage :interval "2s" "${pkgs.procps}/bin/top -bn1 | ${pkgs.gnugrep}/bin/grep '^%Cpu' | ${pkgs.gawk}/bin/awk '{print 100 - \$8}'")
    (defpoll memory :interval "2s" "${pkgs.procps}/bin/free -h | ${pkgs.gnugrep}/bin/grep '^Mem:' | ${pkgs.gawk}/bin/awk '{print \$3 \"/\" \$2}'")
    (defpoll load :interval "2s" "${pkgs.coreutils}/bin/cat /proc/loadavg | ${pkgs.gawk}/bin/awk '{print \$1}'")
    (defpoll temperature :interval "5s" "${pkgs.lm_sensors}/bin/sensors | ${pkgs.gnugrep}/bin/grep 'Tctl:' | ${pkgs.gawk}/bin/awk '{print \$2}' | ${pkgs.gnused}/bin/sed 's/+//'")
    (defpoll volume :interval "2s" "${pkgs.pulseaudio}/bin/pactl get-sink-volume @DEFAULT_SINK@ | ${pkgs.gawk}/bin/awk '{print \$5}' | ${pkgs.gnused}/bin/sed 's/%//'")
    (defpoll mute :interval "2s" "${pkgs.pulseaudio}/bin/pactl get-sink-mute @DEFAULT_SINK@ | ${pkgs.gnugrep}/bin/grep -q 'Mute: yes' && echo 'true' || echo 'false'")
    (defpoll backlight :interval "2s" "${pkgs.brightnessctl}/bin/brightnessctl g")
    (defpoll battery :interval "10s" "${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/capacity 2>/dev/null || echo '0'")
    (defpoll battery-status :interval "10s" "${pkgs.coreutils}/bin/cat /sys/class/power_supply/BAT0/status 2>/dev/null || echo 'Unknown'")
    (defpoll failed-units :interval "30s" "${pkgs.systemd}/bin/systemctl --failed --no-legend | ${pkgs.coreutils}/bin/wc -l")
    (defpoll processes :interval "10s" "${pkgs.procps}/bin/ps -e --no-headers | ${pkgs.coreutils}/bin/wc -l")
    (defpoll sockets :interval "10s" "${pkgs.iproute2}/bin/ss -tuln | ${pkgs.coreutils}/bin/tail -n +2 | ${pkgs.coreutils}/bin/wc -l")
    (defpoll keyboard-layout :interval "5s" "${pkgs.hyprland}/bin/hyprctl getoption general:kb_layout -j | ${pkgs.jq}/bin/jq -r .str")

    ;; Hyprland workspace tracking
    (defpoll workspaces :interval "1s" "${pkgs.hyprland}/bin/hyprctl workspaces -j")
    (defpoll active-workspace :interval "1s" "${pkgs.hyprland}/bin/hyprctl activeworkspace -j | ${pkgs.jq}/bin/jq -r .id")
    (defpoll current-window :interval "1s" "${pkgs.hyprland}/bin/hyprctl activewindow -j | ${pkgs.jq}/bin/jq -r .title")

    ;; Widgets
    (defwidget bar []
      (box :orientation "h" :class "bar" :space-evenly false
        (box :class "left" :halign "start" :spacing 8
          ;; Start menu with eventbox for hover
          (eventbox :onhover "${pkgs.pulseaudio}/bin/paplay ${config.home.homeDirectory}/.config/eww/beep.ogg &"
            (button :class "startmenu" :onclick "${pkgs.walker}/bin/walker" ""))
          (box :class "workspaces" :spacing 4
            (for ws in workspaces
              (button :onclick "${pkgs.hyprland}/bin/hyprctl dispatch workspace ''${ws.id}"
                      :class { ws.id == active-workspace ? "active" : "" }
                "''${ws.name}")))
          (label :class "clock" :text time)
          (label :class "timer" :text (timer-widget)))

        (box :class "center" :halign "center"
          (label :text {current-window ? current-window : "No Windows"}))

        (box :class "right" :halign "end" :spacing 8
          (label :class "cpu" :text " {cpu-usage}%")
          (label :class "memory" :text " {memory}")
          (label :class "temperature" :text " {temperature}")
          ;; Pulseaudio with eventbox for hover
          (eventbox :onhover "${pkgs.pulseaudio}/bin/paplay ${config.home.homeDirectory}/.config/eww/beep.ogg &" :onclick "${pkgs.lxqt.pavucontrol-qt}/bin/pavucontrol-qt"
            (label :class "pulseaudio" :text {mute ? "" : ""} " {volume}%"))
          (label :class "battery" :text {battery-status == "Charging" ? "󰂄" : "󰁹"} " {battery}%")
          ;; Bluetooth with eventbox for hover
          (eventbox :onhover "${pkgs.pulseaudio}/bin/paplay ${config.home.homeDirectory}/.config/eww/beep.ogg &" :onclick "${pkgs.bluetui}/bin/bluetui"
            (button :class "bluetooth" ""))
          ;; Exit with eventbox for hover
          (eventbox :onhover "${pkgs.pulseaudio}/bin/paplay ${config.home.homeDirectory}/.config/eww/beep.ogg &" :onclick "${pkgs.wlogout}/bin/wlogout"
            (button :class "exit" ""))))

    ;; Timer logic
    (defpoll timer-display :interval "1s" "${timerScript}/bin/timer.sh")

    (defwidget timer-widget []
      (label :text timer-display))

    ;; Window
    (defwindow bar
      :monitor 0
      :geometry (geometry :x "0%" :y "0%" :width "100%" :height "40px")
      :stacking "fg"
      :windowtype "dock"
      :reserve (struts :distance "40px" :side "top")
      (bar))
  '';

  home.file.".config/eww/eww.css".text = ''
    * {
      font-family: "JetBrainsMono Nerd Font", monospace;
      font-size: 14px;
      color: #ff9999;
      background-color: transparent;
    }

    .bar {
      background-color: #1a0000;
      border-bottom: 1px solid #ff4d4d;
      padding: 0 16px;
      min-height: 40px;
    }

    .left, .center, .right {
      padding: 8px 0;
    }

    button, label {
      padding: 4px 12px;
      border-radius: 4px;
      background-color: transparent;
    }

    button:hover, eventbox:hover > * {
      background-color: rgba(255, 77, 77, 0.2);
    }

    .active {
      background-color: rgba(255, 77, 77, 0.3);
      box-shadow: 0 0 8px rgba(255, 77, 77, 0.5);
    }

    .cpu, .memory, .temperature, .pulseaudio, .battery {
      padding: 4px 8px;
    }

    .exit {
      background-color: rgba(255, 77, 77, 0.3);
      margin-left: 8px;
    }

    .exit:hover {
      background-color: rgba(255, 77, 77, 0.5);
    }

    .bluetooth {
      background-color: rgba(77, 77, 255, 0.2);
    }

    .bluetooth:hover {
      background-color: rgba(77, 77, 255, 0.4);
    }
  '';

  # Ensure EWW starts with Hyprland
  wayland.windowManager.hyprland.settings.exec-once = [
    "${pkgs.eww}/bin/eww daemon"
    "sleep 1 && ${pkgs.eww}/bin/eww open bar"
  ];
}