diff --git a/README.md b/README.md
index b2c4690..7b9fd0a 100644
--- a/README.md
+++ b/README.md
@@ -42,8 +42,31 @@ local globalkeys = awful.util.table.join(
-- more config follows
```
-Now, when you activate CAPS LOCK, a chevron sign will be
-displayed: ![capslock screenshot](/screenshots/capslock_widget.png?raw=true)
+Now, when CAPS LOCK is active, an uppercase letter **A** will be displayed
+
+![active_capslock screenshot](/screenshots/active_capslock_widget.png?raw=true)
+
+when CAPS LOCK is inactive, a lowecase letter **a** will be displayed:
+
+![inactive_capslock screenshot](/screenshots/inactive_capslock_widget.png?raw=true)
+
+These can be changed by changing the `activated` and `deactivated`
+attributes of the widget
+as
+[Pango markup](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html)
+strings. You will probably need to adjust the `forced_width` attribute too.
+
+For example:
+
+``` lua
+local capslock = require("capslock")
+capslock.forced_width = 35
+capslock.activated = "CAPS"
+capslock.deactivated = "caps"
+```
+
+When the mouse is over the widget, a tooltip that says `Caps Lock on`/`Caps
+Lock off` is also shown.
# Contributing
diff --git a/capslock.lua b/capslock.lua
index 296ae63..3a72a51 100644
--- a/capslock.lua
+++ b/capslock.lua
@@ -39,34 +39,35 @@
]]
-local math = math
local awful = require("awful")
-local gears = require("gears")
local wibox = require("wibox")
-local checkbox = wibox.widget {
- checked = false,
- border_width = 0,
- paddings = 2,
- check_shape = function (cr, w, h)
- gears.shape.transform(gears.shape.powerline)
- :rotate(-math.pi/2)
- :translate(-h, 0)(cr, w, h)
- end,
- widget = wibox.widget.checkbox
+local capslock = wibox.widget {
+ widget = wibox.widget.textbox,
+ align = "center",
+ valign = "center",
+ forced_width = 15,
}
-local function check_caps_lock()
+capslock.activated = "A"
+capslock.deactivated = "a"
+
+local tooltip = awful.tooltip({})
+
+tooltip:add_to_object(capslock)
+
+function capslock:check()
awful.spawn.with_line_callback(
"bash -c 'sleep 0.2 && xset q'",
{
stdout = function (line)
if line:match("Caps Lock") then
local status = line:gsub(".*(Caps Lock:%s+)(%a+).*", "%2")
+ tooltip.text = "Caps Lock " .. status
if status == "on" then
- checkbox.checked = true
+ self.markup = self.activated
else
- checkbox.checked = false
+ self.markup = self.deactivated
end
end
end
@@ -74,9 +75,11 @@ local function check_caps_lock()
)
end
-local capslock = awful.key({}, "Caps_Lock", check_caps_lock)
-checkbox.key = capslock
+capslock.key = awful.key(
+ {},
+ "Caps_Lock",
+ function () capslock:check() end)
-check_caps_lock()
+capslock:check()
-return checkbox
+return capslock
diff --git a/screenshots/active_capslock_widget.png b/screenshots/active_capslock_widget.png
new file mode 100644
index 0000000..aeff397
Binary files /dev/null and b/screenshots/active_capslock_widget.png differ
diff --git a/screenshots/capslock_widget.png b/screenshots/capslock_widget.png
deleted file mode 100644
index c272f36..0000000
Binary files a/screenshots/capslock_widget.png and /dev/null differ
diff --git a/screenshots/inactive_capslock_widget.png b/screenshots/inactive_capslock_widget.png
new file mode 100644
index 0000000..bd3d202
Binary files /dev/null and b/screenshots/inactive_capslock_widget.png differ