summaryrefslogtreecommitdiff
path: root/awesome/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'awesome/widgets')
-rw-r--r--awesome/widgets/audio.lua22
-rw-r--r--awesome/widgets/classiclayoutbox.lua113
-rw-r--r--awesome/widgets/classiclayouts.lua27
-rw-r--r--awesome/widgets/cpu.lua41
-rw-r--r--awesome/widgets/ram.lua36
-rw-r--r--awesome/widgets/temperature.lua25
6 files changed, 264 insertions, 0 deletions
diff --git a/awesome/widgets/audio.lua b/awesome/widgets/audio.lua
new file mode 100644
index 0000000..fa5c747
--- /dev/null
+++ b/awesome/widgets/audio.lua
@@ -0,0 +1,22 @@
+local awful = require("awful")
+local wibox = require("wibox")
+local gears = require("gears")
+
+local audio_dropdown = awful.popup {
+ widget = {
+ margins = 10,
+ widget = wibox.container.margin,
+ {
+ layout = wibox.layout.fixed.horizontal,
+ wibox.widget.textbox "AUDIO",
+ },
+ },
+ ontop = true,
+ placement = awful.placement.centered,
+ --shape = gears.shape.infobubble,
+ border_width = 1,
+ border_color = "#ff0000",
+ visible = true,
+}
+
+return audio_dropdown
diff --git a/awesome/widgets/classiclayoutbox.lua b/awesome/widgets/classiclayoutbox.lua
new file mode 100644
index 0000000..ac08671
--- /dev/null
+++ b/awesome/widgets/classiclayoutbox.lua
@@ -0,0 +1,113 @@
+---------------------------------------------------------------------------
+--- Layoutbox widget.
+--
+-- @author Julien Danjou <julien@danjou.info>
+-- @copyright 2009 Julien Danjou
+-- @classmod awful.widget.layoutbox
+---------------------------------------------------------------------------
+
+local setmetatable = setmetatable
+local capi = { screen = screen, tag = tag }
+local layout = require("awful.layout")
+local tooltip = require("awful.tooltip")
+local wibox = require("wibox")
+local surface = require("gears.surface")
+
+local layout_icons = {
+ cornernw = "",
+ cornerne = "",
+ cornersw = "",
+ cornerse = "",
+ fairh = "",
+ fairv = "",
+ max = "[M]",
+ floating = "><>",
+ magnifier = "[M]",
+ fullscreen = "",
+ spiral = "",
+ dwindle = "",
+ tile = "[]=",
+ tiletop = "TTT",
+ tilebottom = "TTT",
+ tileleft = "=[]",
+}
+
+local function get_screen(s)
+return s and capi.screen[s]
+end
+
+local layoutbox = { mt = {} }
+
+local boxes = nil
+
+local function update(w, screen)
+screen = get_screen(screen)
+local name = layout.getname(layout.get(screen))
+w._layoutbox_tooltip:set_text(name or "[no name]")
+
+ if name == "max" and #screen.clients > 0 then
+ w.textbox.text = "[" .. #screen.clients .. "]"
+ return
+ end
+
+ w.textbox.text = layout_icons[name]
+end
+
+local function update_from_tag(t)
+local screen = get_screen(t.screen)
+local w = boxes[screen]
+if w then
+ update(w, screen)
+end
+end
+
+--- Create a layoutbox widget. It draws a picture with the current layout
+-- symbol of the current tag.
+-- @param screen The screen number that the layout will be represented for.
+-- @return An imagebox widget configured as a layoutbox.
+function layoutbox.new(screen)
+screen = get_screen(screen or 1)
+
+-- Do we already have the update callbacks registered?
+if boxes == nil then
+ boxes = setmetatable({}, { __mode = "kv" })
+ capi.tag.connect_signal("property::selected", update_from_tag)
+ capi.tag.connect_signal("property::layout", update_from_tag)
+ capi.tag.connect_signal("property::screen", function()
+ for s, w in pairs(boxes) do
+ if s.valid then
+ update(w, s)
+ end
+ end
+ end)
+ layoutbox.boxes = boxes
+end
+
+-- Do we already have a layoutbox for this screen?
+local w = boxes[screen]
+if not w then
+ w = wibox.widget {
+ {
+ id = "textbox",
+ widget = wibox.widget.textbox
+ },
+ layout = wibox.layout.fixed.horizontal
+ }
+
+ w._layoutbox_tooltip = tooltip {objects = {w}, delay_show = 1}
+
+ update(w, screen)
+ boxes[screen] = w
+end
+
+return w
+end
+
+function layoutbox.mt:__call(...)
+return layoutbox.new(...)
+end
+
+return setmetatable(layoutbox, layoutbox.mt)
+
+-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
+
diff --git a/awesome/widgets/classiclayouts.lua b/awesome/widgets/classiclayouts.lua
new file mode 100644
index 0000000..917ca00
--- /dev/null
+++ b/awesome/widgets/classiclayouts.lua
@@ -0,0 +1,27 @@
+local awful = require("awful")
+
+local layoutbox = {}
+
+local layout_icons = {
+ cornernw = "",
+ cornerne = "",
+ cornersw = "",
+ cornerse = "",
+ fairh = "",
+ fairv = "",
+ max = "[M]",
+ floating = "><>",
+ magnifier = "[M]",
+ fullscreen = "",
+ spiral = "",
+ dwindle = "",
+ tile = "[]=",
+ tiletop = "TTT",
+ tilebottom = "TTT",
+ tileleft = "=[]",
+}
+
+function(s)
+ s = screen[s or 1]
+
+end
diff --git a/awesome/widgets/cpu.lua b/awesome/widgets/cpu.lua
new file mode 100644
index 0000000..cbd5916
--- /dev/null
+++ b/awesome/widgets/cpu.lua
@@ -0,0 +1,41 @@
+local wibox = require("wibox")
+local widgets = require("util.widgets")
+local osname = require("util.osname")
+
+
+-- this is directly adapted from slstatus's cpu.c module
+local cpu_time = { 0,0,0,0,0,0,0 } -- user, nice, system, idle, iowait, irq, softirq
+
+function linux_cpu_usage(widget)
+ -- read stat
+ local statf = io.open("/proc/stat")
+ local stat_iter = statf:read():gmatch("%d+")
+ statf:close()
+
+ -- calc
+ local sum = 0
+ local a, b = cpu_time, {} -- set cpu_time as a for smaller code
+ table.move(a, 1, 7, 1, b) -- copy first 7 to b
+
+ for i = 1, 7 do
+ a[i] = stat_iter()
+ sum = sum + b[i] - a[i]
+ end
+
+ if sum == 0 then
+ return
+ end
+
+ local usage = ((b[1] + b[2] + b[3] + b[6] + b[7]) -
+ (a[1] + a[2] + a[3] + a[6] + a[7])) * 100 / sum
+
+ widget:set_text(math.floor(usage))
+end
+
+
+-- return correct widget for os
+if osname == "Linux" then
+ return widgets.watchfn(linux_cpu_usage, 5)
+end
+
+return wibox.widget.textbox("unsupported os")
diff --git a/awesome/widgets/ram.lua b/awesome/widgets/ram.lua
new file mode 100644
index 0000000..2347ca4
--- /dev/null
+++ b/awesome/widgets/ram.lua
@@ -0,0 +1,36 @@
+local wibox = require("wibox")
+local widgets = require("util.widgets")
+local osname = require("util.osname")
+
+
+function linux_ram_usage(widget)
+ -- read meminfo
+ local meminfof = io.open("/proc/meminfo")
+
+ local total = meminfof:read():match("%d+")
+ local free = meminfof:read():match("%d+")
+
+ meminfof:read() -- memavailable not used
+
+ local buffers = meminfof:read():match("%d+")
+ local cached = meminfof:read():match("%d+")
+
+ meminfof:close()
+
+ -- calc
+ if total == nil then
+ return
+ end
+
+ local used = (total - free - buffers - cached) * 100 / total
+
+ widget:set_text(math.floor(used))
+end
+
+
+-- return correct widget for os
+if osname == "Linux" then
+ return widgets.watchfn(linux_ram_usage, 5)
+end
+
+return wibox.widget.textbox("unsupported os")
diff --git a/awesome/widgets/temperature.lua b/awesome/widgets/temperature.lua
new file mode 100644
index 0000000..8cf1aa9
--- /dev/null
+++ b/awesome/widgets/temperature.lua
@@ -0,0 +1,25 @@
+local wibox = require("wibox")
+local widgets = require("util.widgets")
+local osname = require("util.osname")
+
+
+local linux = { file = nil }
+function linux.temperature(widget)
+ -- read meminfo
+ local tempf = io.open(linux.file)
+ local temp = tempf:read() / 1000
+ tempf:close()
+
+ widget:set_text(math.floor(temp))
+end
+
+
+-- return correct widget for os
+if osname == "Linux" then
+ return function(file)
+ linux.file = file
+ return widgets.watchfn(linux.temperature, 5)
+ end
+end
+
+return wibox.widget.textbox("unsupported os")