dotfiles/awesome/theme.lua

432 lines
14 KiB
Lua
Raw Normal View History

2022-12-24 20:58:57 +00:00
--[[
Multicolor Awesome WM theme 2.0
github.com/lcpz
--]]
2023-01-21 15:34:13 +00:00
local gears = require('gears')
local lain = require('lain')
local awful = require('awful')
local wibox = require('wibox')
local dpi = require('beautiful.xresources').apply_dpi
2023-01-25 19:10:58 +00:00
local naughty = require('naughty')
local settings = (function()
local status, settings = pcall(function()
return dofile(os.getenv('HOME') .. '/.config/awesome/settings.lua')
end)
if status then
return settings
else
naughty.notify({
preset = naughty.config.presets.critical,
title = 'Error while parsing settings!',
text = settings,
})
return {}
end
end)()
2022-12-24 20:58:57 +00:00
local os = os
local my_table = awful.util.table or gears.table -- 4.{0,1} compatibility
2023-01-21 15:34:13 +00:00
local theme = {}
theme.confdir = os.getenv('HOME') .. '/.config/awesome/'
2023-01-25 19:10:58 +00:00
theme.wallpaper = os.getenv('HOME') .. '/.config/awesome/' .. (settings['wallpaper'] or 'wall.png')
2023-01-21 15:34:13 +00:00
theme.font = 'Terminus 8'
theme.menu_bg_normal = '#000000'
theme.menu_bg_focus = '#000000'
theme.bg_normal = '#000000'
theme.bg_focus = '#000000'
theme.bg_urgent = '#000000'
theme.fg_normal = '#aaaaaa'
theme.fg_focus = '#ff8c00'
theme.fg_urgent = '#af1d18'
theme.fg_minimize = '#ffffff'
theme.border_width = dpi(1)
theme.border_normal = '#1c2022'
theme.border_focus = '#606060'
theme.border_marked = '#3ca4d8'
theme.menu_border_width = 0
theme.menu_width = dpi(130)
theme.menu_submenu_icon = theme.confdir .. '/icons/submenu.png'
theme.menu_fg_normal = '#aaaaaa'
theme.menu_fg_focus = '#ff8c00'
theme.menu_bg_normal = '#050505dd'
theme.menu_bg_focus = '#050505dd'
theme.widget_cpu = theme.confdir .. '/icons/info/cpu.png'
theme.widget_mem = theme.confdir .. '/icons/info/mem.png'
theme.widget_netdown = theme.confdir .. '/icons/info/download.png'
theme.widget_netup = theme.confdir .. '/icons/info/upload.png'
theme.widget_bat_charge = theme.confdir .. '/icons/info/batcharge.png'
theme.widget_bat_empty = theme.confdir .. '/icons/info/batempty.png'
theme.widget_bat_low = theme.confdir .. '/icons/info/batlow.png'
theme.widget_bat_mid = theme.confdir .. '/icons/info/batmid.png'
theme.widget_bat_high = theme.confdir .. '/icons/info/bathigh.png'
theme.widget_bat_full = theme.confdir .. '/icons/info/batfull.png'
theme.widget_vol_mute = theme.confdir .. '/icons/info/volmute.png'
theme.widget_vol_low = theme.confdir .. '/icons/info/vollow.png'
theme.widget_vol_high = theme.confdir .. '/icons/info/volhigh.png'
2023-01-30 14:10:44 +00:00
theme.taglist_fg_focus = '#000000'
2023-01-30 14:09:45 +00:00
theme.taglist_bg_focus = '#b3b3b3'
theme.taglist_squares_unsel = theme.confdir .. '/icons/usedtag.png'
theme.taglist_squares_resize = true
2023-01-21 15:34:13 +00:00
theme.tasklist_plain_task_name = true
theme.tasklist_disable_icon = true
theme.useless_gap = 0
theme.layout_tile = theme.confdir .. '/icons/tile.png'
theme.layout_tilegaps = theme.confdir .. '/icons/tilegaps.png'
theme.layout_tileleft = theme.confdir .. '/icons/tileleft.png'
theme.layout_tilebottom = theme.confdir .. '/icons/tilebottom.png'
theme.layout_tiletop = theme.confdir .. '/icons/tiletop.png'
theme.layout_fairv = theme.confdir .. '/icons/fairv.png'
theme.layout_fairh = theme.confdir .. '/icons/fairh.png'
theme.layout_spiral = theme.confdir .. '/icons/spiral.png'
theme.layout_dwindle = theme.confdir .. '/icons/dwindle.png'
theme.layout_max = theme.confdir .. '/icons/max.png'
theme.layout_fullscreen = theme.confdir .. '/icons/fullscreen.png'
theme.layout_magnifier = theme.confdir .. '/icons/magnifier.png'
theme.layout_floating = theme.confdir .. '/icons/floating.png'
theme.titlebar_close_button_normal = theme.confdir .. '/icons/titlebar/close_normal.png'
theme.titlebar_close_button_focus = theme.confdir .. '/icons/titlebar/close_focus.png'
theme.titlebar_minimize_button_normal = theme.confdir .. '/icons/titlebar/minimize_normal.png'
theme.titlebar_minimize_button_focus = theme.confdir .. '/icons/titlebar/minimize_focus.png'
theme.titlebar_ontop_button_normal_inactive = theme.confdir .. '/icons/titlebar/ontop_normal_inactive.png'
theme.titlebar_ontop_button_focus_inactive = theme.confdir .. '/icons/titlebar/ontop_focus_inactive.png'
theme.titlebar_ontop_button_normal_active = theme.confdir .. '/icons/titlebar/ontop_normal_active.png'
theme.titlebar_ontop_button_focus_active = theme.confdir .. '/icons/titlebar/ontop_focus_active.png'
theme.titlebar_sticky_button_normal_inactive = theme.confdir .. '/icons/titlebar/sticky_normal_inactive.png'
theme.titlebar_sticky_button_focus_inactive = theme.confdir .. '/icons/titlebar/sticky_focus_inactive.png'
theme.titlebar_sticky_button_normal_active = theme.confdir .. '/icons/titlebar/sticky_normal_active.png'
theme.titlebar_sticky_button_focus_active = theme.confdir .. '/icons/titlebar/sticky_focus_active.png'
theme.titlebar_floating_button_normal_inactive = theme.confdir .. '/icons/titlebar/floating_normal_inactive.png'
theme.titlebar_floating_button_focus_inactive = theme.confdir .. '/icons/titlebar/floating_focus_inactive.png'
theme.titlebar_floating_button_normal_active = theme.confdir .. '/icons/titlebar/floating_normal_active.png'
theme.titlebar_floating_button_focus_active = theme.confdir .. '/icons/titlebar/floating_focus_active.png'
theme.titlebar_maximized_button_normal_inactive = theme.confdir .. '/icons/titlebar/maximized_normal_inactive.png'
theme.titlebar_maximized_button_focus_inactive = theme.confdir .. '/icons/titlebar/maximized_focus_inactive.png'
theme.titlebar_maximized_button_normal_active = theme.confdir .. '/icons/titlebar/maximized_normal_active.png'
theme.titlebar_maximized_button_focus_active = theme.confdir .. '/icons/titlebar/maximized_focus_active.png'
2022-12-24 20:58:57 +00:00
theme.tasklist_fg_minimize = '#b3b3b3'
theme.tasklist_bg_minimize = '#4d4d4d'
2022-12-24 20:58:57 +00:00
local markup = lain.util.markup
local function build_widget_list(widgets)
local out = {}
local last_bg = 'alpha'
2022-12-24 20:58:57 +00:00
for _, widget in pairs(widgets) do
table.insert(out, lain.util.separators.arrow_left(last_bg, widget.bg))
2022-12-24 20:58:57 +00:00
local bg_widget = wibox.widget.background(wibox.container.margin(widget.widget, 5, 5), widget.bg)
2023-01-30 14:10:44 +00:00
bg_widget.fg = '#000000'
table.insert(out, bg_widget)
2022-12-24 20:58:57 +00:00
last_bg = widget.bg
end
return out
end
local info_widgets = {}
-- > Net
local netdowninfo = wibox.widget.textbox()
local netupinfo = lain.widget.net({
2023-01-21 15:34:13 +00:00
settings = function()
-- luacheck: globals widget net_now
widget:set_text(net_now.sent)
netdowninfo:set_text(net_now.received)
2023-01-21 15:34:13 +00:00
end,
2022-12-24 20:58:57 +00:00
})
table.insert(info_widgets, {
widget = wibox.layout.fixed.horizontal(wibox.widget.imagebox(theme.widget_netdown), netdowninfo),
2023-01-30 14:09:45 +00:00
bg = '#87af5f',
})
table.insert(info_widgets, {
widget = wibox.layout.fixed.horizontal(wibox.widget.imagebox(theme.widget_netup), netupinfo.widget),
2023-01-30 14:09:45 +00:00
bg = '#e54c62',
})
-- < Net
2022-12-24 20:58:57 +00:00
-- > Battery
2023-01-25 19:10:58 +00:00
if settings['show_battery'] == true then
local baticon = wibox.widget.imagebox(nil)
2023-01-25 19:10:58 +00:00
local bat = lain.widget.bat({
settings = function()
-- luacheck: globals widget bat_now
if bat_now.ac_status == 1 or bat_now.perc == 'N/A' then
baticon:set_image(theme.widget_bat_charge)
elseif bat_now.perc < 5 then
baticon:set_image(theme.widget_bat_empty)
elseif bat_now.perc < 15 then
baticon:set_image(theme.widget_bat_low)
elseif bat_now.perc < 50 then
baticon:set_image(theme.widget_bat_mid)
elseif bat_now.perc < 95 then
baticon:set_image(theme.widget_bat_high)
else
baticon:set_image(theme.widget_bat_full)
end
2023-01-25 19:10:58 +00:00
local perc = bat_now.perc ~= 'N/A' and bat_now.perc .. '%' or bat_now.perc
2022-12-24 20:58:57 +00:00
2023-01-25 19:10:58 +00:00
if bat_now.ac_status == 1 then
perc = perc .. ' plug'
end
2022-12-24 20:58:57 +00:00
2023-01-25 19:10:58 +00:00
widget:set_markup(markup.fontfg(theme.font, theme.fg_normal, perc .. ' '))
end,
})
table.insert(info_widgets, {
widget = wibox.layout.fixed.horizontal(baticon, bat.widget),
2023-01-30 14:09:45 +00:00
bg = '#e54c62',
})
2023-01-25 19:10:58 +00:00
end
-- < Battery
2022-12-24 20:58:57 +00:00
-- > ALSA volume
local volumeicon = wibox.widget.imagebox(nil)
local volume = lain.widget.alsa({
2023-01-21 15:34:13 +00:00
settings = function()
-- luacheck: globals widget volume_now
if volume_now.status == 'off' then
volumeicon:set_image(theme.widget_vol_mute)
volume_now.level = 'M ' .. volume_now.level
elseif volume_now.level == 0 then
volumeicon:set_image(theme.widget_vol_mute)
elseif volume_now.level <= 50 then
volumeicon:set_image(theme.widget_vol_low)
else
volumeicon:set_image(theme.widget_vol_high)
2023-01-21 15:34:13 +00:00
end
2022-12-24 20:58:57 +00:00
widget:set_text(' ' .. volume_now.level .. '%')
2023-01-21 15:34:13 +00:00
end,
2022-12-24 20:58:57 +00:00
})
local volumebuttons = awful.util.table.join(
2023-01-30 14:09:45 +00:00
awful.button({}, 1, function() -- left click
os.execute(string.format('%s set %s toggle', volume.cmd, volume.togglechannel or volume.channel))
volume.update()
2023-01-30 14:09:45 +00:00
end),
2023-01-21 15:34:13 +00:00
awful.button({}, 4, function()
os.execute(string.format('%s set %s 1%%+', volume.cmd, volume.channel))
volume.update()
2023-01-21 15:34:13 +00:00
end),
awful.button({}, 5, function()
os.execute(string.format('%s set %s 1%%-', volume.cmd, volume.channel))
volume.update()
2023-01-21 15:34:13 +00:00
end)
)
2022-12-24 20:58:57 +00:00
volume.widget:buttons(volumebuttons)
volumeicon:buttons(volumebuttons)
table.insert(info_widgets, {
widget = wibox.layout.fixed.horizontal(volumeicon, volume.widget),
2023-01-30 14:09:45 +00:00
bg = '#7493d2',
2022-12-24 20:58:57 +00:00
})
-- < ALSA volume
2022-12-24 20:58:57 +00:00
-- > MEM
2022-12-24 20:58:57 +00:00
local memory = lain.widget.mem({
2023-01-21 15:34:13 +00:00
settings = function()
-- luacheck: globals widget mem_now
widget:set_text(mem_now.used .. 'M')
end,
})
table.insert(info_widgets, {
widget = wibox.layout.fixed.horizontal(wibox.widget.imagebox(theme.widget_mem), memory.widget),
2023-01-30 14:09:45 +00:00
bg = '#e0da37',
})
-- < MEM
-- > CPU
local cpu = lain.widget.cpu({
settings = function()
-- luacheck: globals widget cpu_now
widget:set_markup(cpu_now.usage .. '%')
2023-01-21 15:34:13 +00:00
end,
2022-12-24 20:58:57 +00:00
})
table.insert(info_widgets, {
widget = wibox.layout.fixed.horizontal(wibox.widget.imagebox(theme.widget_cpu), cpu.widget),
2023-01-30 14:09:45 +00:00
bg = '#e33a6e',
})
-- < CPU
-- > fs
local fs = lain.widget.fs({
notification_preset = { font = 'Monospace 10', fg = theme.fg_normal },
settings = function()
-- luacheck: max line length 150, globals widget fs_now
widget:set_text(
fs_now['/'].percentage
.. '% ('
.. string.format('%.3f', fs_now['/'].free)
.. ' '
.. fs_now['/'].units
.. ' left)'
)
end,
})
fs.widget:buttons(gears.table.join(awful.button({}, 1, function()
awful.spawn('Thunar')
end)))
table.insert(info_widgets, {
widget = fs.widget,
2023-01-30 14:09:45 +00:00
bg = '#80d9d8',
})
-- < fs
-- > Textclock
os.setlocale(os.getenv('LANG')) -- to localize the clock
--local clockicon = wibox.widget.imagebox(theme.widget_clock)
local mytextclock = wibox.widget.textclock('%I:%M %a %d.%m')
mytextclock.font = theme.font
lain.widget.cal({
attach_to = { mytextclock },
notification_preset = {
font = 'Monospace 10',
fg = theme.fg_normal,
bg = theme.bg_normal,
},
})
table.insert(info_widgets, {
widget = mytextclock,
2023-01-30 14:09:45 +00:00
bg = '#7788af',
})
-- < Textclock
2022-12-24 20:58:57 +00:00
-- MPD
2023-01-13 13:40:21 +00:00
--[[
2022-12-24 20:58:57 +00:00
local mpdicon = wibox.widget.imagebox()
theme.mpd = lain.widget.mpd({
settings = function()
mpd_notification_preset = {
text = string.format("%s [%s] - %s\n%s", mpd_now.artist,
mpd_now.album, mpd_now.date, mpd_now.title)
}
if mpd_now.state == "play" then
artist = mpd_now.artist .. " > "
title = mpd_now.title .. " "
mpdicon:set_image(theme.widget_note_on)
elseif mpd_now.state == "pause" then
artist = "mpd "
title = "paused "
else
artist = ""
title = ""
--mpdicon:set_image() -- not working in 4.0
mpdicon._private.image = nil
mpdicon:emit_signal("widget::redraw_needed")
mpdicon:emit_signal("widget::layout_changed")
end
widget:set_markup(markup.fontfg(theme.font, "#e54c62", artist) .. markup.fontfg(theme.font, "#b2b2b2", title))
end
})
2023-01-21 15:34:13 +00:00
]]
--
2022-12-24 20:58:57 +00:00
local final_info_widgets = build_widget_list(info_widgets)
2022-12-24 20:58:57 +00:00
function theme.at_screen_connect(s)
2023-01-21 15:34:13 +00:00
-- Quake application
s.quake = lain.util.quake({ app = awful.util.terminal })
2022-12-24 20:58:57 +00:00
2023-01-21 15:34:13 +00:00
-- If wallpaper is a function, call it with the screen
local wallpaper = theme.wallpaper
if type(wallpaper) == 'function' then
wallpaper = wallpaper(s)
end
gears.wallpaper.maximized(wallpaper, s, true)
2022-12-24 20:58:57 +00:00
2023-01-21 15:34:13 +00:00
-- Tags
awful.tag(awful.util.tagnames, s, awful.layout.layouts[1])
2022-12-24 20:58:57 +00:00
2023-01-21 15:34:13 +00:00
-- Create a promptbox for each screen
s.mypromptbox = awful.widget.prompt()
-- Create an imagebox widget which will contains an icon indicating which layout we're using.
-- We need one layoutbox per screen.
s.mylayoutbox = awful.widget.layoutbox(s)
s.mylayoutbox:buttons(my_table.join(
awful.button({}, 1, function()
awful.layout.inc(1)
end),
awful.button({}, 2, function()
awful.layout.set(awful.layout.layouts[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)
))
-- Create a taglist widget
s.mytaglist = awful.widget.taglist(s, awful.widget.taglist.filter.all, awful.util.taglist_buttons)
2022-12-24 20:58:57 +00:00
2023-01-21 15:34:13 +00:00
-- Create a tasklist widget
s.mytasklist = awful.widget.tasklist({
screen = s,
filter = awful.widget.tasklist.filter.minimizedcurrenttags,
buttons = awful.util.tasklist_buttons,
style = {
shape = function(cr, w, h)
gears.shape.partially_rounded_rect(cr, w, h, false, false, true, true, 10)
end,
},
layout = {
spacing = 5,
layout = wibox.layout.flex.horizontal,
},
widget_template = {
{
{
id = 'text_role',
widget = wibox.widget.textbox,
},
left = 10,
right = 10,
widget = wibox.container.margin,
},
id = 'background_role',
widget = wibox.container.background,
},
})
s.mytasklist = wibox.container.margin(s.mytasklist, 10, 10, 0, 0)
2022-12-24 20:58:57 +00:00
2023-01-21 15:34:13 +00:00
-- Create the wibox
s.mywibox =
awful.wibar({ position = 'top', screen = s, height = dpi(19), bg = theme.bg_normal, fg = theme.fg_normal })
2022-12-24 20:58:57 +00:00
2023-01-21 15:34:13 +00:00
-- Add widgets to the wibox
s.mywibox:setup({
layout = wibox.layout.align.horizontal,
{ -- Left widgets
layout = wibox.layout.fixed.horizontal,
s.mylayoutbox,
s.mytaglist,
s.mypromptbox,
--mpdicon,
--theme.mpd.widget,
},
s.mytasklist, -- Middle widget
--nil,
2023-01-30 14:09:45 +00:00
gears.table.join({ -- Right widgets
layout = wibox.layout.fixed.horizontal,
wibox.container.margin(wibox.widget.systray(), 0, 5),
}, final_info_widgets),
2023-01-21 15:34:13 +00:00
})
2022-12-24 20:58:57 +00:00
end
return theme