From 5fc63c644cd90b2888fb930b4845b329690c3fc0 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sun, 11 Sep 2022 16:10:30 +1000 Subject: [PATCH] import working --- drive-harddisk-solidstate.svg | 171 ++++++++++++++ drive-harddisk.svg | 431 ++++++++++++++++++++++++++++++++++ init.lua | 126 ++++++++++ media-memory-mmc.svg | 144 ++++++++++++ 4 files changed, 872 insertions(+) create mode 100644 drive-harddisk-solidstate.svg create mode 100644 drive-harddisk.svg create mode 100644 init.lua create mode 100644 media-memory-mmc.svg diff --git a/drive-harddisk-solidstate.svg b/drive-harddisk-solidstate.svg new file mode 100644 index 0000000..69c42e7 --- /dev/null +++ b/drive-harddisk-solidstate.svg @@ -0,0 +1,171 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/drive-harddisk.svg b/drive-harddisk.svg new file mode 100644 index 0000000..e446150 --- /dev/null +++ b/drive-harddisk.svg @@ -0,0 +1,431 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..ad9a6b3 --- /dev/null +++ b/init.lua @@ -0,0 +1,126 @@ +local longpress = require "awesome-longpress" +local beautiful = require "beautiful" +local posix = require "posix" +local wibox = require "wibox" +local gears = require "gears" +local fswidget = { + mounts = {}, + ignoreMounts = {["/boot"]=true}, + ignoreDevs = {}, + iconSize = 96, + iconPath = "/home/izaya/.config/awesome/awesome-fswidget" +} +local fstypes = {} +local f = io.open("/proc/filesystems") +for line in f:lines() do + if not line:match("nodev") then + fstypes[line:match("%S+")] = true + end +end + +local function getMountedFilesystems() + local f = io.open("/proc/mounts") + for line in f:lines() do + local dev,mp,fst,opt = line:match("(%S+)%s+(%S+)%s+(%S+)%s+(.+)") + if fstypes[fst] and not fswidget.ignoreMounts[mp] and not fswidget.ignoreDevs[dev] then + fswidget.mounts[dev] = fswidget.mounts[dev] or {} + fswidget.mounts[dev][#fswidget.mounts[dev]+1] = mp + fswidget.mounts[dev].device = dev + if opt:match("ssd") then + fswidget.mounts[dev].ssd = true + end + end + end +end + +local function chooseIcon(mount) + local icon = "drive-harddisk" + if mount.ssd then + icon = "drive-harddisk-solidstate" + end + if mount.device:match("mmcblk") then + icon = "media-memory-mmc" + end + return icon +end + +local sizeTable = {[0] = "B", "K","M","G","T","P"} +local function formatSize(n) + local i = 0 + while n > 1024 do + n = n / 1024 + i = i + 1 + end + return string.format("%0.1f%s",n,sizeTable[i]) +end + +local function updateWidget(self) + local stat = posix.statvfs(self.mountpoint) + if stat then + local free, used, fraction = stat.bfree * stat.bsize, (stat.blocks - stat.bfree) * stat.bsize, (stat.blocks - stat.bfree) / stat.blocks + self.fsbar.value = fraction + self.fspercent.text = string.format("%.1f%%",fraction*100) + self.fsused.text = formatSize(used) + self.fsfree.text = formatSize(free) + end +end + +function fswidget.new(mount) + local fs = mount[1] + local fsbar = wibox.widget{ + widget = wibox.widget.progressbar, + max_value = 1, + forced_height = fswidget.iconSize / 6, + border_color = beautiful.fg_focus, + color = beautiful.bg_focus, + background_color = beautiful.bg_normal, + } + local fspercent = wibox.widget{ + widget = wibox.widget.textbox, + } + local fsused = wibox.widget{ + widget = wibox.widget.textbox, + visible = false + } + local fsfree = wibox.widget{ + widget = wibox.widget.textbox, + visible = false + } + local w = wibox.widget{ + layout = wibox.layout.stack, + wibox.widget{ + widget = wibox.widget.imagebox, + forced_width = fswidget.iconSize, + forced_height = fswidget.iconSize, + image = string.format("%s/%s.svg", fswidget.iconPath, chooseIcon(mount)) + }, + wibox.container.place(wibox.widget{ + widget = wibox.widget.textbox, + text = fs + },"center","top"), + wibox.container.place(fsbar,"center","bottom"), + wibox.container.place(fspercent,"center","bottom"), + wibox.container.place(fsused,"left","bottom"), + wibox.container.place(fsfree,"right","bottom") + } + local c = wibox.container.constraint(w,nil,fswidget.iconSize,fswidget.iconSize) + c.update, c.mountpoint, c.fsbar, c.fspercent, c.fsused, c.fsfree = updateWidget, fs, fsbar, fspercent, fsused, fsfree + longpress.add(c, function() + fspercent.visible = not fspercent.visible + fsused.visible = not fsused.visible + fsfree.visible = not fsfree.visible + end) + c:update() + return c +end + +function fswidget.all() + local r = {} + getMountedFilesystems() + for k,v in pairs(fswidget.mounts) do + r[#r+1] = fswidget.new(v) + end + return r +end + +return fswidget diff --git a/media-memory-mmc.svg b/media-memory-mmc.svg new file mode 100644 index 0000000..d577f8a --- /dev/null +++ b/media-memory-mmc.svg @@ -0,0 +1,144 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +