Change widget from checkbox to textbox
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.
This commit is contained in:
parent
dee1751b53
commit
7a52f31e4e
27
README.md
27
README.md
|
@ -42,8 +42,31 @@ local globalkeys = awful.util.table.join(
|
||||||
-- more config follows
|
-- more config follows
|
||||||
```
|
```
|
||||||
|
|
||||||
Now, when you activate CAPS LOCK, a chevron sign will be
|
Now, when CAPS LOCK is active, an uppercase letter **A** will be displayed
|
||||||
displayed: ![capslock screenshot](/screenshots/capslock_widget.png?raw=true)
|
|
||||||
|
![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
|
# Contributing
|
||||||
|
|
||||||
|
|
41
capslock.lua
41
capslock.lua
|
@ -39,34 +39,35 @@
|
||||||
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local math = math
|
|
||||||
local awful = require("awful")
|
local awful = require("awful")
|
||||||
local gears = require("gears")
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local checkbox = wibox.widget {
|
local capslock = wibox.widget {
|
||||||
checked = false,
|
widget = wibox.widget.textbox,
|
||||||
border_width = 0,
|
align = "center",
|
||||||
paddings = 2,
|
valign = "center",
|
||||||
check_shape = function (cr, w, h)
|
forced_width = 15,
|
||||||
gears.shape.transform(gears.shape.powerline)
|
|
||||||
:rotate(-math.pi/2)
|
|
||||||
:translate(-h, 0)(cr, w, h)
|
|
||||||
end,
|
|
||||||
widget = wibox.widget.checkbox
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
awful.spawn.with_line_callback(
|
||||||
"bash -c 'sleep 0.2 && xset q'",
|
"bash -c 'sleep 0.2 && xset q'",
|
||||||
{
|
{
|
||||||
stdout = function (line)
|
stdout = function (line)
|
||||||
if line:match("Caps Lock") then
|
if line:match("Caps Lock") then
|
||||||
local status = line:gsub(".*(Caps Lock:%s+)(%a+).*", "%2")
|
local status = line:gsub(".*(Caps Lock:%s+)(%a+).*", "%2")
|
||||||
|
tooltip.text = "Caps Lock " .. status
|
||||||
if status == "on" then
|
if status == "on" then
|
||||||
checkbox.checked = true
|
self.markup = self.activated
|
||||||
else
|
else
|
||||||
checkbox.checked = false
|
self.markup = self.deactivated
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -74,9 +75,11 @@ local function check_caps_lock()
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local capslock = awful.key({}, "Caps_Lock", check_caps_lock)
|
capslock.key = awful.key(
|
||||||
checkbox.key = capslock
|
{},
|
||||||
|
"Caps_Lock",
|
||||||
|
function () capslock:check() end)
|
||||||
|
|
||||||
check_caps_lock()
|
capslock:check()
|
||||||
|
|
||||||
return checkbox
|
return capslock
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 589 B |
Binary file not shown.
Before Width: | Height: | Size: 962 B |
Binary file not shown.
After Width: | Height: | Size: 550 B |
Loading…
Reference in New Issue