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.

118 lines
4.2 KiB

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