2020-10-24 23:39:27 +02:00
|
|
|
local awful = require("awful")
|
2020-10-19 17:25:05 +02:00
|
|
|
local gears = require("gears")
|
|
|
|
local wibox = require("wibox")
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
|
|
|
|
local mylayout = {}
|
|
|
|
|
|
|
|
mylayout.name = "mstab"
|
|
|
|
|
2021-11-28 10:13:12 +01:00
|
|
|
local tabbar_disable = beautiful.mstab_bar_disable or false
|
2020-11-24 01:23:57 +01:00
|
|
|
local tabbar_ontop = beautiful.mstab_bar_ontop or false
|
2020-10-22 16:41:22 +02:00
|
|
|
local tabbar_padding = beautiful.mstab_bar_padding or "default"
|
2021-08-27 20:01:22 +02:00
|
|
|
local border_radius = beautiful.mstab_border_radius
|
|
|
|
or beautiful.border_radius
|
|
|
|
or 0
|
|
|
|
local tabbar_position = beautiful.mstab_tabbar_position
|
|
|
|
or beautiful.tabbar_position
|
|
|
|
or "top"
|
|
|
|
|
|
|
|
local bar_style = beautiful.mstab_tabbar_style
|
|
|
|
or beautiful.tabbar_style
|
|
|
|
or "default"
|
|
|
|
local bar = require(
|
|
|
|
tostring(...):match(".*bling") .. ".widget.tabbar." .. bar_style
|
|
|
|
)
|
|
|
|
local tabbar_size = bar.size
|
|
|
|
or beautiful.mstab_bar_height
|
|
|
|
or beautiful.tabbar_size
|
|
|
|
or 40
|
2020-11-29 10:38:05 +01:00
|
|
|
local dont_resize_slaves = beautiful.mstab_dont_resize_slaves or false
|
2020-10-19 17:25:05 +02:00
|
|
|
|
2021-08-27 20:01:22 +02:00
|
|
|
-- The top_idx is the idx of the slave clients (excluding all master clients)
|
2020-10-19 17:25:05 +02:00
|
|
|
-- that should be on top of all other slave clients ("the focused slave")
|
|
|
|
-- by creating a variable outside of the arrange function, this layout can "remember" that client
|
2021-08-27 20:01:22 +02:00
|
|
|
-- by creating it as a new property of every tag, this layout can be active on different tags and
|
2020-10-19 17:25:05 +02:00
|
|
|
-- still have different "focused slave clients"
|
2021-08-27 20:01:22 +02:00
|
|
|
for idx, tag in ipairs(root.tags()) do
|
|
|
|
tag.top_idx = 1
|
|
|
|
end
|
2020-10-19 17:25:05 +02:00
|
|
|
|
|
|
|
-- Haven't found a signal that is emitted when a new tag is added. That should work though
|
|
|
|
-- since you can't use a layout on a tag that you haven't selected previously
|
2021-08-27 20:01:22 +02:00
|
|
|
tag.connect_signal("property::selected", function(t)
|
|
|
|
if not t.top_idx then
|
|
|
|
t.top_idx = 1
|
|
|
|
end
|
|
|
|
end)
|
2020-10-19 17:25:05 +02:00
|
|
|
|
2021-08-27 20:01:22 +02:00
|
|
|
function update_tabbar(
|
|
|
|
clients,
|
|
|
|
t,
|
|
|
|
top_idx,
|
|
|
|
area,
|
|
|
|
master_area_width,
|
|
|
|
slave_area_width
|
|
|
|
)
|
2020-10-19 17:25:05 +02:00
|
|
|
local s = t.screen
|
|
|
|
|
|
|
|
-- create the list of clients for the tabbar
|
2020-11-24 01:23:57 +01:00
|
|
|
local clientlist = bar.layout()
|
|
|
|
for idx, c in ipairs(clients) do
|
2020-10-24 11:47:27 +02:00
|
|
|
-- focus with right click, kill with mid click, minimize with left click
|
2020-11-24 01:23:57 +01:00
|
|
|
local buttons = gears.table.join(
|
2020-11-29 10:38:05 +01:00
|
|
|
awful.button({}, 1, function()
|
2020-11-24 01:23:57 +01:00
|
|
|
c:raise()
|
|
|
|
client.focus = c
|
2021-08-27 20:01:22 +02:00
|
|
|
end),
|
|
|
|
awful.button({}, 2, function()
|
|
|
|
c:kill()
|
2020-11-29 10:38:05 +01:00
|
|
|
end),
|
|
|
|
awful.button({}, 3, function()
|
2020-11-24 01:23:57 +01:00
|
|
|
c.minimized = true
|
2021-08-27 20:01:22 +02:00
|
|
|
end)
|
|
|
|
)
|
2020-11-24 01:23:57 +01:00
|
|
|
local client_box = bar.create(c, (idx == top_idx), buttons)
|
2020-10-19 17:25:05 +02:00
|
|
|
clientlist:add(client_box)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- if no tabbar exists, create one
|
2020-11-29 10:38:05 +01:00
|
|
|
if not s.tabbar then
|
2021-08-27 20:01:22 +02:00
|
|
|
s.tabbar = wibox({
|
2020-11-24 01:23:57 +01:00
|
|
|
ontop = tabbar_ontop,
|
|
|
|
shape = function(cr, width, height)
|
|
|
|
gears.shape.rounded_rect(cr, width, height, border_radius)
|
|
|
|
end,
|
2020-11-29 10:38:05 +01:00
|
|
|
bg = bar.bg_normal,
|
2021-08-27 20:01:22 +02:00
|
|
|
visible = true,
|
|
|
|
})
|
2020-11-24 01:23:57 +01:00
|
|
|
|
2020-11-02 08:38:21 +01:00
|
|
|
-- Change visibility of the tab bar when layout, selected tag or number of clients (visible, master, slave) changes
|
2022-05-10 17:47:38 +02:00
|
|
|
local function adjust_visibility()
|
|
|
|
local name = awful.layout.getname( awful.layout.get( s ) )
|
|
|
|
s.tabbar.visible = (name == mylayout.name)
|
2020-10-19 17:25:05 +02:00
|
|
|
end
|
|
|
|
|
2022-05-10 17:47:38 +02:00
|
|
|
tag.connect_signal("property::selected", adjust_visibility)
|
|
|
|
tag.connect_signal("property::layout", adjust_visibility)
|
|
|
|
tag.connect_signal("tagged", adjust_visibility)
|
|
|
|
tag.connect_signal("untagged", adjust_visibility)
|
|
|
|
tag.connect_signal("property::master_count", adjust_visibility)
|
|
|
|
client.connect_signal("property::minimized", adjust_visibility)
|
2020-10-19 17:25:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- update the tabbar size and position (to support gap size change on the fly)
|
2020-11-29 10:38:05 +01:00
|
|
|
if tabbar_position == "top" then
|
|
|
|
s.tabbar.x = area.x + master_area_width + t.gap
|
|
|
|
s.tabbar.y = area.y + t.gap
|
|
|
|
s.tabbar.width = slave_area_width - 2 * t.gap
|
|
|
|
s.tabbar.height = tabbar_size
|
|
|
|
elseif tabbar_position == "bottom" then
|
|
|
|
s.tabbar.x = area.x + master_area_width + t.gap
|
|
|
|
s.tabbar.y = area.y + area.height - tabbar_size - t.gap
|
|
|
|
s.tabbar.width = slave_area_width - 2 * t.gap
|
|
|
|
s.tabbar.height = tabbar_size
|
2021-08-27 20:01:22 +02:00
|
|
|
elseif tabbar_position == "left" then
|
2020-11-29 10:38:05 +01:00
|
|
|
s.tabbar.x = area.x + master_area_width + t.gap
|
|
|
|
s.tabbar.y = area.y + t.gap
|
2021-08-27 20:01:22 +02:00
|
|
|
s.tabbar.width = tabbar_size
|
2020-11-29 10:38:05 +01:00
|
|
|
s.tabbar.height = area.height - 2 * t.gap
|
2021-08-27 20:01:22 +02:00
|
|
|
elseif tabbar_position == "right" then
|
|
|
|
s.tabbar.x = area.x
|
|
|
|
+ master_area_width
|
|
|
|
+ slave_area_width
|
|
|
|
- tabbar_size
|
|
|
|
- t.gap
|
2020-11-29 10:38:05 +01:00
|
|
|
s.tabbar.y = area.y + t.gap
|
|
|
|
s.tabbar.width = tabbar_size
|
|
|
|
s.tabbar.height = area.height - 2 * t.gap
|
2020-11-24 01:23:57 +01:00
|
|
|
end
|
2020-10-19 17:25:05 +02:00
|
|
|
|
2021-08-27 20:01:22 +02:00
|
|
|
-- update clientlist
|
|
|
|
s.tabbar:setup({ layout = wibox.layout.flex.horizontal, clientlist })
|
2020-10-19 17:25:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function mylayout.arrange(p)
|
|
|
|
local area = p.workarea
|
|
|
|
local t = p.tag or screen[p.screen].selected_tag
|
|
|
|
local s = t.screen
|
|
|
|
local mwfact = t.master_width_factor
|
|
|
|
local nmaster = math.min(t.master_count, #p.clients)
|
|
|
|
local nslaves = #p.clients - nmaster
|
|
|
|
|
|
|
|
local master_area_width = area.width * mwfact
|
|
|
|
local slave_area_width = area.width - master_area_width
|
|
|
|
|
2020-10-22 16:41:22 +02:00
|
|
|
-- "default" means that it uses standard useless gap size
|
2021-08-27 20:01:22 +02:00
|
|
|
if tabbar_padding == "default" then
|
|
|
|
tabbar_padding = 2 * t.gap
|
|
|
|
end
|
2020-10-22 16:41:22 +02:00
|
|
|
|
2020-10-19 17:25:05 +02:00
|
|
|
-- Special case: No masters -> full screen slave width
|
|
|
|
if nmaster == 0 then
|
|
|
|
master_area_width = 1
|
|
|
|
slave_area_width = area.width
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Special case: One or zero slaves -> no tabbar (essentially tile right)
|
|
|
|
if nslaves <= 1 then
|
|
|
|
-- since update_tabbar isnt called that way we have to hide it manually
|
2021-08-27 20:01:22 +02:00
|
|
|
if s.tabbar then
|
|
|
|
s.tabbar.visible = false
|
|
|
|
end
|
|
|
|
-- otherwise just do tile right
|
2020-10-19 17:25:05 +02:00
|
|
|
awful.layout.suit.tile.right.arrange(p)
|
2020-11-24 01:23:57 +01:00
|
|
|
return
|
|
|
|
end
|
2020-10-19 17:25:05 +02:00
|
|
|
|
|
|
|
-- Iterate through masters
|
2020-11-24 01:23:57 +01:00
|
|
|
for idx = 1, nmaster do
|
|
|
|
local c = p.clients[idx]
|
|
|
|
local g = {
|
2020-10-19 17:25:05 +02:00
|
|
|
x = area.x,
|
2020-11-24 01:23:57 +01:00
|
|
|
y = area.y + (idx - 1) * (area.height / nmaster),
|
2020-10-19 17:25:05 +02:00
|
|
|
width = master_area_width,
|
2021-08-27 20:01:22 +02:00
|
|
|
height = area.height / nmaster,
|
2020-11-24 01:23:57 +01:00
|
|
|
}
|
|
|
|
p.geometries[c] = g
|
2020-10-19 17:25:05 +02:00
|
|
|
end
|
|
|
|
|
2021-08-27 20:01:22 +02:00
|
|
|
local tabbar_size_change = 0
|
|
|
|
local tabbar_width_change = 0
|
|
|
|
local tabbar_y_change = 0
|
|
|
|
local tabbar_x_change = 0
|
2021-11-28 10:13:12 +01:00
|
|
|
if not tabbar_disable then
|
|
|
|
if tabbar_position == "top" then
|
|
|
|
tabbar_size_change = tabbar_size + tabbar_padding
|
|
|
|
tabbar_y_change = tabbar_size + tabbar_padding
|
|
|
|
elseif tabbar_position == "bottom" then
|
|
|
|
tabbar_size_change = tabbar_size + tabbar_padding
|
|
|
|
elseif tabbar_position == "left" then
|
|
|
|
tabbar_width_change = tabbar_size + tabbar_padding
|
|
|
|
tabbar_x_change = tabbar_size + tabbar_padding
|
|
|
|
elseif tabbar_position == "right" then
|
|
|
|
tabbar_width_change = tabbar_size + tabbar_padding
|
|
|
|
end
|
2020-11-29 10:38:05 +01:00
|
|
|
end
|
2020-11-24 01:23:57 +01:00
|
|
|
|
2020-10-19 17:25:05 +02:00
|
|
|
-- Iterate through slaves
|
|
|
|
-- (also creates a list of all slave clients for update_tabbar)
|
|
|
|
local slave_clients = {}
|
2020-11-24 01:23:57 +01:00
|
|
|
for idx = 1, nslaves do
|
|
|
|
local c = p.clients[idx + nmaster]
|
|
|
|
slave_clients[#slave_clients + 1] = c
|
2021-08-27 20:01:22 +02:00
|
|
|
if c == client.focus then
|
|
|
|
t.top_idx = #slave_clients
|
|
|
|
end
|
2020-11-24 01:23:57 +01:00
|
|
|
local g = {
|
2021-08-27 20:01:22 +02:00
|
|
|
x = area.x + master_area_width + tabbar_x_change,
|
|
|
|
y = area.y + tabbar_y_change,
|
|
|
|
width = slave_area_width - tabbar_width_change,
|
|
|
|
height = area.height - tabbar_size_change,
|
2020-11-24 01:23:57 +01:00
|
|
|
}
|
2021-08-27 20:01:22 +02:00
|
|
|
if not dont_resize_slaves and idx ~= t.top_idx then
|
2020-11-29 10:38:05 +01:00
|
|
|
g = {
|
|
|
|
x = area.x + master_area_width + slave_area_width / 4,
|
|
|
|
y = area.y + tabbar_size + area.height / 4,
|
|
|
|
width = slave_area_width / 2,
|
2021-08-27 20:01:22 +02:00
|
|
|
height = area.height / 4 - tabbar_size,
|
2020-11-29 10:38:05 +01:00
|
|
|
}
|
2020-11-24 01:23:57 +01:00
|
|
|
end
|
|
|
|
p.geometries[c] = g
|
2020-10-19 17:25:05 +02:00
|
|
|
end
|
|
|
|
|
2021-11-28 10:13:12 +01:00
|
|
|
if not tabbar_disable then
|
|
|
|
update_tabbar(
|
|
|
|
slave_clients,
|
|
|
|
t,
|
|
|
|
t.top_idx,
|
|
|
|
area,
|
|
|
|
master_area_width,
|
|
|
|
slave_area_width
|
|
|
|
)
|
|
|
|
end
|
2020-10-19 17:25:05 +02:00
|
|
|
end
|
|
|
|
|
2021-11-06 19:33:58 +01:00
|
|
|
return mylayout
|