diff --git a/core/titlebar.lua b/core/titlebar.lua index b77f58f..e8bc1b9 100644 --- a/core/titlebar.lua +++ b/core/titlebar.lua @@ -43,6 +43,37 @@ awful.screen.connect_for_each_screen(function(s) toggle_tags }) end) +local controls_widget = wibox.widget { + forced_width = 72, + forced_height = 24, + layout = wibox.layout.fixed.horizontal, +} +-- To conserve memory we keep one menu at a time +local menu_widget = menu({ + before = { + controls_widget + }, + items = { + { "Move to tag" , + move_screentags + }, + { "Toggle on tag", + toggle_screentags + }, + { "Stop task", + function() + awful.spawn("kill "..tostring(c.pid)) + end + }, + { "Kill task", + function() + awful.spawn("kill -s KILL "..tostring(c.pid)) + end + } + }, + vertical = true +}) + return function(c) local buttons = gears.table.join( awful.button({ }, 1, function() @@ -54,45 +85,26 @@ return function(c) awful.mouse.client.resize(c) end) ) - c.menu = menu({ - before = { - { - awful.titlebar.widget.floatingbutton (c), - awful.titlebar.widget.stickybutton (c), - awful.titlebar.widget.ontopbutton (c), - forced_width = 72, - forced_height = 24, - layout = wibox.layout.fixed.horizontal, - } - }, - items = { - { "Move to tag" , - move_screentags - }, - { "Toggle on tag", - toggle_screentags - }, - { "Stop task", - function() - awful.spawn("kill "..tostring(c.pid)) - end - }, - { "Kill task", - function() - awful.spawn("kill -s KILL "..tostring(c.pid)) - end - } - }, - vertical = true - }) c.menu_button = awful.titlebar.widget.iconwidget(c) + -- A little trick we do to conserve memory and cpu usage on regenerating + -- buttons is we pop up a menu in the location of the icon + -- and insert buttons into the controls widget layout. + c.hidden_floatingbutton = awful.titlebar.widget.floatingbutton(c) + c.hidden_stickybutton = awful.titlebar.widget.stickybutton(c) + c.hidden_ontopbutton = awful.titlebar.widget.ontopbutton(c) c.menu_button:connect_signal("button::press", function() - c.menu.toggle() + menu_widget.toggle() + if controls_widget then + controls_widget:reset() + controls_widget:add(c.hidden_floatingbutton) + controls_widget:add(c.hidden_stickybutton) + controls_widget:add(c.hidden_ontopbutton) + end c:emit_signal("request::activate", "titlebar", {raise = true}) end) c:connect_signal("unfocus",function() - if c.menu.visible then - c.menu.toggle(0,0) + if menu_widget.visible then + menu_widget.toggle(0,0) end end) return awful.titlebar(c) : setup {