Reno is the second iteration of the AWMTK-powered AwesomeWM config.
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.

145 lines
5.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. -- This file is part of Reno desktop.
  2. --
  3. -- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  4. --
  5. -- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. --
  7. -- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
  8. -- Widget for interacting with mpd
  9. -- MPC IS REQUIRED
  10. local awmtk2 = require("awmtk2")
  11. local wibox = require("wibox")
  12. local gears = require("gears")
  13. local awful = require("awful")
  14. local beautiful = require("beautiful")
  15. local ask = require("asckey")
  16. return function(args)
  17. local style = awmtk2.create_style("soundclown",
  18. awmtk2.generic.oneline_widget,args.style)
  19. local templates = awmtk2.create_template_lib("soundclown",awmtk2.templates,args.templates)
  20. local t = awmtk2.build_templates(templates,style)
  21. local test = os.execute("mpc help")
  22. if type(test) == "number" then
  23. test = (test == 0)
  24. end
  25. if not test then
  26. return
  27. end
  28. local widget = wibox.widget({
  29. t.container({
  30. {
  31. t.textbox({
  32. markup = "MPC Loading..",
  33. id = "display"
  34. }),
  35. widget = wibox.container.scroll.horizontal,
  36. step_function = wibox.container.scroll.step_functions
  37. .linear_back_and_forth,
  38. speed = 50,
  39. },
  40. widget = wibox.container.constraint,
  41. height = style.base.height,
  42. width = style.base.width,
  43. strategy = "exact"
  44. }),
  45. ((not args.hide_controls) and {
  46. t.button({
  47. image = beautiful["mpc-previous-symbolic"],
  48. widget = wibox.widget.imagebox
  49. },{
  50. id = "prev"
  51. }),
  52. t.button({
  53. image = beautiful["mpc-play-symbolic"],
  54. widget = wibox.widget.imagebox,
  55. id = "statusicon"
  56. },{
  57. id = "play"
  58. }),
  59. t.button({
  60. image = beautiful["mpc-next-symbolic"],
  61. widget = wibox.widget.imagebox
  62. },{
  63. id = "next"
  64. }),
  65. spacing = style.base.spacing,
  66. layout = wibox.layout.fixed.horizontal
  67. }),
  68. spacing = style.base.spacing,
  69. layout = wibox.layout.fixed.horizontal
  70. })
  71. local display = widget:get_children_by_id("display")[1]
  72. local bprev = widget:get_children_by_id("prev")[1]
  73. bprev:connect_signal("button::press",style.button.onpress)
  74. bprev:connect_signal("button::release",style.button.onrelease)
  75. local function prev()
  76. awful.spawn("mpc cdprev")
  77. end
  78. bprev:connect_signal("button::press",prev)
  79. local pause_state = true
  80. local icon = widget:get_children_by_id("statusicon")[1]
  81. local bplay = widget:get_children_by_id("play")[1]
  82. bplay:connect_signal("button::press",style.button.onpress)
  83. bplay:connect_signal("button::release",style.button.onrelease)
  84. local function play()
  85. pause_state = (not pause_state)
  86. if pause_state == false then
  87. icon.image = beautiful["mpc-pause-symbolic"]
  88. awful.spawn("mpc pause")
  89. else
  90. icon.image = beautiful["mpc-play-symbolic"]
  91. awful.spawn("mpc play")
  92. end
  93. end
  94. bplay:connect_signal("button::press",play)
  95. local bnext = widget:get_children_by_id("next")[1]
  96. bnext:connect_signal("button::press",style.button.onpress)
  97. bnext:connect_signal("button::release",style.button.onrelease)
  98. local function nextb()
  99. awful.spawn("mpc next")
  100. end
  101. bnext:connect_signal("button::press",nextb)
  102. local update_ready = true
  103. local function update_mpd_status()
  104. awful.spawn.easy_async("mpc",function(out)
  105. local status = ""
  106. if not out:match("playing") then
  107. if not out:match("paused") then
  108. state = true
  109. icon.image = beautiful["mpc-play-symbolic"]
  110. display:set_markup(status)
  111. update_ready = true
  112. return
  113. else
  114. status = status.."[PAUSED] "
  115. end
  116. end
  117. status = status..out:match("#%d*").." "..
  118. out:match("[^\n]*").." "..
  119. out:match("%d*:%d*/%d*:%d*%s*%(%d*%%%)")
  120. display:set_markup(status)
  121. update_ready = true
  122. end)
  123. end
  124. update_mpd_status()
  125. gears.timer {
  126. timeout = args.polling_delay or 1,
  127. autostart = true,
  128. callback = function()
  129. if not update_ready then return end
  130. update_ready = false
  131. update_mpd_status()
  132. end
  133. }
  134. root.keys(gears.table.join(
  135. root.keys(),
  136. ask.k(":mpc.prev",prev,
  137. {description = "switch to previous MPD track",group="widgets"}),
  138. ask.k(":mpc.play",play,
  139. {description = "play/pause MPD",group="widgets"}),
  140. ask.k(":mpc.next",nextb,
  141. {description = "switch to next MPD track",group="widgets"})
  142. ))
  143. return widget
  144. end