dock.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. local awful = require("awful")
  2. local gears = require("gears")
  3. local beautiful = require("beautiful")
  4. local wibox = require("wibox")
  5. local naughty = require("naughty")
  6. local dpi = require("beautiful.xresources").apply_dpi
  7. local HOME = os.getenv('HOME')
  8. local ICON_DIR = HOME .. '/.config/awesome/widgets/dock/icons/'
  9. local rows = { layout = wibox.layout.fixed.vertical }
  10. local menu_items = {
  11. { name = 'Blender', icon_name = 'blender.svg', command = function() awful.spawn("blender") end },
  12. { name = 'Krita', icon_name = 'blender.svg', command = function() awful.spawn("krita") end },
  13. }
  14. --blender:connect_signal("button::press", function() awful.spawn("blender") end)
  15. function update_dock(s)
  16. -- How do I access and modify dock_items (id = "dock_items") from here?
  17. -- I can access the dock_bar itself: s.dock_bar,
  18. -- because it's part of the screen object I get from func arguments.
  19. end
  20. function create_dock(s)
  21. s.dockheight = (55 * s.workarea.height)/100
  22. s.dock_bar = awful.wibar({
  23. position = "left",
  24. screen = s,
  25. x=0,
  26. y=s.workarea.height/2 - s.dockheight/2,
  27. --ontop = true,
  28. width = dpi(9),
  29. height = s.dockheight,
  30. type = "dock"
  31. })
  32. local dock_items = {
  33. layout = wibox.layout.fixed.horizontal,
  34. id = "dock_items",
  35. {
  36. markup = "Sample Text",
  37. widget = wibox.widget.textbox
  38. },
  39. offset = {
  40. y = 10,
  41. },
  42. widget = wibox.container.rotate
  43. }
  44. if s.index > 1 and s.dock_bar.y == 0 then
  45. s.dock_bar.y = screen[1].dock_bar.y
  46. end
  47. s.dock_bar:setup {
  48. layout = wibox.layout.align.horizontal,
  49. expand = "outside",
  50. nil, -- Left
  51. dock_items -- Middle
  52. }
  53. -- Add toggling functionalities
  54. s.docktimer = gears.timer{ timeout = 2 }
  55. s.docktimer:connect_signal("timeout", function()
  56. local s = awful.screen.focused()
  57. s.dock_bar.width = dpi(9)
  58. if s.docktimer.started then
  59. s.docktimer:stop()
  60. end
  61. end)
  62. tag.connect_signal("property::selected", function(t)
  63. local s = t.screen or awful.screen.focused()
  64. s.dock_bar.width = dpi(38)
  65. if not s.docktimer.started then
  66. s.docktimer:start()
  67. end
  68. end)
  69. s.dock_bar:connect_signal("mouse::leave", function()
  70. local s = awful.screen.focused()
  71. s.dock_bar.width = dpi(9)
  72. end)
  73. s.dock_bar:connect_signal("mouse::enter", function()
  74. local s = awful.screen.focused()
  75. s.dock_bar.width = dpi(38)
  76. end)
  77. end
  78. -- Add dock only to the first screen
  79. --create_dock(screen[1])
  80. awful.screen.connect_for_each_screen(create_dock)
  81. -- Call update_dock when adding/removeing clients
  82. client.connect_signal("list", function(c) update_dock(screen[1]) end)