3 [Read here.](https://github.com/lcpz/lain/wiki/Widgets#usage)
10 local mympd = lain.widget.mpd()
13 Now playing songs are notified like this:
15 +--------------------------------------------------------+
17 | |/^\_/^\| Now playing |
18 | |\ O O /| Cannibal Corpse (Hammer Smashed Face) - 1993 |
19 | | '.o.' | Hammer Smashed Face (Radio Disney Version) |
21 +--------------------------------------------------------+
23 **Note:** if MPD is turned off or not set correctly, the widget will constantly display "N/A" values.
27 Variable | Meaning | Type | Default
29 `timeout` | Refresh timeout (in seconds) | integer | 2
30 `password` | MPD password | string | ""
31 `host` | MPD server | string | "127.0.0.1"
32 `port` | MPD port | string | "6600"
33 `music_dir` | Music directory | string | "~/Music"
34 `cover_size` | Album art notification size (both height and width) | integer | 100
35 `cover_pattern` | Pattern for the album art file | string | `*.(jpg\|jpeg\|png\|gif)$`
36 `default_art` | Default art | string | `nil`
37 `notify` | Show notification popups | string | "on"
38 `followtag` | Notification behaviour | boolean | false
39 `settings` | User settings | function | empty function
41 \* In Lua, "\\\\" means "\" escaped.
43 Default `cover_pattern` definition will made the widget set the first jpg, jpeg, png or gif file found in the directory as the album art.
45 Pay attention to case sensitivity when defining `music_dir`.
47 `settings` can use `mpd_now` table, which contains the following values:
49 (**note:** the first four are boolean [flags](https://github.com/lcpz/lain/pull/205), the remaining are all strings)
55 - pls_pos (playlist position)
56 - pls_len (playlist length)
57 - state (possible values: "play", "pause", "stop")
66 - [time](https://github.com/lcpz/lain/pull/90) (length of current song, in seconds)
67 - [elapsed](https://github.com/lcpz/lain/pull/90) (elapsed time of current song, in seconds)
69 and can modify `mpd_notification_preset` table, which will be the preset for the naughty notifications. Check [here](https://awesomewm.org/doc/api/libraries/naughty.html#notify) for the list of variables it can contain. Default definition:
72 mpd_notification_preset = {
73 title = "Now playing",
75 text = string.format("%s (%s) - %s\n%s", mpd_now.artist,
76 mpd_now.album, mpd_now.date, mpd_now.title)
80 With multiple screens, the default behaviour is to show a visual notification pop-up window on the first screen. By setting `followtag` to `true` it will be shown on the currently focused tag screen.
84 Variable | Meaning | Type
86 `widget` | The textbox | `wibox.widget.textbox`
87 `update` | Update `widget` | function
88 `timer` | The widget timer | [`gears.timer`](https://awesomewm.org/doc/api/classes/gears.timer.html)
90 The `update` function can be used to refresh the widget before `timeout` expires.
92 You can use `timer` to start/stop the widget as you like.
96 You can control the widget with keybindings like these:
100 awful.key({ altkey, "Control" }, "Up",
102 awful.spawn.with_shell("mpc toggle || ncmpc toggle || pms toggle")
105 awful.key({ altkey, "Control" }, "Down",
107 awful.spawn.with_shell("mpc stop || ncmpc stop || pms stop")
110 awful.key({ altkey, "Control" }, "Left",
112 awful.spawn.with_shell("mpc prev || ncmpc prev || pms prev")
115 awful.key({ altkey, "Control" }, "Right",
117 awful.spawn.with_shell("mpc next || ncmpc next || pms next")
122 where `altkey = "Mod1"`.
124 If you don't use the widget for long periods and wish to spare CPU, you can toggle it with a keybinding like this:
127 -- disable MPD widget
128 awful.key({ altkey }, "0",
131 text = "MPD widget ",
132 position = "top_middle",
135 if mympd.timer.started then
137 common.text = common.text .. markup.bold("OFF")
140 common.text = common.text .. markup.bold("ON")
142 naughty.notify(common)
148 ### Cover not showing in notifications
150 If the cover file is existent but not showed in notifications, [try](https://github.com/lcpz/lain/issues/393) setting `music_dir` to a symlink of your music folder, rather than to a physical path. This can be easily done through
152 ln -s /the/real_path_to_your_music/ /home/username/Music
154 However, this only applies if the music is stored outside your user-specific folder, for instance in an external partition.
156 ### Always use `set_markup`
158 In `settings`, if you use `widget:set_text`, [it will ignore Pango markup](https://github.com/lcpz/lain/issues/258), so be sure to always use `widget:set_markup`.
160 ### Volume fade in toggling MPD
162 If you want a fade in/out in toggling MPD, you can put [this script](https://gist.github.com/lcpz/76e315bc27c6cdf7edd5021964b88df1) in your local `bin` directory:
165 $ curl https://gist.githubusercontent.com/lcpz/76e315bc27c6cdf7edd5021964b88df1/raw/97f7ba586418a4e07637cfbc91d2974278dfa623/mpd-fade -o ~/bin/mpc-fade
166 $ chmod +x ~/bin/mpc-fade
169 Set your 1% decrease/increase commands [here](https://gist.github.com/lcpz/76e315bc27c6cdf7edd5021964b88df1#file-mpd-fade-L8-L9), then use a keybinding like this:
172 -- MPD toggle with volume fading
173 awful.key({ "Shift" }, "Pause",
175 awful.spawn.easy_async("mpc-fade 20 4", -- mpc-fade <percentage> <length in secs>
176 function(stdout, stderr, reason, exit_code)