This commit is contained in:
Luca 2022-11-22 13:25:44 +01:00
parent 8268fba83d
commit 7ed2a6e110
9565 changed files with 1315332 additions and 90 deletions

View file

@ -0,0 +1,80 @@
local awful = require("awful")
local math = math
local mylayout = {}
mylayout.name = "centered"
function mylayout.arrange(p)
local area = p.workarea
local t = p.tag or screen[p.screen].selected_tag
local nmaster = math.min(t.master_count, #p.clients)
local nslaves = #p.clients - nmaster
local master_area_width = area.width * t.master_width_factor
if t.master_count == 0 then master_area_width = 0 end
local slave_width = 0.5 * (area.width - master_area_width)
local master_area_x = area.x + slave_width
-- Special case: few slaves -> make masters take more space - unless requested otherwise!
if nslaves < 2 and t.master_fill_policy ~= "master_width_factor" then
master_area_x = area.x
if nslaves == 1 then
slave_width = area.width - master_area_width
else
master_area_width = area.width
end
end
-- iterate through masters
for idx = 1, nmaster do
local c = p.clients[idx]
local g
g = {
x = master_area_x,
y = area.y + (nmaster - idx) * (area.height / nmaster),
width = master_area_width,
height = area.height / nmaster,
}
p.geometries[c] = g
end
-- iterate through slaves
local number_of_left_sided_slaves = math.floor(nslaves / 2)
local number_of_right_sided_slaves = nslaves - number_of_left_sided_slaves
local left_iterator = 0
local right_iterator = 0
for idx = 1, nslaves do
local c = p.clients[idx + nmaster]
local g
if idx % 2 == 0 then
g = {
x = area.x,
y = area.y
+ left_iterator
* (area.height / number_of_left_sided_slaves),
width = slave_width,
height = area.height / number_of_left_sided_slaves,
}
left_iterator = left_iterator + 1
else
g = {
x = master_area_x + master_area_width,
y = area.y
+ right_iterator
* (area.height / number_of_right_sided_slaves),
width = slave_width,
height = area.height / number_of_right_sided_slaves,
}
right_iterator = right_iterator + 1
end
p.geometries[c] = g
end
end
return mylayout

View file

@ -0,0 +1,37 @@
local mylayout = {}
mylayout.name = "deck"
function mylayout.arrange(p)
local area = p.workarea
local t = p.tag or screen[p.screen].selected_tag
local client_count = #p.clients
if client_count == 1 then
local c = p.clients[1]
local g = {
x = area.x,
y = area.y,
width = area.width,
height = area.height,
}
p.geometries[c] = g
return
end
local xoffset = area.width * 0.1 / (client_count - 1)
local yoffset = area.height * 0.1 / (client_count - 1)
for idx = 1, client_count do
local c = p.clients[idx]
local g = {
x = area.x + (idx - 1) * xoffset,
y = area.y + (idx - 1) * yoffset,
width = area.width - (xoffset * (client_count - 1)),
height = area.height - (yoffset * (client_count - 1)),
}
p.geometries[c] = g
end
end
return mylayout

View file

@ -0,0 +1,77 @@
local math = math
local screen = screen
local mylayout = {}
mylayout.name = "equalarea"
local function divide(p, g, low, high, cls, mwfact, mcount)
if low == high then
p.geometries[cls[low]] = g
else
local masters = math.max(0, math.min(mcount, high) - low + 1)
local numblock = high - low + 1
local slaves = numblock - masters
local smalldiv
if numblock > 5 and (numblock % 5) == 0 then
smalldiv = math.floor(numblock / 5)
else
if (numblock % 3) == 0 then
smalldiv = math.floor(numblock / 3)
else
smalldiv = math.floor(numblock / 2)
end
end
local bigdiv = numblock - smalldiv
local smallmasters = math.min(masters, smalldiv)
local bigmasters = masters - smallmasters
local smallg = {}
local bigg = {}
smallg.x = g.x
smallg.y = g.y
if g.width > (g.height * 1.3) then
smallg.height = g.height
bigg.height = g.height
bigg.width = math.floor(
g.width
* (bigmasters * (mwfact - 1) + bigdiv)
/ (slaves + mwfact * masters)
)
smallg.width = g.width - bigg.width
bigg.y = g.y
bigg.x = g.x + smallg.width
else
smallg.width = g.width
bigg.width = g.width
bigg.height = math.floor(
g.height
* (bigmasters * (mwfact - 1) + bigdiv)
/ (slaves + mwfact * masters)
)
smallg.height = g.height - bigg.height
bigg.x = g.x
bigg.y = g.y + smallg.height
end
divide(p, smallg, low, high - bigdiv, cls, mwfact, mcount)
divide(p, bigg, low + smalldiv, high, cls, mwfact, mcount)
end
return
end
function mylayout.arrange(p)
local t = p.tag or screen[p.screen].selected_tag
local wa = p.workarea
local cls = p.clients
if #cls == 0 then
return
end
local mwfact = t.master_width_factor * 2
local mcount = t.master_count
local g = {}
g.height = wa.height
g.width = wa.width
g.x = wa.x
g.y = wa.y
divide(p, g, 1, #cls, cls, mwfact, mcount)
end
return mylayout

View file

@ -0,0 +1,56 @@
local math = math
local mylayout = {}
mylayout.name = "horizontal"
function mylayout.arrange(p)
local area = p.workarea
local t = p.tag or screen[p.screen].selected_tag
local mwfact = t.master_width_factor
local nmaster = math.min(t.master_count, #p.clients)
local nslaves = #p.clients - nmaster
local master_area_height = area.height * mwfact
local slave_area_height = area.height - master_area_height
-- Special case: no slaves
if nslaves == 0 then
master_area_height = area.height
slave_area_height = 0
end
-- Special case: no masters
if nmaster == 0 then
master_area_height = 0
slave_area_height = area.height
end
-- itearte through masters
for idx = 1, nmaster do
local c = p.clients[idx]
local g = {
x = area.x + (idx - 1) * (area.width / nmaster),
y = area.y,
width = area.width / nmaster,
height = master_area_height,
}
p.geometries[c] = g
end
-- iterate through slaves
for idx = 1, nslaves do
local c = p.clients[idx + nmaster]
local g = {
x = area.x,
y = area.y
+ master_area_height
+ (idx - 1) * (slave_area_height / nslaves),
width = area.width,
height = slave_area_height / nslaves,
}
p.geometries[c] = g
end
end
return mylayout

View file

@ -0,0 +1,46 @@
local beautiful = require("beautiful")
local gears = require("gears")
local M = {}
local relative_lua_path = tostring(...)
local function get_layout_icon_path(name)
local relative_icon_path = relative_lua_path
:match("^.*bling"):gsub("%.", "/")
.. "/icons/layouts/" .. name .. ".png"
for p in package.path:gmatch('([^;]+)') do
p = p:gsub("?.*", "")
local absolute_icon_path = p .. relative_icon_path
if gears.filesystem.file_readable(absolute_icon_path) then
return absolute_icon_path
end
end
end
local function get_icon(icon_raw)
if icon_raw ~= nil then
return gears.color.recolor_image(icon_raw, beautiful.fg_normal)
else
return nil
end
end
local layouts = {
"mstab",
"vertical",
"horizontal",
"centered",
"equalarea",
"deck"
}
for _, layout_name in ipairs(layouts) do
local icon_raw = get_layout_icon_path(layout_name)
if beautiful["layout_" .. layout_name] == nil then
beautiful["layout_" .. layout_name] = get_icon(icon_raw)
end
M[layout_name] = require(... .. "." .. layout_name)
end
return M

View file

@ -0,0 +1,236 @@
local awful = require("awful")
local gears = require("gears")
local wibox = require("wibox")
local beautiful = require("beautiful")
local mylayout = {}
mylayout.name = "mstab"
local tabbar_disable = beautiful.mstab_bar_disable or false
local tabbar_ontop = beautiful.mstab_bar_ontop or false
local tabbar_padding = beautiful.mstab_bar_padding or "default"
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
local dont_resize_slaves = beautiful.mstab_dont_resize_slaves or false
-- 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
local clientlist = bar.layout()
for idx, c in ipairs(clients) do
-- 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)
)
local client_box = bar.create(c, (idx == top_idx), buttons)
clientlist:add(client_box)
end
-- if no tabbar exists, create one
if not s.tabbar then
s.tabbar = wibox({
ontop = tabbar_ontop,
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, border_radius)
end,
bg = bar.bg_normal,
visible = true,
})
-- Change visibility of the tab bar when layout, selected tag or number of clients (visible, master, slave) changes
local function adjust_visibility()
local name = awful.layout.getname( awful.layout.get( s ) )
s.tabbar.visible = (name == mylayout.name)
end
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)
end
-- update the tabbar size and position (to support gap size change on the fly)
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
elseif tabbar_position == "left" then
s.tabbar.x = area.x + master_area_width + t.gap
s.tabbar.y = area.y + t.gap
s.tabbar.width = tabbar_size
s.tabbar.height = area.height - 2 * t.gap
elseif tabbar_position == "right" then
s.tabbar.x = area.x
+ master_area_width
+ slave_area_width
- tabbar_size
- t.gap
s.tabbar.y = area.y + t.gap
s.tabbar.width = tabbar_size
s.tabbar.height = area.height - 2 * t.gap
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
-- "default" means that it uses standard useless gap size
if tabbar_padding == "default" then
tabbar_padding = 2 * t.gap
end
-- 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 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
local tabbar_size_change = 0
local tabbar_width_change = 0
local tabbar_y_change = 0
local tabbar_x_change = 0
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
end
-- 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 = 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,
}
if not dont_resize_slaves and idx ~= t.top_idx then
g = {
x = area.x + master_area_width + slave_area_width / 4,
y = area.y + tabbar_size + area.height / 4,
width = slave_area_width / 2,
height = area.height / 4 - tabbar_size,
}
end
p.geometries[c] = g
end
if not tabbar_disable then
update_tabbar(
slave_clients,
t,
t.top_idx,
area,
master_area_width,
slave_area_width
)
end
end
return mylayout

View file

@ -0,0 +1,56 @@
local math = math
local mylayout = {}
mylayout.name = "vertical"
function mylayout.arrange(p)
local area = p.workarea
local t = p.tag or screen[p.screen].selected_tag
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
-- Special case: no slaves
if nslaves == 0 then
master_area_width = area.width
slave_area_width = 0
end
-- Special case: no masters
if nmaster == 0 then
master_area_width = 0
slave_area_width = area.width
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
-- itearte through slaves
for idx = 1, nslaves do
local c = p.clients[idx + nmaster]
local g = {
x = area.x
+ master_area_width
+ (idx - 1) * (slave_area_width / nslaves),
y = area.y,
width = slave_area_width / nslaves,
height = area.height,
}
p.geometries[c] = g
end
end
return mylayout