Wibox improvements
This commit is contained in:
parent
730f0beba5
commit
2ef8481ca1
|
@ -0,0 +1,25 @@
|
||||||
|
return {
|
||||||
|
widgets = {
|
||||||
|
left = {
|
||||||
|
|
||||||
|
},
|
||||||
|
mid = {
|
||||||
|
"mpd"
|
||||||
|
},
|
||||||
|
right = {
|
||||||
|
"memory",
|
||||||
|
"cpu",
|
||||||
|
"volume",
|
||||||
|
"backlight",
|
||||||
|
"wifi",
|
||||||
|
"battery",
|
||||||
|
"clock"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
battery = "BAT1",
|
||||||
|
net_interface = "wlp3s0",
|
||||||
|
volume = {
|
||||||
|
options = {"Master", "-D", "pulse"},
|
||||||
|
sink = "@DEFAULT_SINK@"
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,10 +16,19 @@ local menubar = require("menubar")
|
||||||
local hotkeys_popup = require("awful.hotkeys_popup")
|
local hotkeys_popup = require("awful.hotkeys_popup")
|
||||||
local vicious = require("vicious")
|
local vicious = require("vicious")
|
||||||
local timer = require("gears.timer")
|
local timer = require("gears.timer")
|
||||||
|
local config = require("config_laptop")
|
||||||
|
|
||||||
-- Enable hotkeys help widget for VIM and other apps
|
-- Enable hotkeys help widget for VIM and other apps
|
||||||
-- when client with a matching name is opened:
|
-- when client with a matching name is opened:
|
||||||
require("awful.hotkeys_popup.keys")
|
require("awful.hotkeys_popup.keys")
|
||||||
|
|
||||||
|
local function round(x)
|
||||||
|
if x%2 ~= 0.5 then
|
||||||
|
return math.floor(x+0.5)
|
||||||
|
end
|
||||||
|
return x-0.5
|
||||||
|
end
|
||||||
|
|
||||||
-- {{{ Error handling
|
-- {{{ Error handling
|
||||||
-- Check if awesome encountered an error during startup and fell back to
|
-- Check if awesome encountered an error during startup and fell back to
|
||||||
-- another config (This code will only ever execute for the fallback config)
|
-- another config (This code will only ever execute for the fallback config)
|
||||||
|
@ -170,30 +179,163 @@ local function set_wallpaper(s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local backlight_widget_type = {
|
||||||
|
async = function (format, warg, callback)
|
||||||
|
awful.spawn.easy_async("xbacklight ", function (stdout)
|
||||||
|
callback{ round(tonumber(stdout)) }
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
local battery_icon_table = {
|
||||||
|
not_charging = {
|
||||||
|
["0"] = "",
|
||||||
|
["10"] = "",
|
||||||
|
["20"] = "",
|
||||||
|
["30"] = "",
|
||||||
|
["40"] = "",
|
||||||
|
["50"] = "",
|
||||||
|
["60"] = "",
|
||||||
|
["70"] = "",
|
||||||
|
["80"] = "",
|
||||||
|
["90"] = "",
|
||||||
|
["100"] = ""
|
||||||
|
},
|
||||||
|
charging = {
|
||||||
|
["0"] = "",
|
||||||
|
["10"] = "",
|
||||||
|
["20"] = "",
|
||||||
|
["30"] = "",
|
||||||
|
["40"] = "",
|
||||||
|
["50"] = "",
|
||||||
|
["60"] = "",
|
||||||
|
["70"] = "",
|
||||||
|
["80"] = "",
|
||||||
|
["90"] = "",
|
||||||
|
["100"] = ""
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local brightness_icon_table = {
|
||||||
|
"", "", "", "", "", "", ""
|
||||||
|
}
|
||||||
|
|
||||||
|
local volume_icon_table = {
|
||||||
|
levels = {
|
||||||
|
"", "", ""
|
||||||
|
},
|
||||||
|
muted = "婢"
|
||||||
|
}
|
||||||
|
|
||||||
|
local function format_widget(...)
|
||||||
|
local result = " "
|
||||||
|
for _, v in ipairs({...}) do
|
||||||
|
result = result .. v .. " "
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
local function battery_icon(percent, charging)
|
||||||
|
local key = ""..(round(percent / 10) * 10)..""
|
||||||
|
if charging then
|
||||||
|
return battery_icon_table.charging[key]
|
||||||
|
else
|
||||||
|
|
||||||
|
return battery_icon_table.not_charging[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function format_battery(widget, args)
|
||||||
|
return format_widget(battery_icon(args[2], args[1] == "+"), args[2])
|
||||||
|
end
|
||||||
|
|
||||||
|
local function format_wifi(widget, args)
|
||||||
|
if args["{ssid}"] ~= "N/A" then
|
||||||
|
return format_widget("", args["{linp}"])
|
||||||
|
end
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local function format_brightness(widget, args)
|
||||||
|
local index = math.min(round(args[1] / 100 * 6 + 1), 7)
|
||||||
|
return format_widget(brightness_icon_table[index], args[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
local function format_volume(widget, args)
|
||||||
|
if args[2] == "🔉" then
|
||||||
|
local index = math.min(round(args[1] / 100 * 2 + 1), 3)
|
||||||
|
return format_widget(volume_icon_table.levels[index], args[1])
|
||||||
|
else
|
||||||
|
return format_widget(volume_icon_table.muted, "")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function format_memory(widget, args)
|
||||||
|
return format_widget("", round(args[2] / 100) / 10 .. " GiB")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function format_cpu(widget, args)
|
||||||
|
return format_widget("", args[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
local function format_mpd(widget, args)
|
||||||
|
if args["{state}"] == "Stop" then
|
||||||
|
return ''
|
||||||
|
else
|
||||||
|
return format_widget("", ('%s - %s'):format(args["{Artist}"], args["{Title}"]), "")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
volumebox = wibox.widget.textbox()
|
volumebox = wibox.widget.textbox()
|
||||||
vicious.cache(vicious.widgets.volume)
|
vicious.cache(vicious.widgets.volume)
|
||||||
vicious.register(volumebox, vicious.widgets.volume, " $1 ", 3, {"Master", "-D", "pulse"})
|
vicious.register(volumebox, vicious.widgets.volume, format_volume, 3, config.volume.options)
|
||||||
|
|
||||||
backlightbox = wibox.widget.textbox()
|
backlightbox = wibox.widget.textbox()
|
||||||
vicious.cache(vicious.contrib.xbacklight)
|
vicious.cache(backlight_widget_type)
|
||||||
vicious.register(backlightbox, vicious.contrib.xbacklight, " $1 ", 3)
|
vicious.register(backlightbox, backlight_widget_type, format_brightness, 3)
|
||||||
|
|
||||||
batwidget = wibox.widget.textbox()
|
batwidget = wibox.widget.textbox()
|
||||||
vicious.cache(vicious.widgets.bat)
|
vicious.cache(vicious.widgets.bat)
|
||||||
vicious.register(batwidget, vicious.widgets.bat, " $2 ", 61, "BAT1")
|
vicious.register(batwidget, vicious.widgets.bat, format_battery, 61, config.battery)
|
||||||
|
|
||||||
|
|
||||||
wifiwidget = wibox.widget.textbox()
|
wifiwidget = wibox.widget.textbox()
|
||||||
vicious.cache(vicious.widgets.wifi)
|
vicious.cache(vicious.widgets.wifi)
|
||||||
vicious.register(wifiwidget, vicious.widgets.wifi, " ${linp} ", 10, "wlp3s0")
|
vicious.register(wifiwidget, vicious.widgets.wifi, format_wifi, 3, config.net_interface)
|
||||||
|
|
||||||
cpuwidget = wibox.widget.textbox()
|
cpuwidget = wibox.widget.textbox()
|
||||||
vicious.cache(vicious.widgets.cpu)
|
vicious.cache(vicious.widgets.cpu)
|
||||||
vicious.register(cpuwidget, vicious.widgets.cpu, " $1 ", 1)
|
vicious.register(cpuwidget, vicious.widgets.cpu, format_cpu, 1)
|
||||||
|
|
||||||
memwidget = wibox.widget.textbox()
|
memwidget = wibox.widget.textbox()
|
||||||
vicious.cache(vicious.widgets.mem)
|
vicious.cache(vicious.widgets.mem)
|
||||||
vicious.register(memwidget, vicious.widgets.mem, " $2 MiB ", 1)
|
vicious.register(memwidget, vicious.widgets.mem, format_memory, 1)
|
||||||
|
|
||||||
|
mpdwidget = wibox.widget.textbox()
|
||||||
|
vicious.cache(vicious.widgets.mpd)
|
||||||
|
vicious.register(mpdwidget, vicious.widgets.mpd, format_mpd)
|
||||||
|
|
||||||
|
local widget_table = {
|
||||||
|
["mpd"] = mpdwidget,
|
||||||
|
["memory"] = memwidget,
|
||||||
|
["cpu"] = cpuwidget,
|
||||||
|
["volume"] = volumebox,
|
||||||
|
["backlight"] = backlightbox,
|
||||||
|
["wifi"] = wifiwidget,
|
||||||
|
["battery"] = batwidget,
|
||||||
|
["clock"] = mytextclock
|
||||||
|
}
|
||||||
|
|
||||||
|
local function load_widget_config(conf)
|
||||||
|
local t = {}
|
||||||
|
|
||||||
|
for _, v in ipairs(conf) do
|
||||||
|
table.insert(t, widget_table[v])
|
||||||
|
end
|
||||||
|
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
|
-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
|
||||||
screen.connect_signal("property::geometry", set_wallpaper)
|
screen.connect_signal("property::geometry", set_wallpaper)
|
||||||
|
@ -239,22 +381,22 @@ awful.screen.connect_for_each_screen(function(s)
|
||||||
{ -- Left widgets
|
{ -- Left widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
s.mytaglist,
|
s.mytaglist,
|
||||||
s.mypromptbox,
|
|
||||||
|
table.unpack(load_widget_config(config.widgets.left))
|
||||||
|
},
|
||||||
|
{
|
||||||
|
layout = wibox.layout.flex.horizontal,
|
||||||
|
|
||||||
|
wibox.widget { widget = wibox.widget.separator, visible = false },
|
||||||
|
|
||||||
|
table.unpack(load_widget_config(config.widgets.mid)),
|
||||||
|
|
||||||
|
wibox.widget { widget = wibox.widget.separator, visible = false },
|
||||||
},
|
},
|
||||||
--s.mytasklist, -- Middle widget
|
|
||||||
wibox.widget { widget = wibox.widget.separator, visible = false },
|
|
||||||
{ -- Right widgets
|
{ -- Right widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
--mykeyboardlayout,
|
|
||||||
memwidget,
|
table.unpack(load_widget_config(config.widgets.right)),
|
||||||
cpuwidget,
|
|
||||||
volumebox,
|
|
||||||
backlightbox,
|
|
||||||
wifiwidget,
|
|
||||||
batwidget,
|
|
||||||
--wibox.widget.systray(),
|
|
||||||
mytextclock,
|
|
||||||
--s.mylayoutbox,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,15 +531,15 @@ globalbuttons = gears.table.join(
|
||||||
globalkeys = gears.table.join(
|
globalkeys = gears.table.join(
|
||||||
|
|
||||||
awful.key({}, "XF86AudioRaiseVolume", function ()
|
awful.key({}, "XF86AudioRaiseVolume", function ()
|
||||||
awful.spawn("sh -c 'pactl set-sink-mute 0 false && pactl set-sink-volume 0 +5%'")
|
awful.spawn("sh -c 'pactl set-sink-mute "..config.volume.sink.." false && pactl set-sink-volume "..config.volume.sink.." +5%'")
|
||||||
gears.timer.start_new(0.2, function () vicious.force({ volumebox, }) end)
|
gears.timer.start_new(0.2, function () vicious.force({ volumebox, }) end)
|
||||||
end),
|
end),
|
||||||
awful.key({}, "XF86AudioLowerVolume", function ()
|
awful.key({}, "XF86AudioLowerVolume", function ()
|
||||||
awful.spawn("sh -c 'pactl set-sink-mute 0 false && pactl set-sink-volume 0 -5%'")
|
awful.spawn("sh -c 'pactl set-sink-mute "..config.volume.sink.." false && pactl set-sink-volume "..config.volume.sink.." -5%'")
|
||||||
gears.timer.start_new(0.2, function () vicious.force({ volumebox, }) end)
|
gears.timer.start_new(0.2, function () vicious.force({ volumebox, }) end)
|
||||||
end),
|
end),
|
||||||
awful.key({}, "XF86AudioMute", function ()
|
awful.key({}, "XF86AudioMute", function ()
|
||||||
awful.spawn("pactl set-sink-mute 0 toggle")
|
awful.spawn("pactl set-sink-mute "..config.volume.sink.." toggle")
|
||||||
gears.timer.start_new(0.2, function () vicious.force({ volumebox, }) end)
|
gears.timer.start_new(0.2, function () vicious.force({ volumebox, }) end)
|
||||||
end),
|
end),
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue