3 [Read here.](https://github.com/lcpz/lain/wiki/Widgets#usage)
7 A widget for showing the current song track's information from MOC (Music On Console).
10 local mymoc = lain.widget.contrib.moc()
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 +--------------------------------------------------------+
25 Variable | Meaning | Type | Default
27 `timeout` | Refresh timeout (in seconds) | integer | 1
28 `music_dir` | Music directory | string | "~/Music"
29 `cover_size` | Album art notification size (both height and width) | integer | 100
30 `cover_pattern` | Pattern for the album art file | string | `*\\.(jpg|jpeg|png|gif)`*
31 `default_art` | Default art | string | ""
32 `followtag` | Display the notification on currently focused screen | boolean | false
33 `settings` | User settings | function | empty function
35 \* In Lua, "\\\\" means "\" escaped.
37 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.
39 Pay attention to case sensitivity when defining `music_dir`.
41 `settings` can use `moc_now` table, which contains the following string values:
43 - state (possible values: "PLAY", "PAUSE", "STOP")
48 - elapsed (Time elapsed for the current track)
49 - total (The current track's total time)
51 and can modify `moc_notification_preset` table, which will be the preset for the naughty notifications. Check [here](https://awesomewm.org/apidoc/libraries/naughty.html#notify) for the list of variables it can contain. Default definition:
54 moc_notification_preset = {
55 title = "Now playing",
57 text = string.format("%s (%s) - %s\n%s", moc_now.artist,
58 moc_now.album, moc_now.elapsed, moc_now.title)
62 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.
66 Variable | Meaning | Type
68 `widget` | The widget | `wibox.widget.textbox`
69 `update` | Update `widget` | function
70 `timer` | The widget timer | [`gears.timer`](https://awesomewm.org/doc/api/classes/gears.timer.html)
72 The `update` function can be used to refresh the widget before `timeout` expires.
74 You can use `timer` to start/stop the widget as you like.
78 You can control the widget with key bindings like these:
82 awful.key({ altkey, "Control" }, "Up",
84 os.execute("mocp -G") -- toggle
87 awful.key({ altkey, "Control" }, "Down",
89 os.execute("mocp -s") -- stop
92 awful.key({ altkey, "Control" }, "Left",
94 os.execute("mocp -r") -- previous
97 awful.key({ altkey, "Control" }, "Right",
99 os.execute("mocp -f") -- next
104 where `altkey = "Mod1"`.
106 If you don't use the widget for long periods and wish to spare CPU, you can toggle it with a keybinding like this:
110 awful.key({ altkey }, "0",
112 local common = { text = "MOC widget ", position = "top_middle", timeout = 2 }
113 if moc.timer.started then
115 common.text = common.text .. markup.bold("OFF")
118 common.text = common.text .. markup.bold("ON")
120 naughty.notify(common)