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.

137 lines
5.3 KiB

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. -- JSON layout builder
  9. local json = require("dkjson")
  10. local gears = require("gears")
  11. local wibox = require("wibox")
  12. local awful = require("awful")
  13. local builtins = {
  14. h_spacer = function(o)
  15. return {
  16. forced_width = o.size or 3,
  17. widget = wibox.container.background
  18. }
  19. end,
  20. v_spacer = function(o)
  21. return {
  22. forced_height = o.size or 3,
  23. widget = wibox.container.background
  24. }
  25. end
  26. -- Insert your other builtins here
  27. }
  28. -- Load a bunch of builtins from awful.titlebar
  29. for _,name in pairs({
  30. "titlewidget","iconwidget","floatingbutton",
  31. "maximizedbutton","minimizebutton","closebutton",
  32. "ontopbutton","stickybutton"
  33. }) do
  34. builtins[name] = function(o)
  35. o.widget = awful.titlebar.widget[name](o.client)
  36. return o
  37. end
  38. end
  39. return function(description,opts)
  40. local style = opts.style or {}
  41. local c = opts.client
  42. local s = opts.screen
  43. local buttons = opts.buttons
  44. -- Build a layout given a JSON description, a style and client
  45. -- (if applicable)
  46. local test,err = json.decode(description)
  47. if not test then
  48. error("Builder failure: "..err)
  49. end
  50. local function inner_builder(struct,vertical)
  51. if struct.widget then -- External widget descriptions
  52. local args = gears.table.join({
  53. layout = (struct.layout and inner_builder(struct.layout)), client = (struct.client and c),
  54. screen = (struct.screen and s),
  55. vertical = (function()
  56. if type(struct.vertical) ~= "nil" then
  57. return struct.vertical
  58. end
  59. return vertical
  60. end)()
  61. },struct.options or {},opts.passthrough or {})
  62. return require(struct.widget)(args)
  63. elseif struct.list then -- List descriptions
  64. local list = {
  65. layout = wibox.layout.fixed[(
  66. (struct.vertical and "vertical") or
  67. "horizontal"
  68. )],
  69. spacing = style.spacing
  70. }
  71. for _,v in pairs(struct.list) do
  72. if v.draggable then
  73. list.buttons = buttons
  74. else
  75. local new_obj = inner_builder(v,struct.vertical)
  76. if new_obj then
  77. table.insert(list,new_obj)
  78. end
  79. end
  80. end
  81. return list
  82. elseif struct.align then -- Align structure descriptions
  83. local orient = (
  84. (struct.vertical and "vertical") or
  85. "horizontal"
  86. )
  87. local list = {
  88. {
  89. layout = wibox.layout.fixed[orient],
  90. spacing = style.spacing
  91. },{
  92. layout = wibox.layout.flex[orient],
  93. spacing = style.spacing
  94. },{
  95. -- Simulating "spacing" parameter
  96. widget = builtins[(struct.vertical and "v_spacer") or
  97. "h_spacer"]({size = style.spacing}),
  98. layout = wibox.layout.fixed[orient],
  99. spacing = style.spacing
  100. },
  101. layout = wibox.layout.align[orient]
  102. }
  103. for k,v in pairs({"left","center","right"}) do
  104. for _,obj in pairs(struct.align[v]) do
  105. if obj.draggable then
  106. list[k].buttons = buttons
  107. else
  108. local new_obj = inner_builder(obj,struct.vertical)
  109. if new_obj then
  110. table.insert(list[k],new_obj)
  111. end
  112. end
  113. end
  114. end
  115. -- Part of simulating "spacing" parameter
  116. table.insert(list[1],builtins[(struct.vertical and "v_spacer") or
  117. "h_spacer"]({size = style.spacing}))
  118. return list
  119. elseif struct.builtin then -- Builtin widget descriptions
  120. if not builtins[struct.builtin] then
  121. error("Builtin not defined: "..struct.builtin)
  122. end
  123. return builtins[struct.builtin](gears.table.join({
  124. client = (struct.client and c)
  125. },struct.options or {}))
  126. end
  127. -- If this gets interpreted it's safe to say none of the constructions
  128. -- above got matched.
  129. print("Object where the error occured: ")
  130. gears.debug.dump(struct)
  131. error("Builder error: invalid object description")
  132. end
  133. return inner_builder(test),test.context_options
  134. end