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.

142 lines
5.3 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
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,args.vertical)
  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(t.icon({
  47. image = beautiful["mpc-previous-symbolic"],
  48. }),{
  49. id = "prev"
  50. }),
  51. t.button(t.icon({
  52. image = beautiful["mpc-play-symbolic"],
  53. id = "statusicon"
  54. }),{
  55. id = "play"
  56. }),
  57. t.button(t.icon({
  58. image = beautiful["mpc-next-symbolic"],
  59. }),{
  60. id = "next"
  61. }),
  62. spacing = style.base.spacing,
  63. layout = wibox.layout.fixed.horizontal
  64. }),
  65. spacing = style.base.spacing,
  66. layout = wibox.layout.fixed.horizontal
  67. })
  68. local display = widget:get_children_by_id("display")[1]
  69. local bprev = widget:get_children_by_id("prev")[1]
  70. bprev:connect_signal("button::press",style.button.onpress)
  71. bprev:connect_signal("button::release",style.button.onrelease)
  72. local function prev()
  73. awful.spawn("mpc cdprev")
  74. end
  75. bprev:connect_signal("button::press",prev)
  76. local pause_state = true
  77. local icon = widget:get_children_by_id("statusicon")[1]
  78. local bplay = widget:get_children_by_id("play")[1]
  79. bplay:connect_signal("button::press",style.button.onpress)
  80. bplay:connect_signal("button::release",style.button.onrelease)
  81. local function play()
  82. pause_state = (not pause_state)
  83. if pause_state == false then
  84. icon.image = beautiful["mpc-pause-symbolic"]
  85. awful.spawn("mpc pause")
  86. else
  87. icon.image = beautiful["mpc-play-symbolic"]
  88. awful.spawn("mpc play")
  89. end
  90. end
  91. bplay:connect_signal("button::press",play)
  92. local bnext = widget:get_children_by_id("next")[1]
  93. bnext:connect_signal("button::press",style.button.onpress)
  94. bnext:connect_signal("button::release",style.button.onrelease)
  95. local function nextb()
  96. awful.spawn("mpc next")
  97. end
  98. bnext:connect_signal("button::press",nextb)
  99. local update_ready = true
  100. local function update_mpd_status()
  101. awful.spawn.easy_async("mpc",function(out)
  102. local status = ""
  103. if not out:match("playing") then
  104. if not out:match("paused") then
  105. state = true
  106. icon.image = beautiful["mpc-play-symbolic"]
  107. display:set_markup(status)
  108. update_ready = true
  109. return
  110. else
  111. status = status.."[PAUSED] "
  112. end
  113. end
  114. status = status..out:match("#%d*").." "..
  115. out:match("[^\n]*").." "..
  116. out:match("%d*:%d*/%d*:%d*%s*%(%d*%%%)")
  117. display:set_markup(status)
  118. update_ready = true
  119. end)
  120. end
  121. update_mpd_status()
  122. gears.timer {
  123. timeout = args.polling_delay or 1,
  124. autostart = true,
  125. callback = function()
  126. if not update_ready then return end
  127. update_ready = false
  128. update_mpd_status()
  129. end
  130. }
  131. root.keys(gears.table.join(
  132. root.keys(),
  133. ask.k(":mpc.prev",prev,
  134. {description = "switch to previous MPD track",group="widgets"}),
  135. ask.k(":mpc.play",play,
  136. {description = "play/pause MPD",group="widgets"}),
  137. ask.k(":mpc.next",nextb,
  138. {description = "switch to next MPD track",group="widgets"})
  139. ))
  140. return widget
  141. end