My configuration files for Debian/Ubuntu applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

moc.md 3.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ## Usage
  2. [Read here.](https://github.com/lcpz/lain/wiki/Widgets#usage)
  3. ### Description
  4. A widget for showing the current song track's information from MOC (Music On Console).
  5. ```lua
  6. local mymoc = lain.widget.contrib.moc()
  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. ## Input table
  17. Variable | Meaning | Type | Default
  18. --- | --- | --- | ---
  19. `timeout` | Refresh timeout (in seconds) | integer | 1
  20. `music_dir` | Music directory | string | "~/Music"
  21. `cover_size` | Album art notification size (both height and width) | integer | 100
  22. `cover_pattern` | Pattern for the album art file | string | `*\\.(jpg|jpeg|png|gif)`*
  23. `default_art` | Default art | string | ""
  24. `followtag` | Display the notification on currently focused screen | boolean | false
  25. `settings` | User settings | function | empty function
  26. `widget` | Widget to render | function | `wibox.widget.textbox`
  27. \* In Lua, "\\\\" means "\" escaped.
  28. 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.
  29. Pay attention to case sensitivity when defining `music_dir`.
  30. `settings` can use `moc_now` table, which contains the following string values:
  31. - state (possible values: "PLAY", "PAUSE", "STOP")
  32. - file
  33. - artist
  34. - title
  35. - album
  36. - elapsed (Time elapsed for the current track)
  37. - total (The current track's total time)
  38. 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:
  39. ```lua
  40. moc_notification_preset = {
  41. title = "Now playing",
  42. timeout = 6,
  43. text = string.format("%s (%s) - %s\n%s", moc_now.artist,
  44. moc_now.album, moc_now.elapsed, moc_now.title)
  45. }
  46. ```
  47. 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.
  48. ## Output table
  49. Variable | Meaning | Type
  50. --- | --- | ---
  51. `widget` | The widget | `wibox.widget.textbox`
  52. `update` | Update `widget` | function
  53. `timer` | The widget timer | [`gears.timer`](https://awesomewm.org/doc/api/classes/gears.timer.html)
  54. The `update` function can be used to refresh the widget before `timeout` expires.
  55. You can use `timer` to start/stop the widget as you like.
  56. ## Keybindings
  57. You can control the widget with key bindings like these:
  58. ```lua
  59. -- MOC control
  60. awful.key({ altkey, "Control" }, "Up",
  61. function ()
  62. os.execute("mocp -G") -- toggle
  63. moc.update()
  64. end),
  65. awful.key({ altkey, "Control" }, "Down",
  66. function ()
  67. os.execute("mocp -s") -- stop
  68. moc.update()
  69. end),
  70. awful.key({ altkey, "Control" }, "Left",
  71. function ()
  72. os.execute("mocp -r") -- previous
  73. moc.update()
  74. end),
  75. awful.key({ altkey, "Control" }, "Right",
  76. function ()
  77. os.execute("mocp -f") -- next
  78. moc.update()
  79. end),
  80. ```
  81. where `altkey = "Mod1"`.
  82. If you don't use the widget for long periods and wish to spare CPU, you can toggle it with a keybinding like this:
  83. ```lua
  84. -- toggle MOC widget
  85. awful.key({ altkey }, "0",
  86. function ()
  87. local common = { text = "MOC widget ", position = "top_middle", timeout = 2 }
  88. if moc.timer.started then
  89. moc.timer:stop()
  90. common.text = common.text .. markup.bold("OFF")
  91. else
  92. moc.timer:start()
  93. common.text = common.text .. markup.bold("ON")
  94. end
  95. naughty.notify(common)
  96. end),
  97. ```