aboutsummaryrefslogtreecommitdiff
path: root/home/eww.nix
blob: eec241742732a7448e0d13cd920718c963f06d6a (plain)
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
{ config, lib, pkgs, ... }:

{
  home.packages = with pkgs; [
    eww

    (writeShellScriptBin "eww-toggle"''
      #!/usr/bin/env bash

      if ${pkgs.eww}/bin/eww active-windows | grep $1; then
          ${pkgs.eww}/bin/eww close $1
      else
          ${pkgs.eww}/bin/eww open $@
      fi
    '')

    (writeShellScriptBin "get-album-art"''
        #!/usr/bin/env bash

        OUTFILE=".mpris-art"

        while read -r line; do
            if [[ -n $line ]]; then
                rm -f ~/$OUTFILE

                cmus_path=$(cmus-remote -Q | grep file | cut -c 6-)
                if [[ -n $cmus_path ]]; then
                    if [[ -f $(dirname "$cmus_path")/cover.jpg ]]; then
                        cp "$(dirname "$cmus_path")/cover.jpg" ~/$OUTFILE
                    else
                        ffmpeg -y -v quiet -i "$cmus_path" -c:v copy -f mjpeg ~/$OUTFILE
                    fi
                else
                    mpris=$(playerctl --player=cmus,firefox,%any metadata mpris:artUrl)

                    if [[ $mpris == data:image* ]]; then
                        echo $mpris | sed s/.*,//g | base64 --decode > ~/$OUTFILE
                    elif [[ -n $mpris ]]; then
                        curl -s -o ~/$OUTFILE $mpris
                    fi
                fi

                if [[ -f ~/$OUTFILE ]]; then
                    :
                else
                    cp ${../assets/album_art_placeholder.png} ~/$OUTFILE
                fi

                echo ~/$OUTFILE
            fi
        done
    '')
  ];

  xdg.configFile."eww/colors.css".text = let c = config.theme.colors; in ''
    @define-color accent #${c.accent};

    @define-color black   #${c.black};
    @define-color red     #${c.red};
    @define-color green   #${c.green};
    @define-color yellow  #${c.yellow};
    @define-color blue    #${c.blue};
    @define-color magenta #${c.magenta};
    @define-color cyan    #${c.cyan};
    @define-color white   #${c.white};

    @define-color brightBlack   #${c.brightBlack};
    @define-color brightRed     #${c.brightRed};
    @define-color brightGreen   #${c.brightGreen};
    @define-color brightYellow  #${c.brightYellow};
    @define-color brightBlue    #${c.brightBlue};
    @define-color brightMagenta #${c.brightMagenta};
    @define-color brightCyan    #${c.brightCyan};
    @define-color brightWhite   #${c.brightWhite};

    @define-color bg  #${c.bg};
    @define-color bg0 #${c.bg0};
    @define-color bg1 #${c.bg1};
    @define-color bg2 #${c.bg2};
    @define-color bg3 #${c.bg3};
    @define-color bg4 #${c.bg4};

    @define-color fg  #${c.fg};
    @define-color fg0 #${c.fg0};
    @define-color fg1 #${c.fg1};
    @define-color fg2 #${c.fg2};
    @define-color fg3 #${c.fg3};
    @define-color fg4 #${c.fg4};

    @define-color orange #${c.orange};
    @define-color brightOrange #${c.brightOrange};
  '';

  xdg.configFile."eww/eww.css".text = ''
    @import "colors.css";

    window {
        color: @fg;
        background-color: @bg;
        border: 2px solid @bg1;
        font-family: monospace, sans-serif;
    }

    .main {
        margin: 8px;
    }

    .left {
        margin-top: 8px;
    }

    .song-title {
        font-size: 17px;
        font-weight: bold;
    }

    .song-album {
        color: @fg2;
    }

    .song-artist {
        color: @fg2;
    }

    .control {
        font-size: 24;
    }

    button {
        color: @fg;
        background: @bg;

        border: none;
        border-radius: 0;
        box-shadow: none;
        text-shadow: none;
    }

    button:hover {
        background: @bg1;
    }

    button:active {
        background: @bg2;
    }
  '';

  xdg.configFile."eww/eww.yuck".text = ''
    (defwindow music [pos gaps]
        :monitor "<primary>"
        :geometry (geometry
            :x {
                pos == "right"
                    ? gaps == "true"
                        ? "-8px" : "2px"
                    : "0px"
            }
            :y { gaps == "true" ? "-8px" : "2px" }
            :height {128 + 16}
            :anchor { pos == "right" ? "bottom right" : "bottom center" }
        )
        :stacking "fg"
        :windowtype "dock"
        :wm-ignore true

        (box :class "main"
            :orientation "h"
            :spacing 8
            :space-evenly false
            :height {128 + 16}

            (image
                :path song-cover
                :image-width 128
                :image-height 128
            )

            (box :class "left"
                :orientation "v"
                :spacing 0
                :space-evenly true
                :hexpand true

                (box :class "info"
                    :orientation "v"
                    :space-evenly false
                    :valign "center"

                    (label :class "song-title"
                        :text {song.title}
                        :halign "start"
                    )
                    (label :class "song-album"
                        :text {song.album}
                        :halign "start"
                    )
                    (label :class "song-artist"
                        :text {song.artist}
                        :halign "start"
                    )
                )

                (box :class "control"
                    :space-evenly false
                    :halign "center"
                    :valign "end"

                    (button
                        :onclick `playerctl --player=cmus,firefox,%any previous`
                        "󰒮"
                    )
                    (button
                        :onclick `playerctl --player=cmus,firefox,%any play-pause`
                        { song.status == "Playing" ? "󰏤" : "󰐊" }
                    )
                    (button
                        :onclick `playerctl --player=cmus,firefox,%any next`
                        "󰒭"
                    )

                    ; Offset controls to center of screen
                    (box :width {128 + 8})
                )
            )
        )
    )

    (deflisten song-cover
        `playerctl --player=cmus,firefox,%any -F metadata title | get-album-art`
    )

    (deflisten song
        `playerctl --player=cmus,firefox,%any -F metadata --format='{"title": "{{title}}", "album": "{{album}}", "artist": "{{artist}}", "status": "{{status}}"}'`
    )
  '';
}