format with stylua

This commit is contained in:
BZ 2021-11-28 17:18:41 +01:00
parent 6e1482e635
commit a6f1df134e
1 changed files with 867 additions and 852 deletions

155
init.lua
View File

@ -15,7 +15,7 @@ local instances = {}
local function update_on_signal(c, signal, widget)
local sig_instances = instances[signal]
if sig_instances == nil then
sig_instances = setmetatable({}, {__mode = "k"})
sig_instances = setmetatable({}, { __mode = "k" })
instances[signal] = sig_instances
client.connect_signal(signal, function(cl)
local widgets = sig_instances[cl]
@ -28,7 +28,7 @@ local function update_on_signal(c, signal, widget)
end
local widgets = sig_instances[c]
if widgets == nil then
widgets = setmetatable({}, {__mode = "v"})
widgets = setmetatable({}, { __mode = "v" })
sig_instances[c] = widgets
end
table.insert(widgets, widget)
@ -114,7 +114,7 @@ local menu_move2screen = function(c)
local desc = next(s.outputs) or ""
if s.index ~= awful.screen.focused().index then
count = count + 1
local entry = {s.index .. ": " .. desc .. " ", menu_move2tag(c, s)}
local entry = { s.index .. ": " .. desc .. " ", menu_move2tag(c, s) }
table.insert(list, entry)
end
end
@ -129,12 +129,12 @@ function module.menu_client(custom_menu, c)
local list_tags = menu_move2tag(c)
if list_tags then
table.insert(list, {"move to tag", list_tags})
table.insert(list, { "move to tag", list_tags })
end
local list_screens = menu_move2screen(c)
if list_screens then
table.insert(list, {"move to screen", list_screens})
table.insert(list, { "move to screen", list_screens })
end
table.insert(list, {
@ -202,12 +202,12 @@ function module.menu_client(custom_menu, c)
if custom_menu and len(custom_menu) > 0 then
local function generate_menu_entry(e)
if e and type(e) == 'table' and e.text then
if e and type(e) == "table" and e.text then
local text = ""
if type(e.text) == 'string' then
if type(e.text) == "string" then
text = e.text
end
if type(e.text) == 'function' then
if type(e.text) == "function" then
text = e.text(c)
end
return {
@ -284,22 +284,25 @@ local add_hot_corner = function(args)
end
local defs = {
{name = "left_click", button = 1},
{name = "middle_click", button = 2},
{name = "right_click", button = 3},
{name = "wheel_up", button = 4},
{name = "wheel_down", button = 5},
{name = "back_click", button = 8},
{name = "forward_click", button = 9},
{ name = "left_click", button = 1 },
{ name = "middle_click", button = 2 },
{ name = "right_click", button = 3 },
{ name = "wheel_up", button = 4 },
{ name = "wheel_down", button = 5 },
{ name = "back_click", button = 8 },
{ name = "forward_click", button = 9 },
}
local buttons = {}
for _, btn in ipairs(defs) do
if actions[btn.name] then
local signal = signal_name(position, btn.name)
table.insert(buttons, awful.button({}, btn.button, function()
table.insert(
buttons,
awful.button({}, btn.button, function()
awesome.emit_signal(signal)
end))
end)
)
if must_connect_signal then
awesome.connect_signal(signal, glib_context(actions[btn.name]))
end
@ -307,7 +310,7 @@ local add_hot_corner = function(args)
end
corner:buttons(buttons)
for _, action in pairs({"enter", "leave"}) do
for _, action in pairs({ "enter", "leave" }) do
if actions[action] then
local signal = signal_name(position, action)
corner:connect_signal("mouse::" .. action, function()
@ -322,8 +325,8 @@ end
local function new(config)
local cfg = config or {}
local positions = cfg.positions or {"left", "right", "top", "bottom"}
local button_positions = cfg.button_positions or {"top"}
local positions = cfg.positions or { "left", "right", "top", "bottom" }
local button_positions = cfg.button_positions or { "top" }
local border_width = cfg.border_width or dpi(6)
local rounded_corner = cfg.rounded_corner or nil
@ -389,23 +392,26 @@ local function new(config)
local align_horizontal = cfg.align_horizontal or "right" -- "left" | "center" | "right"
local align_vertical = cfg.align_vertical or "center" -- "top" | "center" | "bottom"
local buttons = cfg.buttons or {"floating", "minimize", "maximize", "close"}
local buttons = cfg.buttons or { "floating", "minimize", "maximize", "close" }
local button_left_click = cfg.button_left_click or function(c)
local button_left_click = cfg.button_left_click
or function(c)
if c.maximized then
c.maximized = false
end
c:emit_signal("request::activate", "mouse_click", {raise = true})
c:emit_signal("request::activate", "mouse_click", { raise = true })
awful.mouse.client.move(c)
end
local button_double_click = cfg.button_double_click or function(c)
c.maximized = not c.maximized
end
local button_middle_click = cfg.middle_click or function(c)
c:emit_signal("request::activate", "mouse_click", {raise = true})
local button_middle_click = cfg.middle_click
or function(c)
c:emit_signal("request::activate", "mouse_click", { raise = true })
awful.mouse.client.resize(c)
end
local button_right_click = cfg.right_click or function(c)
local button_right_click = cfg.right_click
or function(c)
if c.client_menu then
c.client_menu:hide()
end
@ -562,7 +568,7 @@ local function new(config)
end
if type(button_positions) == "string" then
button_positions = {button_positions}
button_positions = { button_positions }
end
if snapping then
@ -582,8 +588,10 @@ local function new(config)
local dy = math.max(math.abs(m_y - y) - (c.height / 2), 0)
local distance = math.sqrt(dx * dx + dy * dy)
if (not snapping_max_distance or (distance <= snapping_max_distance)) and
(not closest_distance or distance < closest_distance) then
if
(not snapping_max_distance or (distance <= snapping_max_distance))
and (not closest_distance or distance < closest_distance)
then
closest_distance = distance
closest_c = c
end
@ -591,7 +599,7 @@ local function new(config)
end
if closest_c and closest_c.valid then
closest_c:emit_signal("request::activate", "smart_borders::snapping", {raise = true})
closest_c:emit_signal("request::activate", "smart_borders::snapping", { raise = true })
end
return closest_c
@ -602,7 +610,7 @@ local function new(config)
local c = mouse_closest_client()
if c then
if snapping_center_mouse then
mouse.coords {x = c.x + c.width / 2, y = c.y + c.height / 2}
mouse.coords({ x = c.x + c.width / 2, y = c.y + c.height / 2 })
end
left_click_function(c)
end
@ -645,16 +653,15 @@ local function new(config)
end),
})
else
naughty.notify({title = "smart_borders", text = "snapping requires awesomewm git version!", timeout = 0})
naughty.notify({ title = "smart_borders", text = "snapping requires awesomewm git version!", timeout = 0 })
end
end
local smart_border_titlebars = function(c)
local button_widgets = {}
local border_bg = wibox.widget.base.make_widget_declarative(
{
{widget = wibox.container.margin},
local border_bg = wibox.widget.base.make_widget_declarative({
{ widget = wibox.container.margin },
id = "border_bg",
bg = color_normal,
widget = wibox.container.background,
@ -680,8 +687,7 @@ local function new(config)
local border_expander, border_expander_center
if layout == "fixed" then
border_expander_center = wibox.widget.base.make_widget_declarative(
{
border_expander_center = wibox.widget.base.make_widget_declarative({
fill_vertical = true,
fill_horizontal = true,
content_fill_vertical = true,
@ -689,11 +695,10 @@ local function new(config)
border_bg,
widget = wibox.container.place,
})
border_expander = wibox.widget.base.make_widget_declarative(
{
{layout = wibox.layout.fixed.horizontal},
border_expander = wibox.widget.base.make_widget_declarative({
{ layout = wibox.layout.fixed.horizontal },
border_bg,
{layout = wibox.layout.fixed.horizontal},
{ layout = wibox.layout.fixed.horizontal },
widget = wibox.layout.align.horizontal,
})
end
@ -701,7 +706,7 @@ local function new(config)
local _button_positions = list2map(button_positions)
for _, pos in pairs(positions) do
local tb = awful.titlebar(c, {size = border_width, position = pos, bg = "#00000000"})
local tb = awful.titlebar(c, { size = border_width, position = pos, bg = "#00000000" })
local btn_layout
if layout == "fixed" then
@ -713,16 +718,18 @@ local function new(config)
if _button_positions[pos] then
-- border with buttons
local button_layout = wibox.widget.base.make_widget_declarative(
{id = "button_layout", spacing_widget = spacing_widget, layout = btn_layout})
local button_layout = wibox.widget.base.make_widget_declarative({
id = "button_layout",
spacing_widget = spacing_widget,
layout = btn_layout,
})
local titlebar_widget
if layout == "fixed" then
if ori(pos) == "v" then
local expander = align_vertical == "center" and border_expander_center or border_expander
titlebar_widget = wibox.widget.base.make_widget_declarative(
{
titlebar_widget = wibox.widget.base.make_widget_declarative({
align_vertical == "top" and button_layout or expander,
align_vertical == "center" and button_layout or expander,
align_vertical == "bottom" and button_layout or expander,
@ -731,8 +738,7 @@ local function new(config)
})
else
local expander = align_horizontal == "center" and border_expander_center or border_expander
titlebar_widget = wibox.widget.base.make_widget_declarative(
{
titlebar_widget = wibox.widget.base.make_widget_declarative({
align_horizontal == "left" and button_layout or expander,
align_horizontal == "center" and button_layout or expander,
align_horizontal == "right" and button_layout or expander,
@ -743,19 +749,22 @@ local function new(config)
end
if layout == "ratio" then
titlebar_widget = wibox.widget.base.make_widget_declarative(
{button_layout, id = "titlebar_widget", bg = color_normal, widget = wibox.container.background})
titlebar_widget = wibox.widget.base.make_widget_declarative({
button_layout,
id = "titlebar_widget",
bg = color_normal,
widget = wibox.container.background,
})
end
tb:setup{
tb:setup({
titlebar_widget,
bg = "#00000000",
shape = rounded_corner and rounded_corner_shape(rounded_corner, pos) or nil,
widget = wibox.container.background(),
}
})
local ratio_button_layout = wibox.widget.base.make_widget_declarative(
{
local ratio_button_layout = wibox.widget.base.make_widget_declarative({
homogeneous = layout == "ratio" and true or false,
expand = true,
layout = ori(pos) == "h" and wibox.layout.grid.horizontal or wibox.layout.grid.vertical,
@ -776,9 +785,8 @@ local function new(config)
b.action = cfg["button_" .. btn .. "_function"] or nil
end
local button_widget = wibox.widget.base.make_widget_declarative(
{
{widget = wibox.container.margin},
local button_widget = wibox.widget.base.make_widget_declarative({
{ widget = wibox.container.margin },
id = b.name,
forced_width = ori(pos) == "h" and b.button_size or nil,
forced_height = ori(pos) == "v" and b.button_size or nil,
@ -787,13 +795,13 @@ local function new(config)
})
if show_button_tooltips then
awful.tooltip {
objects = {button_widget},
awful.tooltip({
objects = { button_widget },
align = "top_left",
timer_function = function()
return b.name
end,
}
})
end
button_widget:connect_signal("mouse::enter", function()
@ -852,15 +860,22 @@ local function new(config)
table.insert(ratio_children, border_bg)
button_layout:set_children(ratio_children)
if (ori(pos) == "h" and align_horizontal == "left") or (ori(pos) == "v" and align_vertical == "top") then
if
(ori(pos) == "h" and align_horizontal == "left")
or (ori(pos) == "v" and align_vertical == "top")
then
button_layout:ajust_ratio(2, 0, button_ratio, 1.0 - button_ratio)
end
if (ori(pos) == "h" and align_horizontal == "right") or
(ori(pos) == "v" and align_vertical == "bottom") then
if
(ori(pos) == "h" and align_horizontal == "right")
or (ori(pos) == "v" and align_vertical == "bottom")
then
button_layout:ajust_ratio(2, 1.0 - button_ratio, button_ratio, 0)
end
if (ori(pos) == "h" and align_horizontal == "center") or
(ori(pos) == "v" and align_vertical == "center") then
if
(ori(pos) == "h" and align_horizontal == "center")
or (ori(pos) == "v" and align_vertical == "center")
then
local side_ratio = (1.0 - button_ratio) / 2
button_layout:ajust_ratio(2, side_ratio, button_ratio, side_ratio)
end
@ -870,23 +885,23 @@ local function new(config)
button_layout:set_children(list_of_buttons)
end
else
tb:setup{
tb:setup({
border_bg,
bg = "#00000000",
shape = rounded_corner and rounded_corner_shape(rounded_corner, pos) or nil,
widget = wibox.container.background,
}
})
end
end
-- show client title tooltip on border hover
if show_title_tooltip then
awful.tooltip {
objects = {border_bg},
awful.tooltip({
objects = { border_bg },
timer_function = function()
return c.name
end,
}
})
end
local update_border = function()