massive update, probably broken
[dotfiles/.git] / .config / awesome / lain / wiki / moc.md
1 ## Usage
2
3 [Read here.](https://github.com/lcpz/lain/wiki/Widgets#usage)
4
5 ### Description
6
7 A widget for showing the current song track's information from MOC (Music On Console).
8
9 ```lua
10 local mymoc = lain.widget.contrib.moc()
11 ```
12
13 Now playing songs are notified like this:
14
15         +--------------------------------------------------------+
16         | +-------+                                              |
17         | |/^\_/^\| Now playing                                  |
18     | |\ O O /| Cannibal Corpse (Hammer Smashed Face) - 1993 |
19     | | '.o.' | Hammer Smashed Face (Radio Disney Version)   |
20         | +-------+                                              |
21         +--------------------------------------------------------+
22
23 ## Input table
24
25 Variable | Meaning | Type | Default
26 --- | --- | --- | ---
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
34
35 \* In Lua, "\\\\" means "\" escaped.
36
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.
38
39 Pay attention to case sensitivity when defining `music_dir`.
40
41 `settings` can use `moc_now` table, which contains the following string values:
42
43 - state (possible values: "PLAY", "PAUSE", "STOP")
44 - file
45 - artist
46 - title
47 - album
48 - elapsed (Time elapsed for the current track)
49 - total (The current track's total time)
50
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:
52
53 ```lua
54 moc_notification_preset = {
55     title   = "Now playing",
56     timeout = 6,
57     text    = string.format("%s (%s) - %s\n%s", moc_now.artist,
58               moc_now.album, moc_now.elapsed, moc_now.title)
59 }
60 ```
61
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.
63
64 ## Output table
65
66 Variable | Meaning | Type
67 --- | --- | ---
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)
71
72 The `update` function can be used to refresh the widget before `timeout` expires.
73
74 You can use `timer` to start/stop the widget as you like.
75
76 ## Keybindings
77
78 You can control the widget with key bindings like these:
79
80 ```lua
81 -- MOC control
82 awful.key({ altkey, "Control" }, "Up",
83         function ()
84                 os.execute("mocp -G") -- toggle
85                 moc.update()
86         end),
87 awful.key({ altkey, "Control" }, "Down",
88         function ()
89                 os.execute("mocp -s") -- stop
90                 moc.update()
91         end),
92 awful.key({ altkey, "Control" }, "Left",
93         function ()
94                 os.execute("mocp -r") -- previous
95                 moc.update()
96         end),
97 awful.key({ altkey, "Control" }, "Right",
98         function ()
99                 os.execute("mocp -f") -- next
100                 moc.update()
101         end),
102 ```
103
104 where `altkey = "Mod1"`.
105
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:
107
108 ```lua
109 -- toggle MOC widget
110 awful.key({ altkey }, "0",
111         function ()
112             local common = { text = "MOC widget ", position = "top_middle", timeout = 2 }
113             if moc.timer.started then
114                 moc.timer:stop()
115                 common.text = common.text .. markup.bold("OFF")
116             else
117                 moc.timer:start()
118                 common.text = common.text .. markup.bold("ON")
119             end
120             naughty.notify(common)
121         end),
122 ```