From c04c2e325f6fcf58aea1896460bf36d5eff02b22 Mon Sep 17 00:00:00 2001 From: mickael9 Date: Thu, 10 Jan 2013 00:51:02 +0100 Subject: [PATCH] Make title bars work! --- init.lua | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 3c6b566..183a1f2 100644 --- a/init.lua +++ b/init.lua @@ -13,6 +13,7 @@ local table = table local string = string local beautiful = require("beautiful") local awful = require("awful") +local wibox = require("wibox") local pairs = pairs local io = io local tonumber = tonumber @@ -621,11 +622,13 @@ function match(c, startup) -- Add titlebars to all clients when the float, remove when they are -- tiled. if shifty.config.float_bars then + shifty.create_titlebar(c) + c:connect_signal("property::floating", function(c) if awful.client.floating.get(c) then - awful.titlebar.add(c, {modkey=modkey}) + awful.titlebar(c) else - awful.titlebar.remove(c) + awful.titlebar(c, { size = 0 }) end awful.placement.no_offscreen(c) end) @@ -902,6 +905,46 @@ function shifty.init() end end +-- Create a titlebar for the given client +-- By default, make it invisible (size = 0) + +function shifty.create_titlebar(c) + -- Widgets that are aligned to the left + local left_layout = wibox.layout.fixed.horizontal() + left_layout:add(awful.titlebar.widget.iconwidget(c)) + + -- Widgets that are aligned to the right + local right_layout = wibox.layout.fixed.horizontal() + right_layout:add(awful.titlebar.widget.floatingbutton(c)) + right_layout:add(awful.titlebar.widget.maximizedbutton(c)) + right_layout:add(awful.titlebar.widget.stickybutton(c)) + right_layout:add(awful.titlebar.widget.ontopbutton(c)) + right_layout:add(awful.titlebar.widget.closebutton(c)) + + -- The title goes in the middle + local title = awful.titlebar.widget.titlewidget(c) + title:buttons(awful.util.table.join( + awful.button({ }, 1, function() + client.focus = c + c:raise() + awful.mouse.client.move(c) + end), + awful.button({ }, 3, function() + client.focus = c + c:raise() + awful.mouse.client.resize(c) + end) + )) + + -- Now bring it all together + local layout = wibox.layout.align.horizontal() + layout:set_left(left_layout) + layout:set_right(right_layout) + layout:set_middle(title) + + awful.titlebar(c, { size = 0 }):set_widget(layout) +end + --count : utility function returns the index of a table element --FIXME: this is currently used only in remove_dup, so is it really --necessary?