WIP: Somewm migration

This commit is contained in:
Alexander Gehrke 2026-08-12 18:09:07 +02:00
parent f5caff6684
commit ce56320097
17 changed files with 342 additions and 238 deletions

View file

@ -10,23 +10,23 @@ local gears = require("gears")
local wlist = {}
local mytaglist = {}
mytaglist.buttons = awful.util.table.join(
awful.button({ }, 1, awful.tag.viewonly),
awful.button({ modkey }, 1, awful.client.movetotag),
awful.button({ }, 3, awful.tag.viewtoggle),
awful.button({ modkey }, 3, awful.client.toggletag),
awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
mytaglist.buttons = gears.table.join(
awful.button({}, 1, awful.tag.viewonly),
awful.button({ modkey }, 1, awful.client.movetotag),
awful.button({}, 3, awful.tag.viewtoggle),
awful.button({ modkey }, 3, awful.client.toggletag),
awful.button({}, 4, function(t)
awful.tag.viewnext(t.screen)
end),
awful.button({}, 5, function(t)
awful.tag.viewprev(t.screen)
end)
)
local function percentage_overlay(p, color, prefix, suffix)
return (
'<span color="%s">%s%d%%%s</span>'
):format(color, prefix or "", p, suffix or "")
return ('<span color="%s">%s%d%%%s</span>'):format(color, prefix or "", p, suffix or "")
end
local function add_bar(s, position, direction, first, second)
local newbar = awful.wibar({
position = position,
@ -35,29 +35,33 @@ local function add_bar(s, position, direction, first, second)
width = math.floor(s.dpi / 5),
})
newbar:setup {
newbar:setup({
{
first,
nil,
second,
layout = wibox.layout.align.horizontal
layout = wibox.layout.align.horizontal,
},
direction = direction,
widget = wibox.container.rotate
}
widget = wibox.container.rotate,
})
return newbar
end
function widgets.setup(s)
return {
left = function(bottom, top) s.leftwibar = add_bar(s, "left", "east", bottom, top) end,
right = function(top, bottom) s.rightwibar = add_bar(s, "right", "west", top, bottom) end
left = function(bottom, top)
s.leftwibar = add_bar(s, "left", "east", bottom, top)
end,
right = function(top, bottom)
s.rightwibar = add_bar(s, "right", "west", top, bottom)
end,
}
end
function widgets.mail(mailboxes, notify_pos, title)
local widget = wibox.widget.textbox()
local bg = wibox.widget { widget, widget = wibox.container.background }
local bg = wibox.widget({ widget, widget = wibox.container.background })
local callback = function(widget, args)
if args[1] > 0 then
@ -71,7 +75,7 @@ function widgets.mail(mailboxes, notify_pos, title)
else
bg.visible = false
end
return "⬓⬓ Unread "..args[2].." / New "..args[1].. " "
return "⬓⬓ Unread " .. args[2] .. " / New " .. args[1] .. " "
end
vicious.register(widget, vicious.widgets.mdir, callback, 60, mailboxes)
table.insert(wlist, widget)
@ -81,23 +85,29 @@ end
function widgets.layout(s)
local mylayoutbox = awful.widget.layoutbox(s)
mylayoutbox:buttons(awful.util.table.join(
awful.button({ }, 1, function () awful.layout.inc( 1) end),
awful.button({ }, 3, function () awful.layout.inc(-1) end),
awful.button({ }, 4, function () awful.layout.inc( 1) end),
awful.button({ }, 5, function () awful.layout.inc(-1) end)
mylayoutbox:buttons(gears.table.join(
awful.button({}, 1, function()
awful.layout.inc(1)
end),
awful.button({}, 3, function()
awful.layout.inc(-1)
end),
awful.button({}, 4, function()
awful.layout.inc(1)
end),
awful.button({}, 5, function()
awful.layout.inc(-1)
end)
))
return mylayoutbox
end
function widgets.screennum(s)
return wibox.widget.textbox("Screen " .. s.index)
return wibox.widget.textbox("Screen " .. s.index)
end
function widgets.taglist(s)
return awful.widget.taglist(
s, awful.widget.taglist.filter.noempty, mytaglist.buttons
)
return awful.widget.taglist(s, awful.widget.taglist.filter.noempty, mytaglist.buttons)
end
function widgets.systray(s)
@ -109,18 +119,19 @@ function widgets.systray(s)
end
local function graph_label(graph, label, rotation, fontsize)
return wibox.widget {
return wibox.widget({
{
{
text = label,
font = beautiful.fontface and (beautiful.fontface .. " " .. (fontsize or 7)) or beautiful.font,
widget = wibox.widget.textbox
widget = wibox.widget.textbox,
},
direction = rotation or 'east', widget = wibox.container.rotate
direction = rotation or "east",
widget = wibox.container.rotate,
},
graph,
layout = wibox.layout.fixed.horizontal
}
layout = wibox.layout.fixed.horizontal,
})
end
function widgets.cpu(s)
@ -133,16 +144,16 @@ function widgets.ram(s)
end
function widgets.graph(s, label, viciouswidget, viciousformat, interval)
local graph = wibox.widget {
local graph = wibox.widget({
width = 60,
background_color = beautiful.bg_focus,
color = "linear:0,0:0,20:0,#FF0000:0.3,#FFFF00:0.6," .. beautiful.fg_normal,
widget = wibox.widget.graph,
}
local overlay = wibox.widget {
align = 'center',
widget = wibox.widget.textbox
}
})
local overlay = wibox.widget({
align = "center",
widget = wibox.widget.textbox,
})
local callback = function(widget, args)
overlay.markup = percentage_overlay(args[1], beautiful.bg_normal)
return args[1]
@ -153,39 +164,34 @@ function widgets.graph(s, label, viciouswidget, viciousformat, interval)
return {
layout = awful.widget.only_on_screen,
screen = s and s.index or "primary",
graph_label(
{
graph,
overlay,
layout = wibox.layout.stack
},
label,
nil,
7
)
graph_label({
graph,
overlay,
layout = wibox.layout.stack,
}, label, nil, 7),
}
end
local function bar_with_overlay(fg, bg, width, height)
local progress = wibox.widget {
local progress = wibox.widget({
max_value = 1,
color = fg,
background_color = bg,
forced_width = width,
forced_height = height,
widget = wibox.widget.progressbar,
}
widget = wibox.widget.progressbar,
})
progress.overlay = wibox.widget {
progress.overlay = wibox.widget({
font = beautiful.fontface and (beautiful.fontface .. " " .. 7) or beautiful.font,
align = 'center',
widget = wibox.widget.textbox
}
align = "center",
widget = wibox.widget.textbox,
})
return {
progress,
progress.overlay,
layout = wibox.layout.stack
layout = wibox.layout.stack,
}
end
@ -193,12 +199,9 @@ end
function widgets.battery(s)
local bat1 = bar_with_overlay(beautiful.fg_focus, beautiful.bg_focus, 100, math.floor(s.dpi / 10))
local combined_bats = graph_label(
bat1,
"BAT"
)
local combined_bats = graph_label(bat1, "BAT")
local callback = function (widget, args)
local callback = function(widget, args)
if args[2] == 0 then
combined_bats:set_visible(false)
return ""
@ -209,9 +212,7 @@ function widgets.battery(s)
else
widget.background_color = beautiful.bg_focus
end
widget.overlay.markup = percentage_overlay(
args[2], beautiful.bg_normal, args[1] .. " "
)
widget.overlay.markup = percentage_overlay(args[2], beautiful.bg_normal, args[1] .. " ")
return args[2]
end
end
@ -223,26 +224,33 @@ function widgets.battery(s)
end
local tasklist_buttons = gears.table.join(
awful.button({ }, 1, function(c)
if c == client.focus then
c.minimized = true
else
c:emit_signal("request::activate", "tasklist", {raise = true})
end
end),
awful.button({ }, 3, function() awful.menu.client_list({ theme = { width = 250 } }) end),
awful.button({ }, 4, function() awful.client.focus.byidx(1) end),
awful.button({ }, 5, function() awful.client.focus.byidx(-1) end))
awful.button({}, 1, function(c)
if c == client.focus then
c.minimized = true
else
c:emit_signal("request::activate", "tasklist", { raise = true })
end
end),
awful.button({}, 3, function()
awful.menu.client_list({ theme = { width = 250 } })
end),
awful.button({}, 4, function()
awful.client.focus.byidx(1)
end),
awful.button({}, 5, function()
awful.client.focus.byidx(-1)
end)
)
-- display a taskbar
-- `when` is a function taking the current screen, that is called on the given signal, and should return true if the
-- taskbar should be shown.
-- If signal and when are not given, the taskbar will be visible on tags with "max" layout
function widgets.dynamic_taskbar(s, signal, when)
s.mytasklist = awful.widget.tasklist {
screen = s,
filter = awful.widget.tasklist.filter.currenttags,
style = {
s.mytasklist = awful.widget.tasklist({
screen = s,
filter = awful.widget.tasklist.filter.currenttags,
style = {
shape_border_width = 2,
bg_focus = beautiful.bg_focus,
shape_border_color = beautiful.border_focus,
@ -253,32 +261,32 @@ function widgets.dynamic_taskbar(s, signal, when)
{
{
{
{ id = 'icon_role',
widget = wibox.widget.imagebox, },
{ id = "icon_role", widget = wibox.widget.imagebox },
margins = 2,
widget = wibox.container.margin,
widget = wibox.container.margin,
},
{ id = 'text_role',
widget = wibox.widget.textbox, },
{ id = "text_role", widget = wibox.widget.textbox },
layout = wibox.layout.fixed.horizontal,
},
left = 20,
left = 20,
right = 15,
widget = wibox.container.margin
widget = wibox.container.margin,
},
id = 'background_role',
id = "background_role",
widget = wibox.container.background,
},
}
})
s.taskbar = awful.wibar({
position = "top",
screen = s,
opacity = 0.8,
height = math.floor(s.dpi / 4),
widget = s.mytasklist
widget = s.mytasklist,
})
local condition = when or function(s) return awful.layout.get(s).name == "max" end
local condition = when or function(s)
return awful.layout.get(s).name == "max"
end
s:connect_signal(signal or "tag::history::update", function()
s.taskbar.visible = condition(s)
end)
@ -290,4 +298,8 @@ function widgets.update(name)
vicious.force(wlist)
end
return setmetatable(widgets, { __call = function(_, ...) return widgets.setup(...) end })
return setmetatable(widgets, {
__call = function(_, ...)
return widgets.setup(...)
end,
})