aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/ui/statusbar/widgets
diff options
context:
space:
mode:
authordelta <darkussdelta@gmail.com>2023-03-04 22:04:55 +0100
committerdelta <darkussdelta@gmail.com>2023-03-04 22:18:21 +0100
commitf0b32f45746c026d402651013b7e98315d6956a1 (patch)
treef42609e98522da081cebdd21a674a702d1054bbc /.config/awesome/ui/statusbar/widgets
parenta0f8b5fa6acdd1c2477fb1881dd9067956bf0ae6 (diff)
restructure awesome config, add fresnel
Diffstat (limited to '.config/awesome/ui/statusbar/widgets')
-rw-r--r--.config/awesome/ui/statusbar/widgets/app_launcher.lua6
-rw-r--r--.config/awesome/ui/statusbar/widgets/battery.lua67
-rw-r--r--.config/awesome/ui/statusbar/widgets/brightness.lua18
-rw-r--r--.config/awesome/ui/statusbar/widgets/clock.lua18
-rw-r--r--.config/awesome/ui/statusbar/widgets/keyboardlayout.lua327
-rw-r--r--.config/awesome/ui/statusbar/widgets/power_menu.lua0
-rw-r--r--.config/awesome/ui/statusbar/widgets/taglist.lua89
-rw-r--r--.config/awesome/ui/statusbar/widgets/wifi.lua48
8 files changed, 573 insertions, 0 deletions
diff --git a/.config/awesome/ui/statusbar/widgets/app_launcher.lua b/.config/awesome/ui/statusbar/widgets/app_launcher.lua
new file mode 100644
index 0000000..2e1e10a
--- /dev/null
+++ b/.config/awesome/ui/statusbar/widgets/app_launcher.lua
@@ -0,0 +1,6 @@
+local awful = require "awful"
+local wibox = require "wibox"
+local vars = require "misc.vars"
+local h = require "misc.helpers"
+
+
diff --git a/.config/awesome/ui/statusbar/widgets/battery.lua b/.config/awesome/ui/statusbar/widgets/battery.lua
new file mode 100644
index 0000000..b041c3a
--- /dev/null
+++ b/.config/awesome/ui/statusbar/widgets/battery.lua
@@ -0,0 +1,67 @@
+local awful = require "awful"
+local xresources = require "beautiful.xresources"
+local vars = require "misc.vars"
+local wibox = require "wibox"
+local h = require "misc.helpers"
+
+local battery_inner = awful.widget.watch("cat /sys/class/power_supply/BAT0/capacity", 1, function(widget, stdout)
+ local icon = ""
+ local color = vars.colors.red
+
+ if io.popen("cat /sys/class/power_supply/BAT0/status"):read("*a"):sub(0, -2) == "Charging" then
+ icon = ""
+ color = vars.colors.green
+ widget:set_markup("<span color=\"" .. color .. "\">" .. icon .. "</span>")
+ return
+ end
+
+ local percent = tonumber(stdout)
+
+ if percent <= 5 then
+ icon = ""
+ color = vars.colors.red
+ elseif percent <= 10 then
+ icon = ""
+ color = vars.colors.red
+ elseif percent <= 20 then
+ icon = ""
+ color = vars.colors.red
+ elseif percent <= 30 then
+ icon = ""
+ color = vars.colors.yellow
+ elseif percent <= 40 then
+ icon = ""
+ color = vars.colors.yellow
+ elseif percent <= 50 then
+ icon = ""
+ color = vars.colors.yellow
+ elseif percent <= 60 then
+ icon = ""
+ color = vars.colors.yellow
+ elseif percent <= 70 then
+ icon = ""
+ color = vars.colors.yellow
+ elseif percent <= 80 then
+ icon = ""
+ color = vars.colors.green
+ elseif percent <= 90 then
+ icon = ""
+ color = vars.colors.green
+ elseif percent <= 100 then
+ icon = ""
+ color = vars.colors.green
+ end
+
+ widget:set_markup("<span color=\"" .. color .. "\">" .. icon .. "</span>")
+end)
+
+local battery = wibox.widget {
+ widget = wibox.container.place,
+ battery_inner
+}
+
+h.tooltip({ battery }, function()
+ return io.popen("cat /sys/class/power_supply/BAT0/capacity"):read("*a"):sub(0, -2) .. "%"
+end)
+
+return battery
diff --git a/.config/awesome/ui/statusbar/widgets/brightness.lua b/.config/awesome/ui/statusbar/widgets/brightness.lua
new file mode 100644
index 0000000..cceba89
--- /dev/null
+++ b/.config/awesome/ui/statusbar/widgets/brightness.lua
@@ -0,0 +1,18 @@
+local vars = require "misc.vars"
+local wibox = require "wibox"
+local h = require "misc.helpers"
+
+local brightness = wibox.widget {
+ widget = wibox.container.place,
+ {
+ widget = wibox.widget.textbox,
+ font = vars.font,
+ text = ""
+ },
+}
+
+h.tooltip({ brightness }, function()
+ return math.floor(tonumber(io.popen("brightnessctl g"):read("*a"):sub(0, -2)) / 255 * 100) .. "%"
+end)
+
+return brightness
diff --git a/.config/awesome/ui/statusbar/widgets/clock.lua b/.config/awesome/ui/statusbar/widgets/clock.lua
new file mode 100644
index 0000000..c7b3c29
--- /dev/null
+++ b/.config/awesome/ui/statusbar/widgets/clock.lua
@@ -0,0 +1,18 @@
+local vars = require "misc.vars"
+local wibox = require "wibox"
+local h = require "misc.helpers"
+
+local clock = wibox.widget {
+ widget = wibox.container.place,
+ {
+ format = "%H\n%M",
+ widget = wibox.widget.textclock,
+ font = vars.font
+ },
+}
+
+h.tooltip({ clock }, function()
+ return os.date("%a %d/%m/%y")
+end)
+
+return clock
diff --git a/.config/awesome/ui/statusbar/widgets/keyboardlayout.lua b/.config/awesome/ui/statusbar/widgets/keyboardlayout.lua
new file mode 100644
index 0000000..0bbbf14
--- /dev/null
+++ b/.config/awesome/ui/statusbar/widgets/keyboardlayout.lua
@@ -0,0 +1,327 @@
+-- Slightly modified to not take up as much space
+
+---------------------------------------------------------------------------
+-- Display the current keyboard layout name in a widget.
+--
+--
+-- @author Aleksey Fedotov &lt;lexa@cfotr.com&gt;
+-- @copyright 2015 Aleksey Fedotov
+-- @widgetmod awful.widget.keyboardlayout
+-- @supermodule wibox.widget.base
+---------------------------------------------------------------------------
+
+local capi = {awesome = awesome}
+local setmetatable = setmetatable
+local textbox = require("wibox.widget.textbox")
+local button = require("awful.button")
+local widget_base = require("wibox.widget.base")
+local gdebug = require("gears.debug")
+
+--- Keyboard Layout widget.
+-- awful.widget.keyboardlayout
+local keyboardlayout = { mt = {} }
+
+-- As to the country-code-like symbols below, refer to the names of XKB's
+-- data files in /.../xkb/symbols/*.
+keyboardlayout.xkeyboard_country_code = {
+ ["ad"] = true, -- Andorra
+ ["af"] = true, -- Afganistan
+ ["al"] = true, -- Albania
+ ["am"] = true, -- Armenia
+ ["ara"] = true, -- Arabic
+ ["at"] = true, -- Austria
+ ["az"] = true, -- Azerbaijan
+ ["ba"] = true, -- Bosnia and Herzegovina
+ ["bd"] = true, -- Bangladesh
+ ["be"] = true, -- Belgium
+ ["bg"] = true, -- Bulgaria
+ ["br"] = true, -- Brazil
+ ["bt"] = true, -- Bhutan
+ ["bw"] = true, -- Botswana
+ ["by"] = true, -- Belarus
+ ["ca"] = true, -- Canada
+ ["cd"] = true, -- Congo
+ ["ch"] = true, -- Switzerland
+ ["cm"] = true, -- Cameroon
+ ["cn"] = true, -- China
+ ["cz"] = true, -- Czechia
+ ["de"] = true, -- Germany
+ ["dk"] = true, -- Denmark
+ ["ee"] = true, -- Estonia
+ ["epo"] = true, -- Esperanto
+ ["es"] = true, -- Spain
+ ["et"] = true, -- Ethiopia
+ ["eu"] = true, -- EurKey
+ ["fi"] = true, -- Finland
+ ["fo"] = true, -- Faroe Islands
+ ["fr"] = true, -- France
+ ["gb"] = true, -- United Kingdom
+ ["ge"] = true, -- Georgia
+ ["gh"] = true, -- Ghana
+ ["gn"] = true, -- Guinea
+ ["gr"] = true, -- Greece
+ ["hr"] = true, -- Croatia
+ ["hu"] = true, -- Hungary
+ ["ie"] = true, -- Ireland
+ ["il"] = true, -- Israel
+ ["in"] = true, -- India
+ ["iq"] = true, -- Iraq
+ ["ir"] = true, -- Iran
+ ["is"] = true, -- Iceland
+ ["it"] = true, -- Italy
+ ["jp"] = true, -- Japan
+ ["ke"] = true, -- Kenya
+ ["kg"] = true, -- Kyrgyzstan
+ ["kh"] = true, -- Cambodia
+ ["kr"] = true, -- Korea
+ ["kz"] = true, -- Kazakhstan
+ ["la"] = true, -- Laos
+ ["latam"] = true, -- Latin America
+ ["latin"] = true, -- Latin
+ ["lk"] = true, -- Sri Lanka
+ ["lt"] = true, -- Lithuania
+ ["lv"] = true, -- Latvia
+ ["ma"] = true, -- Morocco
+ ["mao"] = true, -- Maori
+ ["me"] = true, -- Montenegro
+ ["mk"] = true, -- Macedonia
+ ["ml"] = true, -- Mali
+ ["mm"] = true, -- Myanmar
+ ["mn"] = true, -- Mongolia
+ ["mt"] = true, -- Malta
+ ["mv"] = true, -- Maldives
+ ["ng"] = true, -- Nigeria
+ ["nl"] = true, -- Netherlands
+ ["no"] = true, -- Norway
+ ["np"] = true, -- Nepal
+ ["ph"] = true, -- Philippines
+ ["pk"] = true, -- Pakistan
+ ["pl"] = true, -- Poland
+ ["pt"] = true, -- Portugal
+ ["ro"] = true, -- Romania
+ ["rs"] = true, -- Serbia
+ ["ru"] = true, -- Russia
+ ["se"] = true, -- Sweden
+ ["si"] = true, -- Slovenia
+ ["sk"] = true, -- Slovakia
+ ["sn"] = true, -- Senegal
+ ["sy"] = true, -- Syria
+ ["th"] = true, -- Thailand
+ ["tj"] = true, -- Tajikistan
+ ["tm"] = true, -- Turkmenistan
+ ["tr"] = true, -- Turkey
+ ["tw"] = true, -- Taiwan
+ ["tz"] = true, -- Tanzania
+ ["ua"] = true, -- Ukraine
+ ["us"] = true, -- USA
+ ["uz"] = true, -- Uzbekistan
+ ["vn"] = true, -- Vietnam
+ ["za"] = true, -- South Africa
+}
+
+-- Callback for updating current layout.
+local function update_status (self)
+ self._current = awesome.xkb_get_layout_group()
+ local text = ""
+ if #self._layout > 0 then
+ -- Please note that the group number reported by xkb_get_layout_group
+ -- is lower by one than the group numbers reported by xkb_get_group_names.
+ local name = self._layout[self._current+1]
+ if name then
+ text = name
+ end
+ end
+ self.widget:set_text(text)
+end
+
+--- Auxiliary function for the local function update_layout().
+-- Create an array whose element is a table consisting of the four fields:
+-- vendor, file, section and group_idx, which all correspond to the
+-- xkb_symbols pattern "vendor/file(section):group_idx".
+-- @tparam string group_names The string `awesome.xkb_get_group_names()` returns.
+-- @treturn table An array of tables whose keys are vendor, file, section, and group_idx.
+-- @staticfct awful.keyboardlayout.get_groups_from_group_names
+function keyboardlayout.get_groups_from_group_names(group_names)
+ if group_names == nil then
+ return nil
+ end
+
+ -- Pattern elements to be captured.
+ local word_pat = "([%w_]+)"
+ local sec_pat = "(%b())"
+ local idx_pat = ":(%d)"
+ -- Pairs of a pattern and its callback. In callbacks, set 'group_idx' to 1
+ -- and return it if there's no specification on 'group_idx' in the given
+ -- pattern.
+ local pattern_and_callback_pairs = {
+ -- vendor/file(section):group_idx
+ ["^" .. word_pat .. "/" .. word_pat .. sec_pat .. idx_pat .. "$"]
+ = function(token, pattern)
+ local vendor, file, section, group_idx = string.match(token, pattern)
+ return vendor, file, section, group_idx
+ end,
+ -- vendor/file(section)
+ ["^" .. word_pat .. "/" .. word_pat .. sec_pat .. "$"]
+ = function(token, pattern)
+ local vendor, file, section = string.match(token, pattern)
+ return vendor, file, section, 1
+ end,
+ -- vendor/file:group_idx
+ ["^" .. word_pat .. "/" .. word_pat .. idx_pat .. "$"]
+ = function(token, pattern)
+ local vendor, file, group_idx = string.match(token, pattern)
+ return vendor, file, nil, group_idx
+ end,
+ -- vendor/file
+ ["^" .. word_pat .. "/" .. word_pat .. "$"]
+ = function(token, pattern)
+ local vendor, file = string.match(token, pattern)
+ return vendor, file, nil, 1
+ end,
+ -- file(section):group_idx
+ ["^" .. word_pat .. sec_pat .. idx_pat .. "$"]
+ = function(token, pattern)
+ local file, section, group_idx = string.match(token, pattern)
+ return nil, file, section, group_idx
+ end,
+ -- file(section)
+ ["^" .. word_pat .. sec_pat .. "$"]
+ = function(token, pattern)
+ local file, section = string.match(token, pattern)
+ return nil, file, section, 1
+ end,
+ -- file:group_idx
+ ["^" .. word_pat .. idx_pat .. "$"]
+ = function(token, pattern)
+ local file, group_idx = string.match(token, pattern)
+ return nil, file, nil, group_idx
+ end,
+ -- file
+ ["^" .. word_pat .. "$"]
+ = function(token, pattern)
+ local file = string.match(token, pattern)
+ return nil, file, nil, 1
+ end
+ }
+
+ -- Split 'group_names' into 'tokens'. The separator is "+".
+ local tokens = {}
+ string.gsub(group_names, "[^+]+", function(match)
+ table.insert(tokens, match)
+ end)
+
+ -- For each token in 'tokens', check if it matches one of the patterns in
+ -- the array 'pattern_and_callback_pairs', where the patterns are used as
+ -- key. If a match is found, extract captured strings using the
+ -- corresponding callback function. Check if those extracted is country
+ -- specific part of a layout. If so, add it to 'layout_groups'; otherwise,
+ -- ignore it.
+ local layout_groups = {}
+ for i = 1, #tokens do
+ for pattern, callback in pairs(pattern_and_callback_pairs) do
+ local vendor, file, section, group_idx = callback(tokens[i], pattern)
+ if file then
+ if not keyboardlayout.xkeyboard_country_code[file] then
+ break
+ end
+
+ if section then
+ section = string.gsub(section, "%(([%w-_]+)%)", "%1")
+ end
+
+ table.insert(layout_groups, { vendor = vendor,
+ file = file,
+ section = section,
+ group_idx = tonumber(group_idx) })
+ break
+ end
+ end
+ end
+
+ return layout_groups
+end
+
+-- Callback for updating list of layouts
+local function update_layout(self)
+ self._layout = {};
+ local layouts = keyboardlayout.get_groups_from_group_names(awesome.xkb_get_group_names())
+ if layouts == nil or layouts[1] == nil then
+ gdebug.print_error("Failed to get list of keyboard groups")
+ return
+ end
+ if #layouts == 1 then
+ layouts[1].group_idx = 1
+ end
+ for _, v in ipairs(layouts) do
+ self._layout[v.group_idx] = self.layout_name(v)
+ end
+ update_status(self)
+end
+
+--- Select the next layout.
+-- @noreturn
+-- @method next_layout
+
+--- Create a keyboard layout widget.
+--
+-- It shows current keyboard layout name in a textbox.
+--
+-- @constructorfct awful.widget.keyboardlayout
+-- @treturn awful.widget.keyboardlayout A keyboard layout widget.
+function keyboardlayout.new()
+ local widget = textbox()
+ local self = widget_base.make_widget(widget, nil, {enable_properties=true})
+
+ self.widget = widget
+
+ self.layout_name = function(v)
+ local name = v.file
+ if v.section ~= nil then
+ name = name .. "(" .. v.section .. ")"
+ end
+ return name
+ end
+
+ self.next_layout = function()
+ self.set_layout((self._current + 1) % (#self._layout + 1))
+ end
+
+ self.set_layout = function(group_number)
+ if (0 > group_number) or (group_number > #self._layout) then
+ error("Invalid group number: " .. group_number ..
+ "expected number from 0 to " .. #self._layout)
+ return;
+ end
+ awesome.xkb_set_layout_group(group_number);
+ end
+
+ update_layout(self);
+
+ -- callback for processing layout changes
+ capi.awesome.connect_signal("xkb::map_changed",
+ function () update_layout(self) end)
+ capi.awesome.connect_signal("xkb::group_changed",
+ function () update_status(self) end);
+
+ -- Mouse bindings
+ self.buttons = {
+ button({ }, 1, self.next_layout)
+ }
+
+ return self
+end
+
+local _instance = nil;
+
+function keyboardlayout.mt:__call(...)
+ if _instance == nil then
+ _instance = keyboardlayout.new(...)
+ end
+ return _instance
+end
+
+
+return setmetatable(keyboardlayout, keyboardlayout.mt)
+
+-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
+
diff --git a/.config/awesome/ui/statusbar/widgets/power_menu.lua b/.config/awesome/ui/statusbar/widgets/power_menu.lua
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/.config/awesome/ui/statusbar/widgets/power_menu.lua
diff --git a/.config/awesome/ui/statusbar/widgets/taglist.lua b/.config/awesome/ui/statusbar/widgets/taglist.lua
new file mode 100644
index 0000000..751cbf0
--- /dev/null
+++ b/.config/awesome/ui/statusbar/widgets/taglist.lua
@@ -0,0 +1,89 @@
+local awful = require "awful"
+local vars = require "misc.vars"
+local wibox = require "wibox"
+local timed = require "lib.rubato".timed
+
+return awful.widget.taglist({
+ screen = screen[1],
+ filter = awful.widget.taglist.filter.all,
+ style = {
+ shape = vars.shape
+ },
+ layout = {
+ spacing = vars.padding,
+ layout = wibox.layout.fixed.vertical
+ },
+ widget_template = {
+ {
+ widget = wibox.container.background,
+ bg = vars.colors.bright.black,
+ shape = vars.shape,
+ forced_height = vars.button_size,
+ forced_width = vars.button_size,
+ id = "indicator_role"
+ },
+ widget = wibox.container.place,
+ create_callback = function(self, tag)
+ local indicator = self:get_children_by_id("indicator_role")[1]
+
+ self._anim = timed {
+ duration = vars.anim_duration,
+ intro = vars.anim_intro,
+ pos = indicator.height,
+ subscribed = function(pos)
+ indicator.forced_height = pos
+ end
+ }
+
+ if tag.selected then
+ indicator.bg = vars.colors.yellow
+ self._anim.target = vars.button_size * 2
+ elseif next(tag:clients()) then
+ indicator.bg = vars.colors.bright.black
+ self._anim.target = vars.button_size * 1.5
+ else
+ self._anim.target = vars.button_size
+ end
+
+ self:connect_signal("mouse::enter", function()
+ if tag.selected then return end
+
+ indicator.bg = vars.colors.yellow
+ end)
+
+ self:connect_signal("mouse::leave", function()
+ if tag.selected then return end
+
+ if next(tag:clients()) then
+ indicator.bg = vars.colors.bright.black
+ return
+ end
+
+ indicator.bg = vars.colors.bright.black
+ end)
+ end,
+ update_callback = function(self, tag)
+ local indicator = self:get_children_by_id("indicator_role")[1]
+
+ if tag.selected then
+ indicator.bg = vars.colors.yellow
+ self._anim.target = vars.button_size * 2
+ elseif next(tag:clients()) then
+ indicator.bg = vars.colors.bright.black
+ self._anim.target = vars.button_size * 1.5
+ else
+ indicator.bg = vars.colors.bright.black
+ self._anim.target = vars.button_size
+ end
+ end
+ },
+ buttons = {
+ awful.button({ }, 1, function(t) t:view_only() end),
+ awful.button(vars.mods.M, 1, function(t)
+ if client.focus then
+ client.focus:move_to_tag(t)
+ end
+ end),
+ awful.button({ }, 3, awful.tag.viewtoggle),
+ }
+})
diff --git a/.config/awesome/ui/statusbar/widgets/wifi.lua b/.config/awesome/ui/statusbar/widgets/wifi.lua
new file mode 100644
index 0000000..d0b7116
--- /dev/null
+++ b/.config/awesome/ui/statusbar/widgets/wifi.lua
@@ -0,0 +1,48 @@
+local awful = require "awful"
+local vars = require "misc.vars"
+local wibox = require "wibox"
+local h = require "misc.helpers"
+
+local wifi_inner = awful.widget.watch("awk 'NR==3 {printf(\"%.0f\", $3*10/7)}' /proc/net/wireless", 1, function(widget, stdout)
+ widget.font = "DejaVu Sans Mono wifi ramp Normal 8"
+ local icon = ""
+ local color = vars.colors.red
+
+ if stdout == "" then
+ widget:set_markup("<span color=\"" .. color .. "\">" .. icon .. "</span>")
+ return
+ end
+
+ local percent = tonumber(stdout)
+
+ if percent <= 20 then
+ icon = ""
+ color = vars.colors.red
+ elseif percent <= 40 then
+ icon = ""
+ color = vars.colors.yellow
+ elseif percent <= 60 then
+ icon = ""
+ color = vars.colors.yellow
+ elseif percent <= 80 then
+ icon = ""
+ color = vars.colors.green
+ elseif percent <= 100 then
+ icon = ""
+ color = vars.colors.green
+ end
+
+
+ widget:set_markup("<span color=\"" .. color .. "\">" .. icon .. "</span>")
+end)
+
+local wifi = wibox.widget {
+ widget = wibox.container.place,
+ wifi_inner
+}
+
+h.tooltip({ wifi }, function()
+ return io.popen("iwgetid -r"):read("*a"):sub(0, -2)
+end)
+
+return wifi