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 gcolor = require("gears.color")
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
|
|
|
|
local mylayout = {}
|
|
|
|
|
|
|
|
mylayout.name = "mstab"
|
|
|
|
|
2020-11-22 10:18:39 +01:00
|
|
|
|
2020-10-22 16:41:22 +02:00
|
|
|
local tabbar_padding = beautiful.mstab_bar_padding or "default"
|
2020-11-22 10:18:39 +01:00
|
|
|
local tabbar_height = beautiful.mstab_bar_height or beautiful.tabbar_size or 40
|
2020-10-24 11:47:27 +02:00
|
|
|
local border_radius = beautiful.mstab_border_radius or beautiful.border_radius or 0
|
2020-11-22 10:18:39 +01:00
|
|
|
local tabbar_font = beautiful.mstab_font or beautiful.tabbar_font or beautiful.font or "Monospace 8"
|
|
|
|
local bg_focus = beautiful.mstab_bg_focus or beautiful.tabbar_bg_focus or beautiful.bg_focus or "#ff0000"
|
|
|
|
local bg_normal = beautiful.mstab_bg_normal or beautiful.tabbar_bg_normal or beautiful.bg_normal or "#000000"
|
|
|
|
local fg_focus = beautiful.mstab_fg_focus or beautiful.tabbar_fg_focus or beautiful.fg_focus or "#000000"
|
|
|
|
local fg_normal = beautiful.mstab_fg_normal or beautiful.tabbar_fg_normal or beautiful.fg_normal or "#ffffff"
|
|
|
|
|
|
|
|
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)
|
2020-10-19 17:25:05 +02:00
|
|
|
|
|
|
|
-- The top_idx is the idx of the slave clients (excluding all master clients)
|
|
|
|
-- 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
|
|
|
|
-- by creating it as a new property of every tag, this layout can be active on different tags and
|
|
|
|
-- still have different "focused slave clients"
|
|
|
|
for idx,tag in ipairs(root.tags()) do
|
|
|
|
tag.top_idx = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
-- 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
|
|
|
|
tag.connect_signal("property::selected", function(t)
|
|
|
|
if not t.top_idx then
|
|
|
|
t.top_idx = 1
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
function update_tabbar(clients, t, top_idx, area, master_area_width, slave_area_width)
|
|
|
|
|
|
|
|
local s = t.screen
|
|
|
|
|
|
|
|
-- create the list of clients for the tabbar
|
2020-11-22 10:18:39 +01:00
|
|
|
local clientlist = bar.layout()
|
2020-10-19 17:25:05 +02:00
|
|
|
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
|
|
|
|
local buttons = gears.table.join(awful.button({}, 1, function() c:raise() client.focus = c end),
|
|
|
|
awful.button({}, 2, function() c:kill() end),
|
|
|
|
awful.button({}, 3, function() c.minimized = true end))
|
2020-11-22 10:18:39 +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
|
|
|
|
if not s.tabbar_exists then
|
|
|
|
s.tabbar = wibox {
|
2020-10-24 11:47:27 +02:00
|
|
|
shape = function(cr, width, height) gears.shape.rounded_rect(cr, width, height, border_radius) end,
|
2020-10-19 17:25:05 +02:00
|
|
|
bg = bg_normal,
|
|
|
|
visible = true
|
|
|
|
}
|
|
|
|
s.tabbar_exists = true
|
|
|
|
|
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
|
2020-10-19 17:25:05 +02:00
|
|
|
local function adjust_visiblity(t)
|
2020-11-02 08:38:21 +01:00
|
|
|
s.tabbar.visible = (#t:clients() - t.master_count > 1) and (t.layout.name == mylayout.name)
|
2020-10-19 17:25:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
tag.connect_signal("property::selected", function(t) adjust_visiblity(t) end)
|
|
|
|
tag.connect_signal("property::layout", function(t, layout) adjust_visiblity(t) end)
|
|
|
|
tag.connect_signal("tagged", function(t, c) adjust_visiblity(t) end)
|
|
|
|
tag.connect_signal("untagged", function(t, c) adjust_visiblity(t) end)
|
2020-11-02 08:38:21 +01:00
|
|
|
tag.connect_signal("property::master_count", function(t) adjust_visiblity(t) end)
|
|
|
|
client.connect_signal("property::minimized", function(c) local t = c.first_tag adjust_visiblity(t) end)
|
2020-10-19 17:25:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- update the tabbar size and position (to support gap size change on the fly)
|
|
|
|
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
|
2020-10-22 06:25:32 +02:00
|
|
|
s.tabbar.height = tabbar_height
|
2020-10-19 17:25:05 +02:00
|
|
|
|
2020-11-22 10:18:39 +01:00
|
|
|
if tabbar_position == "bottom" then
|
2020-10-22 06:25:32 +02:00
|
|
|
s.tabbar.y = area.y + area.height - tabbar_height - t.gap
|
2020-10-19 17:25:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- update clientlist
|
|
|
|
s.tabbar:setup {
|
|
|
|
layout = wibox.layout.flex.horizontal,
|
|
|
|
clientlist,
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
if tabbar_padding == "default" then
|
|
|
|
tabbar_padding = 2*t.gap
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
if s.tabbar_exists then
|
|
|
|
s.tabbar.visible = false
|
|
|
|
end
|
|
|
|
-- otherwise just do tile right
|
|
|
|
awful.layout.suit.tile.right.arrange(p)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Iterate through masters
|
|
|
|
for idx=1,nmaster do
|
|
|
|
local c = p.clients[idx]
|
|
|
|
local g = {
|
|
|
|
x = area.x,
|
|
|
|
y = area.y+(idx-1)*(area.height/nmaster),
|
|
|
|
width = master_area_width,
|
|
|
|
height = area.height/nmaster,
|
|
|
|
}
|
|
|
|
p.geometries[c] = g
|
|
|
|
end
|
|
|
|
|
|
|
|
-- TODO: The way that the slave clients are arranged is currently very hacky and unclean
|
|
|
|
-- because of the requirement that the shadows shouldn't just add up when more slaves are added
|
|
|
|
-- Currently clients are just shrunken down and placed "under" the "focused slave client"
|
|
|
|
-- Ideal would be hide the same way as that small scratchpad script:
|
|
|
|
-- https://github.com/notnew/awesome-scratch/blob/master/scratch.lua
|
|
|
|
|
|
|
|
-- Iterate through slaves
|
|
|
|
-- (also creates a list of all slave clients for update_tabbar)
|
|
|
|
local slave_clients = {}
|
|
|
|
for idx=1,nslaves do
|
|
|
|
local c = p.clients[idx+nmaster]
|
|
|
|
slave_clients[#slave_clients+1] = c
|
|
|
|
if c == client.focus then
|
|
|
|
t.top_idx = #slave_clients
|
|
|
|
end
|
|
|
|
local g = {x=1, y=1, width=1, height=1}
|
|
|
|
local g = {
|
|
|
|
x = area.x + master_area_width + slave_area_width/4,
|
|
|
|
y = area.y + tabbar_height + area.height/4,
|
|
|
|
width = slave_area_width/2,
|
2020-10-22 07:29:19 +02:00
|
|
|
height = area.height/4 - tabbar_height
|
2020-10-19 17:25:05 +02:00
|
|
|
}
|
|
|
|
if idx == t.top_idx then
|
|
|
|
g.width = slave_area_width
|
2020-10-22 07:29:19 +02:00
|
|
|
g.height = area.height - tabbar_height - tabbar_padding
|
2020-10-19 17:25:05 +02:00
|
|
|
g.x = area.x + master_area_width
|
|
|
|
g.y = area.y
|
2020-11-22 10:18:39 +01:00
|
|
|
if tabbar_position == "top" then
|
2020-10-22 06:25:32 +02:00
|
|
|
g.y = g.y + tabbar_height + tabbar_padding
|
2020-10-19 17:25:05 +02:00
|
|
|
else
|
|
|
|
g.y = g.y
|
|
|
|
end
|
|
|
|
end
|
|
|
|
p.geometries[c] = g
|
|
|
|
end
|
|
|
|
|
|
|
|
update_tabbar(slave_clients, t, t.top_idx, area, master_area_width, slave_area_width)
|
|
|
|
end
|
|
|
|
|
2020-10-31 10:28:14 +01:00
|
|
|
local icon_raw = gears.filesystem.get_configuration_dir() .. tostring(...):match("^.*bling"):gsub("%.", "/") .. "/icons/layouts/mstab.png"
|
2020-10-19 17:25:05 +02:00
|
|
|
|
|
|
|
local function get_icon()
|
|
|
|
if icon_raw ~= nil then
|
|
|
|
return gcolor.recolor_image(icon_raw, beautiful.fg_normal)
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
layout = mylayout,
|
|
|
|
icon_raw = icon_raw,
|
|
|
|
get_icon = get_icon,
|
|
|
|
}
|