My configuration files for Debian/Ubuntu applications
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

mpd.md 6.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. ## Usage
  2. [Read here.](https://github.com/lcpz/lain/wiki/Widgets#usage)
  3. ### Description
  4. Shows MPD status.
  5. ```lua
  6. local mympd = lain.widget.mpd()
  7. ```
  8. Now playing songs are notified like this:
  9. +--------------------------------------------------------+
  10. | +-------+ |
  11. | |/^\_/^\| Now playing |
  12. | |\ O O /| Cannibal Corpse (Hammer Smashed Face) - 1993 |
  13. | | '.o.' | Hammer Smashed Face (Radio Disney Version) |
  14. | +-------+ |
  15. +--------------------------------------------------------+
  16. **Note:** if MPD is turned off or not set correctly, the widget will constantly display "N/A" values.
  17. ## Input table
  18. Variable | Meaning | Type | Default
  19. --- | --- | --- | ---
  20. `timeout` | Refresh timeout (in seconds) | integer | 2
  21. `password` | MPD password | string | ""
  22. `host` | MPD server | string | "127.0.0.1"
  23. `port` | MPD port | string | "6600"
  24. `music_dir` | Music directory | string | "~/Music"
  25. `cover_size` | Album art notification size (both height and width) | integer | 100
  26. `cover_pattern` | Pattern for the album art file | string | `*.(jpg\|jpeg\|png\|gif)$`
  27. `default_art` | Default art | string | `nil`
  28. `notify` | Show notification pop-ups | string | "on"
  29. `followtag` | Notification behaviour | boolean | false
  30. `settings` | User settings | function | empty function
  31. `widget` | Widget to render | function | `wibox.widget.textbox`
  32. \* In Lua, "\\\\" means "\" escaped.
  33. The default `cover_pattern` definition will make the widget set the first JPG, JPEG, PNG or GIF file found in the directory as the album art.
  34. Pay attention to case sensitivity when defining `music_dir`.
  35. `settings` can use `mpd_now` table, which contains the following values:
  36. (**note:** the first four are boolean [flags](https://github.com/lcpz/lain/pull/205), the remaining are all strings)
  37. - random_mode
  38. - single_mode
  39. - repeat_mode
  40. - consume_mode
  41. - pls_pos (playlist position)
  42. - pls_len (playlist length)
  43. - state (possible values: "play", "pause", "stop")
  44. - file
  45. - artist
  46. - title
  47. - name
  48. - album
  49. - track
  50. - genre
  51. - date
  52. - [time](https://github.com/lcpz/lain/pull/90) (length of current song, in seconds)
  53. - [elapsed](https://github.com/lcpz/lain/pull/90) (elapsed time of current song, in seconds)
  54. - volume
  55. 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:
  56. ```lua
  57. mpd_notification_preset = {
  58. title = "Now playing",
  59. timeout = 6,
  60. text = string.format("%s (%s) - %s\n%s", mpd_now.artist,
  61. mpd_now.album, mpd_now.date, mpd_now.title)
  62. }
  63. ```
  64. 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.
  65. ## Output table
  66. Variable | Meaning | Type
  67. --- | --- | ---
  68. `widget` | The textbox | `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. The `update` function can be used to refresh the widget before `timeout` expires.
  72. You can use `timer` to start/stop the widget as you like.
  73. ## Key bindings
  74. You can control the widget with key bindings like these:
  75. ```lua
  76. -- MPD control
  77. awful.key({ altkey, "Control" }, "Up",
  78. function ()
  79. awful.spawn.with_shell("mpc toggle || ncmpc toggle || pms toggle")
  80. mympd.update()
  81. end),
  82. awful.key({ altkey, "Control" }, "Down",
  83. function ()
  84. awful.spawn.with_shell("mpc stop || ncmpc stop || pms stop")
  85. mympd.update()
  86. end),
  87. awful.key({ altkey, "Control" }, "Left",
  88. function ()
  89. awful.spawn.with_shell("mpc prev || ncmpc prev || pms prev")
  90. mympd.update()
  91. end),
  92. awful.key({ altkey, "Control" }, "Right",
  93. function ()
  94. awful.spawn.with_shell("mpc next || ncmpc next || pms next")
  95. mympd.update()
  96. end),
  97. ```
  98. Where `altkey = "Mod1"`.
  99. If you don't use the widget for long periods and wish to spare CPU, you can toggle it with a key binding like this:
  100. ```lua
  101. -- disable MPD widget
  102. awful.key({ altkey }, "0",
  103. function ()
  104. local common = {
  105. text = "MPD widget ",
  106. position = "top_middle",
  107. timeout = 2
  108. }
  109. if mympd.timer.started then
  110. mympd.timer:stop()
  111. common.text = common.text .. markup.bold("OFF")
  112. else
  113. mympd.timer:start()
  114. common.text = common.text .. markup.bold("ON")
  115. end
  116. naughty.notify(common)
  117. end),
  118. ```
  119. ## Notes
  120. ### Cover not showing in notifications
  121. 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
  122. ```shell
  123. ln -s /the/real_path_to_your_music/ /home/username/Music
  124. ```
  125. However, this only applies if the music is stored outside your user-specific folder, for instance in an external partition.
  126. ### Always use `set_markup`
  127. 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`.
  128. ### Volume fade in toggling MPD
  129. 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:
  130. ```shell
  131. $ curl https://gist.githubusercontent.com/lcpz/76e315bc27c6cdf7edd5021964b88df1/raw/97f7ba586418a4e07637cfbc91d2974278dfa623/mpd-fade -o ~/bin/mpc-fade
  132. $ chmod +x ~/bin/mpc-fade
  133. ```
  134. Set your 1% decrease/increase commands [here](https://gist.github.com/lcpz/76e315bc27c6cdf7edd5021964b88df1#file-mpd-fade-L8-L9), then use a key binding like this:
  135. ```lua
  136. -- MPD toggle with volume fading
  137. awful.key({ "Shift" }, "Pause",
  138. function()
  139. awful.spawn.easy_async("mpc-fade 20 4", -- mpc-fade <percentage> <length in secs>
  140. function(stdout, stderr, reason, exit_code)
  141. mympd.update()
  142. end)
  143. end),
  144. ```