From 2ef8481ca1ce400480a6ae796463af19eb328e7b Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Thu, 19 Sep 2019 16:13:53 +0200 Subject: [PATCH 1/2] Wibox improvements --- .config/awesome/config_laptop.lua | 25 ++++ .config/awesome/rc.lua | 190 ++++++++++++++++++++++++++---- 2 files changed, 191 insertions(+), 24 deletions(-) create mode 100644 .config/awesome/config_laptop.lua diff --git a/.config/awesome/config_laptop.lua b/.config/awesome/config_laptop.lua new file mode 100644 index 0000000..5724bc2 --- /dev/null +++ b/.config/awesome/config_laptop.lua @@ -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@" + } +} diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua index 5494093..f4b5931 100644 --- a/.config/awesome/rc.lua +++ b/.config/awesome/rc.lua @@ -16,10 +16,19 @@ local menubar = require("menubar") local hotkeys_popup = require("awful.hotkeys_popup") local vicious = require("vicious") local timer = require("gears.timer") +local config = require("config_laptop") + -- Enable hotkeys help widget for VIM and other apps -- when client with a matching name is opened: 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 -- Check if awesome encountered an error during startup and fell back to -- another config (This code will only ever execute for the fallback config) @@ -170,30 +179,163 @@ local function set_wallpaper(s) 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() 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() -vicious.cache(vicious.contrib.xbacklight) -vicious.register(backlightbox, vicious.contrib.xbacklight, "  $1 ", 3) +vicious.cache(backlight_widget_type) +vicious.register(backlightbox, backlight_widget_type, format_brightness, 3) batwidget = wibox.widget.textbox() 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() 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() 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() 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) screen.connect_signal("property::geometry", set_wallpaper) @@ -239,22 +381,22 @@ awful.screen.connect_for_each_screen(function(s) { -- Left widgets layout = wibox.layout.fixed.horizontal, 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 layout = wibox.layout.fixed.horizontal, - --mykeyboardlayout, - memwidget, - cpuwidget, - volumebox, - backlightbox, - wifiwidget, - batwidget, - --wibox.widget.systray(), - mytextclock, - --s.mylayoutbox, + + table.unpack(load_widget_config(config.widgets.right)), }, } @@ -389,15 +531,15 @@ globalbuttons = gears.table.join( globalkeys = gears.table.join( 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) end), 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) end), 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) end), From df3d6e11f04ffa45b96ab3e292b9de02d0fa94cf Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Thu, 19 Sep 2019 16:15:56 +0200 Subject: [PATCH 2/2] Desktop config --- .config/awesome/config_desktop.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .config/awesome/config_desktop.lua diff --git a/.config/awesome/config_desktop.lua b/.config/awesome/config_desktop.lua new file mode 100644 index 0000000..a922b02 --- /dev/null +++ b/.config/awesome/config_desktop.lua @@ -0,0 +1,20 @@ +return { + widgets = { + left = { + + }, + mid = { + "mpd" + }, + right = { + "memory", + "cpu", + "volume", + "clock" + } + }, + volume = { + options = {"Master", "-D", "pulse"}, + sink = "@DEFAULT_SINK@" + } +}