Auto: format source code

This commit is contained in:
github-actions[bot] 2021-09-07 20:41:10 +00:00
parent ae0a999e1b
commit 1727f1d9f3
2 changed files with 224 additions and 132 deletions

View File

@ -182,12 +182,9 @@ local simple_schedule_object = nil
-- @tparam[opt=`setters.simple`] function args.wallpaper_set_function The set_function used by default -- @tparam[opt=`setters.simple`] function args.wallpaper_set_function The set_function used by default
function setters.simple_schedule(args) function setters.simple_schedule(args)
local function update_wallpaper() local function update_wallpaper()
local fake_args = gears.table.join( local fake_args = gears.table.join(args, {
args, wallpaper = args.wallpaper[simple_schedule_object.closest_lower_time],
{ })
wallpaper = args.wallpaper[simple_schedule_object.closest_lower_time],
}
)
simple_schedule_object.schedule_set_function(fake_args) simple_schedule_object.schedule_set_function(fake_args)
end end
if not simple_schedule_object then if not simple_schedule_object then

View File

@ -12,8 +12,16 @@ local window_switcher_grabber
local get_num_clients = function() local get_num_clients = function()
local minimized_clients_in_tag = 0 local minimized_clients_in_tag = 0
local matcher = function (c) local matcher = function(c)
return awful.rules.match(c, { minimized = true, skip_taskbar = false, hidden = false, first_tag = awful.screen.focused().selected_tag }) return awful.rules.match(
c,
{
minimized = true,
skip_taskbar = false,
hidden = false,
first_tag = awful.screen.focused().selected_tag,
}
)
end end
for c in awful.client.iterate(matcher) do for c in awful.client.iterate(matcher) do
minimized_clients_in_tag = minimized_clients_in_tag + 1 minimized_clients_in_tag = minimized_clients_in_tag + 1
@ -28,7 +36,9 @@ local window_switcher_hide = function(window_switcher_box)
awful.client.focus.history.add(window_switcher_last_client) awful.client.focus.history.add(window_switcher_last_client)
-- Raise client that was focused originally -- Raise client that was focused originally
-- Then raise last focused client -- Then raise last focused client
if window_switcher_first_client and window_switcher_first_client.valid then if
window_switcher_first_client and window_switcher_first_client.valid
then
window_switcher_first_client:raise() window_switcher_first_client:raise()
window_switcher_last_client:raise() window_switcher_last_client:raise()
end end
@ -51,84 +61,122 @@ local window_switcher_hide = function(window_switcher_box)
window_switcher_box.visible = false window_switcher_box.visible = false
end end
local function draw_widget(type, background, border_width, border_radius, border_color, local function draw_widget(
clients_spacing, client_icon_horizontal_spacing, client_width, client_height, type,
client_margins, thumbnail_margins, thumbnail_scale, name_margins, name_valign, background,
name_forced_width, name_font, name_normal_color, name_focus_color, border_width,
icon_valign, icon_width, mouse_keys) border_radius,
border_color,
clients_spacing,
client_icon_horizontal_spacing,
client_width,
client_height,
client_margins,
thumbnail_margins,
thumbnail_scale,
name_margins,
name_valign,
name_forced_width,
name_font,
name_normal_color,
name_focus_color,
icon_valign,
icon_width,
mouse_keys
)
local tasklist_widget = type == "thumbnail" local tasklist_widget = type == "thumbnail"
and and awful.widget.tasklist({
awful.widget.tasklist { screen = awful.screen.focused(),
screen = awful.screen.focused(), filter = awful.widget.tasklist.filter.currenttags,
filter = awful.widget.tasklist.filter.currenttags, buttons = mouse_keys,
buttons = mouse_keys, style = {
style = { font = name_font, fg_normal = name_normal_color, fg_focus = name_focus_color }, font = name_font,
layout = { layout = wibox.layout.flex.horizontal, spacing = clients_spacing }, fg_normal = name_normal_color,
widget_template = fg_focus = name_focus_color,
{ },
widget = wibox.container.background, layout = {
id = "bg_role", layout = wibox.layout.flex.horizontal,
forced_width = client_width, spacing = clients_spacing,
forced_height = client_height, },
create_callback = function(self, c, _, __) widget_template = {
local content = gears.surface(c.content) widget = wibox.container.background,
local cr = cairo.Context(content) id = "bg_role",
local x, y, w, h = cr:clip_extents() forced_width = client_width,
local img = cairo.ImageSurface.create(cairo.Format.ARGB32, w - x, h - y) forced_height = client_height,
cr = cairo.Context(img) create_callback = function(self, c, _, __)
cr:set_source_surface(content, 0, 0) local content = gears.surface(c.content)
cr.operator = cairo.Operator.SOURCE local cr = cairo.Context(content)
cr:paint() local x, y, w, h = cr:clip_extents()
self:get_children_by_id("thumbnail")[1].image = gears.surface.load(img) local img = cairo.ImageSurface.create(
end, cairo.Format.ARGB32,
{ w - x,
{ h - y
{ )
horizontal_fit_policy = thumbnail_scale == true and "fit" or "auto", cr = cairo.Context(img)
vertical_fit_policy = thumbnail_scale == true and "fit" or "auto", cr:set_source_surface(content, 0, 0)
id = "thumbnail", cr.operator = cairo.Operator.SOURCE
widget = wibox.widget.imagebox cr:paint()
}, self:get_children_by_id("thumbnail")[1].image =
margins = thumbnail_margins, gears.surface.load(
widget = wibox.container.margin img
}, )
end,
{ {
{ {
{ {
id = "icon_role", horizontal_fit_policy = thumbnail_scale == true
widget = wibox.widget.imagebox and "fit"
or "auto",
vertical_fit_policy = thumbnail_scale == true
and "fit"
or "auto",
id = "thumbnail",
widget = wibox.widget.imagebox,
}, },
forced_width = icon_width, margins = thumbnail_margins,
valign = icon_valign, widget = wibox.container.margin,
widget = wibox.container.place
}, },
{ {
{ {
forced_width = name_forced_width, {
valign = name_valign, id = "icon_role",
id = "text_role", widget = wibox.widget.imagebox,
widget = wibox.widget.textbox },
forced_width = icon_width,
valign = icon_valign,
widget = wibox.container.place,
}, },
margins = name_margins, {
widget = wibox.container.margin {
forced_width = name_forced_width,
valign = name_valign,
id = "text_role",
widget = wibox.widget.textbox,
},
margins = name_margins,
widget = wibox.container.margin,
},
spacing = client_icon_horizontal_spacing,
layout = wibox.layout.fixed.horizontal,
}, },
spacing = client_icon_horizontal_spacing, layout = wibox.layout.flex.vertical,
layout = wibox.layout.fixed.horizontal
}, },
layout = wibox.layout.flex.vertical },
} })
} or awful.widget.tasklist({
}
or
awful.widget.tasklist {
screen = awful.screen.focused(), screen = awful.screen.focused(),
filter = awful.widget.tasklist.filter.currenttags, filter = awful.widget.tasklist.filter.currenttags,
buttons = mouse_keys, buttons = mouse_keys,
style = { font = name_font, fg_normal = name_normal_color, fg_focus = name_focus_color }, style = {
layout = { layout = wibox.layout.fixed.vertical, spacing = clients_spacing }, font = name_font,
widget_template = fg_normal = name_normal_color,
{ fg_focus = name_focus_color,
},
layout = {
layout = wibox.layout.fixed.vertical,
spacing = clients_spacing,
},
widget_template = {
widget = wibox.container.background, widget = wibox.container.background,
id = "bg_role", id = "bg_role",
forced_width = client_width, forced_width = client_width,
@ -136,42 +184,41 @@ local function draw_widget(type, background, border_width, border_radius, border
{ {
{ {
{ {
id = "icon_role", id = "icon_role",
widget = wibox.widget.imagebox widget = wibox.widget.imagebox,
}, },
forced_width = icon_width, forced_width = icon_width,
valign = icon_valign, valign = icon_valign,
widget = wibox.container.place widget = wibox.container.place,
}, },
{ {
{ {
forced_width = name_forced_width, forced_width = name_forced_width,
valign = name_valign, valign = name_valign,
id = "text_role", id = "text_role",
widget = wibox.widget.textbox widget = wibox.widget.textbox,
}, },
margins = name_margins, margins = name_margins,
widget = wibox.container.margin widget = wibox.container.margin,
}, },
spacing = client_icon_horizontal_spacing, spacing = client_icon_horizontal_spacing,
layout = wibox.layout.fixed.horizontal layout = wibox.layout.fixed.horizontal,
}, },
}, },
} })
return wibox.widget return wibox.widget({
{
{ {
tasklist_widget, tasklist_widget,
margins = client_margins, margins = client_margins,
widget = wibox.container.margin widget = wibox.container.margin,
}, },
shape_border_width = border_width, shape_border_width = border_width,
shape_border_color = border_color, shape_border_color = border_color,
bg = background, bg = background,
shape = helpers.shape.rrect(border_radius), shape = helpers.shape.rrect(border_radius),
widget = wibox.container.background widget = wibox.container.background,
} })
end end
local enable = function(opts) local enable = function(opts)
@ -180,22 +227,31 @@ local enable = function(opts)
local type = opts.type or "thumbnail" local type = opts.type or "thumbnail"
local background = beautiful.window_switcher_widget_bg or "#000000" local background = beautiful.window_switcher_widget_bg or "#000000"
local border_width = beautiful.window_switcher_widget_border_width or dpi(3) local border_width = beautiful.window_switcher_widget_border_width or dpi(3)
local border_radius = beautiful.window_switcher_widget_border_radius or dpi(0) local border_radius = beautiful.window_switcher_widget_border_radius
local border_color = beautiful.window_switcher_widget_border_color or "#ffffff" or dpi(0)
local border_color = beautiful.window_switcher_widget_border_color
or "#ffffff"
local clients_spacing = beautiful.window_switcher_clients_spacing or dpi(20) local clients_spacing = beautiful.window_switcher_clients_spacing or dpi(20)
local client_icon_horizontal_spacing = beautiful.window_switcher_client_icon_horizontal_spacing or dpi(5) local client_icon_horizontal_spacing = beautiful.window_switcher_client_icon_horizontal_spacing
local client_width = beautiful.window_switcher_client_width or dpi(type == "thumbnail" and 150 or 500) or dpi(5)
local client_height = beautiful.window_switcher_client_height or dpi(type == "thumbnail" and 250 or 50) local client_width = beautiful.window_switcher_client_width
or dpi(type == "thumbnail" and 150 or 500)
local client_height = beautiful.window_switcher_client_height
or dpi(type == "thumbnail" and 250 or 50)
local client_margins = beautiful.window_switcher_client_margins or dpi(10) local client_margins = beautiful.window_switcher_client_margins or dpi(10)
local thumbnail_margins = beautiful.window_switcher_thumbnail_margins or dpi(5) local thumbnail_margins = beautiful.window_switcher_thumbnail_margins
or dpi(5)
local thumbnail_scale = beautiful.thumbnail_scale or false local thumbnail_scale = beautiful.thumbnail_scale or false
local name_margins = beautiful.window_switcher_name_margins or dpi(10) local name_margins = beautiful.window_switcher_name_margins or dpi(10)
local name_valign = beautiful.window_switcher_name_valign or "center" local name_valign = beautiful.window_switcher_name_valign or "center"
local name_forced_width = beautiful.window_switcher_name_forced_width or dpi(type == "thumbnail" and 200 or 550) local name_forced_width = beautiful.window_switcher_name_forced_width
or dpi(type == "thumbnail" and 200 or 550)
local name_font = beautiful.window_switcher_name_font or beautiful.font local name_font = beautiful.window_switcher_name_font or beautiful.font
local name_normal_color = beautiful.window_switcher_name_normal_color or "#FFFFFF" local name_normal_color = beautiful.window_switcher_name_normal_color
local name_focus_color = beautiful.window_switcher_name_focus_color or "#FF0000" or "#FFFFFF"
local icon_valign = beautiful.window_switcher_icon_valign or "center" local name_focus_color = beautiful.window_switcher_name_focus_color
or "#FF0000"
local icon_valign = beautiful.window_switcher_icon_valign or "center"
local icon_width = beautiful.window_switcher_icon_width or dpi(40) local icon_width = beautiful.window_switcher_icon_width or dpi(40)
local hide_window_switcher_key = opts.hide_window_switcher_key or "Escape" local hide_window_switcher_key = opts.hide_window_switcher_key or "Escape"
@ -216,74 +272,91 @@ local enable = function(opts)
local scroll_previous_key = opts.scroll_previous_key or 4 local scroll_previous_key = opts.scroll_previous_key or 4
local scroll_next_key = opts.scroll_next_key or 5 local scroll_next_key = opts.scroll_next_key or 5
local window_switcher_box = awful.popup local window_switcher_box = awful.popup({
({
bg = "#00000000", bg = "#00000000",
visible = false, visible = false,
ontop = true, ontop = true,
placement = awful.placement.centered, placement = awful.placement.centered,
screen = awful.screen.focused(), screen = awful.screen.focused(),
widget = wibox.container.background, -- A dummy widget to make awful.popup not scream widget = wibox.container.background, -- A dummy widget to make awful.popup not scream
widget = widget = {
{
{ {
draw_widget(), draw_widget(),
margins = client_margins, margins = client_margins,
widget = wibox.container.margin widget = wibox.container.margin,
}, },
shape_border_width = border_width, shape_border_width = border_width,
shape_border_color = border_color, shape_border_color = border_color,
bg = background, bg = background,
shape = helpers.shape.rrect(border_radius), shape = helpers.shape.rrect(border_radius),
widget = wibox.container.background widget = wibox.container.background,
} },
}) })
local mouse_keys = gears.table.join local mouse_keys = gears.table.join(
( awful.button({
awful.button
{
modifiers = { "Any" }, modifiers = { "Any" },
button = select_client_key, button = select_client_key,
on_press = function(c) on_press = function(c)
client.focus = c client.focus = c
end, end,
}, }),
awful.button awful.button({
{
modifiers = { "Any" }, modifiers = { "Any" },
button = scroll_previous_key, button = scroll_previous_key,
on_press = function() on_press = function()
awful.client.focus.byidx(-1) awful.client.focus.byidx(-1)
end, end,
}, }),
awful.button awful.button({
{
modifiers = { "Any" }, modifiers = { "Any" },
button = scroll_next_key, button = scroll_next_key,
on_press = function() on_press = function()
awful.client.focus.byidx(1) awful.client.focus.byidx(1)
end, end,
} })
) )
local keyboard_keys = local keyboard_keys = {
{ [hide_window_switcher_key] = function()
[hide_window_switcher_key] = function() window_switcher_hide(window_switcher_box) end, window_switcher_hide(window_switcher_box)
end,
[minimize_key] = function() if client.focus then client.focus.minimized = true end end, [minimize_key] = function()
[unminimize_key] = function() if awful.client.restore() then client.focus = awful.client.restore() end end, if client.focus then
[kill_client_key] = function() if client.focus then client.focus:kill() end end, client.focus.minimized = true
end
end,
[unminimize_key] = function()
if awful.client.restore() then
client.focus = awful.client.restore()
end
end,
[kill_client_key] = function()
if client.focus then
client.focus:kill()
end
end,
[cycle_key] = function() awful.client.focus.byidx(1) end, [cycle_key] = function()
awful.client.focus.byidx(1)
end,
[previous_key] = function() awful.client.focus.byidx(1) end, [previous_key] = function()
[next_key] = function() awful.client.focus.byidx(-1) end, awful.client.focus.byidx(1)
end,
[next_key] = function()
awful.client.focus.byidx(-1)
end,
[vim_previous_key] = function() awful.client.focus.byidx(1) end, [vim_previous_key] = function()
[vim_next_key] = function() awful.client.focus.byidx(-1) end, awful.client.focus.byidx(1)
end,
[vim_next_key] = function()
awful.client.focus.byidx(-1)
end,
} }
window_switcher_box:connect_signal("property::width", function() window_switcher_box:connect_signal("property::width", function()
@ -332,7 +405,11 @@ local enable = function(opts)
-- Hide if the modifier was released -- Hide if the modifier was released
-- We try to match Super or Alt or Control since we do not know which keybind is -- We try to match Super or Alt or Control since we do not know which keybind is
-- used to activate the window switcher (the keybind is set by the user in keys.lua) -- used to activate the window switcher (the keybind is set by the user in keys.lua)
if key:match("Super") or key:match("Alt") or key:match("Control") then if
key:match("Super")
or key:match("Alt")
or key:match("Control")
then
window_switcher_hide(window_switcher_box) window_switcher_hide(window_switcher_box)
end end
-- Do nothing -- Do nothing
@ -345,13 +422,31 @@ local enable = function(opts)
end end
end) end)
window_switcher_box.widget = draw_widget(type, background, border_width, window_switcher_box.widget = draw_widget(
border_radius, border_color, clients_spacing, client_icon_horizontal_spacing, type,
client_width, client_height, client_margins, thumbnail_margins, thumbnail_scale, background,
name_margins, name_valign, name_forced_width, name_font, name_normal_color, border_width,
name_focus_color, icon_valign, icon_width, mouse_keys) border_radius,
border_color,
clients_spacing,
client_icon_horizontal_spacing,
client_width,
client_height,
client_margins,
thumbnail_margins,
thumbnail_scale,
name_margins,
name_valign,
name_forced_width,
name_font,
name_normal_color,
name_focus_color,
icon_valign,
icon_width,
mouse_keys
)
window_switcher_box.visible = true window_switcher_box.visible = true
end) end)
end end
return {enable = enable} return { enable = enable }