Skip to content

Commit

Permalink
Change widget from checkbox to textbox
Browse files Browse the repository at this point in the history
Now we show an uppercase "A" when capslock is active and a lowercase "a" when
it's inactive. this can be customized too.

Also added a tooltip.
  • Loading branch information
stefano-m committed Jul 27, 2017
1 parent dee1751 commit 7a52f31
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 21 deletions.
27 changes: 25 additions & 2 deletions README.md
Expand Up @@ -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 = "<u>CAPS</u>"
capslock.deactivated = "<u>caps</u>"
```

When the mouse is over the widget, a tooltip that says `Caps Lock on`/`Caps
Lock off` is also shown.

# Contributing

Expand Down
41 changes: 22 additions & 19 deletions capslock.lua
Expand Up @@ -39,44 +39,47 @@
]]

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 = "<b>A</b>"
capslock.deactivated = "<b>a</b>"

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
}
)
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
Binary file added screenshots/active_capslock_widget.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed screenshots/capslock_widget.png
Binary file not shown.
Binary file added screenshots/inactive_capslock_widget.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7a52f31

Please sign in to comment.